|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Fluent API for system initialization and logger registration. More...
#include <system_bootstrapper.h>

Public Member Functions | |
| SystemBootstrapper ()=default | |
| Default constructor. | |
| ~SystemBootstrapper () | |
| Destructor with automatic shutdown. | |
| SystemBootstrapper (const SystemBootstrapper &)=delete | |
| SystemBootstrapper & | operator= (const SystemBootstrapper &)=delete |
| SystemBootstrapper (SystemBootstrapper &&other) noexcept | |
| SystemBootstrapper & | operator= (SystemBootstrapper &&other) noexcept |
| SystemBootstrapper & | with_default_logger (interfaces::LoggerFactory factory) |
| Register a factory for the default logger. | |
| SystemBootstrapper & | with_logger (const std::string &name, interfaces::LoggerFactory factory) |
| Register a factory for a named logger. | |
| SystemBootstrapper & | on_initialize (std::function< void()> callback) |
| Register an initialization callback. | |
| SystemBootstrapper & | on_shutdown (std::function< void()> callback) |
| Register a shutdown callback. | |
| SystemBootstrapper & | with_auto_freeze (bool freeze_logger_registry=true, bool freeze_service_container=true) |
| Enable automatic freezing of registries after initialization. | |
| VoidResult | initialize () |
| Initialize the system. | |
| void | shutdown () |
| Shutdown the system. | |
| bool | is_initialized () const noexcept |
| Check if the system is initialized. | |
| void | reset () |
| Reset the bootstrapper to initial state. | |
Private Member Functions | |
| VoidResult | register_loggers () |
| Register all loggers with GlobalLoggerRegistry. | |
| void | execute_init_callbacks () |
| Execute all initialization callbacks. | |
| void | execute_shutdown_callbacks () |
| Execute all shutdown callbacks in reverse order. | |
| void | clear_loggers () |
| Clear all loggers from GlobalLoggerRegistry. | |
Private Attributes | |
| interfaces::LoggerFactory | default_logger_factory_ |
| std::vector< std::pair< std::string, interfaces::LoggerFactory > > | named_logger_factories_ |
| std::vector< std::function< void()> > | init_callbacks_ |
| std::vector< std::function< void()> > | shutdown_callbacks_ |
| bool | auto_freeze_logger_registry_ = false |
| bool | auto_freeze_service_container_ = false |
| bool | initialized_ = false |
| std::mutex | state_mutex_ |
Fluent API for system initialization and logger registration.
SystemBootstrapper provides a centralized mechanism for:
Key Features:
Design Notes:
Definition at line 90 of file system_bootstrapper.h.
|
default |
Default constructor.
Creates an uninitialized bootstrapper. Call configuration methods and then initialize() to start the system.
|
inline |
Destructor with automatic shutdown.
Automatically calls shutdown() if the bootstrapper was initialized. This ensures proper cleanup even if shutdown() is not called explicitly.
Definition at line 304 of file system_bootstrapper.h.
References initialized_, and shutdown().

|
delete |
|
inlinenoexcept |
Definition at line 310 of file system_bootstrapper.h.
|
inlineprivate |
Clear all loggers from GlobalLoggerRegistry.
Definition at line 520 of file system_bootstrapper.h.
References kcenon::common::interfaces::GlobalLoggerRegistry::clear(), and kcenon::common::interfaces::GlobalLoggerRegistry::instance().
Referenced by register_loggers(), and shutdown().


|
inlineprivate |
Execute all initialization callbacks.
Definition at line 501 of file system_bootstrapper.h.
References init_callbacks_.
Referenced by initialize().

|
inlineprivate |
Execute all shutdown callbacks in reverse order.
Definition at line 509 of file system_bootstrapper.h.
References shutdown_callbacks_.
Referenced by shutdown().

|
inline |
Initialize the system.
Performs the following steps in order:
If any step fails, the operation is rolled back and an error is returned.
Definition at line 385 of file system_bootstrapper.h.
References kcenon::common::error_codes::ALREADY_EXISTS, auto_freeze_logger_registry_, auto_freeze_service_container_, execute_init_callbacks(), kcenon::common::di::service_container::freeze(), kcenon::common::interfaces::GlobalLoggerRegistry::freeze(), kcenon::common::di::service_container::global(), initialized_, kcenon::common::interfaces::GlobalLoggerRegistry::instance(), kcenon::common::make_error(), kcenon::common::Result< T >::ok(), register_loggers(), and state_mutex_.

