|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Configuration manager for unified system configuration. More...
#include <configuration_manager.h>

Public Types | |
| using | change_callback = std::function<void(const std::string&, const config_value&)> |
| Configuration change callback. | |
| using | validator_func = std::function<validation_result(const std::string&, const config_value&)> |
| Configuration validator. | |
Public Member Functions | |
| configuration_manager (std::shared_ptr< event_bus > bus=nullptr) | |
| Constructor. | |
| bool | load_from_file (const std::filesystem::path &config_file) |
| Load configuration from file. | |
| bool | save_to_file (const std::filesystem::path &config_file) const |
| Save configuration to file. | |
| bool | set (const std::string &path, const config_value &value) |
| Set a configuration value. | |
| template<typename T > | |
| T | get (const std::string &path, const T &default_value=T{}) const |
| Get a configuration value. | |
| template<typename T > | |
| std::optional< T > | get_optional (const std::string &path) const |
| Get a configuration value as optional. | |
| bool | has (const std::string &path) const |
| Check if configuration exists. | |
| bool | remove (const std::string &path) |
| Remove a configuration value. | |
| std::size_t | on_change (const std::string &path, change_callback callback) |
| Register a change callback. | |
| void | remove_callback (const std::string &path, std::size_t id) |
| Unregister a change callback. | |
| void | add_validator (const std::string &path, validator_func validator) |
| Register a configuration validator. | |
| validation_result | validate_all () const |
| Validate all configuration. | |
| void | apply_system_config (const std::string &system_name, const std::unordered_map< std::string, config_value > &config) |
| Apply configuration for a specific system. | |
| std::unordered_map< std::string, config_value > | get_system_config (const std::string &system_name) const |
| Get configuration for a specific system. | |
| void | clear () |
| Clear all configuration. | |
Static Public Member Functions | |
| static configuration_manager & | instance () |
| Get singleton instance. | |
Private Member Functions | |
| void | parse_config_line (const std::string &line) |
| Parse a configuration line. | |
| std::string | value_to_string (const config_value &value) const |
| Convert value to string. | |
| bool | values_equal (const config_value &a, const config_value &b) const |
| Check if two values are equal. | |
| void | notify_change (const std::string &path, const config_value &value) |
| Notify change callbacks. | |
Private Attributes | |
| std::mutex | mutex_ |
| std::mutex | callbacks_mutex_ |
| std::unordered_map< std::string, config_value > | config_ |
| std::unordered_map< std::string, validator_func > | validators_ |
| std::unordered_map< std::string, std::unordered_map< std::size_t, change_callback > > | callbacks_ |
| std::shared_ptr< event_bus > | event_bus_ |
| std::size_t | next_callback_id_ {1} |
Configuration manager for unified system configuration.
Definition at line 61 of file configuration_manager.h.
| using kcenon::thread::configuration_manager::change_callback = std::function<void(const std::string&, const config_value&)> |
Configuration change callback.
Definition at line 66 of file configuration_manager.h.
| using kcenon::thread::configuration_manager::validator_func = std::function<validation_result(const std::string&, const config_value&)> |
Configuration validator.
Definition at line 71 of file configuration_manager.h.
|
inlineexplicit |
Constructor.
| event_bus | Optional event bus for change notifications |
Definition at line 77 of file configuration_manager.h.
References event_bus_.
|
inline |
Register a configuration validator.
| path | Configuration path |
| validator | Validator function |
Definition at line 268 of file configuration_manager.h.
References mutex_, and validators_.
|
inline |
Apply configuration for a specific system.
| system_name | System name (e.g., "thread_system") |
| config | Configuration map |
Definition at line 304 of file configuration_manager.h.
References set().

|
inline |
Clear all configuration.
Definition at line 334 of file configuration_manager.h.
|
inline |
Get a configuration value.
| T | Value type |
| path | Configuration path |
| default_value | Default value if not found |
Definition at line 182 of file configuration_manager.h.
|
inline |
Get a configuration value as optional.
| T | Value type |
| path | Configuration path |
Definition at line 202 of file configuration_manager.h.
|
inline |
Get configuration for a specific system.
| system_name | System name |
Definition at line 316 of file configuration_manager.h.
|
inline |
|
inlinestatic |
Get singleton instance.
Definition at line 343 of file configuration_manager.h.
References instance().
Referenced by instance().


|
inline |
Load configuration from file.
| config_file | Path to configuration file |
Definition at line 89 of file configuration_manager.h.
References parse_config_line().

|
inlineprivate |
Notify change callbacks.
Definition at line 428 of file configuration_manager.h.
References kcenon::thread::callback, callbacks_, and callbacks_mutex_.
Referenced by set().

|
inline |
Register a change callback.
| path | Configuration path (empty for all changes) |
| callback | Callback function |
Definition at line 241 of file configuration_manager.h.
References kcenon::thread::callback, callbacks_, callbacks_mutex_, and next_callback_id_.
|
inlineprivate |
Parse a configuration line.
Definition at line 352 of file configuration_manager.h.
References set().
Referenced by load_from_file().


|
inline |
|
inline |
Unregister a change callback.
| path | Configuration path |
| id | Callback ID |
Definition at line 253 of file configuration_manager.h.
References callbacks_, and callbacks_mutex_.
|
inline |
Save configuration to file.
| config_file | Path to configuration file |
Definition at line 118 of file configuration_manager.h.
References config_, mutex_, and value_to_string().

|
inline |
Set a configuration value.
| path | Configuration path (e.g., "thread_system.pool_size") |
| value | Configuration value |
Definition at line 142 of file configuration_manager.h.
References config_, event_bus_, mutex_, notify_change(), validators_, and values_equal().
Referenced by apply_system_config(), and parse_config_line().


|
inline |
Validate all configuration.
Definition at line 277 of file configuration_manager.h.
References config_, mutex_, validators_, and kcenon::thread::warning.
|
inlineprivate |
Convert value to string.
Definition at line 389 of file configuration_manager.h.
Referenced by save_to_file().

|
inlineprivate |
Check if two values are equal.
Uses std::visit to compare per-type because std::unordered_map<std::string, std::any> does not support operator==.
Definition at line 410 of file configuration_manager.h.
Referenced by set().

|
private |
Definition at line 450 of file configuration_manager.h.
Referenced by notify_change(), on_change(), and remove_callback().
|
mutableprivate |
Definition at line 447 of file configuration_manager.h.
Referenced by notify_change(), on_change(), and remove_callback().
|
private |
Definition at line 448 of file configuration_manager.h.
Referenced by clear(), get_optional(), get_system_config(), has(), remove(), save_to_file(), set(), and validate_all().
|
private |
Definition at line 451 of file configuration_manager.h.
Referenced by configuration_manager(), and set().
|
mutableprivate |
Definition at line 446 of file configuration_manager.h.
Referenced by add_validator(), clear(), get_optional(), get_system_config(), has(), remove(), save_to_file(), set(), and validate_all().
|
private |
|
private |
Definition at line 449 of file configuration_manager.h.
Referenced by add_validator(), set(), and validate_all().