RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
ddsSub.hpp
Go to the documentation of this file.
1
11#ifndef RTCTK_COMPONENTFRAMEWORK_DATAPATH_DDSSUB_HPP
12#define RTCTK_COMPONENTFRAMEWORK_DATAPATH_DDSSUB_HPP
13#include <format>
14#include <list>
15#include <memory>
17
19
26 std::string topic_name;
27 std::shared_ptr<DataReaderListener> listener;
28 std::string multicast_address = {};
29
30 DdsReaderParams(const std::string& tn,
31 std::shared_ptr<DataReaderListener> l,
32 const std::string& mc)
33 : topic_name(tn), listener(std::move(l)), multicast_address(mc) {
34 }
35
36 DdsReaderParams(const std::string& tn, std::shared_ptr<DataReaderListener> l)
37 : topic_name(tn), listener(std::move(l)) {
38 }
39
40 explicit DdsReaderParams(const std::string& tn) : topic_name(tn) {
41 }
42};
43
51class DdsSub : public Dds {
52 // cppcheck-suppress-begin unusedStructMember
53
54 Subscriber* m_subscriber = nullptr;
55 std::vector<DataReader*> m_data_readers;
56 std::vector<std::shared_ptr<DataReaderListener>> m_listeners;
57
58 // cppcheck-suppress-end unusedStructMember
59
60public:
72 explicit DdsSub(const std::string& qos_file,
73 const std::string& qos_profile = DEFAULT_QOS_PROFILE,
74 DomainId_t domain_id = DEFAULT_DOMAIN_ID,
75 const std::string& participant_name = "");
76 ~DdsSub() override;
77
82 void CreateSubscriber();
83
87 void DestroySubscriber();
88
97 DataReader* CreateDataReader(Topic* topic,
98 std::shared_ptr<DataReaderListener> listener = nullptr,
99 const std::string& multicast_address = "");
100
107 void DestroyDataReader(DataReader* dr, bool to_be_removed = true);
108
113 void CreateDataReaders();
114
116
123
129 void CreateManyDataReaders(const std::vector<DdsReaderParams>& reader_params);
130
136 void CreateManyDataReaders(std::vector<std::string>& topic_names);
137
141 // Not using virtual methods on purpose because DumpDDSstatistics is called in the destructor.
142 // cppcheck-suppress duplInheritedMember
143 void DumpDDSstatistics();
144
148 std::vector<DataReader*>& GetDataReaders() {
149 return m_data_readers;
150 }
151};
152
153} // namespace rtctk::componentFramework
154
155namespace std {
156
157template <>
158struct formatter<eprosima::fastdds::dds::SampleRejectedStatusKind> : formatter<string_view> {
159 template <typename FormatContext>
160 auto format(eprosima::fastdds::dds::SampleRejectedStatusKind c, FormatContext& ctx) const {
161 using eprosima::fastdds::dds::SampleRejectedStatusKind;
162 string_view name = "unknown";
163 switch (c) {
164 case SampleRejectedStatusKind::NOT_REJECTED:
165 name = "NOT_REJECTED";
166 break;
167 case SampleRejectedStatusKind::REJECTED_BY_INSTANCES_LIMIT:
168 name = "REJECTED_BY_INSTANCES_LIMIT";
169 break;
170 case SampleRejectedStatusKind::REJECTED_BY_SAMPLES_LIMIT:
171 name = "REJECTED_BY_SAMPLES_LIMIT";
172 break;
173 case SampleRejectedStatusKind::REJECTED_BY_SAMPLES_PER_INSTANCE_LIMIT:
174 name = "REJECTED_BY_SAMPLES_PER_INSTANCE_LIMIT";
175 break;
176#if (FASTDDS_VERSION_MAJOR >= 4) || ((FASTDDS_VERSION_MAJOR == 3) && (FASTDDS_VERSION_MINOR >= 5))
177 case SampleRejectedStatusKind::REJECTED_BY_UNKNOWN_INSTANCE:
178 name = "REJECTED_BY_UNKNOWN_INSTANCE";
179 break;
180#endif
181 }
182
183 return formatter<string_view>::format(name, ctx);
184 }
185};
186
187} // namespace std
188
189#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:29
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:29
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:108
void DumpDDSstatistics()
Dumps / logs varios DDS statistic like NACks, ACKs, ... for each DDS writer.
Definition ddsSub.cpp:278
void DestroySubscriber()
Destroys DDS subscriber.
Definition ddsSub.cpp:91
void DestroyAllDataReaders()
Destroys DDS Data Reader for all DDS topics.
Definition ddsSub.cpp:254
void EnableAllDataReaders()
Definition ddsSub.cpp:179
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:227
std::vector< DataReader * > & GetDataReaders()
returns vector of all DDS Data writers
Definition ddsSub.hpp:148
~DdsSub() override
Definition ddsSub.cpp:38
void CreateDataReaders()
Creates DDS Data Reader for all DDS topics.
Definition ddsSub.cpp:265
void CreateSubscriber()
Creates DDS subscriber.
Definition ddsSub.cpp:47
void DestroyDataReader(DataReader *dr, bool to_be_removed=true)
Destroys DDS data reader.
Definition ddsSub.cpp:192
static const DomainId_t DEFAULT_DOMAIN_ID
default Domain Id for different DDS
Definition dds.hpp:173
static const std::string DEFAULT_QOS_PROFILE
default profile name for different DDS QoSs
Definition dds.hpp:167
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:24
Declares common DDS class.
Definition commandReplier.cpp:21
Definition ddsSub.hpp:155
DdsReaderParams(const std::string &tn, std::shared_ptr< DataReaderListener > l, const std::string &mc)
Definition ddsSub.hpp:30
std::string topic_name
Definition ddsSub.hpp:26
std::string multicast_address
Definition ddsSub.hpp:28
DdsReaderParams(const std::string &tn)
Definition ddsSub.hpp:40
DdsReaderParams(const std::string &tn, std::shared_ptr< DataReaderListener > l)
Definition ddsSub.hpp:36
std::shared_ptr< DataReaderListener > listener
Definition ddsSub.hpp:27
DdsReaderParams(const std::string &tn, std::shared_ptr< DataReaderListener > l, const std::string &mc)
Definition ddsSub.hpp:30
auto format(eprosima::fastdds::dds::SampleRejectedStatusKind c, FormatContext &ctx) const
Definition ddsSub.hpp:160