27#include <gazebo/gazebo_config.h>
34#include <boost/filesystem.hpp>
78 public:
typedef boost::shared_ptr<T>
TPtr;
83 this->dlHandle =
nullptr;
114 public:
static TPtr
Create(
const std::string &_filename,
115 const std::string &_name)
121 std::string fullname,
filename(_filename);
122 std::list<std::string>::iterator iter;
123 std::list<std::string> pluginPaths =
130 size_t soSuffix =
filename.rfind(
".so");
131 if (soSuffix != std::string::npos)
133 const std::string macSuffix(
".dylib");
134 filename.replace(soSuffix, macSuffix.length(), macSuffix);
141 size_t soSuffix =
filename.rfind(
".so");
142 if (soSuffix != std::string::npos)
144 const std::string winSuffix(
".dll");
145 filename.replace(soSuffix, winSuffix.length(), winSuffix);
147 size_t libPrefix =
filename.find(
"lib");
156 for (iter = pluginPaths.begin();
157 iter!= pluginPaths.end(); ++iter)
159 fullname = (*iter)+std::string(
"/")+
filename;
160 fullname = boost::filesystem::path(fullname)
161 .make_preferred().string();
162 if (stat(fullname.c_str(), &st) == 0)
172 fptr_union_t registerFunc;
173 std::string registerName =
"RegisterPlugin";
175 void *dlHandle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
178 gzerr <<
"Failed to load plugin " << fullname <<
": "
179 << dlerror() <<
"\n";
183 registerFunc.ptr = dlsym(dlHandle, registerName.c_str());
185 if (!registerFunc.ptr)
187 gzerr <<
"Failed to resolve " << registerName
188 <<
": " << dlerror();
193 result.reset(registerFunc.func());
194 result->dlHandle = dlHandle;
196 result->handleName = _name;
217 protected:
template <
typename V>
void LoadParam(
const sdf::ElementPtr &_sdf,
218 const std::string &_name, V &_target,
219 V _defaultValue = V())
const
221 auto result = _sdf->Get<V>(_name, _defaultValue);
226 << _name.c_str() <<
">, defaults to "
227 << result.first << std::endl;
232 << _name.c_str() <<
"> set to "
233 << result.first << std::endl;
235 _target = result.first;
248 const std::string &_name, std::string &_target,
249 const char* _defaultValue)
const
251 this->LoadParam<std::string>(_sdf, _name, _target, _defaultValue);
264 private:
typedef union
271 private:
void *dlHandle;
294 sdf::ElementPtr _sdf) = 0;
319 sdf::ElementPtr _sdf) = 0;
348 sdf::ElementPtr _sdf) = 0;
375 public:
virtual void Load(
int _argc = 0,
char **_argv =
nullptr) = 0;
401 sdf::ElementPtr _sdf) = 0;
419#define GZ_REGISTER_MODEL_PLUGIN(classname) \
420 extern "C" GZ_PLUGIN_VISIBLE gazebo::ModelPlugin *RegisterPlugin(); \
421 gazebo::ModelPlugin *RegisterPlugin() \
423 return new classname();\
430#define GZ_REGISTER_WORLD_PLUGIN(classname) \
431 extern "C" GZ_PLUGIN_VISIBLE gazebo::WorldPlugin *RegisterPlugin(); \
432 gazebo::WorldPlugin *RegisterPlugin() \
434 return new classname();\
441#define GZ_REGISTER_SENSOR_PLUGIN(classname) \
442 extern "C" GZ_PLUGIN_VISIBLE gazebo::SensorPlugin *RegisterPlugin(); \
443 gazebo::SensorPlugin *RegisterPlugin() \
445 return new classname();\
452#define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
453 extern "C" GZ_PLUGIN_VISIBLE gazebo::SystemPlugin *RegisterPlugin(); \
454 gazebo::SystemPlugin *RegisterPlugin() \
456 return new classname();\
463#define GZ_REGISTER_VISUAL_PLUGIN(classname) \
464 extern "C" GZ_PLUGIN_VISIBLE gazebo::VisualPlugin *RegisterPlugin(); \
465 gazebo::VisualPlugin *RegisterPlugin() \
467 return new classname();\
default namespace for gazebo
Forward declarations and typedefs for sensors.
static SystemPaths * Instance()
Get an instance of the singleton.
Definition SingletonT.hh:36
A plugin with access to physics::Model.
Definition Plugin.hh:304
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)=0
Load function.
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition Plugin.hh:322
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition Plugin.hh:325
virtual ~ModelPlugin()
Destructor.
Definition Plugin.hh:310
ModelPlugin()
Constructor.
Definition Plugin.hh:306
A class which all plugins must inherit from.
Definition Plugin.hh:76
std::string GetFilename() const
Get the name of the handler.
Definition Plugin.hh:98
std::string handleName
Short name.
Definition Plugin.hh:261
PluginType type
Type of plugin.
Definition Plugin.hh:255
boost::shared_ptr< T > TPtr
plugin pointer type definition
Definition Plugin.hh:78
void LoadParam(const sdf::ElementPtr &_sdf, const std::string &_name, V &_target, V _defaultValue=V()) const
Load parameter value from _sdf and store it to the given reference, using the supplied default value ...
Definition Plugin.hh:217
PluginType GetType() const
Returns the type of the plugin.
Definition Plugin.hh:204
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:114
PluginT()
Constructor.
Definition Plugin.hh:81
std::string GetHandle() const
Get the short name of the handler.
Definition Plugin.hh:104
void LoadParam(sdf::ElementPtr &_sdf, const std::string &_name, std::string &_target, const char *_defaultValue) const
Load parameter value from _sdf and store it to the given reference, using the supplied default value ...
Definition Plugin.hh:247
std::string filename
Path to the shared library file.
Definition Plugin.hh:258
virtual ~PluginT()
Destructor.
Definition Plugin.hh:87
A plugin with access to physics::Sensor.
Definition Plugin.hh:333
SensorPlugin()
Constructor.
Definition Plugin.hh:335
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition Plugin.hh:351
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition Plugin.hh:354
virtual void Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)=0
Load function.
virtual ~SensorPlugin()
Destructor.
Definition Plugin.hh:339
A plugin loaded within the gzserver on startup.
Definition Plugin.hh:362
SystemPlugin()
Constructor.
Definition Plugin.hh:364
virtual void Init()
Initialize the plugin.
Definition Plugin.hh:380
virtual ~SystemPlugin()
Destructor.
Definition Plugin.hh:368
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition Plugin.hh:383
virtual void Load(int _argc=0, char **_argv=nullptr)=0
Load function.
A plugin with access to rendering::Visual.
Definition Plugin.hh:390
virtual void Load(rendering::VisualPtr _visual, sdf::ElementPtr _sdf)=0
Load function.
virtual void Init()
Initialize the plugin.
Definition Plugin.hh:406
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition Plugin.hh:409
VisualPlugin()
Definition Plugin.hh:391
A plugin with access to physics::World.
Definition Plugin.hh:279
virtual ~WorldPlugin()
Destructor.
Definition Plugin.hh:285
virtual void Init()
Definition Plugin.hh:296
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)=0
Load function.
WorldPlugin()
Constructor.
Definition Plugin.hh:281
virtual void Reset()
Definition Plugin.hh:297
#define gzmsg
Output a message.
Definition Console.hh:41
PluginType
Used to specify the type of plugin.
Definition Plugin.hh:56
#define gzerr
Output an error message.
Definition Console.hh:50
@ SYSTEM_PLUGIN
A System plugin.
Definition Plugin.hh:64
@ GUI_PLUGIN
A GUI plugin.
Definition Plugin.hh:68
@ VISUAL_PLUGIN
A Visual plugin.
Definition Plugin.hh:66
@ SENSOR_PLUGIN
A Sensor plugin.
Definition Plugin.hh:62
@ MODEL_PLUGIN
A Model plugin.
Definition Plugin.hh:60
@ WORLD_PLUGIN
A World plugin.
Definition Plugin.hh:58
boost::shared_ptr< World > WorldPtr
Definition PhysicsTypes.hh:89
boost::shared_ptr< Model > ModelPtr
Definition PhysicsTypes.hh:93
std::shared_ptr< Visual > VisualPtr
Definition RenderTypes.hh:114
std::shared_ptr< Sensor > SensorPtr
Definition SensorTypes.hh:64
Forward declarations for the common classes.
Definition Animation.hh:27