2#ifndef _CONSOLIX_LOOP_COMPONENT_HPP_INCLUDED
3#define _CONSOLIX_LOOP_COMPONENT_HPP_INCLUDED
76 }
catch (
const std::exception& e) {
77# if CONSOLIX_USE_LOGIT == 1
78 LOGIT_PRINT_ERROR(
"Unhandled exception during initialization: ", e.what());
80 CONSOLIX_STREAM() <<
"Unhandled exception during initialization: " << e.what() << std::endl;
100 else std::this_thread::sleep_for(std::chrono::milliseconds(1));
101 }
catch (
const std::exception& e) {
102# if CONSOLIX_USE_LOGIT == 1
103 LOGIT_PRINT_ERROR(
"Unhandled exception during execution: , e.what());
105 CONSOLIX_STREAM() << "Unhandled exception during execution: << e.what() << std::endl;
118 }
catch (
const std::exception& e) {
119# if CONSOLIX_USE_LOGIT == 1
120 LOGIT_PRINT_ERROR(
"Unhandled exception during shutdown: ", e.what());
122 CONSOLIX_STREAM() <<
"Unhandled exception during shutdown: " << e.what() << std::endl;
#define CONSOLIX_STREAM()
Fallback for general logging.
Interface for defining application components.
Interface for components supporting shutdown logic.
std::function< void()> m_on_execute
Execution function for the loop.
std::atomic< bool > m_is_init
Indicates whether the component is initialized.
std::function< void(int)> & on_shutdown()
Access the shutdown function.
bool initialize() override
Initializes the component.
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.
bool is_initialized() override const
Checks if the component is initialized.
std::function< bool()> & on_initialize()
Access the initialization function.
void shutdown(int signal) override
Shuts down the component.
std::function< void()> & on_execute()
Access the execution function.
std::function< void(int)> m_on_shutdown
Shutdown function.
void execute() override
Executes the main loop logic.
virtual ~LoopComponent() override=default
Virtual destructor.
std::function< bool()> m_on_initialize
Initialization function.
< Utility modules and helpers.
void stop()
Stops the application. Stops the application's main loop and begins the shutdown process.