Plug-ins

Simple plug-in library

See OBT::Plugin and OBT::PluginInformation. This is the old version of plug-in. See Plug-in object library for the new one.

Plug-in object library

See OBT::PluginInterface and OBT::PluginLoader.

How to create a plug-in object ?

You must define a son of the plug-in interface to implements the methods of the interface.
Declaration in the header file:
...
#include "OBTPluginInterface.h"
...
class MY_EXPORT_API MyPlugin : public OBT::PluginInterface
{
protected :
  MyPlugin() ;
public:
  virtual const OBT::PluginInformation& getInformation() const { return _info ; }
  void aMethod() ;
protected:
  // Minimal method
  virtual bool init( const std::string& ) { return true ; }
  // Minimal method
  virtual bool finish() { return true ; }
protected :
  virtual ~MyPlugin() {}
  OBT::PluginInformation _info ;
} ;
...
Implementation in the .cpp file:
...
MyPlugin::MyPlugin()
: _info( ... my plug-in informations ... )
{
}
void MyPlugin::aMethod() 
{
  ...
}
Declaration of the entry method in the .cpp file (see How to export the plug-in entry method ?):
...
OBT_EXPORT_PLUGIN_API( MyPlugin ) ;
...

How to export the plug-in entry method ?

The best way is to use OBT_EXPORT_PLUGIN_API or OBT_EXPORT_BASIC_PLUGIN_API macros to declare the plug-in entry method.
  • For the first macro, the argument is the name of the plug-in object class and this class must have a constructor with no arguments.
  • For the second one the argument is a OBT::PluginInformation object.
If your plug-in object needs parameters to call the constructor you must write the get_OBT_PluginInterface function by hand. The prototype of the function is:
extern "C"
{
  OBT_EXPORT_API_DECL PluginInterface* get_OBT_PluginInterface()
  {
    ...
  } 
}

How is located the plug-in library while it is loaded ?

See load method.

How to load a plug-in object ?

How to parametrise a plug-in ?

The last argument of load or loadT is a parameter string. This string is passed as the argument to the init method of the plug-in. So it can be used to change the initialisation of the plug-in.
Three main usage of the string:

What are the error messages during a load ?

On error always returns a null pointer, and display the following messages in the console:

How to unload a plug-in object ?

All the loaded plug-ins are unloaded when the singleton of the plug-ins loader is destroyed. This occures during the end step of the application running.
To explicitly unload a plug-in object:
...
MyPlugin* plugin = ...
...
OBT::PluginLoader::getInstance().unload( plugin ) ;
...

Can old plug-ins be loaded ?

Yes, the OBT::OldPlugin plug-in interface is provided for old plug-ins. The only available methode is getInformation.
...
OBT::PluginInterface* plugin = OBT::PluginLoader::getInstance().load( path, "myPlugin" ) ;
OBT::OldPlugin* oldPlugin = dynamic_cast< OBT::OldPlugin* >( plugin ) ;
MyPlugin* newPlugin = dynamic_cast< MyPlugin* >( plugin ) ;
if( 0 != oldPlugin )
{ 
  // this is an old plugin
  const OBT::PluginInformation& info = plugin->getInformation() ;
  ...
}
if( 0 != newPlugin )
{ 
  // this is an new plugin
  plugin->aMethod() ;
  ...
}
else
{
  // Bad type
  delete plugin ;
}

How to get informations about the loaded plug-in ?

  • getInformation to get the information about the plug-in.
  • getType to get the type id of the plug-in. The meaning of the id is defined by the application. Nevertheless 0 is reserved for OBT::BasicPlugin and -1 is reserved for OBT::OldPlugin.


Generated on 1 Jan 2010 for OBT by  doxygen 1.6.1