te::plugin::PluginManager Class Reference

A singleton for managing plugins. More...

#include <PluginManager.h>

Inheritance diagram for te::plugin::PluginManager:
te::common::Singleton< PluginManager >

Public Member Functions

void add (const PluginInfo &plugin)
 Adds plug-in to unload list. More...
 
void add (PluginInfo *plugin)
 Adds plugin to unload list and take its ownership. More...
 
void addCategory (const std::string &name)
 Add a new category type. More...
 
void clear ()
 Unload all plugins and them clear the internal list. More...
 
AbstractPlugindetach (const std::string &pluginName)
 It detaches the given plugin from the list of loaded plugins. More...
 
const boost::ptr_vector< PluginInfo > & getBrokenPlugins () const
 It returns the list of plugins that could not be loaded. More...
 
void getCategories (std::vector< std::string > &categories) const
 Get plugins category types. More...
 
std::vector< std::string > getDependents (const std::string &pluginName) const
 It searches for all plugins that depends on the given plugin. More...
 
std::size_t getNumPlugins () const
 It returns the number of plugins kept in the manager. More...
 
const PluginInfogetPlugin (const std::string &name) const
 It returns the plugin identified by the given name. More...
 
std::vector< std::string > getPlugins () const
 It returns the list of plugins managed by PluginManager. More...
 
const boost::ptr_vector< PluginInfo > & getUnloadedPlugins () const
 It returns the list of plugins that are not loaded. More...
 
bool hasDependents (const std::string &pluginName) const
 If there is a plugin that depends on the informed plugin it returns true, otherwise, if no plugin depends on it, return false. More...
 
bool isBrokenPlugin (const std::string &pluginName) const
 It returns true if the plugin is in the broken list of plugins. More...
 
bool isLoaded (const std::string &pname) const
 It returns true if the plugin is loaded otherwise returns false. More...
 
bool isLoaded (const std::vector< std::string > &plugins) const
 It returns true if each plugin in the list are loaded otherwise returns false. More...
 
bool isUnloadedPlugin (const std::string &pluginName) const
 It returns true if the plugin is in the not-loaded list of plugins. More...
 
void load (boost::ptr_vector< PluginInfo > &plugins, const bool start=true)
 It tries to load all informed plugins. More...
 
void load (const PluginInfo &pInfo, const bool start=true)
 It loads the informed plugin and adds it to the list of managed plugins. More...
 
void load (const std::string &pluginName)
 
void loadAll (const bool start=true)
 It loads all the plugins in the not-loaded list or searchs for installed plugin with installed finders. More...
 
void remove (const std::string &plugin)
 
void setBrokenPlugins (boost::ptr_vector< te::plugin::PluginInfo > brokenPlugins)
 
void setUnloadedPlugins (boost::ptr_vector< te::plugin::PluginInfo > unloadedPlugins)
 
void shutdownAll ()
 It try to shutdown all plugins. More...
 
void unload (const std::string &name)
 It tries to unload a given plugin. More...
 
void unload (AbstractPlugin *plugin)
 It tries to unload a given plugin. More...
 
void unloadAll ()
 It try to unload all plugins. More...
 

Static Public Member Functions

static PluginManagergetInstance ()
 It returns a reference to the singleton instance. More...
 

Protected Member Functions

void moveDependentsToBrokenList (const std::string &plugin, const bool &unloadPlugin=false)
 
void moveToBrokenList (const PluginInfo &pInfo)
 
void removeFromBrokenList (const PluginInfo &pInfo)
 
void removeFromCategory (AbstractPlugin *plugin, const std::string &category)
 It removes the given plugin from the category and then updates the internal category index. More...
 
void removeFromUnloadedList (const PluginInfo &pInfo)
 
void sort (boost::ptr_vector< PluginInfo > &plugins) const
 It sorts the plugins according to their dependency. More...
 
void updateDependents (const std::string &plugin)
 

Private Member Functions

 PluginManager ()
 It creates a new plugin. More...
 
 ~PluginManager ()
 Singleton destructor. More...
 

Private Attributes

boost::ptr_vector< PluginInfom_brokenPlugins
 The list of plugins that could not be loaded. More...
 
std::vector< AbstractFinder * > m_finders
 The list of plugin finders. More...
 
std::map< std::string, std::vector< AbstractPlugin * > > m_pluginCategoryMap
 A map from (plugin category) to (plugins in category) More...
 
std::vector< AbstractPlugin * > m_plugins
 The list of managed plugins: this will be need to unload accordinly the plugins! More...
 
