RTC Toolkit 6.0.0-pre2
Loading...
Searching...
No Matches
ddsSub.hpp
Go to the documentation of this file.
1
12#ifndef RTCTK_COMPONENTFRAMEWORK_DATAPATH_DDSSUB_HPP
13#define RTCTK_COMPONENTFRAMEWORK_DATAPATH_DDSSUB_HPP
14#include <format>
15#include <list>
16#include <memory>
18
20
27 std::string topic_name;
28 std::shared_ptr<DataReaderListener> listener;
29 std::string multicast_address = {};
30
31 DdsReaderParams(const std::string& tn,
32 std::shared_ptr<DataReaderListener> l,
33 const std::string& mc)
34 : topic_name(tn), listener(std::move(l)), multicast_address(mc) {
35 }
36
37 DdsReaderParams(const std::string& tn, std::shared_ptr<DataReaderListener> l)
38 : topic_name(tn), listener(std::move(l)) {
39 }
40
41 explicit DdsReaderParams(const std::string& tn) : topic_name(tn) {
42 }
43};
44
52class DdsSub : public Dds {
53 // cppcheck-suppress-begin unusedStructMember
54
55 Subscriber* m_subscriber = nullptr;
56 std::vector<DataReader*> m_data_readers;
57 std::vector<std::shared_ptr<DataReaderListener>> m_listeners;
58
59 // cppcheck-suppress-end unusedStructMember
60
61public:
73 explicit DdsSub(const std::string& qos_file,
74 const std::string& qos_profile = DEFAULT_QOS_PROFILE,
75 DomainId_t domain_id = DEFAULT_DOMAIN_ID,
76 const std::string& participant_name = "");
77 ~DdsSub() override;
78
83 void CreateSubscriber();
84
88 void DestroySubscriber();
89
98 DataReader* CreateDataReader(Topic* topic,
99 std::shared_ptr<DataReaderListener> listener = nullptr,
100 const std::string& multicast_address = "");
101
108 void DestroyDataReader(DataReader* dr, bool to_be_removed = true);
109
114 void CreateDataReaders();
115
117
124
130 void CreateManyDataReaders(const std::vector<DdsReaderParams>& reader_params);
131
137 void CreateManyDataReaders(std::vector<std::string>& topic_names);
138
142 // Not using virtual methods on purpose because DumpDDSstatistics is called in the destructor.
143 // cppcheck-suppress duplInheritedMember
144 void DumpDDSstatistics();
145
149 std::vector<DataReader*>& GetDataReaders() {
150 return m_data_readers;
151 }
152};
153
154} // namespace rtctk::componentFramework
155
156namespace std {
157
158template <>
159struct formatter<eprosima::fastdds::dds::SampleRejectedStatusKind> : formatter<string_view> {
160 template <typename FormatContext>
161 auto format(eprosima::fastdds::dds::SampleRejectedStatusKind c, FormatContext& ctx) const {
162 using eprosima::fastdds::dds::SampleRejectedStatusKind;
163 string_view name = "unknown";
164 switch (c) {
165 case SampleRejectedStatusKind::NOT_REJECTED:
166 name = "NOT_REJECTED";
167 break;
168 case SampleRejectedStatusKind::REJECTED_BY_INSTANCES_LIMIT:
169 name = "REJECTED_BY_INSTANCES_LIMIT";
170 break;
171 case SampleRejectedStatusKind::REJECTED_BY_SAMPLES_LIMIT:
172 name = "REJECTED_BY_SAMPLES_LIMIT";
173 break;
174 case SampleRejectedStatusKind::REJECTED_BY_SAMPLES_PER_INSTANCE_LIMIT:
175 name = "REJECTED_BY_SAMPLES_PER_INSTANCE_LIMIT";
176 break;
177 case SampleRejectedStatusKind::REJECTED_BY_UNKNOWN_INSTANCE:
178 name = "REJECTED_BY_UNKNOWN_INSTANCE";
179 break;
180 }
181
182 return formatter<string_view>::format(name, ctx);
183 }
184};
185
186} // namespace std
187
188#endif // RTCTK_COMPONENTFRAMEWORK_DATAPATH_DDSSUB_HPP
DdsSub(const std::string &qos_file, const std::string &qos_profile=DEFAULT_QOS_PROFILE, DomainId_t domain_id=DEFAULT_DOMAIN_ID, const std::string &participant_name="")
Definition ddsSub.cpp:30
DdsSub(const std::string &qos_file, const std::string &qos_profile=DEFAULT_QOS_PROFILE, DomainId_t domain_id=DEFAULT_DOMAIN_ID, const std::string &participant_name="")
Definition ddsSub.cpp:30
DataReader * CreateDataReader(Topic *topic, std::shared_ptr< DataReaderListener > listener=nullptr, const std::string &multicast_address="")
Creates DDS data reader for particular topic for topic of type: rtctk::AgnosticTopic.
Definition ddsSub.cpp:109
void DumpDDSstatistics()
Dumps / logs varios DDS statistic like NACks, ACKs, ... for each DDS writer.
Definition ddsSub.cpp:279
void DestroySubscriber()
Destroys DDS subscriber.
Definition ddsSub.cpp:92
void DestroyAllDataReaders()
Destroys DDS Data Reader for all DDS topics.
Definition ddsSub.cpp:255
void EnableAllDataReaders()
Definition ddsSub.cpp:180
void CreateManyDataReaders(const std::vector< DdsReaderParams > &reader_params)
create DDS topics and DDS readers for the given list (vector) of topic names and rtctk::componentFram...
Definition ddsSub.cpp:228
std::vector< DataReader * > & GetDataReaders()
returns vector of all DDS Data writers
Definition ddsSub.hpp:149
~DdsSub() override
Definition ddsSub.cpp:39
void CreateDataReaders()
Creates DDS Data Reader for all DDS topics.
Definition ddsSub.cpp:266
void CreateSubscriber()
Creates DDS subscriber.
Definition ddsSub.cpp:48
void DestroyDataReader(DataReader *dr, bool to_be_removed=true)
Destroys DDS data reader.
Definition ddsSub.cpp:193
static const DomainId_t DEFAULT_DOMAIN_ID
default Domain Id for different DDS
Definition dds.hpp:174
static const std::string DEFAULT_QOS_PROFILE
default profile name for different DDS QoSs
Definition dds.hpp:168
Dds(const std::string &qos_file, const std::string &qos_profile=DEFAULT_QOS_PROFILE, DomainId_t domain_id=DEFAULT_DOMAIN_ID, const std::string &participant_name="")
Constructor for Base class for both DDS Publisher and DDS Subscriber.
Definition dds.cpp:25
Declares common DDS class.
Definition commandReplier.cpp:22
Definition ddsSub.hpp:156
DdsReaderParams(const std::string &tn, std::shared_ptr< DataReaderListener > l, const std::string &mc)
Definition ddsSub.hpp:31
std::string topic_name
Definition ddsSub.hpp:27
std::string multicast_address
Definition ddsSub.hpp:29
DdsReaderParams(const std::string &tn)
Definition ddsSub.hpp:41
DdsReaderParams(const std::string &tn, std::shared_ptr< DataReaderListener > l)
Definition ddsSub.hpp:37
std::shared_ptr< DataReaderListener > listener
Definition ddsSub.hpp:28
DdsReaderParams(const std::string &tn, std::shared_ptr< DataReaderListener > l, const std::string &mc)
Definition ddsSub.hpp:31
auto format(eprosima::fastdds::dds::SampleRejectedStatusKind c, FormatContext &ctx) const
Definition ddsSub.hpp:161