Belle II Software development
|
The ModuleManager Class. More...
#include <ModuleManager.h>
Public Member Functions | |
void | registerModuleProxy (ModuleProxyBase *moduleProxy) |
Registers a module proxy. | |
void | addModuleSearchPath (const std::string &path) |
Adds a new filepath to the list of filepaths which are searched for a requested module. | |
const std::list< std::string > & | getModuleSearchPaths () const |
Returns a reference to the list of the modules search filepaths. | |
const std::map< std::string, std::string > & | getAvailableModules () const |
Returns a map of all modules that were found in the module search paths. | |
std::shared_ptr< Module > | registerModule (const std::string &moduleName, std::string sharedLibPath="") noexcept(false) |
Creates an instance of a module and registers it to the ModuleManager. | |
const std::list< std::shared_ptr< Module > > & | getCreatedModules () const |
Returns a reference to the list of created modules. | |
void | reset () |
Delete all created modules. | |
Static Public Member Functions | |
static ModuleManager & | Instance () |
Exception is thrown if the requested module could not be created by the ModuleManager. | |
static std::list< std::shared_ptr< Module > > | getModulesByProperties (const std::list< std::shared_ptr< Module > > &modulePathList, unsigned int propertyFlags) |
Returns a list of those modules which carry property flags matching the specified ones. | |
static bool | allModulesHaveFlag (const std::list< std::shared_ptr< Module > > &list, unsigned int flag) |
Returns true if and only if all modules in list have the given flag (or list is empty). | |
Private Member Functions | |
ModuleManager () | |
The constructor is hidden to avoid that someone creates an instance of this class. | |
ModuleManager (const ModuleManager &) | |
Disable/Hide the copy constructor. | |
ModuleManager & | operator= (const ModuleManager &) |
Disable/Hide the copy assignment operator. | |
~ModuleManager () | |
The ModuleManager destructor. | |
Static Private Member Functions | |
static void | fillModuleNameLibMap (std::map< std::string, std::string > &moduleNameLibMap, const std::filesystem::directory_entry &mapPath) |
Adds the module names defined in the map file to the list of known module names. | |
Private Attributes | |
std::list< std::string > | m_moduleSearchPathList |
List of all checked and validated filepaths that are searched for map files. | |
std::map< std::string, std::string > | m_moduleNameLibMap |
Maps the module name to the filename of the shared library which containes the module. | |
std::map< std::string, ModuleProxyBase * > | m_registeredProxyMap |
Maps the module name to a pointer of its proxy. | |
std::list< std::shared_ptr< Module > > | m_createdModulesList |
List of all created modules. | |
The ModuleManager Class.
This class is responsible for creating and managing new module instances. The module manager can only find those modules, whose shared library files are located in one of the directories known to the module manager. Directories can be added to the directory list with the method addModuleSearchPath(). By adding a new directory, the directory is searched for *.map files which specify the kind of modules that can be found in the shared library files. The map files are parsed and the found modules are added to an internal list.
If a shared library is loaded by the module manager, all modules inside the library automatically register themselves to the module manager. This is done by a so-called proxy class. Each module has a proxy class attached to it, which does the registration with the module manager and is later used to create the actual instance of the module. By using a proxy class, the module itself is only instantiated if the user requests it.
The creation of a new module instance works as following: 1) The user requests a new module by calling the method registerModule() with the module name given as a parameter.
2) The ModuleManager checks if a proxy class was already registered for the given module name. If yes, the proxy creates a new module instance. Otherwise the modules known to the manager are searched for the given module name. If the module is known to the module manager the associated shared library is dynamically loaded.
This class is designed as a singleton.
Definition at line 53 of file ModuleManager.h.
|
privatedefault |
The ModuleManager destructor.
Deletes the ModuleManager.
void addModuleSearchPath | ( | const std::string & | path | ) |
Adds a new filepath to the list of filepaths which are searched for a requested module.
If a module is requested by the method registerModule(), all module search paths are scanned for the first occurrence of a shared library carrying the module name in its filename. E.g modules in the path added with the first call to addModuleSearchPath() will take precedence over those added later on.
path | The module search path which should be added to the list of paths. |
Definition at line 43 of file ModuleManager.cc.
|
static |
Returns true if and only if all modules in list have the given flag (or list is empty).
Definition at line 140 of file ModuleManager.cc.
|
staticprivate |
Adds the module names defined in the map file to the list of known module names.
If the given map already contains this module, an error is raised
moduleNameLibMap | map to be filled. |
mapPath | The filename (path+name) of the map file which should be parsed for module names. |
Definition at line 154 of file ModuleManager.cc.
const map< string, string > & getAvailableModules | ( | ) | const |
Returns a map of all modules that were found in the module search paths.
The key of the map represents the module name and the value the shared library file in which the module is defined.
Definition at line 74 of file ModuleManager.cc.
const ModulePtrList & getCreatedModules | ( | ) | const |
Returns a reference to the list of created modules.
Definition at line 124 of file ModuleManager.cc.
|
static |
Returns a list of those modules which carry property flags matching the specified ones.
Loops over all module instances specified in a list and adds those to the returned list whose property flags match the given property flags.
modulePathList | The list containing all module instances added to a path. |
propertyFlags | The flags for the module properties. |
Definition at line 130 of file ModuleManager.cc.
const list< string > & getModuleSearchPaths | ( | ) | const |
Returns a reference to the list of the modules search filepaths.
Definition at line 68 of file ModuleManager.cc.
|
static |
Exception is thrown if the requested module could not be created by the ModuleManager.
Static method to get a reference to the ModuleManager instance.
Definition at line 24 of file ModuleManager.cc.
ModulePtr registerModule | ( | const std::string & | moduleName, |
std::string | sharedLibPath = "" |
||
) |
Creates an instance of a module and registers it to the ModuleManager.
Each module carries an unique name, which is used to find the corresponding shared library file. The found shared library is dynamically loaded and the module proxy registered. Using the proxy an instance of the module is created and returned.
The search order is as following:
1) First the method checks if a proxy associated with the module name was already registered
2) If not, the method checks if a shared library path was given and tries to load the module from that shared library
3) If not, the method searches for the module name in the map of known modules due to the given search paths
moduleName | The unique name of the Module which should be created. |
sharedLibPath | Optional: The shared library from which the module should be registered (not a map file!). |
Definition at line 80 of file ModuleManager.cc.
void registerModuleProxy | ( | ModuleProxyBase * | moduleProxy | ) |
Registers a module proxy.
Each module has a proxy assigned to it, which registers itself to the ModuleManager. The proxy is then responsible to create an instance of a module.
moduleProxy | Pointer to the module proxy which should be registered. |
Definition at line 31 of file ModuleManager.cc.
void reset | ( | ) |
Delete all created modules.
Definition at line 199 of file ModuleManager.cc.
|
private |
List of all created modules.
Definition at line 159 of file ModuleManager.h.
|
private |
Maps the module name to the filename of the shared library which containes the module.
Definition at line 156 of file ModuleManager.h.
|
private |
List of all checked and validated filepaths that are searched for map files.
Definition at line 153 of file ModuleManager.h.
|
private |
Maps the module name to a pointer of its proxy.
Definition at line 158 of file ModuleManager.h.