00001
00002
00003
00004 #include <iostream>
00005
00006
00007
00008 #include "eirods_fd_plugin.h"
00009
00010 namespace eirods {
00011
00012
00013
00014
00015 bool load_filedriver_plugin( fd_table& _table, const std::string _fd ) {
00016 using namespace std;
00017
00018 typedef fileDriver_t (*fac_ptr)();
00019
00020 if( _fd.empty() ) {
00021 cout << "load_filedriver_plugin :: empty filedriver name parameter" << endl;
00022 return false;
00023 }
00024
00025
00026
00027 if( _table.has_entry( _fd ) ) {
00028 cout << "load_filedriver_plugin :: filedriver already exists. " << _fd << endl;
00029
00030 return true;
00031 }
00032
00033
00034
00035 string so_name = EIRODS_FD_HOME + string("/lib") + _fd + string(".so");
00036 void* handle = dlopen( so_name.c_str(), RTLD_LAZY );
00037
00038 if( !handle ) {
00039 cout << "load_filedriver_plugin :: failed to load filedriver plugin: " << so_name << endl;
00040 cout << " :: dlerror is " << dlerror() << endl;
00041 return false;
00042 }
00043
00044
00045
00046 dlerror();
00047
00048
00049
00050 int plugin_version = *static_cast< int* >( dlsym( handle, "EIRODS_PLUGIN_VERSION" ) );
00051
00052 char* err = 0;
00053 if( ( err = dlerror() ) != 0 ) {
00054 cout << "load_filedriver_plugin :: failed to load sybol from shared object handle - "
00055 << "EIRODS_PLUGIN_VERSION" << endl;
00056 cout << " :: dlerror is " << err << endl;
00057 }
00058
00059
00060
00061
00062
00063
00064 fac_ptr fcn = reinterpret_cast< funcPtr >( dlsym( handle, "fd_factory" ) );
00065
00066 if( ( err = dlerror() ) != 0 ) {
00067 cout << "load_filedriver_plugin :: failed to load sybol from shared object handle - " << _fd << endl;
00068 cout << " :: dlerror is " << err << endl;
00069 }
00070
00071
00072
00073 fileDriver_t drv = fac_ptr();
00074
00075
00076
00077
00078
00079
00080
00081 cout << "load_filedriver_plugin :: loaded " << _fd << " with " << num_param << " parameters." << endl;
00082
00083
00084
00085 _table[ _fd ] = drv;
00086
00087
00088
00089 return true;
00090
00091 }
00092
00093 };