|
MarlinMT
0.1.0
|
PluginManager singleton class Responsible for loading shared libraries and collecting processor factory instances. More...
#include <PluginManager.h>
Classes | |
| struct | FactoryData |
Public Types | |
| using | FactoryFunction = std::any |
| template<typename B > | |
| using | FactoryFunctionT = std::function< std::unique_ptr< B >()> |
| typedef std::map< std::string, FactoryData > | PluginFactoryMap |
| typedef std::map< std::filesystem::path, void * > | LibraryList |
| typedef Logging::Logger | Logger |
| typedef std::recursive_mutex | mutex_type |
| typedef std::lock_guard< mutex_type > | lock_type |
Public Member Functions | |
| template<typename B , typename T > | |
| void | registerPlugin (const std::string &name, bool ignoreDuplicate=false) |
| Register a new plugin to the manager. More... | |
| void | registerPlugin (const std::string &name, FactoryFunction factoryFunction, bool ignoreDuplicate=false) |
| Register a new plugin to the manager. More... | |
| void | loadLibrary (const std::string &library) |
| Load a shared library to populate the list of plugins. More... | |
| void | loadLibraries (const std::vector< std::string > &libraries) |
| Load shared libraries to populate the list of plugins. More... | |
| std::vector< std::string > | pluginNames () const |
| Get all registered plugin name. More... | |
| template<typename Base > | |
| std::vector< std::string > | pluginNames () const |
| Get all registered plugin name with the Base type. More... | |
| bool | pluginRegistered (const std::string &name) const |
| Whether the plugin with of a given name is registered. More... | |
| template<typename T > | |
| std::unique_ptr< T > | create (const std::string &name) const |
| Create a new plugin instance. More... | |
| void | dump () const |
| Dump plugin manager content in console. More... | |
| Logger | logger () const |
| Get the plugin manager logger. More... | |
Static Public Member Functions | |
| static PluginManager & | instance () |
| Get the plugin manager instance. More... | |
Private Member Functions | |
| PluginManager (const PluginManager &)=delete | |
| PluginManager & | operator= (const PluginManager &)=delete |
| ~PluginManager ()=default | |
| PluginManager () | |
| Constructor. More... | |
| void | doLoadLibrary (const std::string &library) |
| the workhorse ! More... | |
Private Attributes | |
| PluginFactoryMap | _pluginFactories {} |
| The map of plugin factories. More... | |
| LibraryList | _libraries {} |
| The list of loaded libraries. More... | |
| Logger | _logger {nullptr} |
| The plugin manager logger. More... | |
| mutex_type | _mutex {} |
| The synchronization mutex. More... | |
| std::string | _currentLibrary {} |
| The current library being loaded. More... | |
PluginManager singleton class Responsible for loading shared libraries and collecting processor factory instances.
Processor instances can be created from factories using the PluginManager::create() method on query.
Definition at line 64 of file PluginManager.h.
| using marlinmt::PluginManager::FactoryFunction = std::any |
Definition at line 67 of file PluginManager.h.
| using marlinmt::PluginManager::FactoryFunctionT = std::function<std::unique_ptr<B>()> |
Definition at line 69 of file PluginManager.h.
| typedef std::map<std::filesystem::path, void*> marlinmt::PluginManager::LibraryList |
Definition at line 81 of file PluginManager.h.
| typedef std::lock_guard<mutex_type> marlinmt::PluginManager::lock_type |
Definition at line 84 of file PluginManager.h.
Definition at line 82 of file PluginManager.h.
| typedef std::recursive_mutex marlinmt::PluginManager::mutex_type |
Definition at line 83 of file PluginManager.h.
| typedef std::map<std::string, FactoryData> marlinmt::PluginManager::PluginFactoryMap |
Definition at line 80 of file PluginManager.h.
|
privatedelete |
|
privatedefault |
|
private |
Constructor.
Definition at line 15 of file PluginManager.cc.
References _logger, and marlinmt::Logging::createLogger().
|
inline |
Create a new plugin instance.
A factory function must have been registered before hand. The template parameter T is the final plugin type requested by the caller.
| name | the plugin name |
Definition at line 230 of file PluginManager.h.
References _mutex, and _pluginFactories.
Referenced by marlinmt::ConfigHelper::readConfig(), and marlinmt::ConfigHelper::writeConfig().
|
private |
the workhorse !
Definition at line 109 of file PluginManager.cc.
References _currentLibrary, _libraries, _logger, and MARLINMT_THROW.
Referenced by loadLibraries(), and loadLibrary().
| void marlinmt::PluginManager::dump | ( | ) | const |
Dump plugin manager content in console.
Definition at line 79 of file PluginManager.cc.
References _logger, _mutex, and _pluginFactories.
|
static |
Get the plugin manager instance.
Definition at line 56 of file PluginManager.cc.
Referenced by marlinmt::SuperSequence::addProcessor(), marlinmt::GeometryManager::initialize(), marlinmt::ConfigHelper::readConfig(), and marlinmt::ConfigHelper::writeConfig().
| void marlinmt::PluginManager::loadLibraries | ( | const std::vector< std::string > & | libraries | ) |
Load shared libraries to populate the list of plugins.
| libraries | the list of libraries to load |
Definition at line 70 of file PluginManager.cc.
References _mutex, and doLoadLibrary().
| void marlinmt::PluginManager::loadLibrary | ( | const std::string & | library | ) |
Load a shared library to populate the list of plugins.
| library | the library to load |
Definition at line 63 of file PluginManager.cc.
References _mutex, and doLoadLibrary().
| PluginManager::Logger marlinmt::PluginManager::logger | ( | ) | const |
|
privatedelete |
| std::vector< std::string > marlinmt::PluginManager::pluginNames | ( | ) | const |
Get all registered plugin name.
Definition at line 42 of file PluginManager.cc.
References _mutex, _pluginFactories, and marlinmt::details::keys().
|
inline |
Get all registered plugin name with the Base type.
Definition at line 213 of file PluginManager.h.
References _pluginFactories.
| bool marlinmt::PluginManager::pluginRegistered | ( | const std::string & | name | ) | const |
Whether the plugin with of a given name is registered.
| name | the plugin name to check |
Definition at line 49 of file PluginManager.cc.
References _mutex, and _pluginFactories.
|
inline |
Register a new plugin to the manager.
A new factory function creating an object of type T is inserted into the registry. The type T must be default constructible. If you want to provide a custom factory function, use the corresponding overloaded function. If the flag ignoreDuplicate is set to true, no exception is thrown in case a duplicate is found in the registry. In this case, the registry is not modified.
| name | the plugin name |
| ignoreDuplicate | whether to avoid exception throw in case of duplicate entry |
Definition at line 202 of file PluginManager.h.
| void marlinmt::PluginManager::registerPlugin | ( | const std::string & | name, |
| FactoryFunction | factoryFunction, | ||
| bool | ignoreDuplicate = false |
||
| ) |
Register a new plugin to the manager.
See overloaded function description for more details
| name | the plugin name |
| factoryFunction | the factory function responsible for the plugin creation |
| ignoreDuplicate | whether to avoid exception throw in case of duplicate entry |
Definition at line 22 of file PluginManager.cc.
References _currentLibrary, marlinmt::PluginManager::FactoryData::_libraryName, _logger, _mutex, _pluginFactories, and MARLINMT_THROW.
|
private |
The current library being loaded.
Definition at line 195 of file PluginManager.h.
Referenced by doLoadLibrary(), and registerPlugin().
|
private |
The list of loaded libraries.
Definition at line 189 of file PluginManager.h.
Referenced by doLoadLibrary().
|
mutableprivate |
The plugin manager logger.
Definition at line 191 of file PluginManager.h.
Referenced by doLoadLibrary(), dump(), logger(), PluginManager(), and registerPlugin().
|
mutableprivate |
The synchronization mutex.
Definition at line 193 of file PluginManager.h.
Referenced by create(), dump(), loadLibraries(), loadLibrary(), pluginNames(), pluginRegistered(), and registerPlugin().
|
private |
The map of plugin factories.
Definition at line 187 of file PluginManager.h.
Referenced by create(), dump(), pluginNames(), pluginRegistered(), and registerPlugin().