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();\
PluginType GetType() const
Returns the type of the plugin.
Definition: Plugin.hh:177
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:279
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:82
static SystemPaths * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
A Visual plugin.
Definition: Plugin.hh:62
virtual ~PluginT()
Destructor.
Definition: Plugin.hh:81
std::string GetFilename() const
Get the name of the handler.
Definition: Plugin.hh:92
ModelPlugin()
Constructor.
Definition: Plugin.hh:234
static TPtr Create(const std::string &_filename, const std::string &_handle)
a class method that creates a plugin from a file name.
Definition: Plugin.hh:108
virtual void Init()
Definition: Plugin.hh:224
A plugin with access to physics::World.
Definition: Plugin.hh:206
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:282
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:317
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:250
std::string handle
Short name.
Definition: Plugin.hh:189
#define gzerr
Output an error message.
Definition: Console.hh:47
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:334
default namespace for gazebo
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:289
A System plugin.
Definition: Plugin.hh:60
A World plugin.
Definition: Plugin.hh:54
VisualPlugin()
Definition: Plugin.hh:319
virtual ~WorldPlugin()
Destructor.
Definition: Plugin.hh:213
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:253
virtual ~SystemPlugin()
Destructor.
Definition: Plugin.hh:296
virtual ~ModelPlugin()
Destructor.
Definition: Plugin.hh:238
std::string filename
Path to the shared library file.
Definition: Plugin.hh:186
PluginT()
Constructor.
Definition: Plugin.hh:75
A Model plugin.
Definition: Plugin.hh:56
boost::shared_ptr< T > TPtr
plugin pointer type definition
Definition: Plugin.hh:72
A Sensor plugin.
Definition: Plugin.hh:58
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:78
#define NULL
Definition: CommonTypes.hh:30
A class which all plugins must inherit from.
Definition: Plugin.hh:69
virtual ~SensorPlugin()
Destructor.
Definition: Plugin.hh:267
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:100
Forward declarations and typedefs for sensors.
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:337
PluginType
Used to specify the type of plugin.
Definition: Plugin.hh:51
WorldPlugin()
Constructor.
Definition: Plugin.hh:209
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:308
PluginType type
Type of plugin.
Definition: Plugin.hh:183
boost::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:55
virtual void Reset()
Definition: Plugin.hh:225
A plugin with access to physics::Sensor.
Definition: Plugin.hh:260
SensorPlugin()
Constructor.
Definition: Plugin.hh:263
SystemPlugin()
Constructor.
Definition: Plugin.hh:292
std::string GetHandle() const
Get the short name of the handler.
Definition: Plugin.hh:98
A plugin with access to physics::Model.
Definition: Plugin.hh:231
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:311