RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
operationalLogic.hpp
Go to the documentation of this file.
1
12#ifndef RTCKT_TELSUB_OPERATIONALLOGIC_HPP
13#define RTCKT_TELSUB_OPERATIONALLOGIC_HPP
14#include <atomic>
15#include <chrono>
16#include <mutex>
17#include <optional>
18#include <system_error>
19#include <thread>
20
26
27namespace rtctk::telSub {
28
79public:
95 std::unique_ptr<CorrelatorIf>&& correlator,
96 std::unique_ptr<ShmPublisherIf>&& shm_publisher,
99 std::unique_ptr<std::pmr::monotonic_buffer_resource>&& resource = {},
100 std::unique_ptr<std::byte[]>&& memory = {});
101
105 ~OperationalLogic() noexcept;
106
114 void RunAsync() RTCTK_NOEXCEPT override;
115
121 void IdleAsync() RTCTK_NOEXCEPT override;
122
123 LastError GetLastError() const RTCTK_NOEXCEPT override;
124 uint64_t GetErrorCount() const RTCTK_NOEXCEPT override;
125
126private:
127 enum class State : uint8_t { Idle = 0, Run, Exit };
128
132 void ProcessingLoop();
136 void MonitoringLoop();
137
138 log4cplus::Logger& m_logger;
139
140 // First members because other members might have memory allocated to these
141 std::unique_ptr<std::byte[]> m_mem;
142 std::unique_ptr<std::pmr::monotonic_buffer_resource> m_resource;
144
145 const OperationalParams m_params;
146
161 std::mutex mutable m_error_mutex;
162 std::optional<CorrelationError> m_last_corr_error;
163 ShmPublisherIf::PublisherError m_last_pub_error;
164 uint64_t m_error_count;
166 componentFramework::AlertSource m_correlator_alert;
167 componentFramework::AlertSource m_blender_alert;
174 std::atomic<State> m_requested_state;
175 std::unique_ptr<CorrelatorIf> m_correlator;
176 std::unique_ptr<ShmPublisherIf> m_shm_publisher;
177 std::thread m_processing_thread;
182 std::thread m_monitoring_thread;
183};
184
185} // namespace rtctk::telSub
186
187#endif // RTCKT_TELSUB_OPERATIONALLOGIC_HPP
Declares AlertService.
Alert Service interface.
Definition alertServiceIf.hpp:128
Models a single alert source that can be set or cleared.
Definition alertServiceIf.hpp:47
Component metrics interface.
Definition componentMetricsIf.hpp:85
Interface to the operational logic implementation.
Definition operationalLogicIf.hpp:74
Implements the behaviour for Operational state.
Definition operationalLogic.hpp:78
uint64_t GetErrorCount() const RTCTK_NOEXCEPT override
Get current error count.
Definition operationalLogic.cpp:117
void IdleAsync() RTCTK_NOEXCEPT override
Stop publishing.
Definition operationalLogic.cpp:107
~OperationalLogic() noexcept
Requests threads to exit and joins with it.
Definition operationalLogic.cpp:87
LastError GetLastError() const RTCTK_NOEXCEPT override
Return last recorded error.
Definition operationalLogic.cpp:112
void RunAsync() RTCTK_NOEXCEPT override
Start publishing.
Definition operationalLogic.cpp:99
OperationalLogic(OperationalParams params, std::unique_ptr< CorrelatorIf > &&correlator, std::unique_ptr< ShmPublisherIf > &&shm_publisher, componentFramework::ComponentMetricsIf &metrics, componentFramework::AlertServiceIf &alerts, std::unique_ptr< std::pmr::monotonic_buffer_resource > &&resource={}, std::unique_ptr< std::byte[]> &&memory={})
Spawns reader thread and starts subscribing to DDS data, but does not publish until StartAsync() is i...
Definition operationalLogic.cpp:37
std::variant< std::monostate, BlenderError, ShmError > PublisherError
Definition shmPublisherIf.hpp:45
#define RTCTK_NOEXCEPT
Definition config.hpp:63
Header file for ComponentMetricsIf.
Declares CorrelatorIf.
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition main.cpp:24
Declares OperationalLogicIf.
Declares ShmPublisher.
Describes last errors.
Definition operationalLogicIf.hpp:82
Configuration parameters needed for operational logic.
Definition operationalLogicIf.hpp:55