RTC Toolkit  1.0.0
ddsSubscriber.hpp
Go to the documentation of this file.
1 
11 #ifndef RTCKT_TELSUB_DDSSUBSCRIBER_HPP
12 #define RTCKT_TELSUB_DDSSUBSCRIBER_HPP
13 
14 #include <list>
15 #include <map>
16 #include <memory>
17 #include <set>
18 
22 
23 namespace rtctk::telSub {
24 
30 class DdsSubscriber final : public DdsSubscriberIf, SeqLoanerIf {
31 public:
32  using Alloc = std::pmr::polymorphic_allocator<std::byte>;
33  DdsSubscriber(const DdsParams& params, Alloc const& alloc = {});
34  virtual ~DdsSubscriber() noexcept;
35 
36  DdsSubscriber(DdsSubscriber&& rhs) = delete;
37  DdsSubscriber& operator=(DdsSubscriber&& rhs) = delete;
38 
39  AgnosticDataSamples& GetSamples() noexcept override;
40  std::error_code Take(std::chrono::nanoseconds timeout) noexcept override;
41 
42  size_t GetNumberOfTopics() const noexcept override;
43  const std::string& GetTopicName(size_t index) const noexcept override;
44 
46  std::error_code
47  ReturnLoan(std::uint8_t idx, DdsSampleSeq& samples, DdsInfoSeq& infos) noexcept override;
48 
49 private:
50  // Do not allow copying of this object.
51  DdsSubscriber(const DdsSubscriber& rhs) = delete;
52  DdsSubscriber& operator=(const DdsSubscriber& rhs) = delete;
53 
54  void Initialise(const DdsParams& params);
55  void Finalise();
56 
57  struct ReaderContext {
58  ReaderContext() : m_topic_name(""), m_reader(nullptr), m_topic(nullptr){};
59 
63  std::string m_topic_name;
64 
68 #ifdef USE_RTI_DDS
69  rtctk::AgnosticTopicDataReader* m_reader;
70 #else
71  DataReader* m_reader;
72 #endif
73 
77  Topic* m_topic;
78  };
79 
80  DomainParticipantFactory* m_factory;
81  DomainParticipant* m_participant;
82  Subscriber* m_subscriber;
83  std::unique_ptr<DdsReaderListener> m_listener;
84  std::vector<ReaderContext> m_readers;
85  std::map<Condition*, std::vector<ReaderContext>::iterator> m_reader_context_lut;
86  std::unique_ptr<WaitSet> m_waitset;
87  AgnosticDataSamples m_samples;
88 };
89 
90 } // namespace rtctk::telSub
91 #endif // RTCKT_TELSUB_DDSSUBSCRIBER_HPP
ddsReaderListener.hpp
DDS Reader Listener.
rtctk::telSub::DdsSubscriber::ReturnLoan
std::error_code ReturnLoan(std::uint8_t idx, DdsSampleSeq &samples, DdsInfoSeq &infos) noexcept override
Returns loaned sample sequence.
Definition: ddsSubscriber.cpp:571
rtctk::telSub::DdsSubscriber
Implements DDS communication using RTI DDS.
Definition: ddsSubscriber.hpp:30
rtctk::telSub::DdsSubscriberIf
Base class abstracting DDS communication code.
Definition: ddsSubscriberIf.hpp:50
rtctk::telSub::SeqLoanerIf
Loaner interface.
Definition: agnosticDataSamples.hpp:36
rtctk::telSub::DdsInfoSeq
SampleInfoSeq DdsInfoSeq
Definition: agnosticDataSamples.hpp:29
rtctk::telSub::DdsSubscriber::GetTopicName
const std::string & GetTopicName(size_t index) const noexcept override
Returns a string containing the name of a configured topic.
Definition: ddsSubscriber.cpp:586
rtctk::telSub::DdsSubscriber::Take
std::error_code Take(std::chrono::nanoseconds timeout) noexcept override
Takes new samples from DDS readers and updates data structure accessable from GetSamples()
Definition: ddsSubscriber.cpp:519
rtctk::telSub::DdsSubscriber::Alloc
std::pmr::polymorphic_allocator< std::byte > Alloc
Definition: ddsSubscriber.hpp:32
rtctk::telSub::DdsSampleSeq
rtctk::AgnosticTopicSeq DdsSampleSeq
Definition: agnosticDataSamples.hpp:27
rtctk::telSub::DdsSubscriber::DdsSubscriber
DdsSubscriber(const DdsParams &params, Alloc const &alloc={})
Constructs a DDS subscriber from given configuration parameters.
Definition: ddsSubscriber.cpp:52
rtctk::telSub
Definition: main.cpp:6
rtctk::telSub::DdsParams
Parameter set to be passed to classes deriving from DdsSubscriberIf.
Definition: ddsSubscriberIf.hpp:36
std
Definition: mudpiProcessingError.hpp:119
ddsSubscriberIf.hpp
Declares DdsSubscriberIf.
rtctk::telSub::DdsSubscriber::GetNumberOfTopics
size_t GetNumberOfTopics() const noexcept override
Returns the number of configured topics.
Definition: ddsSubscriber.cpp:582
dds.hpp
Declares common DDS class.
rtctk::telSub::DdsSubscriber::GetSamples
AgnosticDataSamples & GetSamples() noexcept override
Returns reference to data structure holding taken data samples.
Definition: ddsSubscriber.cpp:102
rtctk::telSub::AgnosticDataSamples
Container of DDS samples and associated sample information.
Definition: agnosticDataSamples.hpp:71
rtctk::telSub::DdsSubscriber::~DdsSubscriber
virtual ~DdsSubscriber() noexcept
Destroys the DDS subscriber and releases all RTI DDS resources.
Definition: ddsSubscriber.cpp:77