1 #ifndef __IRODS_LOAD_PLUGIN_HPP__
2 #define __IRODS_LOAD_PLUGIN_HPP__
23 #include <boost/static_assert.hpp>
24 #include <boost/filesystem.hpp>
34 const std::string& _type,
35 std::string& _path ) {
36 namespace fs = boost::filesystem;
42 if ( strlen(
env.irodsPluginHome ) > 0 ) {
43 plugin_home =
env.irodsPluginHome;
48 if (plugin_home.empty()) {
57 plugin_home.append(_type);
61 std::string msg(
"does not exist [" );
62 msg += plugin_home.string();
70 fs::path
p = fs::canonical( plugin_home );
72 _path = plugin_home.string();
74 if ( fs::path::preferred_separator != *_path.rbegin() ) {
75 _path += fs::path::preferred_separator;
80 "resolved plugin home [%s]",
86 catch (
const fs::filesystem_error& _e ) {
87 std::string msg(
"does not exist [" );
88 msg += plugin_home.string();
125 template<
typename PluginType,
typename ...Ts >
127 const std::string& _plugin_name,
128 const std::string& _interface,
129 const std::string& _instance_name,
130 const Ts&... _args ) {
131 namespace fs = boost::filesystem;
134 std::string plugin_home;
143 ret = name_gen( _plugin_name, plugin_home, so_name );
145 std::stringstream msg;
147 msg <<
" - Failed to generate an appropriate shared library name for plugin: \"";
148 msg << _plugin_name <<
"\".";
149 return PASSMSG( msg.str(), ret );
154 std::string msg(
"shared library does not exist [" );
160 catch (
const fs::filesystem_error& _e ) {
161 std::string msg(
"boost filesystem exception when checking existence of [" );
163 msg +=
"] with message [";
171 void* handle = dlopen( so_name.c_str(), RTLD_LAZY | RTLD_LOCAL );
173 std::stringstream msg;
174 msg <<
"failed to open shared object file [" << so_name
175 <<
"] :: dlerror: is [" << dlerror() <<
"]";
185 typedef PluginType* ( *factory_type )(
const std::string& ,
const Ts&... );
186 factory_type factory =
reinterpret_cast< factory_type
>( dlsym( handle,
"plugin_factory" ) );
187 char* err = dlerror();
188 if ( 0 != err || !factory ) {
189 std::stringstream msg;
190 msg <<
"failed to load symbol from shared object handle - plugin_factory"
191 <<
" :: dlerror is [" << err <<
"]";
196 rodsLog(
LOG_DEBUG,
"load_plugin - calling plugin_factory() in [%s]", so_name.c_str());
200 _plugin = factory( _instance_name, _args... );
202 std::stringstream msg;
203 msg <<
"failed to create plugin object for [" << _plugin_name <<
"]";
213 "load_plugin - loaded [%s]",
214 _plugin_name.c_str() );
224 #endif // __IRODS_LOAD_PLUGIN_HPP__