RTC Toolkit  2.0.0
malDdsEventService.hpp
Go to the documentation of this file.
1 
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 
27 namespace rtctk::componentFramework {
28 
35 public:
36 
38 
42  std::unique_ptr<EventPublisherIf> MakePublisher(std::string const& topic) override;
43 
47  std::unique_ptr<EventSubscriberIf> MakeSubscriber(std::string const& topic) override;
48 
49 private:
50  elt::mal::Mal::Properties GetMalProperties();
51 
52  // mal objects
53  elt::mal::Mal::Properties const m_props;
54  std::shared_ptr<elt::mal::Mal> m_mal;
55  elt::mal::CiiFactory& m_factory;
56 };
57 
64 public:
65  // Use factory method from MalDdsEventService to construct publisher objects
67 
71  void Publish(JsonPayload const& sample) override;
72 
73 private:
74  MalDdsEventPublisher(elt::mal::CiiFactory& factory,
75  std::string const& topic,
76  elt::mal::Mal::Properties const& props);
77 
78  std::unique_ptr<elt::mal::ps::Publisher<rtctkif::GenericEvent>> m_publisher;
79  std::mutex m_mutex;
80 };
81 
88 public:
89  // Use factory method from MalDdsEventService to construct subscriber objects
91 
95  void Subscribe(std::function<void(JsonPayload const&)> cb) override;
96 
100  void Unsubscribe() override;
101 
102  inline static const std::string QOS_FILE = "config/rtctk/dds/eventServiceDdsQos.xml";
103 private:
104  MalDdsEventSubscriber(elt::mal::CiiFactory& factory,
105  std::string const& topic,
106  elt::mal::Mal::Properties const& props);
107 
108  std::unique_ptr<elt::mal::ps::Subscriber<rtctkif::GenericEvent>> m_subscriber;
109  std::unique_ptr<elt::mal::ps::Subscription> m_subscription;
110  std::mutex m_mutex;
111 };
112 
113 } // namespace rtctk::componentFramework
114 
115 #endif // RTCTK_COMPONENTFRAMEWORK_MALDDSEVENTSERVICE_HPP
rtctk::componentFramework::MalDdsEventSubscriber
Implementation of event subscriber.
Definition: malDdsEventService.hpp:87
rtctk::componentFramework::MalDdsEventSubscriber::MalDdsEventService
friend MalDdsEventService
Definition: malDdsEventService.hpp:90
rtctk::componentFramework::MalDdsEventPublisher::MalDdsEventService
friend MalDdsEventService
Definition: malDdsEventService.hpp:66
rtctk::componentFramework::MalDdsEventService
Implementation of low-level event service using CII MAL DDS as middleware.
Definition: malDdsEventService.hpp:34
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::MalDdsEventService::MalDdsEventService
MalDdsEventService()
Definition: malDdsEventService.cpp:30
rtctk::componentFramework::EventPublisherIf
Interface class for publishing JSON events.
Definition: eventServiceIf.hpp:48
rtctk::componentFramework::MalDdsEventSubscriber::Unsubscribe
void Unsubscribe() override
Unsubscribes from the topic.
Definition: malDdsEventService.cpp:126
rtctk::componentFramework::EventSubscriberIf
Interface class for subscribing to JSON events.
Definition: eventServiceIf.hpp:63
jsonPayload.hpp
Defines the JSON payload type JsonPayload.
rtctk::componentFramework::MalDdsEventSubscriber::Subscribe
void Subscribe(std::function< void(JsonPayload const &)> cb) override
Subscribes to the topic.
Definition: malDdsEventService.cpp:111
rtctk::componentFramework::MalDdsEventService::MakeSubscriber
std::unique_ptr< EventSubscriberIf > MakeSubscriber(std::string const &topic) override
Factory method to create a new subscriber object.
Definition: malDdsEventService.cpp:71
rtctk::componentFramework::EventServiceIf
Interface class for providing pub/sub facilities for JSON events.
Definition: eventServiceIf.hpp:26
rtctk::componentFramework::MalDdsEventPublisher::Publish
void Publish(JsonPayload const &sample) override
Publishes a new data sample.
Definition: malDdsEventService.cpp:86
rtctk::componentFramework::MalDdsEventService::MakePublisher
std::unique_ptr< EventPublisherIf > MakePublisher(std::string const &topic) override
Factory method to create a new publisher object.
Definition: malDdsEventService.cpp:66
eventServiceIf.hpp
Low-level interface of the event service.
rtctk::componentFramework::MalDdsEventPublisher
Implementation of event publisher.
Definition: malDdsEventService.hpp:63
rtctk::componentFramework::MalDdsEventSubscriber::QOS_FILE
static const std::string QOS_FILE
Definition: malDdsEventService.hpp:102
rtctk::componentFramework::JsonPayload
nlohmann::json JsonPayload
Type requirements:
Definition: jsonPayload.hpp:24