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 attic/src/plugin/PluginManager.h.
|
private |
It creates a new plugin.
Definition at line 699 of file attic/src/plugin/PluginManager.cpp.
|
private |
Singleton destructor.
Definition at line 703 of file attic/src/plugin/PluginManager.cpp.
References te::common::FreeContents(), m_finders, and m_plugins.
| void te::plugin::PluginManager::add | ( | const PluginInfo & | plugin | ) |
Adds plug-in to unload list.
| plugin | Information of the plug-in. |
Definition at line 405 of file attic/src/plugin/PluginManager.cpp.
| void te::plugin::PluginManager::add | ( | PluginInfo * | plugin | ) |
Adds plugin to unload list and take its ownership.
| plugin | Information of the plug-in. |
Definition at line 410 of file attic/src/plugin/PluginManager.cpp.
References m_unloadedPlugins.
| void te::plugin::PluginManager::addCategory | ( | const std::string & | name | ) |
Add a new category type.
| name | The category name. |
Definition at line 528 of file attic/src/plugin/PluginManager.cpp.
References m_pluginCategoryMap.
| 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.
Definition at line 189 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, m_unloadedPlugins, and unloadAll().
| te::plugin::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. |
Definition at line 481 of file attic/src/plugin/PluginManager.cpp.
References te::plugin::AbstractPlugin::getInfo(), hasDependents(), te::plugin::PluginInfo::m_category, m_plugins, m_pluginsMap, moveDependentsToBrokenList(), p, removeFromCategory(), and TE_TR.
Referenced by remove().
| const boost::ptr_vector< te::plugin::PluginInfo > & te::plugin::PluginManager::getBrokenPlugins | ( | ) | const |
It returns the list of plugins that could not be loaded.
Definition at line 104 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins.
Referenced by updateDependents().
| 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. |
Definition at line 516 of file attic/src/plugin/PluginManager.cpp.
References m_pluginCategoryMap.
| 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. |
Definition at line 447 of file attic/src/plugin/PluginManager.cpp.
References m_plugins.
Referenced by hasDependents(), and moveDependentsToBrokenList().
|
staticinherited |
It returns a reference to the singleton instance.
Referenced by LoadDrivers(), LoadModules(), te::tools::dscopy::Utils::loadModules(), Utils::loadModules(), te::tools::rastermanager::Utils::loadModules(), te::idl::loadTerralibModules(), and main().
| std::size_t te::plugin::PluginManager::getNumPlugins | ( | ) | const |
It returns the number of plugins kept in the manager.
Definition at line 389 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, m_pluginsMap, and m_unloadedPlugins.
| const te::plugin::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. |
Definition at line 71 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, m_pluginsMap, and m_unloadedPlugins.
Referenced by load(), moveDependentsToBrokenList(), and remove().
| 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. |
Definition at line 52 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, m_plugins, and m_unloadedPlugins.
Referenced by loadAll().
| const boost::ptr_vector< te::plugin::PluginInfo > & te::plugin::PluginManager::getUnloadedPlugins | ( | ) | const |
It returns the list of plugins that are not loaded.
Definition at line 94 of file attic/src/plugin/PluginManager.cpp.
References m_unloadedPlugins.
| 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. |
Definition at line 476 of file attic/src/plugin/PluginManager.cpp.
References getDependents().
| bool te::plugin::PluginManager::isBrokenPlugin | ( | const std::string & | pluginName | ) | const |
It returns true if the plugin is in the broken list of plugins.
Definition at line 114 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins.
Referenced by moveDependentsToBrokenList().
| 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. |
Definition at line 132 of file attic/src/plugin/PluginManager.cpp.
References m_pluginsMap.
Referenced by isLoaded(), load(), moveDependentsToBrokenList(), remove(), and updateDependents().
| 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. |
Definition at line 394 of file attic/src/plugin/PluginManager.cpp.
References isLoaded().
| bool te::plugin::PluginManager::isUnloadedPlugin | ( | const std::string & | pluginName | ) | const |
It returns true if the plugin is in the not-loaded list of plugins.
Definition at line 123 of file attic/src/plugin/PluginManager.cpp.
References m_unloadedPlugins.
Referenced by remove().
| 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. |
Definition at line 196 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, te::plugin::PluginInfo::m_name, sort(), and TE_TR.
| 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. |
Definition at line 225 of file attic/src/plugin/PluginManager.cpp.
References te::common::Singleton< TerraLib >::getInstance(), TerraLib::getNumRegModules(), TerraLib::initialize(), isLoaded(), te::plugin::PluginInfo::m_category, te::plugin::PluginInfo::m_engine, te::plugin::PluginInfo::m_name, m_pluginCategoryMap, m_plugins, m_pluginsMap, te::plugin::PluginInfo::m_requiredPlugins, te::common::AbstractFactory< AbstractPluginEngine, std::string >::make(), moveToBrokenList(), removeFromBrokenList(), removeFromUnloadedList(), TE_TR, and updateDependents().
| void te::plugin::PluginManager::load | ( | const std::string & | pluginName | ) |
Definition at line 310 of file attic/src/plugin/PluginManager.cpp.
References getPlugin(), and load().
| 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. |
Definition at line 137 of file attic/src/plugin/PluginManager.cpp.
References getPlugins(), te::plugin::DefaultFinder::getPlugins(), load(), m_finders, m_unloadedPlugins, and unloadAll().
|
protected |
Definition at line 651 of file attic/src/plugin/PluginManager.cpp.
References getDependents(), getPlugin(), isBrokenPlugin(), isLoaded(), te::plugin::PluginInfo::m_name, moveToBrokenList(), and unload().
|
protected |
Definition at line 618 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, removeFromBrokenList(), and removeFromUnloadedList().
Referenced by load(), and moveDependentsToBrokenList().
| void te::plugin::PluginManager::remove | ( | const std::string & | plugin | ) |
Definition at line 425 of file attic/src/plugin/PluginManager.cpp.
References detach(), getPlugin(), isLoaded(), isUnloadedPlugin(), removeFromBrokenList(), removeFromUnloadedList(), and te::plugin::AbstractPlugin::shutdown().
|
protected |
Definition at line 627 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins, and te::plugin::PluginInfo::m_name.
Referenced by load(), moveToBrokenList(), remove(), and updateDependents().
|
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. |
Definition at line 593 of file attic/src/plugin/PluginManager.cpp.
References m_pluginCategoryMap.
|
protected |
Definition at line 639 of file attic/src/plugin/PluginManager.cpp.
References te::plugin::PluginInfo::m_name, and m_unloadedPlugins.
Referenced by load(), moveToBrokenList(), and remove().
| void te::plugin::PluginManager::setBrokenPlugins | ( | boost::ptr_vector< te::plugin::PluginInfo > | brokenPlugins | ) |
*brief It sets a list of broken plugins.
Definition at line 109 of file attic/src/plugin/PluginManager.cpp.
References m_brokenPlugins.
| void te::plugin::PluginManager::setUnloadedPlugins | ( | boost::ptr_vector< te::plugin::PluginInfo > | unloadedPlugins | ) |
*brief It sets a list of unloaded plugins.
Definition at line 99 of file attic/src/plugin/PluginManager.cpp.
References m_unloadedPlugins.
| 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. |
Definition at line 375 of file attic/src/plugin/PluginManager.cpp.
References m_plugins.
|
protected |
It sorts the plugins according to their dependency.
Definition at line 539 of file attic/src/plugin/PluginManager.cpp.
Referenced by load().
| 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. |
Definition at line 316 of file attic/src/plugin/PluginManager.cpp.
References m_pluginsMap.
Referenced by moveDependentsToBrokenList(), and unloadAll().
| 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. |
Definition at line 331 of file attic/src/plugin/PluginManager.cpp.
References te::plugin::AbstractPlugin::getInfo(), hasDependents(), te::plugin::AbstractPlugin::isStarted(), te::plugin::PluginInfo::m_category, te::plugin::PluginInfo::m_engine, te::plugin::PluginInfo::m_name, m_plugins, m_pluginsMap, m_unloadedPlugins, te::common::AbstractFactory< AbstractPluginEngine, std::string >::make(), moveDependentsToBrokenList(), removeFromCategory(), and te::plugin::AbstractPlugin::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. |
Definition at line 170 of file attic/src/plugin/PluginManager.cpp.
References m_pluginCategoryMap, m_plugins, m_pluginsMap, m_unloadedPlugins, and unload().
|
protected |
Definition at line 677 of file attic/src/plugin/PluginManager.cpp.
References getBrokenPlugins(), isLoaded(), m_unloadedPlugins, and removeFromBrokenList().
Referenced by load().
|
friend |
Definition at line 63 of file attic/src/plugin/PluginManager.h.
|
private |
The list of plugins that could not be loaded.
Definition at line 361 of file attic/src/plugin/PluginManager.h.
Referenced by clear(), getBrokenPlugins(), getNumPlugins(), getPlugin(), getPlugins(), isBrokenPlugin(), load(), moveToBrokenList(), removeFromBrokenList(), and setBrokenPlugins().
|
private |
The list of plugin finders.
Definition at line 356 of file attic/src/plugin/PluginManager.h.
Referenced by loadAll(), and ~PluginManager().
|
private |
A map from (plugin category) to (plugins in category)
Definition at line 359 of file attic/src/plugin/PluginManager.h.
Referenced by addCategory(), getCategories(), load(), removeFromCategory(), and unloadAll().
|
private |
The list of managed plugins: this will be need to unload accordinly the plugins!
Definition at line 357 of file attic/src/plugin/PluginManager.h.
Referenced by detach(), getDependents(), getPlugins(), load(), shutdownAll(), unload(), unloadAll(), and ~PluginManager().
|
private |
A map from (plugin's name) to (plugin instance).
Definition at line 358 of file attic/src/plugin/PluginManager.h.
Referenced by detach(), getNumPlugins(), getPlugin(), isLoaded(), load(), unload(), and unloadAll().
|
private |
The list of plugins that are not loaded.
Definition at line 360 of file attic/src/plugin/PluginManager.h.
Referenced by add(), clear(), getNumPlugins(), getPlugin(), getPlugins(), getUnloadedPlugins(), isUnloadedPlugin(), loadAll(), removeFromUnloadedList(), setUnloadedPlugins(), unload(), unloadAll(), and updateDependents().