Leosac  0.8.0
Open Source Access Control
ModuleManager Class Reference

A second module manager that loads "ZMQ aware" module – modules that talks to the application through message passing. More...

#include <module_manager.hpp>

+ Collaboration diagram for ModuleManager:

Classes

struct  ModuleInfo
 Internal helper struct that store informations related to module that are useful to the module manager. More...
 

Public Member Functions

 ModuleManager (zmqpp::context &ctx, Leosac::Kernel &k)
 Construct the module manager. More...
 
 ~ModuleManager ()
 
void initModules ()
 Actually call the init_module() function of each library we loaded. More...
 
bool initModule (const std::string &name)
 Attempt to find a module using its name, then load it. More...
 
void initModule (ModuleInfo *modinfo)
 Initialize a module. More...
 
void stopModules (bool soft=false)
 Opposite of init module. More...
 
void addToPath (const std::string &dir)
 Add a directory to a path. More...
 
bool loadModule (const std::string &module_name)
 Search the path and load a module based on a property tree for this module. More...
 
std::vector< std::string > modules_names () const
 Returns the list of the name of the loaded modules. More...
 
bool has_module (const std::string &name) const
 Do we have some informations about the module "name". More...
 
const std::vector< std::string > & get_module_path () const
 Return the list of paths where we search for module. More...
 

Private Member Functions

void unloadLibraries ()
 Close library handler. More...
 
bool stopModule (const std::string &name)
 Stop a module by name and remove its config info from the config manager. More...
 
void stopModule (ModuleInfo *modinfo, bool soft=false)
 Stop a specific module and remove its config info from the config manager. More...
 
ModuleInfofind_module_by_name (const std::string &name) const
 
std::shared_ptr< DynamicLibraryload_library_file (const std::string &full_path)
 This will load (actually calling dlopen()) the library file located at full_path. More...
 

Private Attributes

std::vector< std::string > path_
 
std::set< ModuleInfomodules_
 
zmqpp::context & ctx_
 
Leosac::ConfigManagerconfig_manager_
 
Leosac::CoreUtilsPtr core_utils_
 

Detailed Description

A second module manager that loads "ZMQ aware" module – modules that talks to the application through message passing.

A second loader is necessary because the procedure of loading a module differs. No reference to an object is returned when loading a module. The module will lives in its own thread and other components can talk to it.

Note
: Only the ModuleManager object has "direct access" to the module object. It is zmqpp::actor that launches the module in its own thread.
: Use the "level" property to define module initialization order. This initialization order is mandatory, and the lower the value is, the sooner the module is loaded.

Definition at line 54 of file module_manager.hpp.

Constructor & Destructor Documentation

◆ ModuleManager()

ModuleManager::ModuleManager ( zmqpp::context &  ctx,
Leosac::Kernel k 
)

Construct the module manager.

Parameters
ctxthe zeroMQ context to pass around to module.

Definition at line 29 of file module_manager.cpp.

◆ ~ModuleManager()

ModuleManager::~ModuleManager ( )

Definition at line 36 of file module_manager.cpp.

Member Function Documentation

◆ addToPath()

void ModuleManager::addToPath ( const std::string &  dir)

Add a directory to a path.

If the path already exist, it is ignored.

Definition at line 148 of file module_manager.cpp.

◆ find_module_by_name()

ModuleManager::ModuleInfo * ModuleManager::find_module_by_name ( const std::string &  name) const
private

Definition at line 291 of file module_manager.cpp.

◆ get_module_path()

const std::vector< std::string > & ModuleManager::get_module_path ( ) const

Return the list of paths where we search for module.

Definition at line 306 of file module_manager.cpp.

◆ has_module()

bool ModuleManager::has_module ( const std::string &  name) const

Do we have some informations about the module "name".

It returns true if we have it in our modules_ list. Returning true here means that we have a shared library handler, thus meaning the module is loaded (maybe not initialized).

Definition at line 301 of file module_manager.cpp.

◆ initModule() [1/2]

bool ModuleManager::initModule ( const std::string &  name)

Attempt to find a module using its name, then load it.

Returns
false if a module with this name cannot be found. True otherwise.
Note
Even if the module is found, loading it could fail. In that case, an exception would be thrown.

Definition at line 133 of file module_manager.cpp.

◆ initModule() [2/2]

void ModuleManager::initModule ( ModuleInfo modinfo)

Initialize a module.

Definition at line 78 of file module_manager.cpp.

◆ initModules()

void ModuleManager::initModules ( )

Actually call the init_module() function of each library we loaded.

The module initialization order is honored because the modules_ set is ordered.

Exceptions

Definition at line 69 of file module_manager.cpp.

◆ load_library_file()

std::shared_ptr< DynamicLibrary > ModuleManager::load_library_file ( const std::string &  full_path)
private

This will load (actually calling dlopen()) the library file located at full_path.

It returns a DynamicLibrary pointer that can be used to retrieve symbol from the shared object. It it failed, returns nullptr.

Definition at line 182 of file module_manager.cpp.

◆ loadModule()

bool ModuleManager::loadModule ( const std::string &  module_name)

Search the path and load a module based on a property tree for this module.

Mandatory data are the module "name" and the "file" location (the name of the .so to load).

The first file to match (looping over the path array) will be loaded.

Definition at line 154 of file module_manager.cpp.

◆ modules_names()

std::vector< std::string > ModuleManager::modules_names ( ) const

Returns the list of the name of the loaded modules.

Definition at line 278 of file module_manager.cpp.

◆ stopModule() [1/2]

bool ModuleManager::stopModule ( const std::string &  name)
private

Stop a module by name and remove its config info from the config manager.

Note
This does not unload the underlying shared library.
Stopping individual module must be done carefully. Be careful wrt dependencies between modules. It's recommended to also stop modules that depends on the module you initially wanted to stop.
Returns
false if a module with this name cannot be found. True otherwise.
Warning
OUTDATED

Definition at line 240 of file module_manager.cpp.

◆ stopModule() [2/2]

void ModuleManager::stopModule ( ModuleInfo modinfo,
bool  soft = false 
)
private

Stop a specific module and remove its config info from the config manager.

Note
This does not unload the underlying shared library.
Stopping individual module must be done carefully. Be careful wrt dependencies between modules. It's recommended to also stop modules that depends on the module you initially wanted to stop.
Warning
OUTDATED

Definition at line 211 of file module_manager.cpp.

◆ stopModules()

void ModuleManager::stopModules ( bool  soft = false)

Opposite of init module.

this stop all modules thread and perform cleanup.

Note
Dynamic libraries handlers are NOT released.

Definition at line 198 of file module_manager.cpp.

◆ unloadLibraries()

void ModuleManager::unloadLibraries ( )
private

Close library handler.

Cleanup code, call from destructor only.

Definition at line 53 of file module_manager.cpp.

Member Data Documentation

◆ config_manager_

Leosac::ConfigManager& ModuleManager::config_manager_
private

Definition at line 217 of file module_manager.hpp.

◆ core_utils_

Leosac::CoreUtilsPtr ModuleManager::core_utils_
private

Definition at line 218 of file module_manager.hpp.

◆ ctx_

zmqpp::context& ModuleManager::ctx_
private

Definition at line 216 of file module_manager.hpp.

◆ modules_

std::set<ModuleInfo> ModuleManager::modules_
private

Definition at line 214 of file module_manager.hpp.

◆ path_

std::vector<std::string> ModuleManager::path_
private

Definition at line 213 of file module_manager.hpp.


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