MarlinMT  0.1.0
marlinmt::PluginManager Class Reference

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, FactoryDataPluginFactoryMap
 
typedef std::map< std::filesystem::path, void * > LibraryList
 
typedef Logging::Logger Logger
 
typedef std::recursive_mutex mutex_type
 
typedef std::lock_guard< mutex_typelock_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 PluginManagerinstance ()
 Get the plugin manager instance. More...
 

Private Member Functions

 PluginManager (const PluginManager &)=delete
 
PluginManageroperator= (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...
 

Detailed Description

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.

Member Typedef Documentation

◆ FactoryFunction

Definition at line 67 of file PluginManager.h.

◆ FactoryFunctionT

template<typename B >
using marlinmt::PluginManager::FactoryFunctionT = std::function<std::unique_ptr<B>()>

Definition at line 69 of file PluginManager.h.

◆ LibraryList

typedef std::map<std::filesystem::path, void*> marlinmt::PluginManager::LibraryList

Definition at line 81 of file PluginManager.h.

◆ lock_type

Definition at line 84 of file PluginManager.h.

◆ Logger

◆ mutex_type

typedef std::recursive_mutex marlinmt::PluginManager::mutex_type

Definition at line 83 of file PluginManager.h.

◆ PluginFactoryMap

Definition at line 80 of file PluginManager.h.

Constructor & Destructor Documentation

◆ PluginManager() [1/2]

marlinmt::PluginManager::PluginManager ( const PluginManager )
privatedelete

◆ ~PluginManager()

marlinmt::PluginManager::~PluginManager ( )
privatedefault

◆ PluginManager() [2/2]

marlinmt::PluginManager::PluginManager ( )
private

Constructor.

Definition at line 15 of file PluginManager.cc.

References _logger, and marlinmt::Logging::createLogger().

Member Function Documentation

◆ create()

template<typename T >
std::unique_ptr< T > marlinmt::PluginManager::create ( const std::string &  name) const
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.

Parameters
namethe plugin name

Definition at line 230 of file PluginManager.h.

References _mutex, and _pluginFactories.

Referenced by marlinmt::ConfigHelper::readConfig(), and marlinmt::ConfigHelper::writeConfig().

◆ doLoadLibrary()

void marlinmt::PluginManager::doLoadLibrary ( const std::string &  library)
private

the workhorse !

Definition at line 109 of file PluginManager.cc.

References _currentLibrary, _libraries, _logger, and MARLINMT_THROW.

Referenced by loadLibraries(), and loadLibrary().

◆ dump()

void marlinmt::PluginManager::dump ( ) const

Dump plugin manager content in console.

Definition at line 79 of file PluginManager.cc.

References _logger, _mutex, and _pluginFactories.

◆ instance()

PluginManager & marlinmt::PluginManager::instance ( )
static

◆ loadLibraries()

void marlinmt::PluginManager::loadLibraries ( const std::vector< std::string > &  libraries)

Load shared libraries to populate the list of plugins.

Parameters
librariesthe list of libraries to load

Definition at line 70 of file PluginManager.cc.

References _mutex, and doLoadLibrary().

◆ loadLibrary()

void marlinmt::PluginManager::loadLibrary ( const std::string &  library)

Load a shared library to populate the list of plugins.

Parameters
librarythe library to load

Definition at line 63 of file PluginManager.cc.

References _mutex, and doLoadLibrary().

◆ logger()

PluginManager::Logger marlinmt::PluginManager::logger ( ) const

Get the plugin manager logger.

Definition at line 103 of file PluginManager.cc.

References _logger.

◆ operator=()

PluginManager& marlinmt::PluginManager::operator= ( const PluginManager )
privatedelete

◆ pluginNames() [1/2]

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().

◆ pluginNames() [2/2]

template<typename Base >
std::vector< std::string > marlinmt::PluginManager::pluginNames ( ) const
inline

Get all registered plugin name with the Base type.

Definition at line 213 of file PluginManager.h.

References _pluginFactories.

◆ pluginRegistered()

bool marlinmt::PluginManager::pluginRegistered ( const std::string &  name) const

Whether the plugin with of a given name is registered.

Parameters
namethe plugin name to check

Definition at line 49 of file PluginManager.cc.

References _mutex, and _pluginFactories.

◆ registerPlugin() [1/2]

template<typename B , typename T >
void marlinmt::PluginManager::registerPlugin ( const std::string &  name,
bool  ignoreDuplicate = false 
)
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.

Parameters
namethe plugin name
ignoreDuplicatewhether to avoid exception throw in case of duplicate entry

Definition at line 202 of file PluginManager.h.

◆ registerPlugin() [2/2]

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

Parameters
namethe plugin name
factoryFunctionthe factory function responsible for the plugin creation
ignoreDuplicatewhether 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.

Member Data Documentation

◆ _currentLibrary

std::string marlinmt::PluginManager::_currentLibrary {}
private

The current library being loaded.

Definition at line 195 of file PluginManager.h.

Referenced by doLoadLibrary(), and registerPlugin().

◆ _libraries

LibraryList marlinmt::PluginManager::_libraries {}
private

The list of loaded libraries.

Definition at line 189 of file PluginManager.h.

Referenced by doLoadLibrary().

◆ _logger

Logger marlinmt::PluginManager::_logger {nullptr}
mutableprivate

The plugin manager logger.

Definition at line 191 of file PluginManager.h.

Referenced by doLoadLibrary(), dump(), logger(), PluginManager(), and registerPlugin().

◆ _mutex

mutex_type marlinmt::PluginManager::_mutex {}
mutableprivate

The synchronization mutex.

Definition at line 193 of file PluginManager.h.

Referenced by create(), dump(), loadLibraries(), loadLibrary(), pluginNames(), pluginRegistered(), and registerPlugin().

◆ _pluginFactories

PluginFactoryMap marlinmt::PluginManager::_pluginFactories {}
private

The map of plugin factories.

Definition at line 187 of file PluginManager.h.

Referenced by create(), dump(), pluginNames(), pluginRegistered(), and registerPlugin().


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