|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Coordinates system initialization and shutdown. More...
#include <unified_bootstrapper.h>

Classes | |
| struct | module_entry |
| struct | shutdown_hook_entry |
Public Member Functions | |
| unified_bootstrapper ()=delete | |
| ~unified_bootstrapper ()=delete | |
| unified_bootstrapper (const unified_bootstrapper &)=delete | |
| unified_bootstrapper & | operator= (const unified_bootstrapper &)=delete |
Static Public Member Functions | |
| static VoidResult | initialize (const bootstrapper_options &opts={}) |
| Initialize the unified system. | |
| static VoidResult | shutdown (std::chrono::milliseconds timeout=std::chrono::seconds(30)) |
| Shutdown the unified system gracefully. | |
| static service_container & | services () |
| Get the service container. | |
| static bool | is_initialized () |
| Check if the system is initialized. | |
| static bool | is_shutdown_requested () |
| Check if shutdown has been requested. | |
| static VoidResult | register_shutdown_hook (const std::string &name, shutdown_hook hook) |
| Register a shutdown hook. | |
| static VoidResult | unregister_shutdown_hook (const std::string &name) |
| Unregister a shutdown hook. | |
| static void | request_shutdown (bool trigger_shutdown=false) |
| Request graceful shutdown. | |
| static bootstrapper_options | get_options () |
| Get the initialization options. | |
| static VoidResult | register_module (const std::string &name, module_registration_fn fn) |
| Register a module's service registration function. | |
| template<typename M > requires concepts::ModuleRegistrar<M> | |
| static VoidResult | register_module (M registrar) |
| Register a class-based module registrar. | |
| static VoidResult | unregister_module (const std::string &name) |
| Unregister a module. | |
| static std::vector< std::string > | registered_modules () |
| Get list of registered module names. | |
| static bool | is_module_registered (const std::string &name) |
| Check if a module is registered. | |
Static Private Member Functions | |
| static VoidResult | register_core_services () |
| Register core services that are always required. | |
| static VoidResult | register_optional_services (const bootstrapper_options &opts) |
| Register optional services based on options. | |
| static void | setup_default_shutdown_hooks () |
| Set up default shutdown hooks. | |
| static void | setup_signal_handlers () |
| Set up signal handlers. | |
| static void | signal_handler (int signal) |
| Signal handler function. | |
| static void | execute_shutdown_hooks (std::chrono::milliseconds timeout) |
| Execute all shutdown hooks. | |
Static Private Attributes | |
| static std::atomic< bool > | initialized_ {false} |
| static std::atomic< bool > | shutdown_requested_ {false} |
| static std::mutex | mutex_ |
| static bootstrapper_options | options_ |
| static std::vector< shutdown_hook_entry > | shutdown_hooks_ |
| static std::vector< module_entry > | modules_ |
Coordinates system initialization and shutdown.
The unified bootstrapper provides a single entry point for initializing all system components. It manages:
Usage Example:
Definition at line 130 of file unified_bootstrapper.h.
|
delete |
|
delete |
|
delete |
|
inlinestaticprivate |
Execute all shutdown hooks.
Definition at line 743 of file unified_bootstrapper.h.
References shutdown_hooks_.
Referenced by shutdown().

|
inlinestatic |
Get the initialization options.
Definition at line 533 of file unified_bootstrapper.h.
|
inlinestatic |
Initialize the unified system.
Performs the following steps:
This method is idempotent - calling it multiple times after successful initialization returns success without re-initializing.
| opts | Configuration options |
Possible errors:
Definition at line 380 of file unified_bootstrapper.h.
References kcenon::common::di::service_container::clear(), kcenon::common::di::service_container::global(), initialized_, modules_, mutex_, kcenon::common::Result< T >::ok(), options_, register_core_services(), register_optional_services(), kcenon::common::di::bootstrapper_options::register_signal_handlers, setup_default_shutdown_hooks(), setup_signal_handlers(), and shutdown_requested_.
Referenced by main().


|
inlinestatic |
Check if the system is initialized.
Thread-safe check of initialization state.
Definition at line 466 of file unified_bootstrapper.h.
References initialized_.
|
inlinestatic |
Check if a module is registered.
| name | Module name to check |
Definition at line 617 of file unified_bootstrapper.h.
|
inlinestatic |
Check if shutdown has been requested.
Thread-safe check of shutdown state. Useful for long-running operations to check if they should abort.
Definition at line 470 of file unified_bootstrapper.h.
References shutdown_requested_.
|
delete |
|
inlinestaticprivate |
Register core services that are always required.
Definition at line 626 of file unified_bootstrapper.h.
References kcenon::common::Result< T >::ok().
Referenced by initialize().


|
inlinestatic |
Register a module's service registration function.
Modules can be registered before or after initialization:
| name | Unique module name (e.g., "logger", "monitoring") |
| fn | Registration function that registers services with the container |
Possible errors:
Definition at line 542 of file unified_bootstrapper.h.
References kcenon::common::error_codes::ALREADY_EXISTS, kcenon::common::di::service_container::global(), initialized_, kcenon::common::make_error(), modules_, mutex_, and kcenon::common::Result< T >::ok().
Referenced by register_module().


