Consolix
Loading...
Searching...
No Matches
consolix::BaseLoopComponent Class Referenceabstract

Abstract base class for application components with looping functionality. More...

#include <BaseLoopComponent.hpp>

Inheritance diagram for consolix::BaseLoopComponent:
consolix::IAppComponent consolix::IShutdownable CustomLoop

Public Member Functions

 BaseLoopComponent ()=default
 Constructs a BaseLoopComponent.
 
virtual ~BaseLoopComponent ()=default
 Destroys the BaseLoopComponent.
 
virtual bool on_once ()=0
 Called once during component initialization.
 
virtual void on_loop ()=0
 Called repeatedly during the application's main loop.
 
virtual void on_shutdown (int signal)=0
 Called when the application shuts down.
 
- 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 final
 Initializes the component.
 
bool is_initialized () const override final
 Checks if the component has been initialized.
 
void process () override final
 Executes the loop logic for the component.
 
void shutdown (int signal) override final
 Shuts down the component.
 

Private Attributes

std::atomic< bool > m_is_init {false}
 Tracks whether the component is initialized.
 

Detailed Description

Abstract base class for application components with looping functionality.

This class provides a framework for implementing components that require a continuous execution cycle. Derived classes must define:

  • on_once() for one-time initialization logic.
  • on_loop() for the recurring loop logic.
  • on_shutdown(signal) for handling cleanup when the application shuts down.
Examples
example_application_main_loop.cpp.

Definition at line 23 of file BaseLoopComponent.hpp.

Constructor & Destructor Documentation

◆ BaseLoopComponent()

consolix::BaseLoopComponent::BaseLoopComponent ( )
default

Constructs a BaseLoopComponent.

◆ ~BaseLoopComponent()

virtual consolix::BaseLoopComponent::~BaseLoopComponent ( )
virtualdefault

Destroys the BaseLoopComponent.

Member Function Documentation

◆ initialize()

bool consolix::BaseLoopComponent::initialize ( )
inlinefinaloverrideprotectedvirtual

Initializes the component.

Calls on_once() to perform one-time setup and marks the component as initialized if successful.

Returns
true if initialization succeeds, false otherwise.

Implements consolix::IAppComponent.

Definition at line 58 of file BaseLoopComponent.hpp.

◆ is_initialized()

bool consolix::BaseLoopComponent::is_initialized ( ) const
inlinefinaloverrideprotectedvirtual

Checks if the component has been initialized.

Returns
true if the component is initialized, false otherwise.

Implements consolix::IAppComponent.

Definition at line 65 of file BaseLoopComponent.hpp.

◆ on_loop()

virtual void consolix::BaseLoopComponent::on_loop ( )
pure virtual

Called repeatedly during the application's main loop.

Derived classes should implement this method to define the recurring functionality of the component.

Implemented in CustomLoop.

◆ on_once()

virtual bool consolix::BaseLoopComponent::on_once ( )
pure virtual

Called once during component initialization.

Derived classes should implement this method to perform setup operations that need to happen before the main loop starts.

Returns
true if initialization succeeds, false otherwise.

Implemented in CustomLoop.

◆ on_shutdown()

virtual void consolix::BaseLoopComponent::on_shutdown ( int signal)
pure virtual

Called when the application shuts down.

Derived classes should implement this method to release resources or perform cleanup operations before termination.

Parameters
signalThe signal that triggered the shutdown.

Implemented in CustomLoop.

◆ process()

void consolix::BaseLoopComponent::process ( )
inlinefinaloverrideprotectedvirtual

Executes the loop logic for the component.

Calls on_loop() to run the recurring functionality of the component.

Implements consolix::IAppComponent.

Definition at line 72 of file BaseLoopComponent.hpp.

◆ shutdown()

void consolix::BaseLoopComponent::shutdown ( int signal)
inlinefinaloverrideprotectedvirtual

Shuts down the component.

Calls on_shutdown(signal) to clean up resources or terminate processes.

Parameters
signalThe signal that triggered the shutdown.

Implements consolix::IShutdownable.

Definition at line 80 of file BaseLoopComponent.hpp.

Member Data Documentation

◆ m_is_init

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

Tracks whether the component is initialized.

Definition at line 85 of file BaseLoopComponent.hpp.


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