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 | 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.
Definition at line 688 of file PluginManager.cpp.
|
private |
Singleton destructor.
Definition at line 692 of file PluginManager.cpp.
References te::common::FreeContents().
void te::plugin::PluginManager::add | ( | const PluginInfo & | plugin | ) |
Adds plug-in to unload list.
plugin | Information of the plug-in. |
Definition at line 394 of file 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 399 of file PluginManager.cpp.
void te::plugin::PluginManager::addCategory | ( | const std::string & | name | ) |
Add a new category type.
name | The category name. |
Definition at line 517 of file PluginManager.cpp.
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 179 of file PluginManager.cpp.
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 470 of file PluginManager.cpp.
References te::plugin::AbstractPlugin::getInfo(), te::plugin::PluginInfo::m_category, and TE_TR.
Referenced by te::plugin::Module::initialize().
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 99 of file PluginManager.cpp.
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 505 of file PluginManager.cpp.
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 436 of file PluginManager.cpp.
|
staticinherited |
It returns a reference to the singleton instance.
Referenced by te::qt::widgets::PluginManagerDialog::addEntry(), CheckLoadedDependencies(), CheckRequiredDependencies(), te::qt::widgets::PluginManagerDialog::fillInstalledPlugins(), te::plugin::Module::finalize(), te::qt::af::ApplicationController::finalize(), te::plugin::Module::initialize(), te::qt::af::ApplicationController::initializePlugins(), te::tools::dscopy::Utils::loadModules(), Utils::loadModules(), te::tools::rastermanager::Utils::loadModules(), te::idl::loadTerralibModules(), MakeAdd(), MakeDisable(), MakeEnable(), MakeRemove(), te::plugin::Module::Module(), te::qt::widgets::PluginBuilderWizard::PluginBuilderWizard(), PluginExists(), and te::qt::af::UpdateUserSettings().
std::size_t te::plugin::PluginManager::getNumPlugins | ( | ) | const |
It returns the number of plugins kept in the manager.
Definition at line 378 of file PluginManager.cpp.
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 PluginManager.cpp.
Referenced by te::qt::widgets::PluginManagerDialog::fillInstalledPlugins().
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 PluginManager.cpp.
References m_brokenPlugins, m_plugins, and m_unloadedPlugins.
Referenced by te::qt::widgets::PluginManagerDialog::fillInstalledPlugins().
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 PluginManager.cpp.
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 465 of file PluginManager.cpp.
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 104 of file PluginManager.cpp.
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 122 of file PluginManager.cpp.
Referenced by te::qt::widgets::PluginManagerDialog::fillInstalledPlugins().
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 383 of file PluginManager.cpp.
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 113 of file PluginManager.cpp.
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 186 of file PluginManager.cpp.
References te::plugin::PluginInfo::m_name, and TE_TR.
Referenced by te::plugin::Module::initialize().
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 215 of file PluginManager.cpp.
References te::common::Singleton< TerraLib >::getInstance(), TerraLib::getNumRegModules(), TerraLib::initialize(), te::plugin::PluginInfo::m_category, te::plugin::PluginInfo::m_engine, te::plugin::PluginInfo::m_name, te::plugin::PluginInfo::m_requiredPlugins, te::common::AbstractFactory< AbstractPluginEngine, std::string >::make(), and TE_TR.
void te::plugin::PluginManager::load | ( | const std::string & | pluginName | ) |
Definition at line 300 of file PluginManager.cpp.
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 127 of file PluginManager.cpp.
References te::plugin::DefaultFinder::getPlugins().
|
protected |
Definition at line 640 of file PluginManager.cpp.
References te::plugin::PluginInfo::m_name.
|
protected |
Definition at line 607 of file PluginManager.cpp.
void te::plugin::PluginManager::remove | ( | const std::string & | plugin | ) |
Definition at line 414 of file PluginManager.cpp.
References te::plugin::AbstractPlugin::shutdown().
|
protected |
Definition at line 616 of file PluginManager.cpp.
References te::plugin::PluginInfo::m_name.
|
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 582 of file PluginManager.cpp.
|
protected |
Definition at line 628 of file PluginManager.cpp.
References te::plugin::PluginInfo::m_name.
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 364 of file PluginManager.cpp.
|
protected |
It sorts the plugins according to their dependency.
Definition at line 528 of file PluginManager.cpp.
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 305 of file PluginManager.cpp.
Referenced by te::plugin::Module::finalize().
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 320 of file PluginManager.cpp.
References te::plugin::AbstractPlugin::getInfo(), te::plugin::AbstractPlugin::isStarted(), te::plugin::PluginInfo::m_category, te::plugin::PluginInfo::m_engine, te::plugin::PluginInfo::m_name, te::common::AbstractFactory< AbstractPluginEngine, std::string >::make(), 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 160 of file PluginManager.cpp.
Referenced by te::plugin::Module::finalize().
|
protected |
Definition at line 666 of file PluginManager.cpp.
|
friend |
Definition at line 63 of file PluginManager.h.
|
private |
The list of plugins that could not be loaded.
Definition at line 355 of file PluginManager.h.
Referenced by getPlugins().
|
private |
The list of plugin finders.
Definition at line 350 of file PluginManager.h.
|
private |
A map from (plugin category) to (plugins in category)
Definition at line 353 of file PluginManager.h.
|
private |
The list of managed plugins: this will be need to unload accordinly the plugins!
Definition at line 351 of file PluginManager.h.
Referenced by getPlugins().
|
private |
A map from (plugin's name) to (plugin instance).
Definition at line 352 of file PluginManager.h.
|
private |
The list of plugins that are not loaded.
Definition at line 354 of file PluginManager.h.
Referenced by getPlugins().