RTC Toolkit  1.0.0
recordingThread.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_REUSABLECOMPONENT_TELEMETRYRECORDER_RECORDINGTHREAD_HPP
13 #define RTCTK_REUSABLECOMPONENT_TELEMETRYRECORDER_RECORDINGTHREAD_HPP
14 
15 #include <mutex>
16 #include <thread>
17 
18 #include <ipcq/reader.hpp>
20 
21 namespace rtctk::telemetryRecorder {
22 
27  STOPPED = 0,
28  RUNNING = 1,
29  PAUSED = 2,
30 };
31 
35 template<typename Writer, typename Topic = typename Writer::TelemetryType, typename Reader = ipcq::Reader<Topic>>
37 {
42  class InvalidStorageURLException : public ::elt::error::CiiBaseException {
43  public:
44  using ::elt::error::CiiBaseException::CiiBaseException;
45  explicit InvalidStorageURLException(const std::string& uri) :
46  CiiBaseException("Invalid Telemetry Storage URL: " +uri) {}
47  };
51  class InvalidRecordingThreadOperation : public ::elt::error::CiiBaseException {
52  public:
53  using ::elt::error::CiiBaseException::CiiBaseException;
54  explicit InvalidRecordingThreadOperation(const std::string& message) :
55  CiiBaseException("Invalid Operation on Recording Thread: " + message) {}
56  };
57 
61  class RecordingThreadIPCQError : public ::elt::error::CiiBaseException {
62  public:
63  using ::elt::error::CiiBaseException::CiiBaseException;
64  explicit RecordingThreadIPCQError(const std::string& message) :
65  CiiBaseException("Error in IPCQ: " + message) {}
66  };
67 
71  class RecordingThreadInvalidStartSample : public ::elt::error::CiiBaseException {
72  public:
73  using ::elt::error::CiiBaseException::CiiBaseException;
74  explicit RecordingThreadInvalidStartSample(const uint64_t sample_id) :
75  CiiBaseException("Invalid Start SampleID " + std::to_string(sample_id)) {}
76  };
77 
78  public:
85  RecordingThread(std::unique_ptr<Writer>&& writer, const std::string& topic);
91  RecordingThread(std::unique_ptr<Writer>&& writer, std::unique_ptr<Reader>&& reader);
92  RecordingThread(const RecordingThread&) = delete;
95 
96  // Mutex would prevent these anyways, but let us be explicit
99 
103  void Open();
107  void Close();
112  void SetTelemetrySubSet(const std::string& mask);
118  void SetSubSampleFactor(uint64_t rate);
123  void SetOutputUri(const ::elt::mal::Uri& storage_uri);
128  void SetTopic(const std::string& topic);
134  void SetStartSampleId(const uint64_t sample_id);
135 
140  void Start();
144  void Pause();
148  void Unpause();
152  void Stop();
153 
154  private:
158  void Process();
162  void ReadDataWrapper(const Topic& telemetry_data);
163 
164  std::mutex m_state_lock;
165  enum ThreadState m_state = STOPPED;
166  std::unique_ptr<Reader> m_reader;
167  std::unique_ptr<Writer> m_writer;
168  std::thread m_thread;
169  uint64_t m_subsample_rate = 0;
170  size_t m_sampling_counter = 0;
171  std::string m_topic_name;
172  std::string m_output_dir;
173  uint64_t m_start_sample = 0;
174  uint64_t m_last_observed_sample_id = 0;
175 };
176 
177 }
178 
180 
181 #endif //RTCTK_REUSABLECOMPONENT_TELEMETRYRECORDER_RECORDINGTHREAD_HPP
182 
rtctk::telemetryRecorder::RecordingThread::RecordingThread
RecordingThread()
Definition: recordingThreadDetail.hpp:25
rtctk::telemetryRecorder::RecordingThread::RecordingThread
RecordingThread(const RecordingThread &)=delete
rtctk::telemetryRecorder::RecordingThread::operator=
RecordingThread & operator=(RecordingThread &&)=delete
rtctk::telemetryRecorder::RecordingThread::Open
void Open()
Open the reader and writer.
Definition: recordingThreadDetail.hpp:145
rtctk::telemetryRecorder::RecordingThread::SetTopic
void SetTopic(const std::string &topic)
Set the topic for the ipc queue.
Definition: recordingThreadDetail.hpp:192
fitsRecorder.hpp
Business Logic of the Telemetry Recorder.
rtctk::telemetryRecorder::RecordingThread::Pause
void Pause()
Pause recording.
Definition: recordingThreadDetail.hpp:77
recordingThreadDetail.hpp
Recording Thread of the Telemetry Recorder template implementations.
rtctk::telemetryRecorder::RecordingThread::RecordingThread
RecordingThread(RecordingThread &&)=delete
rtctk::telemetryRecorder::PAUSED
@ PAUSED
Definition: recordingThread.hpp:29
rtctk::telemetryRecorder::RecordingThread
The RecordingThread is responsible for reading from the ipc queue and writing to the provided Writer.
Definition: recordingThread.hpp:37
rtctk::telemetryRecorder::RUNNING
@ RUNNING
Definition: recordingThread.hpp:28
rtctk::telemetryRecorder::RecordingThread::Stop
void Stop()
Stop the recording thread and wait for it's termination.
Definition: recordingThreadDetail.hpp:64
rtctk::telemetryRecorder::RecordingThread::SetSubSampleFactor
void SetSubSampleFactor(uint64_t rate)
Set the Subsample Factor.
Definition: recordingThreadDetail.hpp:178
rtctk::telemetryRecorder::RecordingThread::SetOutputUri
void SetOutputUri(const ::elt::mal::Uri &storage_uri)
Sets this URI where the output files should be written to.
Definition: recordingThreadDetail.hpp:170
rtctk::telemetryRecorder::RecordingThread::SetTelemetrySubSet
void SetTelemetrySubSet(const std::string &mask)
Set the TelemetrySubset for the Writer.
Definition: recordingThreadDetail.hpp:183
rtctk::telemetryRecorder::RecordingThread::SetStartSampleId
void SetStartSampleId(const uint64_t sample_id)
Set the first sample_id that should be recorded.
Definition: recordingThreadDetail.hpp:197
rtctk::telemetryRecorder::RecordingThread::Close
void Close()
Close the writer file.
Definition: recordingThreadDetail.hpp:161
rtctk::telemetryRecorder::RecordingThread::~RecordingThread
~RecordingThread()
Definition: recordingThreadDetail.hpp:43
rtctk::telemetryRecorder::RecordingThread::Unpause
void Unpause()
Unpause the recording or begin recording after having started the recording thread.
Definition: recordingThreadDetail.hpp:85
rtctk::telemetryRecorder
Definition: businessLogic.hpp:20
rtctk::telemetryRecorder::RecordingThread::Start
void Start()
Start the recording thread.
Definition: recordingThreadDetail.hpp:55
rtctk::telemetryRecorder::RecordingThread::operator=
RecordingThread & operator=(const RecordingThread &)=delete
rtctk::telemetryRecorder::STOPPED
@ STOPPED
Definition: recordingThread.hpp:27
rtctk::telemetryRecorder::ThreadState
ThreadState
State of the RecordingThread.
Definition: recordingThread.hpp:26