Consolix
Loading...
Searching...
No Matches
consolix::AppComponentManager Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AppComponentManager()

consolix::AppComponentManager::AppComponentManager ( )
default

Constructs an empty component manager.

◆ ~AppComponentManager()

consolix::AppComponentManager::~AppComponentManager ( )
inline

Destroys the component manager and clears all components.

Definition at line 32 of file AppComponentManager.hpp.

Member Function Documentation

◆ add() [1/2]

template<typename Component, typename... Args>
std::shared_ptr< Component > consolix::AppComponentManager::add ( Args &&... args)
inline

Adds a new component to the manager.

Constructs a new component of type Component and registers it with the manager.

Template Parameters
ComponentThe type of the component to create.
ArgsArgument types for the component's constructor.
Parameters
argsArguments for constructing the component.
Returns
A shared pointer to the newly created component.

Definition at line 44 of file AppComponentManager.hpp.

◆ add() [2/2]

void consolix::AppComponentManager::add ( std::shared_ptr< IAppComponent > component)
inline

Adds an existing component to the manager.

Parameters
componentA std::shared_ptr to the component to add.

Definition at line 52 of file AppComponentManager.hpp.

◆ initialize()

bool consolix::AppComponentManager::initialize ( )
inline

Initializes all registered components.

Skips components that are already initialized.

Returns
true if all components are initialized successfully, false otherwise.
Exceptions
std::exceptionIf any component fails during initialization.

Definition at line 61 of file AppComponentManager.hpp.

◆ is_initialized()

bool consolix::AppComponentManager::is_initialized ( ) const
inline

Checks if all components are initialized.

Returns
true if all components are initialized, false otherwise.

Definition at line 78 of file AppComponentManager.hpp.

◆ process()

void consolix::AppComponentManager::process ( )
inline

Executes the main functionality of all components.

Calls process() on each managed component.

Exceptions
std::exceptionIf any component fails during execution.

Definition at line 89 of file AppComponentManager.hpp.

◆ shutdown()

void consolix::AppComponentManager::shutdown ( int signal)
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.

Parameters
signalThe signal to pass to the shutdown method.
Exceptions
std::runtime_errorIf one or more components fail during shutdown.

Definition at line 115 of file AppComponentManager.hpp.

Member Data Documentation

◆ m_components

std::vector<std::shared_ptr<IAppComponent> > consolix::AppComponentManager::m_components
private

List of managed application components.

Definition at line 156 of file AppComponentManager.hpp.


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