std::map< std::string, AbstractPlugin * > m_pluginsMap
 A map from (plugin's name) to (plugin instance). More...
 
boost::ptr_vector< PluginInfom_unloadedPlugins
 The list of plugins that are not loaded. More...
 

Friends

class te::common::Singleton< PluginManager >
 

Detailed Description

A singleton for managing plugins.

See also
AbstractPlugin, PluginInfo, AbstractFinder, PluginEngine, PluginEngineFactory

Definition at line 61 of file PluginManager.h.

Constructor & Destructor Documentation

te::plugin::PluginManager::PluginManager ( )
private

It creates a new plugin.

te::plugin::PluginManager::~PluginManager ( )
private

Singleton destructor.

Member Function Documentation

void te::plugin::PluginManager::add ( const PluginInfo plugin)

Adds plug-in to unload list.

Parameters
pluginInformation of the plug-in.
void te::plugin::PluginManager::add ( PluginInfo plugin)

Adds plugin to unload list and take its ownership.

Parameters
pluginInformation of the plug-in.
void te::plugin::PluginManager::addCategory ( const std::string &  name)

Add a new category type.

Parameters
nameThe category name.
void te::plugin::PluginManager::clear ( )

Unload all plugins and them clear the internal list.

After calling this method if you call loadAll the manager will look for plugins using the registered finders.

AbstractPlugin* te::plugin::PluginManager::detach ( const std::string &  pluginName)

It detaches the given plugin from the list of loaded plugins.

Parameters
pluginNameThe plugin name.
Exceptions
ExceptionIf there are plugins that depends on the plugin being detached or if the plugin is not found this method raises an exception.
Note
The caller of this method will take the ownership of the given plugin.
const boost::ptr_vector<PluginInfo>& te::plugin::PluginManager::getBrokenPlugins ( ) const

It returns the list of plugins that could not be loaded.

void te::plugin::PluginManager::getCategories ( std::vector< std::string > &  categories) const

Get plugins category types.

Parameters
Avector to output the name of plugins categories managed by this singleton.
std::vector<std::string> te::plugin::PluginManager::getDependents ( const std::string &  pluginName) const

It searches for all plugins that depends on the given plugin.

Parameters
pluginNameThe plugin to be checked.
Returns
It returns the list of plugins that depends on the given plugin.
static PluginManager & te::common::Singleton< PluginManager >::getInstance ( )
staticinherited

It returns a reference to the singleton instance.

Returns
A reference to the singleton instance.
std::size_t te::plugin::PluginManager::getNumPlugins ( ) const

It returns the number of plugins kept in the manager.

Returns
The number of plugins in the manager.
Note
This will account for loaded, unloaded and broken plugins.
const PluginInfo& te::plugin::PluginManager::getPlugin ( const std::string &  name) const

It returns the plugin identified by the given name.

Parameters
nameThe plugin name.
Returns
A plugin identified by the given name.
Exceptions
ExceptionIt throws an exception if there isn't a plugin with the given name in the manager.
std::vector<std::string> te::plugin::PluginManager::getPlugins ( ) const

It returns the list of plugins managed by PluginManager.

Parameters
pluginsA vector to output the name of plugins managed by this singleton.
Note
The list will contain: loaded, not-loaded and broken plugins.
const boost::ptr_vector<PluginInfo>& te::plugin::PluginManager::getUnloadedPlugins ( ) const

It returns the list of plugins that are not loaded.

bool te::plugin::PluginManager::hasDependents ( const std::string &  pluginName) const

If there is a plugin that depends on the informed plugin it returns true, otherwise, if no plugin depends on it, return false.

Parameters
pluginNameThe plugin to be checked.
Returns
It returns true if there is a plugin that depends on the given plugin.
bool te::plugin::PluginManager::isBrokenPlugin ( const std::string &  pluginName) const

It returns true if the plugin is in the broken list of plugins.

bool te::plugin::PluginManager::isLoaded ( const std::string &  pname) const

It returns true if the plugin is loaded otherwise returns false.

Parameters
pnameThe plugin name to be checked.
Returns
It returns true if the plugin in the list are loaded otherwise returns false.
bool te::plugin::PluginManager::isLoaded ( const std::vector< std::string > &  plugins) const

It returns true if each plugin in the list are loaded otherwise returns false.

Parameters
pluginsA list with plugin names to be checked.
Returns
It returns true if all plugins in the list are loaded otherwise returns false.
Note
This method can be used to check if a given plugin has all pre-requisites to be loaded.
bool te::plugin::PluginManager::isUnloadedPlugin ( const std::string &  pluginName) const

It returns true if the plugin is in the not-loaded list of plugins.

void te::plugin::PluginManager::load ( boost::ptr_vector< PluginInfo > &  plugins,
const bool  start = true 
)

It tries to load all informed plugins.

PluginManager will check the dependency between plugins before trying to load them.

Parameters
pluginsThe list of plugins to be loaded
startIf true it will try to startup the plugin if false it doesn't automatically call plugin startup method.
Exceptions
ExceptionIt throws an exception if any plugin can not be loaded or started.
Note
If a plugin in the list is already loaded this methods will throw an exception.
If a plugin load fails this method will add it to the list of broken plugins and continues. In this case at the end an exception is thrown.
The manager will sort the plugins according to their load priority.
void te::plugin::PluginManager::load ( const PluginInfo pInfo,
const bool  start = true 
)

It loads the informed plugin and adds it to the list of managed plugins.

PluginManager will check the dependency between plugins before trying to load the informed plugin.

Parameters
pInfoInformation about the plugin to be loaded.
startIf true it will try to startup the plugin if false it doesn't automatically call plugin startup method.
Exceptions
ExceptionIt throws an exception if something goes wrong during plugin load.
Note
This method can checks for category dependency and plugin dependency. It throws an error if the dependency is not satisfied.
If a plugin in the list is already loaded this methods will raise an exception.
If an exception occurs the plugin will be added to the list of broken plugins (except if it is already loaded!).
If no plugin folder or an invalid folder was supplied the interal finders will be used to locate the plugin file.
void te::plugin::PluginManager::load ( const std::string &  pluginName)
void te::plugin::PluginManager::loadAll ( const bool  start = true)

It loads all the plugins in the not-loaded list or searchs for installed plugin with installed finders.

PluginManager will check the dependency between plugins before trying to load them.

The associated plugin finders will be used to locate the information about plugins.

If no plugin finder is available this method will use the default finder to look up for plugins.

After the fitrst call to this method the plugins list is cached until clear is explicitly called.

Parameters
startIf true it will try to startup the plugins if false it doesn't automatically call plugins startup method and applications must control this.
Exceptions
ExceptionIt throws an exception if any plugin can not be loaded.
Note
This method will unload all previously loaded plugins.
If a plugin load fails this method will add it to the list of broken plugins and continues. In this case at the end an exception is thrown.
void te::plugin::PluginManager::moveDependentsToBrokenList ( const std::string &  plugin,
const bool &  unloadPlugin = false 
)
protected
void te::plugin::PluginManager::moveToBrokenList ( const PluginInfo pInfo)
protected
void te::plugin::PluginManager::remove ( const std::string &  plugin)
void te::plugin::PluginManager::removeFromBrokenList ( const PluginInfo pInfo)
protected
void te::plugin::PluginManager::removeFromCategory ( AbstractPlugin plugin,
const std::string &  category 
)
protected

It removes the given plugin from the category and then updates the internal category index.

Parameters
pluginThe plugin to be removed from the given category.
categoryThe categpry to be updated.
void te::plugin::PluginManager::removeFromUnloadedList ( const PluginInfo pInfo)
protected
void te::plugin::PluginManager::setBrokenPlugins ( boost::ptr_vector< te::plugin::PluginInfo brokenPlugins)

*brief It sets a list of broken plugins.

void te::plugin::PluginManager::setUnloadedPlugins ( boost::ptr_vector< te::plugin::PluginInfo unloadedPlugins)

*brief It sets a list of unloaded plugins.

void te::plugin::PluginManager::shutdownAll ( )

It try to shutdown all plugins.

This method calls shutdown for all managed plugins.

Exceptions
Itwill raise an exception if it is not possible to shutdown a plugin.
void te::plugin::PluginManager::sort ( boost::ptr_vector< PluginInfo > &  plugins) const
protected

It sorts the plugins according to their dependency.

void te::plugin::PluginManager::unload ( const std::string &  name)

It tries to unload a given plugin.

This method will call plugin's shutdown method if needed.

Parameters
nameThe plugin to be unloaded.
Exceptions
Itwill raise an exception if plugin's code is not unloaded, if it fails to shutdown or if the plugin's is not managed by PluginManager.
void te::plugin::PluginManager::unload ( AbstractPlugin plugin)

It tries to unload a given plugin.

This method will call plugin's shutdown method if needed.

Parameters
pluginThe plugin to be unloaded. The pointer will be invalidated if it acomplishes the task.
Exceptions
Itwill raise an exception if plugin's code is not unloaded or if it fails to shutdown.
Note
It doesn't throw exceptions if the plugin is not managed by the manager.
void te::plugin::PluginManager::unloadAll ( )

It try to unload all plugins.

This method will call shutdown for all managed plugins.

Exceptions
Itwill raise an exception if it is not possible to unload a plugin.
void te::plugin::PluginManager::updateDependents ( const std::string &  plugin)
protected

Friends And Related Function Documentation

friend class te::common::Singleton< PluginManager >
friend

Definition at line 63 of file PluginManager.h.

Member Data Documentation

boost::ptr_vector<PluginInfo> te::plugin::PluginManager::m_brokenPlugins
private

The list of plugins that could not be loaded.

Definition at line 361 of file PluginManager.h.

std::vector<AbstractFinder*> te::plugin::PluginManager::m_finders
private

The list of plugin finders.

Definition at line 356 of file PluginManager.h.

std::map<std::string, std::vector<AbstractPlugin*> > te::plugin::PluginManager::m_pluginCategoryMap
private

A map from (plugin category) to (plugins in category)

Definition at line 359 of file PluginManager.h.

std::vector<AbstractPlugin*> te::plugin::PluginManager::m_plugins
private

The list of managed plugins: this will be need to unload accordinly the plugins!

Definition at line 357 of file PluginManager.h.

std::map<std::string, AbstractPlugin*> te::plugin::PluginManager::m_pluginsMap
private

A map from (plugin's name) to (plugin instance).

Definition at line 358 of file PluginManager.h.

boost::ptr_vector<PluginInfo> te::plugin::PluginManager::m_unloadedPlugins
private

The list of plugins that are not loaded.

Definition at line 360 of file PluginManager.h.


The documentation for this class was generated from the following file: