00001
00002 #ifndef __EIRODS_PLUGIN_LOADER_H__
00003 #define __EIRODS_PLUGIN_LOADER_H__
00004
00005
00006
00007 #include <string>
00008 #include <iostream>
00009
00010
00011
00012 #include <dlfcn.h>
00013 #include "eirods_plugin.h"
00014
00015 namespace eirods {
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 eirods_plugin* load_plugin( const std::string _plugin_name, const std::string _dir ) {
00042 using namespace std;
00043
00044 eirods_plugin* plugin = 0;
00045
00046
00047
00048 if( _plugin_name.empty() ) {
00049 cout << "load_plugin :: empty _plugin_name parameter" << endl;
00050 return 0;
00051 }
00052
00053
00054
00055 string so_name = _dir + string("/lib") + _plugin_name + string(".so");
00056 void* handle = dlopen( so_name.c_str(), RTLD_LAZY );
00057 if( !handle ) {
00058 cout << "load_plugin :: failed to open shared object file: " << so_name << endl;
00059 cout << " :: dlerror is " << dlerror() << endl;
00060 dlclose( handle );
00061 return 0;
00062 }
00063
00064
00065
00066 dlerror();
00067
00068
00069
00070 char* err = 0;
00071 int plugin_version = *static_cast< int* >( dlsym( handle, "EIRODS_PLUGIN_VERSION" ) );
00072 if( ( err = dlerror() ) != 0 ) {
00073 cout << "load_plugin :: failed to load sybol from shared object handle - "
00074 << "EIRODS_PLUGIN_VERSION" << endl;
00075 cout << " :: dlerror is " << err << endl;
00076 dlclose( handle );
00077 return 0;
00078 }
00079
00080
00081
00082 if( 1.0 == plugin_version ) {
00083
00084 } else {
00085
00086 }
00087
00088
00089
00090 typedef eirods_plugin* (*factory_type)( );
00091 factory_type factory = reinterpret_cast< factory_type >( dlsym( handle, "plugin_factory" ) );
00092 if( ( err = dlerror() ) != 0 ) {
00093 cout << "load_plugin :: failed to load sybol from shared object handle - plugin_factory" << endl;
00094 cout << " :: dlerror is " << err << endl;
00095 dlclose( handle );
00096 return 0;
00097 }
00098
00099 if( !factory ) {
00100 cout << "load_plugin :: failed to cast plugin factor" << endl;
00101 dlclose( handle );
00102 return 0;
00103 }
00104
00105
00106
00107 plugin = factory();
00108 if( plugin ) {
00109
00110
00111
00112 #ifdef DEBUG
00113 cout << "load_plugin :: loaded " << _plugin_name << endl;
00114 #endif
00115
00116
00117 if( !plugin->delay_load( handle ) ) {
00118 cout << "load_plugin :: failed on delayed load for [" << _plugin_name << "]" << endl;
00119 dlclose( handle );
00120 return 0;
00121 }
00122
00123 return plugin;
00124
00125 } else {
00126 cout << "load_plugin :: failed to create plugin object for " << _plugin_name << endl;
00127 dlclose( handle );
00128 return 0;
00129 }
00130
00131
00132
00133 cout << "load_plugin :: ERROR - this shouldnt happen. " << __FILE__ << ":" << __LINE__ << endl;
00134 dlclose( handle );
00135 return 0;
00136
00137 }
00138
00139
00140 };
00141
00142 #endif // __EIRODS_PLUGIN_LOADER_H__
00143
00144
00145