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;
80 this->dlHandle =
NULL;
87 dlclose(this->dlHandle);
109 const std::string &_handle)
115 std::string fullname;
116 std::list<std::string>::iterator iter;
117 std::list<std::string> pluginPaths =
120 for (iter = pluginPaths.begin();
121 iter!= pluginPaths.end(); ++iter)
123 fullname = (*iter)+std::string(
"/")+_filename;
124 if (stat(fullname.c_str(), &st) == 0)
132 fullname = _filename;
135 fptr_union_t registerFunc;
136 std::string registerName =
"RegisterPlugin";
138 void *dlHandle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
141 gzerr <<
"Failed to load plugin " << fullname <<
": "
142 << dlerror() <<
"\n";
146 registerFunc.ptr = dlsym(dlHandle, registerName.c_str());
148 if (!registerFunc.ptr)
150 gzerr <<
"Failed to resolve " << registerName
151 <<
": " << dlerror();
156 result.reset(registerFunc.func());
157 result->dlHandle = dlHandle;
160 gzerr <<
"LTDL is deprecated as of Gazebo 1.10\n";
161 fptr_union_t registerFunc;
162 std::string registerName =
"RegisterPlugin";
164 static bool init_done =
false;
168 int errors = lt_dlinit();
171 gzerr <<
"Error(s) initializing dynamic loader ("
172 << errors <<
", " << lt_dlerror() <<
")";
179 lt_dlhandle
handle = lt_dlopenext(fullname.c_str());
183 gzerr <<
"Failed to load " << fullname
184 <<
": " << lt_dlerror();
188 T *(*registerFunc)() =
189 (T *(*)())lt_dlsym(handle, registerName.c_str());
190 resigsterFunc.ptr = lt_dlsym(handle, registerName.c_str());
191 if (!registerFunc.ptr)
193 gzerr <<
"Failed to resolve " << registerName <<
": "
199 result.result(registerFunc.func());
200 result->dlHandle =
NULL;
204 gzthrow(
"Cannot load plugins as libtool is not installed.");
208 result->handle = _handle;
209 result->filename = _filename;
231 private:
typedef union
238 private:
void *dlHandle;
261 sdf::ElementPtr _sdf) = 0;
286 sdf::ElementPtr _sdf) = 0;
315 sdf::ElementPtr _sdf) = 0;
342 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
368 sdf::ElementPtr _sdf) = 0;
385 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
386 extern "C" gazebo::ModelPlugin *RegisterPlugin(); \
387 gazebo::ModelPlugin *RegisterPlugin() \
389 return new classname();\
396 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
397 extern "C" gazebo::WorldPlugin *RegisterPlugin(); \
398 gazebo::WorldPlugin *RegisterPlugin() \
400 return new classname();\
407 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
408 extern "C" gazebo::SensorPlugin *RegisterPlugin(); \
409 gazebo::SensorPlugin *RegisterPlugin() \
411 return new classname();\
418 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
419 extern "C" gazebo::SystemPlugin *RegisterPlugin(); \
420 gazebo::SystemPlugin *RegisterPlugin() \
422 return new classname();\
429 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
430 extern "C" gazebo::VisualPlugin *RegisterPlugin(); \
431 gazebo::VisualPlugin *RegisterPlugin() \
433 return new classname();\