|
static |
Register a class-based module registrar.
Convenience overload that accepts any type satisfying the ModuleRegistrar concept.
| M | Type satisfying concepts::ModuleRegistrar |
| registrar | Module registrar instance |
Definition at line 577 of file unified_bootstrapper.h.
References register_module().

|
inlinestaticprivate |
Register optional services based on options.
Definition at line 642 of file unified_bootstrapper.h.
References kcenon::common::di::bootstrapper_options::enable_database, kcenon::common::di::bootstrapper_options::enable_logging, kcenon::common::di::bootstrapper_options::enable_monitoring, kcenon::common::di::bootstrapper_options::enable_network, kcenon::common::di::service_container::global(), kcenon::common::make_error(), modules_, and kcenon::common::Result< T >::ok().
Referenced by initialize().


|
inlinestatic |
Register a shutdown hook.
Hooks are called in reverse order of registration during shutdown. Use for cleanup operations that must complete before the system shuts down.
| name | Unique name for the hook (for logging) |
| hook | Callback function to execute during shutdown |
Possible errors:
Definition at line 474 of file unified_bootstrapper.h.
References kcenon::common::error_codes::ALREADY_EXISTS, initialized_, kcenon::common::make_error(), mutex_, kcenon::common::error_codes::NOT_INITIALIZED, kcenon::common::Result< T >::ok(), and shutdown_hooks_.

|
inlinestatic |
Get list of registered module names.
Definition at line 606 of file unified_bootstrapper.h.
|
inlinestatic |
Request graceful shutdown.
Sets the shutdown flag and optionally triggers shutdown. Can be called from signal handlers.
| trigger_shutdown | If true, also calls shutdown() |
Definition at line 525 of file unified_bootstrapper.h.
References options_, shutdown(), shutdown_requested_, and kcenon::common::di::bootstrapper_options::shutdown_timeout.

|
inlinestatic |
Get the service container.
| std::runtime_error | if not initialized |
Definition at line 456 of file unified_bootstrapper.h.
References kcenon::common::di::service_container::global(), and initialized_.
Referenced by main().


|
inlinestaticprivate |
Set up default shutdown hooks.
Definition at line 706 of file unified_bootstrapper.h.
References shutdown_hooks_.
Referenced by initialize().

|
inlinestaticprivate |
Set up signal handlers.
Definition at line 718 of file unified_bootstrapper.h.
References signal_handler().
Referenced by initialize().


|
inlinestatic |
Shutdown the unified system gracefully.
Performs the following steps:
| timeout | Maximum time to wait for graceful shutdown |
Possible errors:
Definition at line 424 of file unified_bootstrapper.h.
References kcenon::common::di::service_container::clear(), execute_shutdown_hooks(), kcenon::common::di::service_container::global(), initialized_, kcenon::common::make_error(), modules_, mutex_, kcenon::common::error_codes::NOT_INITIALIZED, kcenon::common::Result< T >::ok(), options_, shutdown_hooks_, and shutdown_requested_.
Referenced by main(), and request_shutdown().


|
inlinestaticprivate |
Signal handler function.
Definition at line 735 of file unified_bootstrapper.h.
References shutdown_requested_.
Referenced by setup_signal_handlers().

|
inlinestatic |
Unregister a module.
Removes a module registration. Does not unregister services that were already registered with the container.
| name | Name of the module to unregister |
Possible errors:
Definition at line 586 of file unified_bootstrapper.h.
References kcenon::common::make_error(), modules_, mutex_, kcenon::common::error_codes::NOT_FOUND, and kcenon::common::Result< T >::ok().

|
inlinestatic |
Unregister a shutdown hook.
| name | Name of the hook to unregister |
Definition at line 503 of file unified_bootstrapper.h.
References kcenon::common::make_error(), mutex_, kcenon::common::error_codes::NOT_FOUND, kcenon::common::Result< T >::ok(), and shutdown_hooks_.

|
inlinestaticprivate |
Definition at line 346 of file unified_bootstrapper.h.
Referenced by initialize(), is_initialized(), register_module(), register_shutdown_hook(), services(), and shutdown().
|
inlinestaticprivate |
Definition at line 364 of file unified_bootstrapper.h.
Referenced by initialize(), is_module_registered(), register_module(), register_optional_services(), registered_modules(), shutdown(), and unregister_module().
|
inlinestaticprivate |
Definition at line 348 of file unified_bootstrapper.h.
Referenced by get_options(), initialize(), is_module_registered(), register_module(), register_shutdown_hook(), registered_modules(), shutdown(), unregister_module(), and unregister_shutdown_hook().
|
inlinestaticprivate |
Definition at line 349 of file unified_bootstrapper.h.
Referenced by get_options(), initialize(), request_shutdown(), and shutdown().
|
inlinestaticprivate |
Definition at line 356 of file unified_bootstrapper.h.
Referenced by execute_shutdown_hooks(), register_shutdown_hook(), setup_default_shutdown_hooks(), shutdown(), and unregister_shutdown_hook().
|
inlinestaticprivate |
Definition at line 347 of file unified_bootstrapper.h.
Referenced by initialize(), is_shutdown_requested(), request_shutdown(), shutdown(), and signal_handler().