RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
malDdsEventService.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_COMPONENTFRAMEWORK_MALDDSEVENTSERVICE_HPP
13#define RTCTK_COMPONENTFRAMEWORK_MALDDSEVENTSERVICE_HPP
14
15#include <Rtctkif.hpp>
18
19#include <mal/Cii.hpp>
20#include <mal/Mal.hpp>
21#include <mal/utility/LoadMal.hpp>
22
23#include <map>
24#include <mutex>
25#include <string>
26
28
36public:
38
42 std::unique_ptr<EventPublisherIf> MakePublisher(const std::string& topic) override;
43
47 std::unique_ptr<EventSubscriberIf> MakeSubscriber(const std::string& topic) override;
48
49private:
50 elt::mal::Mal::Properties GetMalProperties();
51
52 // cppcheck-suppress-begin unusedStructMember
53
54 // mal objects
55 const elt::mal::Mal::Properties m_props;
56 std::shared_ptr<elt::mal::Mal> m_mal;
57 elt::mal::CiiFactory& m_factory;
58
59 // cppcheck-suppress-end unusedStructMember
60};
61
68class MalDdsEventPublisher : public EventPublisherIf {
69public:
70 // Use factory method from MalDdsEventService to construct publisher objects
72
76 void Publish(const JsonPayload& sample) override;
77
78private:
79 MalDdsEventPublisher(elt::mal::CiiFactory& factory,
80 const std::string& topic,
81 const elt::mal::Mal::Properties& props);
82
83 std::unique_ptr<elt::mal::ps::Publisher<rtctkif::GenericEvent>> m_publisher;
84 std::mutex m_mutex;
85};
86
93class MalDdsEventSubscriber : public EventSubscriberIf {
94public:
95 // Use factory method from MalDdsEventService to construct subscriber objects
97
101 void Subscribe(std::function<void(const JsonPayload&)> cb) override;
102
106 void Unsubscribe() override;
107
108 // cppcheck-suppress unusedStructMember
109 inline static const std::string QOS_FILE = "config/rtctk/dds/eventServiceDdsQos.xml";
110
111private:
112 MalDdsEventSubscriber(elt::mal::CiiFactory& factory,
113 const std::string& topic,
114 const elt::mal::Mal::Properties& props);
115
116 std::unique_ptr<elt::mal::ps::Subscriber<rtctkif::GenericEvent>> m_subscriber;
117 std::unique_ptr<elt::mal::ps::Subscription> m_subscription;
118 std::mutex m_mutex;
119};
120
121} // namespace rtctk::componentFramework
122
123#endif // RTCTK_COMPONENTFRAMEWORK_MALDDSEVENTSERVICE_HPP
Interface class for publishing JSON events.
Definition eventServiceIf.hpp:51
Interface class for providing pub/sub facilities for JSON events.
Definition eventServiceIf.hpp:28
Interface class for subscribing to JSON events.
Definition eventServiceIf.hpp:67
void Publish(const JsonPayload &sample) override
Publishes a new data sample.
Definition malDdsEventService.cpp:101
friend MalDdsEventService
Definition malDdsEventService.hpp:71
MalDdsEventService()
Definition malDdsEventService.cpp:31
std::unique_ptr< EventSubscriberIf > MakeSubscriber(const std::string &topic) override
Factory method to create a new subscriber object.
Definition malDdsEventService.cpp:86
std::unique_ptr< EventPublisherIf > MakePublisher(const std::string &topic) override
Factory method to create a new publisher object.
Definition malDdsEventService.cpp:81
void Subscribe(std::function< void(const JsonPayload &)> cb) override
Subscribes to the topic.
Definition malDdsEventService.cpp:126
friend MalDdsEventService
Definition malDdsEventService.hpp:96
void Unsubscribe() override
Unsubscribes from the topic.
Definition malDdsEventService.cpp:141
static const std::string QOS_FILE
Definition malDdsEventService.hpp:109
Low-level interface of the event service.
Defines the JSON payload type JsonPayload.
Definition commandReplier.cpp:21
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:24