Leosac  0.8.0
Open Source Access Control
Leosac::ConfigManager Class Reference

That class helps manage the configuration for the application and its module. More...

#include <ConfigManager.hpp>

+ Collaboration diagram for Leosac::ConfigManager:

Public Types

enum  ConfigFormat : uint8_t { ConfigFormat::BOOST_ARCHIVE = 0, ConfigFormat::XML = 1 }
 This enum is used internally, when core request module configuration. More...
 

Public Member Functions

 ConfigManager (const boost::property_tree::ptree &cfg)
 Construct the Configuration Manager from a property tree. More...
 
virtual ~ConfigManager ()=default
 
 ConfigManager (const ConfigManager &)=default
 
 ConfigManager (ConfigManager &&)=delete
 
ConfigManageroperator= (const ConfigManager &)=delete
 
ConfigManageroperator= (ConfigManager &&)=delete
 
boost::property_tree::ptree get_general_config () const
 Extract the current "general configuration". More...
 
boost::property_tree::ptree get_exportable_general_config () const
 Return the property_tree of item inside the <kernel> tag (except <modules>`) that are marked exportable. More...
 
boost::property_tree::ptree get_application_config ()
 Retrieve the (current, running) configuration from the application and its modules. More...
 
bool store_config (const std::string &module, const boost::property_tree::ptree &cfg)
 Store the configuration tree for a module. More...
 
bool has_config (const std::string &module) const
 Do we have config information for the module. More...
 
const boost::property_tree::ptree & load_config (const std::string &module) const
 Return the stored configuration for a given module. More...
 
bool remove_config (const std::string &module)
 Remove the config entry for the module named module. More...
 
const boost::property_tree::ptree & kconfig () const
 Return const & on the general config tree. More...
 
boost::property_tree::ptree & kconfig ()
 Returns non-const ref to general config tree. More...
 
void set_kconfig (const boost::property_tree::ptree &new_cfg)
 Update Leosac's core config ptree. More...
 
std::list< std::string > get_non_importable_modules () const
 Returns a list of module name that should not be imported. More...
 
bool is_module_importable (const std::string &) const
 Helper around get_non_importable_modules() More...
 
uint64_t config_version () const
 Return the current configuration version. More...
 
void config_version (uint64_t new_version)
 
void incr_version ()
 Increment by 1 the current version number. More...
 
const std::string & instance_name () const
 Return the name of the instanced assigned in the configuration file. More...
 

Private Attributes

std::map< std::string, boost::property_tree::ptree > modules_configs_
 Maps a module's name to a property tree object. More...
 
boost::property_tree::ptree kernel_config_
 Property tree for general configuration. More...
 
uint64_t version_
 
std::string instance_name_
 

Detailed Description

That class helps manage the configuration for the application and its module.

It's goal is to help saving the configuration to be used to maintain each module configuration.

The load_config() and store_config() are used to retrieve or update module config. For example, when remote control is doing a SYNC_FROM, it pushes the new config to the ConfigManager using store_config().

Definition at line 45 of file ConfigManager.hpp.

Member Enumeration Documentation

◆ ConfigFormat

enum Leosac::ConfigManager::ConfigFormat : uint8_t
strong

This enum is used internally, when core request module configuration.

Enumerator
BOOST_ARCHIVE 
XML 

Definition at line 118 of file ConfigManager.hpp.

Constructor & Destructor Documentation

◆ ConfigManager() [1/3]

ConfigManager::ConfigManager ( const boost::property_tree::ptree &  cfg)

Construct the Configuration Manager from a property tree.

Definition at line 31 of file ConfigManager.cpp.

◆ ~ConfigManager()

virtual Leosac::ConfigManager::~ConfigManager ( )
virtualdefault

◆ ConfigManager() [2/3]

Leosac::ConfigManager::ConfigManager ( const ConfigManager )
default

◆ ConfigManager() [3/3]

Leosac::ConfigManager::ConfigManager ( ConfigManager &&  )
delete

Member Function Documentation

◆ config_version() [1/2]

uint64_t ConfigManager::config_version ( ) const

Return the current configuration version.

This is supposed to work similar to Bind9 serial.

It should only ever increase.

Definition at line 251 of file ConfigManager.cpp.

◆ config_version() [2/2]

void ConfigManager::config_version ( uint64_t  new_version)

Definition at line 266 of file ConfigManager.cpp.

◆ get_application_config()

boost::property_tree::ptree ConfigManager::get_application_config ( )

Retrieve the (current, running) configuration from the application and its modules.

Since the ConfigManager shall have an up-to-date view of the modules' configuration tree, it can build a global config tree. It returns a proper property tree that can be serialized.

Definition at line 41 of file ConfigManager.cpp.

◆ get_exportable_general_config()

boost::property_tree::ptree ConfigManager::get_exportable_general_config ( ) const

Return the property_tree of item inside the <kernel> tag (except <modules>`) that are marked exportable.

