RTC Toolkit  1.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 
22 
23 namespace rtctk::telSub {
24 
73 class OperationalLogic final : public OperationalLogicIf {
74 public:
88  std::unique_ptr<CorrelatorIf>&& correlator,
89  std::unique_ptr<ShmPublisherIf>&& shm_publisher,
90  std::unique_ptr<std::pmr::monotonic_buffer_resource>&& resource = {},
91  std::unique_ptr<std::byte[]>&& memory = {});
92 
96  ~OperationalLogic() noexcept;
97 
105  void RunAsync() RTCTK_NOEXCEPT override;
106 
112  void IdleAsync() RTCTK_NOEXCEPT override;
113 
114  std::error_code GetLastError() const RTCTK_NOEXCEPT override;
115  uint64_t GetErrorCount() const RTCTK_NOEXCEPT override;
116 
117 private:
118  enum class State : int { Idle = 0, Run, Exit };
119 
123  void ProcessingLoop();
127  void MonitoringLoop();
128 
129  // First members because other members might have memory allocated to these
130  std::unique_ptr<std::byte[]> m_mem;
131  std::unique_ptr<std::pmr::monotonic_buffer_resource> m_resource;
132 
133  OperationalParams const m_params;
134 
149  std::mutex mutable m_error_mutex;
150  std::error_code m_last_error;
151  uint64_t m_error_count;
157  std::atomic<State> m_requested_state;
158  std::unique_ptr<CorrelatorIf> m_correlator;
159  std::unique_ptr<ShmPublisherIf> m_shm_publisher;
160  std::thread m_processing_thread;
165  std::thread m_monitoring_thread;
166 };
167 
168 } // namespace rtctk::telSub
169 #endif // #ifndef RTCKT_TELSUB_OPERATIONALLOGIC_HPP
rtctk::telSub::OperationalLogic::GetLastError
std::error_code GetLastError() const RTCTK_NOEXCEPT override
Return last recorded error.
Definition: operationalLogic.cpp:79
rtctk::telSub::OperationalLogicIf
Interface to the operational logic implementation.
Definition: operationalLogicIf.hpp:64
shmPublisherIf.hpp
Declares ShmPublisher.
operationalLogicIf.hpp
Declares OperationalLogicIf.
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, 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:22
rtctk::telSub::OperationalLogic::~OperationalLogic
~OperationalLogic() noexcept
Requests threads to exit and joins with it.
Definition: operationalLogic.cpp:50
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:84
rtctk::telSub::OperationalLogic::IdleAsync
void IdleAsync() RTCTK_NOEXCEPT override
Stop publishing.
Definition: operationalLogic.cpp:74
rtctk::telSub::OperationalLogic::RunAsync
void RunAsync() RTCTK_NOEXCEPT override
Start publishing.
Definition: operationalLogic.cpp:62
rtctk::telSub::OperationalLogic
Implements the behaviour for Operational state.
Definition: operationalLogic.hpp:73