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

Component for managing a customizable execution loop. More...

#include <LoopComponent.hpp>

Inheritance diagram for consolix::LoopComponent:
consolix::IAppComponent consolix::IShutdownable

Public Member Functions

 LoopComponent ()=default
 Default constructor.
 LoopComponent (std::function< bool()> on_initialize, std::function< void()> on_execute, std::function< void(int)> on_shutdown)
 Constructor with customizable callbacks.
virtual ~LoopComponent () override=default
 Virtual destructor.
std::function< bool()> & on_initialize ()
 Access the initialization function.
std::function< void()> & on_execute ()
 Access the execution function.
std::function< void(int)> & on_shutdown ()
 Access the shutdown function.
Public Member Functions inherited from consolix::IAppComponent
virtual ~IAppComponent ()=default
 Virtual destructor for polymorphic usage.
Public Member Functions inherited from consolix::IShutdownable
virtual ~IShutdownable ()=default
 Virtual destructor for polymorphic use.

Protected Member Functions

bool initialize () override
 Initializes the component.
bool is_initialized () const override
 Checks if the component is initialized.
void process () override
 Executes the main loop logic.
void shutdown (int signal) override
 Shuts down the component. This callback runs outside the POSIX signal handler even when a signal initiated shutdown.

Private Attributes

std::function< bool()> m_on_initialize
 Initialization function.
std::function< void()> m_on_execute
 Execution function for the loop.
std::function< void(int)> m_on_shutdown
 Shutdown function.
std::atomic< bool > m_is_init {false}
 Indicates whether the component is initialized.

Detailed Description

Component for managing a customizable execution loop.

This component allows for running a loop with user-defined behavior. It supports three customizable functions:

  • on_initialize: Called once during initialization.
  • on_execute: Called repeatedly while the loop is running.
  • on_shutdown: Called during shutdown from the normal application path.

Definition at line 24 of file LoopComponent.hpp.

Constructor & Destructor Documentation

◆ LoopComponent() [1/2]

consolix::LoopComponent::LoopComponent ( )
default

Default constructor.

◆ LoopComponent() [2/2]

consolix::LoopComponent::LoopComponent ( std::function< bool()> on_initialize,
std::function< void()> on_execute,
std::function< void(int)> on_shutdown )
inline

Constructor with customizable callbacks.

Parameters
on_initializeFunction to execute during initialization.
on_executeFunction to execute in the loop.
on_shutdownFunction to execute during shutdown.

Definition at line 36 of file LoopComponent.hpp.

◆ ~LoopComponent()

virtual consolix::LoopComponent::~LoopComponent ( )
overridevirtualdefault

Virtual destructor.

Member Function Documentation

◆ initialize()

bool consolix::LoopComponent::initialize ( )
inlineoverrideprotectedvirtual

Initializes the component.

Returns
true if initialization succeeds, false otherwise.

Implements consolix::IAppComponent.

Definition at line 70 of file LoopComponent.hpp.

◆ is_initialized()

bool consolix::LoopComponent::is_initialized ( ) const
inlineoverrideprotectedvirtual

Checks if the component is initialized.

Returns
true if the component is initialized, false otherwise.

Implements consolix::IAppComponent.

Definition at line 88 of file LoopComponent.hpp.

◆ on_execute()

std::function< void()> & consolix::LoopComponent::on_execute ( )
inline

Access the execution function.

Returns
Reference to the execution function.

Definition at line 56 of file LoopComponent.hpp.

◆ on_initialize()

std::function< bool()> & consolix::LoopComponent::on_initialize ( )
inline

Access the initialization function.

Returns
Reference to the initialization function.

Definition at line 50 of file LoopComponent.hpp.

◆ on_shutdown()

std::function< void(int)> & consolix::LoopComponent::on_shutdown ( )
inline

Access the shutdown function.

Returns
Reference to the shutdown function.

Definition at line 62 of file LoopComponent.hpp.

◆ process()

void consolix::LoopComponent::process ( )
inlineoverrideprotectedvirtual

Executes the main loop logic.

Calls the on_execute function repeatedly. If no function is provided, the loop idles with a short sleep.

Implements consolix::IAppComponent.

Definition at line 96 of file LoopComponent.hpp.

◆ shutdown()

void consolix::LoopComponent::shutdown ( int signal)
inlineoverrideprotectedvirtual

Shuts down the component. This callback runs outside the POSIX signal handler even when a signal initiated shutdown.

Parameters
signalThe shutdown signal.

Implements consolix::IShutdownable.

Definition at line 113 of file LoopComponent.hpp.

Member Data Documentation

◆ m_is_init

std::atomic<bool> consolix::LoopComponent::m_is_init {false}
private

Indicates whether the component is initialized.

Definition at line 130 of file LoopComponent.hpp.

◆ m_on_execute

std::function<void()> consolix::LoopComponent::m_on_execute
private

Execution function for the loop.

Definition at line 128 of file LoopComponent.hpp.

◆ m_on_initialize

std::function<bool()> consolix::LoopComponent::m_on_initialize
private

Initialization function.

Definition at line 127 of file LoopComponent.hpp.

◆ m_on_shutdown

std::function<void(int)> consolix::LoopComponent::m_on_shutdown
private

Shutdown function.

Definition at line 129 of file LoopComponent.hpp.


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