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;
99 else std::this_thread::sleep_for(std::chrono::milliseconds(1));
100 }
catch (
const std::exception& e) {
101# if CONSOLIX_USE_LOGIT == 1
102 LOGIT_PRINT_ERROR(
"Unhandled exception during execution: ", e.what());
104 CONSOLIX_STREAM() <<
"Unhandled exception during execution: " << e.what() << std::endl;
116 }
catch (
const std::exception& e) {
117# if CONSOLIX_USE_LOGIT == 1
118 LOGIT_PRINT_ERROR(
"Unhandled exception during shutdown: ", e.what());
120 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.
void process() override
Executes the main loop logic.
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() const override
Checks if the component is initialized.
std::function< bool()> & on_initialize()
Access the initialization function.
void shutdown(int signal) override
Shuts down the component. This callback runs outside the POSIX signal handler even when a signal init...
std::function< void()> & on_execute()
Access the execution function.
std::function< void(int)> m_on_shutdown
Shutdown function.
virtual ~LoopComponent() override=default
Virtual destructor.
std::function< bool()> m_on_initialize
Initialization function.
< Utility modules and helpers.