RTC Toolkit  2.0.0
udpReceiver.hpp
Go to the documentation of this file.
1 
11 #ifndef RTCTK_REUSABLECOMPONENT_TELREPUB_UDPRECEIVER_HPP_
12 #define RTCTK_REUSABLECOMPONENT_TELREPUB_UDPRECEIVER_HPP_
13 #include <array>
14 #include <cstdint>
15 #include <map>
16 #include <thread>
17 
19 
20 #include <boost/asio/io_context.hpp>
21 #include <boost/asio/ip/udp.hpp>
22 #include <log4cplus/logger.h>
23 
24 #include "mudpiProcessor.hpp"
25 #include <numapp/numapolicies.hpp>
26 
27 namespace rtctk::telRepub {
28 
32 constexpr int DATAGRAM_SIZE = 9500;
33 
43 class UdpReceiver {
44 public:
48  using MudpiProcessors = std::map<mudpi::uint16_t, PubThreadBase<>&>;
49 
62  explicit UdpReceiver(uint16_t idx,
63  MudpiProcessors const& processors,
64  boost::asio::ip::udp::endpoint const& endpoint,
66  numapp::NumaPolicies const& receive_thread_policies);
67  ~UdpReceiver() noexcept;
68 
74  void Enable();
75 
81  void Disable();
82 
86  void Statistics();
87 
88 private:
89  enum class State { Idle, Run, Exit };
93  void InitReceive();
97  void HandleReceive(boost::system::error_code const& error, std::size_t length);
98 
100  boost::asio::io_service m_io_context;
102  boost::asio::ip::udp::socket m_socket;
106  boost::asio::ip::udp::endpoint m_sender;
107  std::array<std::byte, DATAGRAM_SIZE> m_recv_buffer;
108  std::thread m_rcv_thr;
110 
111  std::atomic<State> m_requested_state;
112 
116  std::uint16_t m_idx;
117  std::vector<std::pair<mudpi::uint16_t, std::unique_ptr<MudpiProcessor>>> m_processors;
118 
120 
121  log4cplus::Logger m_logger;
122 };
123 
124 } // namespace rtctk::telRepub
125 #endif // RTCTK_REUSABLECOMPONENT_TELREPUB_UDPRECEIVER_HPP_
rtctk::telRepub::UdpReceiver::UdpReceiver
UdpReceiver(uint16_t idx, MudpiProcessors const &processors, boost::asio::ip::udp::endpoint const &endpoint, componentFramework::ComponentMetricsIf &metrics, numapp::NumaPolicies const &receive_thread_policies)
Creates UDP receiver.
Definition: udpReceiver.cpp:23
componentMetricsIf.hpp
Header file for ComponentMetricsIf.
rtctk::telRepub
Definition: ddsPubThread.hpp:26
rtctk::telRepub::DATAGRAM_SIZE
constexpr int DATAGRAM_SIZE
maximal UDP datagram size
Definition: udpReceiver.hpp:32
rtctk::telRepub::UdpReceiver::Statistics
void Statistics()
Dumps receiver statistics.
Definition: udpReceiver.cpp:129
mudpi::uint16_t
unsigned short uint16_t
Definition: mudpi.h:15
rtctk::telRepub::UdpReceiver::MudpiProcessors
std::map< mudpi::uint16_t, PubThreadBase<> & > MudpiProcessors
Container of {topic-id, processor}.
Definition: udpReceiver.hpp:48
rtctk::componentFramework::ComponentMetricsIf
Component metrics interface.
Definition: componentMetricsIf.hpp:177
mudpiProcessor.hpp
MUDPI processor: check and aggregate MUDPI payload to a single topic and put to the queue for publish...
rtctk::telRepub::UdpReceiver
Receiving UDP data asynchronously and forwards received packets to provided packet processors.
Definition: udpReceiver.hpp:43
rtctk::telRepub::UdpReceiver::~UdpReceiver
~UdpReceiver() noexcept
Definition: udpReceiver.cpp:60
rtctk::telRepub::UdpReceiver::Disable
void Disable()
Disables processing UDP data from socket.
Definition: udpReceiver.cpp:124
rtctk::telRepub::UdpReceiver::Enable
void Enable()
Enables processing UDP data from socket.
Definition: udpReceiver.cpp:119