17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
33 #include <sys/types.h>
36 #include <gazebo/gazebo_config.h>
86 public:
typedef boost::shared_ptr<T>
TPtr;
91 this->dlHandle =
NULL;
123 const std::string &_name)
129 std::string fullname,
filename(_filename);
130 std::list<std::string>::iterator iter;
131 std::list<std::string> pluginPaths =
138 size_t soSuffix = filename.rfind(
".so");
139 const std::string macSuffix(
".dylib");
140 if (soSuffix != std::string::npos)
141 filename.replace(soSuffix, macSuffix.length(), macSuffix);
143 #endif // ifdef __APPLE__
145 for (iter = pluginPaths.begin();
146 iter!= pluginPaths.end(); ++iter)
148 fullname = (*iter)+std::string(
"/")+
filename;
149 if (stat(fullname.c_str(), &st) == 0)
159 fptr_union_t registerFunc;
160 std::string registerName =
"RegisterPlugin";
162 void *dlHandle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
165 gzerr <<
"Failed to load plugin " << fullname <<
": "
166 << dlerror() <<
"\n";
170 registerFunc.ptr = dlsym(dlHandle, registerName.c_str());
172 if (!registerFunc.ptr)
174 gzerr <<
"Failed to resolve " << registerName
175 <<
": " << dlerror();
180 result.reset(registerFunc.func());
181 result->dlHandle = dlHandle;
183 result->handleName = _name;
206 private:
typedef union
213 private:
void *dlHandle;
236 sdf::ElementPtr _sdf) = 0;
261 sdf::ElementPtr _sdf) = 0;
290 sdf::ElementPtr _sdf) = 0;
317 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
343 sdf::ElementPtr _sdf) = 0;
361 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
362 extern "C" GZ_COMMON_VISIBLE gazebo::ModelPlugin *RegisterPlugin(); \
363 gazebo::ModelPlugin *RegisterPlugin() \
365 return new classname();\
372 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
373 extern "C" GZ_COMMON_VISIBLE gazebo::WorldPlugin *RegisterPlugin(); \
374 gazebo::WorldPlugin *RegisterPlugin() \
376 return new classname();\
383 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
384 extern "C" GZ_COMMON_VISIBLE gazebo::SensorPlugin *RegisterPlugin(); \
385 gazebo::SensorPlugin *RegisterPlugin() \
387 return new classname();\
394 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
395 extern "C" GZ_COMMON_VISIBLE gazebo::SystemPlugin *RegisterPlugin(); \
397 gazebo::SystemPlugin *RegisterPlugin() \
399 return new classname();\
406 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
407 extern "C" GZ_COMMON_VISIBLE gazebo::VisualPlugin *RegisterPlugin(); \
408 gazebo::VisualPlugin *RegisterPlugin() \
410 return new classname();\
PluginType GetType() const
Returns the type of the plugin.
Definition: Plugin.hh:191
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:293
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:88
static SystemPaths * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
A Visual plugin.
Definition: Plugin.hh:74
virtual ~PluginT()
Destructor.
Definition: Plugin.hh:95
std::string GetFilename() const
Get the name of the handler.
Definition: Plugin.hh:106
ModelPlugin()
Constructor.
Definition: Plugin.hh:248
virtual void Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)=0
Load function.
virtual void Init()
Definition: Plugin.hh:238
A plugin with access to physics::World.
Definition: Plugin.hh:220
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:296
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:331
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:112
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:264
#define gzerr
Output an error message.
Definition: Console.hh:49
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:348
default namespace for gazebo
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:303
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)=0
Load function.
A System plugin.
Definition: Plugin.hh:72
A World plugin.
Definition: Plugin.hh:66
VisualPlugin()
Definition: Plugin.hh:333
virtual ~WorldPlugin()
Destructor.
Definition: Plugin.hh:227
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:267
virtual ~SystemPlugin()
Destructor.
Definition: Plugin.hh:310
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)=0
Load function.
virtual ~ModelPlugin()
Destructor.
Definition: Plugin.hh:252
std::string filename
Path to the shared library file.
Definition: Plugin.hh:200
PluginT()
Constructor.
Definition: Plugin.hh:89
A Model plugin.
Definition: Plugin.hh:68
virtual void Load(rendering::VisualPtr _visual, sdf::ElementPtr _sdf)=0
Load function.
boost::shared_ptr< T > TPtr
plugin pointer type definition
Definition: Plugin.hh:86
A Sensor plugin.
Definition: Plugin.hh:70
virtual void Load(int _argc=0, char **_argv=NULL)=0
Load function.
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:84
#define NULL
Definition: CommonTypes.hh:31
A class which all plugins must inherit from.
Definition: Plugin.hh:83
std::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:63
virtual ~SensorPlugin()
Destructor.
Definition: Plugin.hh:281
Forward declarations and typedefs for sensors.
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:351
A GUI plugin.
Definition: Plugin.hh:76
PluginType
Used to specify the type of plugin.
Definition: Plugin.hh:63
WorldPlugin()
Constructor.
Definition: Plugin.hh:223
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:322
PluginType type
Type of plugin.
Definition: Plugin.hh:197
virtual void Reset()
Definition: Plugin.hh:239
A plugin with access to physics::Sensor.
Definition: Plugin.hh:274
SensorPlugin()
Constructor.
Definition: Plugin.hh:277
SystemPlugin()
Constructor.
Definition: Plugin.hh:306
std::string GetHandle() const
Get the short name of the handler.
Definition: Plugin.hh:112
A plugin with access to physics::Model.
Definition: Plugin.hh:245
std::string handleName
Short name.
Definition: Plugin.hh:203
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:325
static TPtr Create(const std::string &_filename, const std::string &_name)
a class method that creates a plugin from a file name.
Definition: Plugin.hh:122