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 =
nullptr;
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 if (soSuffix != std::string::npos)
141 const std::string macSuffix(
".dylib");
142 filename.replace(soSuffix, macSuffix.length(), macSuffix);
149 size_t soSuffix = filename.rfind(
".so");
150 if (soSuffix != std::string::npos)
152 const std::string winSuffix(
".dll");
153 filename.replace(soSuffix, winSuffix.length(), winSuffix);
156 filename.erase(0, 3);
158 #endif // ifdef __APPLE__
160 for (iter = pluginPaths.begin();
161 iter!= pluginPaths.end(); ++iter)
163 fullname = (*iter)+std::string(
"/")+
filename;
164 if (stat(fullname.c_str(), &st) == 0)
174 fptr_union_t registerFunc;
175 std::string registerName =
"RegisterPlugin";
177 void *dlHandle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
180 gzerr <<
"Failed to load plugin " << fullname <<
": "
181 << dlerror() <<
"\n";
185 registerFunc.ptr = dlsym(dlHandle, registerName.c_str());
187 if (!registerFunc.ptr)
189 gzerr <<
"Failed to resolve " << registerName
190 <<
": " << dlerror();
195 result.reset(registerFunc.func());
196 result->dlHandle = dlHandle;
198 result->handleName = _name;
221 private:
typedef union
228 private:
void *dlHandle;
251 sdf::ElementPtr _sdf) = 0;
276 sdf::ElementPtr _sdf) = 0;
305 sdf::ElementPtr _sdf) = 0;
332 public:
virtual void Load(
int _argc = 0,
char **_argv =
nullptr) = 0;
358 sdf::ElementPtr _sdf) = 0;
376 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
377 extern "C" GZ_PLUGIN_VISIBLE gazebo::ModelPlugin *RegisterPlugin(); \
378 gazebo::ModelPlugin *RegisterPlugin() \
380 return new classname();\
387 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
388 extern "C" GZ_PLUGIN_VISIBLE gazebo::WorldPlugin *RegisterPlugin(); \
389 gazebo::WorldPlugin *RegisterPlugin() \
391 return new classname();\
398 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
399 extern "C" GZ_PLUGIN_VISIBLE gazebo::SensorPlugin *RegisterPlugin(); \
400 gazebo::SensorPlugin *RegisterPlugin() \
402 return new classname();\
409 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
410 extern "C" GZ_PLUGIN_VISIBLE gazebo::SystemPlugin *RegisterPlugin(); \
411 gazebo::SystemPlugin *RegisterPlugin() \
413 return new classname();\
420 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
421 extern "C" GZ_PLUGIN_VISIBLE gazebo::VisualPlugin *RegisterPlugin(); \
422 gazebo::VisualPlugin *RegisterPlugin() \
424 return new classname();\
std::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:64
virtual void Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)=0
Load function.
std::string handleName
Short name.
Definition: Plugin.hh:218
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
std::string filename
Path to the shared library file.
Definition: Plugin.hh:215
virtual void Load(rendering::VisualPtr _visual, sdf::ElementPtr _sdf)=0
Load function.
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
virtual void Reset()
Definition: Plugin.hh:254
PluginType type
Type of plugin.
Definition: Plugin.hh:212
A plugin with access to physics::World.
Definition: Plugin.hh:235
A plugin with access to rendering::Visual.
Definition: Plugin.hh:346
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:308
#define gzerr
Output an error message.
Definition: Console.hh:50
A World plugin.
Definition: Plugin.hh:66
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:340
default namespace for gazebo
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:366
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:318
A GUI plugin.
Definition: Plugin.hh:76
PluginType
Used to specify the type of plugin.
Definition: Plugin.hh:63
A Sensor plugin.
Definition: Plugin.hh:70
PluginType GetType() const
Returns the type of the plugin.
Definition: Plugin.hh:206
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:282
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:311
virtual void Init()
Definition: Plugin.hh:253
virtual ~PluginT()
Destructor.
Definition: Plugin.hh:95
virtual ~SystemPlugin()
Destructor.
Definition: Plugin.hh:325
boost::shared_ptr< T > TPtr
plugin pointer type definition
Definition: Plugin.hh:86
VisualPlugin()
Definition: Plugin.hh:348
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:363
A class which all plugins must inherit from.
Definition: Plugin.hh:83
SystemPlugin()
Constructor.
Definition: Plugin.hh:321
A Model plugin.
Definition: Plugin.hh:68
ModelPlugin()
Constructor.
Definition: Plugin.hh:263
virtual ~WorldPlugin()
Destructor.
Definition: Plugin.hh:242
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)=0
Load function.
SensorPlugin()
Constructor.
Definition: Plugin.hh:292
virtual void Load(int _argc=0, char **_argv=nullptr)=0
Load function.
Forward declarations and typedefs for sensors.
WorldPlugin()
Constructor.
Definition: Plugin.hh:238
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:337
virtual ~SensorPlugin()
Destructor.
Definition: Plugin.hh:296
A Visual plugin.
Definition: Plugin.hh:74
std::string GetFilename() const
Get the name of the handler.
Definition: Plugin.hh:106
PluginT()
Constructor.
Definition: Plugin.hh:89
A plugin with access to physics::Sensor.
Definition: Plugin.hh:289
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:260
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)=0
Load function.
virtual ~ModelPlugin()
Destructor.
Definition: Plugin.hh:267
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:279
static SystemPaths * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
A System plugin.
Definition: Plugin.hh:72