17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
21 #include <sys/types.h>
24 #include <gazebo/gazebo_config.h>
72 public:
typedef boost::shared_ptr<T>
TPtr;
77 this->dlHandle =
NULL;
94 return this->filename;
109 const std::string &_handle)
115 std::string fullname, filename(_filename);
116 std::list<std::string>::iterator iter;
117 std::list<std::string> pluginPaths =
124 size_t soSuffix = filename.rfind(
".so");
125 const std::string macSuffix(
".dylib");
126 if (soSuffix != std::string::npos)
127 filename.replace(soSuffix, macSuffix.length(), macSuffix);
129 #endif // ifdef __APPLE__
131 for (iter = pluginPaths.begin();
132 iter!= pluginPaths.end(); ++iter)
134 fullname = (*iter)+std::string(
"/")+filename;
135 if (stat(fullname.c_str(), &st) == 0)
145 fptr_union_t registerFunc;
146 std::string registerName =
"RegisterPlugin";
148 void *dlHandle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
151 gzerr <<
"Failed to load plugin " << fullname <<
": "
152 << dlerror() <<
"\n";
156 registerFunc.ptr = dlsym(dlHandle, registerName.c_str());
158 if (!registerFunc.ptr)
160 gzerr <<
"Failed to resolve " << registerName
161 <<
": " << dlerror();
166 result.reset(registerFunc.func());
167 result->dlHandle = dlHandle;
169 result->handle = _handle;
170 result->filename = filename;
192 private:
typedef union
199 private:
void *dlHandle;
222 sdf::ElementPtr _sdf) = 0;
247 sdf::ElementPtr _sdf) = 0;
276 sdf::ElementPtr _sdf) = 0;
303 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
329 sdf::ElementPtr _sdf) = 0;
346 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
347 extern "C" GAZEBO_VISIBLE gazebo::ModelPlugin *RegisterPlugin(); \
349 gazebo::ModelPlugin *RegisterPlugin() \
351 return new classname();\
358 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
359 extern "C" GAZEBO_VISIBLE gazebo::WorldPlugin *RegisterPlugin(); \
361 gazebo::WorldPlugin *RegisterPlugin() \
363 return new classname();\
370 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
371 extern "C" GAZEBO_VISIBLE gazebo::SensorPlugin *RegisterPlugin(); \
373 gazebo::SensorPlugin *RegisterPlugin() \
375 return new classname();\
382 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
383 extern "C" GAZEBO_VISIBLE gazebo::SystemPlugin *RegisterPlugin(); \
385 gazebo::SystemPlugin *RegisterPlugin() \
387 return new classname();\
394 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
395 extern "C" GAZEBO_VISIBLE gazebo::VisualPlugin *RegisterPlugin(); \
397 gazebo::VisualPlugin *RegisterPlugin() \
399 return new classname();\