Consolix
Loading...
Searching...
No Matches
BaseLoopComponent.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _CONSOLIX_BASE_LOOP_COMPONENT_HPP_INCLUDED
3#define _CONSOLIX_BASE_LOOP_COMPONENT_HPP_INCLUDED
4
8
9#include <thread>
10#include <atomic>
11#include <chrono>
12
13namespace consolix {
14
24 public:
26 BaseLoopComponent() = default;
27
29 virtual ~BaseLoopComponent() = default;
30
36 virtual bool on_once() = 0;
37
42 virtual void on_loop() = 0;
43
50 virtual void on_shutdown(int signal) = 0;
51
52 protected:
53
59 bool initialize() override final {
61 return m_is_init;
62 }
63
66 bool is_initialized() const override final {
67 return m_is_init;
68 }
69
73 void process() override final {
74 on_loop();
75 }
76
81 void shutdown(int signal) override final {
82 on_shutdown(signal);
83 }
84
85 private:
86 std::atomic<bool> m_is_init{false};
87 }; // BaseLoopComponent
88
89}; // namespace consolix
90
91#endif // _CONSOLIX_BASE_LOOP_COMPONENT_HPP_INCLUDED
void shutdown(int signal) override final
Shuts down the component.
std::atomic< bool > m_is_init
Tracks whether the component is initialized.
virtual void on_shutdown(int signal)=0
Called when the application shuts down.
virtual void on_loop()=0
Called repeatedly during the application's main loop.
BaseLoopComponent()=default
Constructs a BaseLoopComponent.
bool initialize() override final
Initializes the component.
void process() override final
Executes the loop logic for the component.
virtual bool on_once()=0
Called once during component initialization.
virtual ~BaseLoopComponent()=default
Destroys the BaseLoopComponent.
bool is_initialized() const override final
Checks if the component has been initialized.
Interface for defining application components.
Interface for components supporting shutdown logic.
< Utility modules and helpers.