![]() |
Consolix
|
Manages a collection of application components with lifecycle support. More...
#include <AppComponentManager.hpp>
Public Member Functions | |
AppComponentManager ()=default | |
Constructs an empty component manager. | |
~AppComponentManager () | |
Destroys the component manager and clears all components. | |
template<typename Component, typename... Args> | |
std::shared_ptr< Component > | add (Args &&... args) |
Adds a new component to the manager. | |
void | add (std::shared_ptr< IAppComponent > component) |
Adds an existing component to the manager. | |
bool | initialize () |
Initializes all registered components. | |
bool | is_initialized () const |
Checks if all components are initialized. | |
void | process () |
Executes the main functionality of all components. | |
void | shutdown (int signal) |
Shuts down all components with "soft shutdown" support. | |
Private Attributes | |
std::vector< std::shared_ptr< IAppComponent > > | m_components |
List of managed application components. | |
Manages a collection of application components with lifecycle support.
The manager provides controlled initialization, execution, and shutdown for all registered components. It ensures:
initialize()
: Prepares each component for execution.process()
: Executes the main loop logic for each component.shutdown(signal)
: Implements a "soft shutdown" by continuing to shut down other components even if one fails, and logs aggregated errors if any occur.Components are stored as std::shared_ptr
for memory safety and compatibility with the ServiceLocator
pattern.
Definition at line 25 of file AppComponentManager.hpp.
|
default |
Constructs an empty component manager.
|
inline |
Destroys the component manager and clears all components.
Definition at line 32 of file AppComponentManager.hpp.
|
inline |
Adds a new component to the manager.
Constructs a new component of type Component
and registers it with the manager.
Component | The type of the component to create. |
Args | Argument types for the component's constructor. |
args | Arguments for constructing the component. |
Definition at line 44 of file AppComponentManager.hpp.
|
inline |
Adds an existing component to the manager.
component | A std::shared_ptr to the component to add. |
Definition at line 52 of file AppComponentManager.hpp.
|
inline |
Initializes all registered components.
Skips components that are already initialized.
true
if all components are initialized successfully, false
otherwise. std::exception | If any component fails during initialization. |
Definition at line 61 of file AppComponentManager.hpp.
|
inline |
Checks if all components are initialized.
true
if all components are initialized, false
otherwise. Definition at line 78 of file AppComponentManager.hpp.
|
inline |
Executes the main functionality of all components.
Calls process()
on each managed component.
std::exception | If any component fails during execution. |
Definition at line 89 of file AppComponentManager.hpp.
|
inline |
Shuts down all components with "soft shutdown" support.
Calls shutdown(signal)
on components implementing the IShutdownable
interface. If any component throws an exception during shutdown, the error is logged and stored, and the shutdown process continues for the remaining components. At the end, a summary of all errors is logged, and a std::runtime_error
is thrown if any errors occurred.
This mechanism ensures that a failure in one component does not prevent others from shutting down gracefully.
signal | The signal to pass to the shutdown method. |
std::runtime_error | If one or more components fail during shutdown. |
Definition at line 115 of file AppComponentManager.hpp.
|
private |
List of managed application components.
Definition at line 156 of file AppComponentManager.hpp.