Note: This tutorial assumes that you have completed the previous tutorials: Create and Export new Plugin, How to use Dynamic Parameters in Plugins, Working with the Plugin Manager.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Important Code Hooks for Plugins

Description: Detailed information about available code hooks to be overwritten for advanced usage of the plugin system.

Keywords: plugin, hooks, overwrite

Tutorial Level: INTERMEDIATE

Next Tutorial: Plugin Description Inheritance

Code Hooks

The vigir_pluginlib::Plugin class includes common used interfaces described below. To use them you have to override the corresponding method in your code. When overloading a member, please ensure to call the first order parent implementation at the beginning of your override to ensure correct operation.

Example:

   1 bool MyConcretePlugin::initialize(const vigir_generic_params::ParameterSet& params)
   2 {
   3   if (!MyInterfacePlugin::initialize(params))
   4     return false;
   5 
   6   // your code here
   7 
   8   return true; // feel free to make this return result conditional
   9 }

loadParams(...)

   1 bool loadParams(const vigir_generic_params::ParameterSet& params) { return true; }

This method is called automatically by initialize(...). Other plugins may have not been initialized yet and therefore should not used here! The given parameter set can be a generic/user specific one or just empty as it is optional. The method must return true on success.

initialize(...)

   1 bool initialize(const vigir_generic_params::ParameterSet& params) { return loadParams(global_params); }

This method is called directly after object instantiation. Other plugins may have not been initialized yet and therefore should not used here! In this case please use the postInitialize method. The given parameter set can be a generic/user specific one or just empty as it is optional. The method must return true on success.

postInitialize(...)

   1 bool postInitialize(const vigir_generic_params::ParameterSet& params) { return true; }

This method is called directly after all plugins have been instantiated. Hence, it is safe to use other plugins inside this method. The given parameter set can be a generic/user specific one or just empty as it is optional. The method must return true on success.

isUnique()

   1 bool isUnique() const  { return true; }

Per default only one plugin of each type can be instantiated at once. If a plugin implementing the identical plugin interface is going to be instantiated, it will replace the current one. But if you are sure that it does not harm to have multiple (and different implementations) of a single type active in parallel, then you must override this method to return false. This may be useful if you are using the Plugin Aggregator.

Warning

Once isUnique() has been overridden, it must not be switched back to true. Therefore, the final declaration should be used here when overriding this method.

Wiki: vigir_pluginlib/Tutorials/ImportantCodeHooks (last edited 2017-04-03 18:55:23 by AlexanderStumpf)