RTC Toolkit  2.0.0
operationalLogic.hpp
Go to the documentation of this file.
1 
11 #ifndef RTCKT_TELSUB_OPERATIONALLOGIC_HPP
12 #define RTCKT_TELSUB_OPERATIONALLOGIC_HPP
13 #include <atomic>
14 #include <chrono>
15 #include <mutex>
16 #include <optional>
17 #include <thread>
18 
24 
25 namespace rtctk::telSub {
26 
75 class OperationalLogic final : public OperationalLogicIf {
76 public:
91  std::unique_ptr<CorrelatorIf>&& correlator,
92  std::unique_ptr<ShmPublisherIf>&& shm_publisher,
95  std::unique_ptr<std::pmr::monotonic_buffer_resource>&& resource = {},
96  std::unique_ptr<std::byte[]>&& memory = {});
97 
101  ~OperationalLogic() noexcept;
102 
110  void RunAsync() RTCTK_NOEXCEPT override;
111 
117  void IdleAsync() RTCTK_NOEXCEPT override;
118 
119  LastError GetLastError() const RTCTK_NOEXCEPT override;
120  uint64_t GetErrorCount() const RTCTK_NOEXCEPT override;
121 
122 private:
123  enum class State : int { Idle = 0, Run, Exit };
124 
128  void ProcessingLoop();
132  void MonitoringLoop();
133 
134  // First members because other members might have memory allocated to these
135  std::unique_ptr<std::byte[]> m_mem;
136  std::unique_ptr<std::pmr::monotonic_buffer_resource> m_resource;
138 
139  OperationalParams const m_params;
140 
155  std::mutex mutable m_error_mutex;
156  std::error_code m_last_corr_error;
157  std::error_code m_last_pub_error;
158  uint64_t m_error_count;
159  componentFramework::AlertSource m_input_alert;
160  componentFramework::AlertSource m_output_alert;
166  std::atomic<State> m_requested_state;
167  std::unique_ptr<CorrelatorIf> m_correlator;
168  std::unique_ptr<ShmPublisherIf> m_shm_publisher;
169  std::thread m_processing_thread;
174  std::thread m_monitoring_thread;
175 };
176 
177 } // namespace rtctk::telSub
178 #endif // #ifndef RTCKT_TELSUB_OPERATIONALLOGIC_HPP
rtctk::componentFramework::AlertSource
Models a single alert source that can be set or cleared.
Definition: alertServiceIf.hpp:42
componentMetricsIf.hpp
Header file for ComponentMetricsIf.
rtctk::telSub::OperationalLogicIf
Interface to the operational logic implementation.
Definition: operationalLogicIf.hpp:64
rtctk::componentFramework::AlertSourceFactoryIf
Interface to create AlertSource.
Definition: alertServiceIf.hpp:179
shmPublisherIf.hpp
Declares ShmPublisher.
alertServiceIf.hpp
Header file for AlertServiceIf and related classes.
rtctk::componentFramework::ComponentMetricsIf
Component metrics interface.
Definition: componentMetricsIf.hpp:177
operationalLogicIf.hpp
Declares OperationalLogicIf.
rtctk::telSub::OperationalLogicIf::LastError
Describes last errors.
Definition: operationalLogicIf.hpp:72
rtctk::telSub
Definition: main.cpp:6
rtctk::telSub::OperationalParams
Configuration parameters needed for operational logic.
Definition: operationalLogicIf.hpp:45
correlatorIf.hpp
Declares CorrelatorIf.
rtctk::telSub::OperationalLogic::OperationalLogic
OperationalLogic(OperationalParams params, std::unique_ptr< CorrelatorIf > &&correlator, std::unique_ptr< ShmPublisherIf > &&shm_publisher, componentFramework::ComponentMetricsIf &metrics, componentFramework::AlertSourceFactoryIf &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:24
rtctk::telSub::OperationalLogic::~OperationalLogic
~OperationalLogic() noexcept
Requests threads to exit and joins with it.
Definition: operationalLogic.cpp:67
rtctk::telSub::OperationalLogic::GetLastError
LastError GetLastError() const RTCTK_NOEXCEPT override
Return last recorded error.
Definition: operationalLogic.cpp:101
RTCTK_NOEXCEPT
#define RTCTK_NOEXCEPT
Definition: config.hpp:15
rtctk::telSub::OperationalLogic::GetErrorCount
uint64_t GetErrorCount() const RTCTK_NOEXCEPT override
Get current error count.
Definition: operationalLogic.cpp:106
rtctk::telSub::OperationalLogic::IdleAsync
void IdleAsync() RTCTK_NOEXCEPT override
Stop publishing.
Definition: operationalLogic.cpp:93
rtctk::telSub::OperationalLogic::RunAsync
void RunAsync() RTCTK_NOEXCEPT override
Start publishing.
Definition: operationalLogic.cpp:79
rtctk::telSub::OperationalLogic
Implements the behaviour for Operational state.
Definition: operationalLogic.hpp:75