17 #ifndef _GZ_PLUGIN_HH_
18 #define _GZ_PLUGIN_HH_
21 #include <sys/types.h>
24 #include <gazebo/gazebo_config.h>
74 public:
typedef boost::shared_ptr<T>
TPtr;
79 this->dlHandle =
NULL;
96 return this->filename;
102 return this->handleName;
111 const std::string &_name)
117 std::string fullname, filename(_filename);
118 std::list<std::string>::iterator iter;
119 std::list<std::string> pluginPaths =
126 size_t soSuffix = filename.rfind(
".so");
127 const std::string macSuffix(
".dylib");
128 if (soSuffix != std::string::npos)
129 filename.replace(soSuffix, macSuffix.length(), macSuffix);
131 #endif // ifdef __APPLE__
133 for (iter = pluginPaths.begin();
134 iter!= pluginPaths.end(); ++iter)
136 fullname = (*iter)+std::string(
"/")+filename;
137 if (stat(fullname.c_str(), &st) == 0)
147 fptr_union_t registerFunc;
148 std::string registerName =
"RegisterPlugin";
150 void *dlHandle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
153 gzerr <<
"Failed to load plugin " << fullname <<
": "
154 << dlerror() <<
"\n";
158 registerFunc.ptr = dlsym(dlHandle, registerName.c_str());
160 if (!registerFunc.ptr)
162 gzerr <<
"Failed to resolve " << registerName
163 <<
": " << dlerror();
168 result.reset(registerFunc.func());
169 result->dlHandle = dlHandle;
171 result->handleName = _name;
172 result->filename = filename;
194 private:
typedef union
201 private:
void *dlHandle;
224 sdf::ElementPtr _sdf) = 0;
249 sdf::ElementPtr _sdf) = 0;
278 sdf::ElementPtr _sdf) = 0;
305 public:
virtual void Load(
int _argc = 0,
char **_argv =
NULL) = 0;
331 sdf::ElementPtr _sdf) = 0;
349 #define GZ_REGISTER_MODEL_PLUGIN(classname) \
350 extern "C" GAZEBO_VISIBLE gazebo::ModelPlugin *RegisterPlugin(); \
352 gazebo::ModelPlugin *RegisterPlugin() \
354 return new classname();\
361 #define GZ_REGISTER_WORLD_PLUGIN(classname) \
362 extern "C" GAZEBO_VISIBLE gazebo::WorldPlugin *RegisterPlugin(); \
364 gazebo::WorldPlugin *RegisterPlugin() \
366 return new classname();\
373 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \
374 extern "C" GAZEBO_VISIBLE gazebo::SensorPlugin *RegisterPlugin(); \
376 gazebo::SensorPlugin *RegisterPlugin() \
378 return new classname();\
385 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \
386 extern "C" GAZEBO_VISIBLE gazebo::SystemPlugin *RegisterPlugin(); \
388 gazebo::SystemPlugin *RegisterPlugin() \
390 return new classname();\
397 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \
398 extern "C" GAZEBO_VISIBLE gazebo::VisualPlugin *RegisterPlugin(); \
400 gazebo::VisualPlugin *RegisterPlugin() \
402 return new classname();\
PluginType GetType() const
Returns the type of the plugin.
Definition: Plugin.hh:179
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:281
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:83
std::string GetFilename() const
Get the name of the handler.
Definition: Plugin.hh:94
ModelPlugin()
Constructor.
Definition: Plugin.hh:236
virtual void Init()
Definition: Plugin.hh:226
A plugin with access to physics::World.
Definition: Plugin.hh:208
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:284
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:319
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:252
#define gzerr
Output an error message.
Definition: Console.hh:49
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:336
default namespace for gazebo
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:291
A System plugin.
Definition: Plugin.hh:60
A World plugin.
Definition: Plugin.hh:54
VisualPlugin()
Definition: Plugin.hh:321
virtual ~WorldPlugin()
Destructor.
Definition: Plugin.hh:215
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:255
virtual ~SystemPlugin()
Destructor.
Definition: Plugin.hh:298
virtual ~ModelPlugin()
Destructor.
Definition: Plugin.hh:240
std::string filename
Path to the shared library file.
Definition: Plugin.hh:188
PluginT()
Constructor.
Definition: Plugin.hh:77
A Model plugin.
Definition: Plugin.hh:56
boost::shared_ptr< T > TPtr
plugin pointer type definition
Definition: Plugin.hh:74
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:71
virtual ~SensorPlugin()
Destructor.
Definition: Plugin.hh:269
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
Forward declarations and typedefs for sensors.
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:339
A GUI plugin.
Definition: Plugin.hh:64
PluginType
Used to specify the type of plugin.
Definition: Plugin.hh:51
WorldPlugin()
Constructor.
Definition: Plugin.hh:211
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:310
PluginType type
Type of plugin.
Definition: Plugin.hh:185
boost::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:55
virtual void Reset()
Definition: Plugin.hh:227
A plugin with access to physics::Sensor.
Definition: Plugin.hh:262
SensorPlugin()
Constructor.
Definition: Plugin.hh:265
SystemPlugin()
Constructor.
Definition: Plugin.hh:294
std::string GetHandle() const
Get the short name of the handler.
Definition: Plugin.hh:100
A plugin with access to physics::Model.
Definition: Plugin.hh:233
std::string handleName
Short name.
Definition: Plugin.hh:191
#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:313
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:110