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;
122 public:
static TPtr
Create(
const std::string &_filename,
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;
219 protected:
template <
typename V>
void LoadParam(
const sdf::ElementPtr &_sdf,
220 const std::string &_name, V &_target,
221 V _defaultValue = V())
const 223 auto result = _sdf->Get<V>(_name, _defaultValue);
228 << _name.c_str() <<
">, defaults to " 229 << result.first << std::endl;
234 << _name.c_str() <<
"> set to " 235 << result.first << std::endl;
237 _target = result.first;
250 const std::string &_name, std::string &_target,
251 const char* _defaultValue)
const 253 this->LoadParam<std::string>(_sdf, _name, _target, _defaultValue);
266 private:
typedef union 273 private:
void *dlHandle;
296 sdf::ElementPtr _sdf) = 0;
321 sdf::ElementPtr _sdf) = 0;
350 sdf::ElementPtr _sdf) = 0;
377 public:
virtual void Load(
int _argc = 0,
char **_argv =
nullptr) = 0;
403 sdf::ElementPtr _sdf) = 0;
421 #define GZ_REGISTER_MODEL_PLUGIN(classname) \ 422 extern "C" GZ_PLUGIN_VISIBLE gazebo::ModelPlugin *RegisterPlugin(); \ 423 gazebo::ModelPlugin *RegisterPlugin() \ 425 return new classname();\ 432 #define GZ_REGISTER_WORLD_PLUGIN(classname) \ 433 extern "C" GZ_PLUGIN_VISIBLE gazebo::WorldPlugin *RegisterPlugin(); \ 434 gazebo::WorldPlugin *RegisterPlugin() \ 436 return new classname();\ 443 #define GZ_REGISTER_SENSOR_PLUGIN(classname) \ 444 extern "C" GZ_PLUGIN_VISIBLE gazebo::SensorPlugin *RegisterPlugin(); \ 445 gazebo::SensorPlugin *RegisterPlugin() \ 447 return new classname();\ 454 #define GZ_REGISTER_SYSTEM_PLUGIN(classname) \ 455 extern "C" GZ_PLUGIN_VISIBLE gazebo::SystemPlugin *RegisterPlugin(); \ 456 gazebo::SystemPlugin *RegisterPlugin() \ 458 return new classname();\ 465 #define GZ_REGISTER_VISUAL_PLUGIN(classname) \ 466 extern "C" GZ_PLUGIN_VISIBLE gazebo::VisualPlugin *RegisterPlugin(); \ 467 gazebo::VisualPlugin *RegisterPlugin() \ 469 return new classname();\ #define gzmsg
Output a message.
Definition: Console.hh:41
std::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:64
std::string handleName
Short name.
Definition: Plugin.hh:263
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
Forward declarations for the common classes.
Definition: Animation.hh:26
std::string filename
Path to the shared library file.
Definition: Plugin.hh:260
std::string GetFilename() const
Get the name of the handler.
Definition: Plugin.hh:106
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:299
std::string GetHandle() const
Get the short name of the handler.
Definition: Plugin.hh:112
PluginType type
Type of plugin.
Definition: Plugin.hh:257
A plugin with access to physics::World.
Definition: Plugin.hh:280
A plugin with access to rendering::Visual.
Definition: Plugin.hh:391
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:353
#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:385
default namespace for gazebo
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:411
A plugin loaded within the gzserver on startup.
Definition: Plugin.hh:363
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
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:327
virtual void Reset()
Override this method for custom plugin reset behavior.
Definition: Plugin.hh:356
virtual void Init()
Definition: Plugin.hh:298
virtual ~PluginT()
Destructor.
Definition: Plugin.hh:95
virtual ~SystemPlugin()
Destructor.
Definition: Plugin.hh:370
boost::shared_ptr< T > TPtr
plugin pointer type definition
Definition: Plugin.hh:86
VisualPlugin()
Definition: Plugin.hh:393
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:408
PluginType GetType() const
Returns the type of the plugin.
Definition: Plugin.hh:206
A class which all plugins must inherit from.
Definition: Plugin.hh:83
SystemPlugin()
Constructor.
Definition: Plugin.hh:366
A Model plugin.
Definition: Plugin.hh:68
ModelPlugin()
Constructor.
Definition: Plugin.hh:308
virtual ~WorldPlugin()
Destructor.
Definition: Plugin.hh:287
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
SensorPlugin()
Constructor.
Definition: Plugin.hh:337
Forward declarations and typedefs for sensors.
WorldPlugin()
Constructor.
Definition: Plugin.hh:283
virtual void Init()
Initialize the plugin.
Definition: Plugin.hh:382
virtual ~SensorPlugin()
Destructor.
Definition: Plugin.hh:341
A Visual plugin.
Definition: Plugin.hh:74
PluginT()
Constructor.
Definition: Plugin.hh:89
A plugin with access to physics::Sensor.
Definition: Plugin.hh:334
A plugin with access to physics::Model.
Definition: Plugin.hh:305
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:219
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:249
virtual ~ModelPlugin()
Destructor.
Definition: Plugin.hh:312
virtual void Init()
Override this method for custom plugin initialization behavior.
Definition: Plugin.hh:324
static SystemPaths * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
A System plugin.
Definition: Plugin.hh:72