17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
21 #include <sys/types.h>
24 #include <gazebo/gazebo_config.h>
75 public:
typedef boost::shared_ptr<T>
TPtr;
95 const std::string &_handle)
101 std::string fullname;
102 std::list<std::string>::iterator iter;
103 std::list<std::string> pluginPaths =
106 for (iter = pluginPaths.begin();
107 iter!= pluginPaths.end(); ++iter)
109 fullname = (*iter)+std::string(
"/")+_filename;
110 if (stat(fullname.c_str(), &st) == 0)
118 fullname = _filename;
121 fptr_union_t registerFunc;
122 std::string registerName =
"RegisterPlugin";
124 void*
handle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
127 gzerr <<
"Failed to load plugin " << fullname <<
": "
128 << dlerror() <<
"\n";
132 registerFunc.ptr = dlsym(handle, registerName.c_str());
134 if (!registerFunc.ptr)
136 gzerr <<
"Failed to resolve " << registerName
137 <<
": " << dlerror();
142 result.reset(registerFunc.func());
145 fptr_union_t registerFunc;
146 std::string registerName =
"RegisterPlugin";
148 static bool init_done =
false;
152 int errors = lt_dlinit();
155 gzerr <<
"Error(s) initializing dynamic loader ("
156 << errors <<
", " << lt_dlerror() <<
")";
163 lt_dlhandle handle = lt_dlopenext(fullname.c_str());
167 gzerr <<
"Failed to load " << fullname
168 <<
": " << lt_dlerror();
172 T *(*registerFunc)() =
173 (T *(*)())lt_dlsym(handle, registerName.c_str());
174 resigsterFunc.ptr = lt_dlsym(handle, registerName.c_str());
175 if (!registerFunc.ptr)
177 gzerr <<
"Failed to resolve " << registerName <<
": "
183 result.result(registerFunc.func());
187 gzthrow(
"Cannot load plugins as libtool is not installed.");
191 result->handle = _handle;
192 result->filename = _filename;
214 private:
typedef union
322 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
365 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
366 extern "C" gazebo::ModelPlugin *RegisterPlugin(); \
367 gazebo::ModelPlugin *RegisterPlugin() \
369 return new classname();\
376 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
377 extern "C" gazebo::WorldPlugin *RegisterPlugin(); \
378 gazebo::WorldPlugin *RegisterPlugin() \
380 return new classname();\
387 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
388 extern "C" gazebo::SensorPlugin *RegisterPlugin(); \
389 gazebo::SensorPlugin *RegisterPlugin() \
391 return new classname();\
398 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
399 extern "C" gazebo::SystemPlugin *RegisterPlugin(); \
400 gazebo::SystemPlugin *RegisterPlugin() \
402 return new classname();\
409 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
410 extern "C" gazebo::VisualPlugin *RegisterPlugin(); \
411 gazebo::VisualPlugin *RegisterPlugin() \
413 return new classname();\