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
49 virtual void on_shutdown(int signal) = 0;
50
51 protected:
52
58 bool initialize() override final {
60 return m_is_init;
61 }
62
65 bool is_initialized() const override final {
66 return m_is_init;
67 }
68
72 void process() override final {
73 on_loop();
74 }
75
80 void shutdown(int signal) override final {
81 on_shutdown(signal);
82 }
83
84 private:
85 std::atomic<bool> m_is_init{false};
86 }; // BaseLoopComponent
87
88}; // namespace consolix
89
90#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.