17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
21 #include <sys/types.h>
24 #include <gazebo_config.h>
74 public:
typedef boost::shared_ptr<T>
TPtr;
94 const std::string &_handle)
100 std::string fullname;
101 std::list<std::string>::iterator iter;
102 std::list<std::string> pluginPaths =
105 for (iter = pluginPaths.begin();
106 iter!= pluginPaths.end(); ++iter)
108 fullname = (*iter)+std::string(
"/")+_filename;
109 if (stat(fullname.c_str(), &st) == 0)
117 fullname = _filename;
119 fptr_union_t registerFunc;
120 std::string registerName =
"RegisterPlugin";
123 void*
handle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
126 gzerr <<
"Failed to load plugin " << fullname <<
": "
127 << dlerror() <<
"\n";
131 registerFunc.ptr = dlsym(handle, registerName.c_str());
133 if (!registerFunc.ptr)
135 gzerr <<
"Failed to resolve " << registerName
136 <<
": " << dlerror();
141 result.reset(registerFunc.func());
145 static bool init_done =
false;
149 int errors = lt_dlinit();
152 gzerr <<
"Error(s) initializing dynamic loader ("
153 << errors <<
", " << lt_dlerror() <<
")";
160 lt_dlhandle handle = lt_dlopenext(fullname.c_str());
164 gzerr <<
"Failed to load " << fullname
165 <<
": " << lt_dlerror();
169 T *(*registerFunc)() =
170 (T *(*)())lt_dlsym(handle, registerName.c_str());
171 resigsterFunc.ptr = lt_dlsym(handle, registerName.c_str());
172 if (!registerFunc.ptr)
174 gzerr <<
"Failed to resolve " << registerName <<
": "
180 result.result(registerFunc.func());
184 gzthrow(
"Cannot load plugins as libtool is not installed.");
211 private:
typedef union
319 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
362 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
363 extern "C" gazebo::ModelPlugin *RegisterPlugin(); \
364 gazebo::ModelPlugin *RegisterPlugin() \
366 return new classname();\
373 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
374 extern "C" gazebo::WorldPlugin *RegisterPlugin(); \
375 gazebo::WorldPlugin *RegisterPlugin() \
377 return new classname();\
384 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
385 extern "C" gazebo::SensorPlugin *RegisterPlugin(); \
386 gazebo::SensorPlugin *RegisterPlugin() \
388 return new classname();\
395 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
396 extern "C" gazebo::SystemPlugin *RegisterPlugin(); \
397 gazebo::SystemPlugin *RegisterPlugin() \
399 return new classname();\
406 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
407 extern "C" gazebo::VisualPlugin *RegisterPlugin(); \
408 gazebo::VisualPlugin *RegisterPlugin() \
410 return new classname();\