|
inlinenoexcept |
Check if the system is initialized.
Definition at line 436 of file system_bootstrapper.h.
References initialized_, and state_mutex_.
Referenced by reset().

|
inline |
Register an initialization callback.
The callback will be invoked during initialize() after all loggers are registered. Multiple callbacks can be registered and will be called in the order of registration.
| callback | Function to call during initialization |
Definition at line 361 of file system_bootstrapper.h.
References init_callbacks_.
|
inline |
Register a shutdown callback.
The callback will be invoked during shutdown() before loggers are cleared. Multiple callbacks can be registered and will be called in reverse order of registration (LIFO).
| callback | Function to call during shutdown |
Definition at line 369 of file system_bootstrapper.h.
References shutdown_callbacks_.
|
delete |
|
inlinenoexcept |
Definition at line 321 of file system_bootstrapper.h.
References auto_freeze_logger_registry_, auto_freeze_service_container_, default_logger_factory_, init_callbacks_, initialized_, named_logger_factories_, shutdown(), and shutdown_callbacks_.

|
inlineprivate |
Register all loggers with GlobalLoggerRegistry.
Definition at line 458 of file system_bootstrapper.h.
References clear_loggers(), default_logger_factory_, kcenon::common::interfaces::GlobalLoggerRegistry::instance(), kcenon::common::error_codes::INTERNAL_ERROR, kcenon::common::make_error(), named_logger_factories_, and kcenon::common::Result< T >::ok().
Referenced by initialize().


|
inline |
Reset the bootstrapper to initial state.
Clears all registered factories, callbacks, and resets the initialized state. If currently initialized, shutdown() is called first.
Useful for testing or reconfiguration scenarios.
Definition at line 441 of file system_bootstrapper.h.
References auto_freeze_logger_registry_, auto_freeze_service_container_, default_logger_factory_, init_callbacks_, is_initialized(), named_logger_factories_, shutdown(), shutdown_callbacks_, and state_mutex_.

|
inline |
Shutdown the system.
Performs the following steps in order:
Definition at line 419 of file system_bootstrapper.h.
References clear_loggers(), execute_shutdown_callbacks(), initialized_, and state_mutex_.
Referenced by operator=(), reset(), and ~SystemBootstrapper().


|
inline |
Enable automatic freezing of registries after initialization.
When enabled, the GlobalLoggerRegistry and service_container::global() will be frozen after all initialization callbacks complete. This prevents unauthorized modifications to loggers and services after system startup.
| freeze_logger_registry | Whether to freeze GlobalLoggerRegistry (default: true) |
| freeze_service_container | Whether to freeze service_container (default: true) |
Definition at line 377 of file system_bootstrapper.h.
References auto_freeze_logger_registry_, and auto_freeze_service_container_.
|
inline |
Register a factory for the default logger.
The factory function will be invoked during initialize() to create the default logger. The logger will be registered with GlobalLoggerRegistry and accessible via get_logger().
| factory | Factory function that creates the default logger |
Definition at line 341 of file system_bootstrapper.h.
References default_logger_factory_.
|
inline |
Register a factory for a named logger.
The factory function will be invoked during initialize() to create the named logger. The logger will be registered with GlobalLoggerRegistry and accessible via get_logger(name).
| name | Logger name (case-sensitive) |
| factory | Factory function that creates the logger |
Definition at line 347 of file system_bootstrapper.h.
References named_logger_factories_.
|
private |
Definition at line 292 of file system_bootstrapper.h.
Referenced by initialize(), operator=(), reset(), and with_auto_freeze().
|
private |
Definition at line 293 of file system_bootstrapper.h.
Referenced by initialize(), operator=(), reset(), and with_auto_freeze().
|
private |
Definition at line 286 of file system_bootstrapper.h.
Referenced by operator=(), register_loggers(), reset(), and with_default_logger().
|
private |
Definition at line 288 of file system_bootstrapper.h.
Referenced by execute_init_callbacks(), on_initialize(), operator=(), and reset().
|
private |
Definition at line 296 of file system_bootstrapper.h.
Referenced by initialize(), is_initialized(), operator=(), shutdown(), and ~SystemBootstrapper().
|
private |
Definition at line 287 of file system_bootstrapper.h.
Referenced by operator=(), register_loggers(), reset(), and with_logger().
|
private |
Definition at line 289 of file system_bootstrapper.h.
Referenced by execute_shutdown_callbacks(), on_shutdown(), operator=(), and reset().
|
mutableprivate |
Definition at line 297 of file system_bootstrapper.h.
Referenced by initialize(), is_initialized(), reset(), and shutdown().