A singleton for managing plugins. More...
#include <PluginManager.h>
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... | |
AbstractPlugin * | detach (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 PluginInfo & | getPlugin (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 PluginManager & | getInstance () |
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< PluginInfo > | m_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< PluginInfo > | m_unloadedPlugins |
The list of plugins that are not loaded. More... | |
Friends | |
class | te::common::Singleton< PluginManager > |
A singleton for managing plugins.
Definition at line 61 of file PluginManager.h.
|
private |
It creates a new plugin.
|
private |
Singleton destructor.
void te::plugin::PluginManager::add | ( | const PluginInfo & | plugin | ) |
Adds plug-in to unload list.
plugin | Information of the plug-in. |
void te::plugin::PluginManager::add | ( | PluginInfo * | plugin | ) |
Adds plugin to unload list and take its ownership.
plugin | Information of the plug-in. |
void te::plugin::PluginManager::addCategory | ( | const std::string & | name | ) |
Add a new category type.
name | The 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.
pluginName | The plugin name. |
Exception | If there are plugins that depends on the plugin being detached or if the plugin is not found this method raises an exception. |
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.
A | vector 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.
pluginName | The plugin to be checked. |
|
staticinherited |
It 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.
const PluginInfo& te::plugin::PluginManager::getPlugin | ( | const std::string & | name | ) | const |
It returns the plugin identified by the given name.
name | The plugin name. |
Exception | It 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.
plugins | A vector to output the name of plugins managed by this singleton. |
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.
pluginName | The plugin to be checked. |
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.
pname | The plugin name to be checked. |
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.
plugins | A list with plugin names to be checked. |
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.
plugins | The list of plugins to be loaded |
start | If true it will try to startup the plugin if false it doesn't automatically call plugin startup method. |
Exception | It throws an exception if any plugin can not be loaded or started. |
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.
pInfo | Information about the plugin to be loaded. |
start | If true it will try to startup the plugin if false it doesn't automatically call plugin startup method. |
Exception | It throws an exception if something goes wrong during plugin load. |
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.
start | If true it will try to startup the plugins if false it doesn't automatically call plugins startup method and applications must control this. |
Exception | It throws an exception if any plugin can not be loaded. |
|
protected |
|
protected |
void te::plugin::PluginManager::remove | ( | const std::string & | plugin | ) |
|
protected |
|
protected |
It removes the given plugin from the category and then updates the internal category index.
plugin | The plugin to be removed from the given category. |
category | The categpry to be updated. |
|
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.
It | will raise an exception if it is not possible to shutdown a plugin. |
|
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.
name | The plugin to be unloaded. |
It | will 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.
plugin | The plugin to be unloaded. The pointer will be invalidated if it acomplishes the task. |
It | will raise an exception if plugin's code is not unloaded or if it fails to shutdown. |
void te::plugin::PluginManager::unloadAll | ( | ) |
It try to unload all plugins.
This method will call shutdown for all managed plugins.
It | will raise an exception if it is not possible to unload a plugin. |
|
protected |
|
friend |
Definition at line 63 of file PluginManager.h.
|
private |
The list of plugins that could not be loaded.
Definition at line 361 of file PluginManager.h.
|
private |
The list of plugin finders.
Definition at line 356 of file PluginManager.h.
|
private |
A map from (plugin category) to (plugins in category)
Definition at line 359 of file PluginManager.h.
|
private |
The list of managed plugins: this will be need to unload accordinly the plugins!
Definition at line 357 of file PluginManager.h.
|
private |
A map from (plugin's name) to (plugin instance).
Definition at line 358 of file PluginManager.h.
|
private |
The list of plugins that are not loaded.
Definition at line 360 of file PluginManager.h.