See the <sync_source> tag in general_config_main.

Definition at line 76 of file ConfigManager.cpp.

◆ get_general_config()

boost::property_tree::ptree ConfigManager::get_general_config ( ) const

Extract the current "general configuration".

General configuration means anything that is not module configuration, i/e "log", "network" and "remote".

Note
This is part of the process to build the whole up-to-date config tree.

Definition at line 59 of file ConfigManager.cpp.

◆ get_non_importable_modules()

std::list< std::string > ConfigManager::get_non_importable_modules ( ) const

Returns a list of module name that should not be imported.

Imported means added or updated when a SYNC_FROM is executed.

Definition at line 230 of file ConfigManager.cpp.

◆ has_config()

bool ConfigManager::has_config ( const std::string &  module) const

Do we have config information for the module.

Definition at line 261 of file ConfigManager.cpp.

◆ incr_version()

void ConfigManager::incr_version ( )

Increment by 1 the current version number.

Definition at line 256 of file ConfigManager.cpp.

◆ instance_name()

const std::string & ConfigManager::instance_name ( ) const

Return the name of the instanced assigned in the configuration file.

Note
This method is thread safe because the instance name shall never change.

Definition at line 271 of file ConfigManager.cpp.

◆ is_module_importable()

bool ConfigManager::is_module_importable ( const std::string &  module_name) const

Helper around get_non_importable_modules()

Definition at line 245 of file ConfigManager.cpp.

◆ kconfig() [1/2]

boost::property_tree::ptree& Leosac::ConfigManager::kconfig ( )

Returns non-const ref to general config tree.

◆ kconfig() [2/2]

boost::property_tree::ptree & ConfigManager::kconfig ( ) const

Return const & on the general config tree.

Definition at line 166 of file ConfigManager.cpp.

◆ load_config()

const boost::property_tree::ptree & ConfigManager::load_config ( const std::string &  module) const

Return the stored configuration for a given module.

Definition at line 133 of file ConfigManager.cpp.

◆ operator=() [1/2]

ConfigManager& Leosac::ConfigManager::operator= ( ConfigManager &&  )
delete

◆ operator=() [2/2]

ConfigManager& Leosac::ConfigManager::operator= ( const ConfigManager )
delete

◆ remove_config()

bool ConfigManager::remove_config ( const std::string &  module)

Remove the config entry for the module named module.

Return true if successfully removed entry, false otherwise.

Definition at line 176 of file ConfigManager.cpp.

◆ set_kconfig()

void ConfigManager::set_kconfig ( const boost::property_tree::ptree &  new_cfg)

Update Leosac's core config ptree.

This function filter the new_cfg tree and does not store configuration for category that are excluded through the sync_dest option.

Definition at line 186 of file ConfigManager.cpp.

◆ store_config()

bool ConfigManager::store_config ( const std::string &  module,
const boost::property_tree::ptree &  cfg 
)

Store the configuration tree for a module.

If pushing the configuration overwrote a previously existing one, this will return true. Otherwise it will return false.

Definition at line 117 of file ConfigManager.cpp.

Member Data Documentation

◆ instance_name_

std::string Leosac::ConfigManager::instance_name_
private

Definition at line 189 of file ConfigManager.hpp.

◆ kernel_config_

boost::property_tree::ptree Leosac::ConfigManager::kernel_config_
private

Property tree for general configuration.

This is the base config tree.

Definition at line 185 of file ConfigManager.hpp.

◆ modules_configs_

std::map<std::string, boost::property_tree::ptree> Leosac::ConfigManager::modules_configs_
private

Maps a module's name to a property tree object.

Definition at line 179 of file ConfigManager.hpp.

◆ version_

uint64_t Leosac::ConfigManager::version_
private

Definition at line 187 of file ConfigManager.hpp.


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