17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
21 #include <sys/types.h>
24 #include <gazebo_config.h>
72 public:
typedef boost::shared_ptr<T>
TPtr;
91 const std::string &_handle)
98 std::list<std::string>::iterator iter;
99 std::list<std::string> pluginPaths =
102 for (iter = pluginPaths.begin();
103 iter!= pluginPaths.end(); ++iter)
105 fullname = (*iter)+std::string(
"/")+_filename;
106 if (stat(fullname.c_str(), &st) == 0)
114 fullname = _filename;
116 fptr_union_t registerFunc;
117 std::string registerName =
"RegisterPlugin";
120 void*
handle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
123 gzerr <<
"Failed to load plugin " << fullname <<
": "
124 << dlerror() <<
"\n";
128 registerFunc.ptr = dlsym(handle, registerName.c_str());
130 if (!registerFunc.ptr)
132 gzerr <<
"Failed to resolve " << registerName
133 <<
": " << dlerror();
138 result.reset(registerFunc.func());
142 static bool init_done =
false;
146 int errors = lt_dlinit();
149 gzerr <<
"Error(s) initializing dynamic loader ("
150 << errors <<
", " << lt_dlerror() <<
")";
157 lt_dlhandle handle = lt_dlopenext(fullname.c_str());
161 gzerr <<
"Failed to load " << fullname
162 <<
": " << lt_dlerror();
166 T *(*registerFunc)() =
167 (T *(*)())lt_dlsym(handle, registerName.c_str());
168 resigsterFunc.ptr = lt_dlsym(handle, registerName.c_str());
169 if (!registerFunc.ptr)
171 gzerr <<
"Failed to resolve " << registerName <<
": "
177 result.result(registerFunc.func());
181 gzthrow(
"Cannot load plugins as libtool is not installed.");
207 private:
typedef union
313 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
356 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
357 extern "C" gazebo::ModelPlugin *RegisterPlugin(); \
358 gazebo::ModelPlugin *RegisterPlugin() \
360 return new classname();\
367 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
368 extern "C" gazebo::WorldPlugin *RegisterPlugin(); \
369 gazebo::WorldPlugin *RegisterPlugin() \
371 return new classname();\
378 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
379 extern "C" gazebo::SensorPlugin *RegisterPlugin(); \
380 gazebo::SensorPlugin *RegisterPlugin() \
382 return new classname();\
389 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
390 extern "C" gazebo::SystemPlugin *RegisterPlugin(); \
391 gazebo::SystemPlugin *RegisterPlugin() \
393 return new classname();\
400 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
401 extern "C" gazebo::VisualPlugin *RegisterPlugin(); \
402 gazebo::VisualPlugin *RegisterPlugin() \
404 return new classname();\