17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
21 #include <sys/types.h>
24 #include <gazebo/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;
120 fptr_union_t registerFunc;
121 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());
144 fptr_union_t registerFunc;
145 std::string registerName =
"RegisterPlugin";
147 static bool init_done =
false;
151 int errors = lt_dlinit();
154 gzerr <<
"Error(s) initializing dynamic loader ("
155 << errors <<
", " << lt_dlerror() <<
")";
162 lt_dlhandle handle = lt_dlopenext(fullname.c_str());
166 gzerr <<
"Failed to load " << fullname
167 <<
": " << lt_dlerror();
171 T *(*registerFunc)() =
172 (T *(*)())lt_dlsym(handle, registerName.c_str());
173 resigsterFunc.ptr = lt_dlsym(handle, registerName.c_str());
174 if (!registerFunc.ptr)
176 gzerr <<
"Failed to resolve " << registerName <<
": "
182 result.result(registerFunc.func());
186 gzthrow(
"Cannot load plugins as libtool is not installed.");
213 private:
typedef union
321 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
364 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
365 extern "C" gazebo::ModelPlugin *RegisterPlugin(); \
366 gazebo::ModelPlugin *RegisterPlugin() \
368 return new classname();\
375 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
376 extern "C" gazebo::WorldPlugin *RegisterPlugin(); \
377 gazebo::WorldPlugin *RegisterPlugin() \
379 return new classname();\
386 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
387 extern "C" gazebo::SensorPlugin *RegisterPlugin(); \
388 gazebo::SensorPlugin *RegisterPlugin() \
390 return new classname();\
397 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
398 extern "C" gazebo::SystemPlugin *RegisterPlugin(); \
399 gazebo::SystemPlugin *RegisterPlugin() \
401 return new classname();\
408 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
409 extern "C" gazebo::VisualPlugin *RegisterPlugin(); \
410 gazebo::VisualPlugin *RegisterPlugin() \
412 return new classname();\