RTC Toolkit 6.0.0-pre2
Loading...
Searching...
No Matches
publisher.hpp
Go to the documentation of this file.
1
12
13#ifndef RTCTK_REUSABLECOMPONENT_MUDPIPUB_PUBLISHER_HPP
14#define RTCTK_REUSABLECOMPONENT_MUDPIPUB_PUBLISHER_HPP
15
16#include <semaphore>
17#include <string>
18#include <thread>
19#include <vector>
20
23
24namespace rtctk::mudpiPub {
25
26// forward declaration to hide internally used class
27class SampleGenerator;
28
35class Publisher {
36public:
37 /*
38 * @brief type alias for provided user data
39 *
40 * user data is basially a vector of blobs, where each element represents a sample
41 */
42 using UserSamples = std::vector<std::vector<uint8_t>>;
43
53 Publisher(const std::string& pub_id, const PubCfg& cfg, UserSamples data = {});
54
58 virtual ~Publisher();
59
63 void SendSample();
64
69
73 void Init();
74
83 void UpdateDynamicConfig(const PubDynamicCfg& cfg, UserSamples user_samples = {});
84
88 const std::string& GetId() const {
89 return m_id;
90 }
91
92private:
93 void Run(std::stop_token st);
94
95 log4cplus::Logger& m_logger;
96
97 std::string m_id;
98
99 PubStaticCfg m_cfg;
100
101 std::binary_semaphore m_sem_start;
102 std::binary_semaphore m_sem_done;
103
104 std::mutex m_generator_mutex;
105 std::unique_ptr<SampleGenerator> m_generator;
106
107 std::jthread m_thread;
108};
109
110} // namespace rtctk::mudpiPub
111
112#endif // RTCTK_REUSABLECOMPONENT_MUDPIPUB_PUBLISHER_HPP
void WaitUntilSendingDone()
Blocks until the sample has been sent.
Definition publisher.cpp:218
Publisher(const std::string &pub_id, const PubCfg &cfg, UserSamples data={})
Constructs a new publisher object.
Definition publisher.cpp:171
void SendSample()
Signals the worker thread to send a sample.
Definition publisher.cpp:214
virtual ~Publisher()
Destroys publisher object.
const std::string & GetId() const
Returns the name of the publisher object.
Definition publisher.hpp:88
void Init()
Resets the sample_id to zero.
Definition publisher.cpp:209
std::vector< std::vector< uint8_t > > UserSamples
Definition publisher.hpp:42
void UpdateDynamicConfig(const PubDynamicCfg &cfg, UserSamples user_samples={})
Updates dynamic configuration.
Definition publisher.cpp:204
Definition publisher.cpp:46
Logging Support Library based on log4cplus.
Definition businessLogic.cpp:24
RTC toolkit MUDPI publisher configuration class declaration.
Configuration (Dynamic + Static) of a single MUDPI Publisher object.
Definition config.hpp:79
Dynamic Configuration of a single MUDPI Publisher object.
Definition config.hpp:29
Static Configuration of a single MUDPI Publisher object.
Definition config.hpp:43