RTC Toolkit  1.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 
18 #include <boost/asio/io_context.hpp>
19 #include <boost/asio/ip/udp.hpp>
20 #include <log4cplus/logger.h>
21 
22 #include "mudpiProcessor.hpp"
23 #include <numapp/numapolicies.hpp>
24 
25 namespace rtctk::telRepub {
26 
30 constexpr int DATAGRAM_SIZE = 9500;
31 
41 class UdpReceiver {
42 public:
46  using MudpiProcessors = std::map<mudpi::uint16_t, PubThreadBase<>&>;
47 
59  explicit UdpReceiver(uint16_t idx,
60  MudpiProcessors const& processors,
61  boost::asio::ip::udp::endpoint const& endpoint,
62  numapp::NumaPolicies const& receive_thread_policies);
63  ~UdpReceiver() noexcept;
64 
70  void Enable();
71 
77  void Disable();
78 
82  void Statistics();
83 
84 private:
85  enum class State { Idle, Run, Exit };
89  void InitReceive();
93  void HandleReceive(boost::system::error_code const& error, std::size_t length);
94 
96  boost::asio::io_service m_io_context;
98  boost::asio::ip::udp::socket m_socket;
102  boost::asio::ip::udp::endpoint m_sender;
103  std::array<std::byte, DATAGRAM_SIZE> m_recv_buffer;
104  std::thread m_rcv_thr;
106 
107  std::atomic<State> m_requested_state;
108 
112  std::uint16_t m_idx;
113  std::vector<std::pair<mudpi::uint16_t, MudpiProcessor>> m_processors;
114 
115  log4cplus::Logger m_logger;
116 };
117 
118 } // namespace rtctk::telRepub
119 #endif // RTCTK_REUSABLECOMPONENT_TELREPUB_UDPRECEIVER_HPP_
rtctk::telRepub
Definition: ddsPubThread.hpp:27
rtctk::telRepub::DATAGRAM_SIZE
constexpr int DATAGRAM_SIZE
maximal UDP datagram size
Definition: udpReceiver.hpp:30
rtctk::telRepub::UdpReceiver::Statistics
void Statistics()
Dumps receiver statistics.
Definition: udpReceiver.cpp:121
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:46
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:41
rtctk::telRepub::UdpReceiver::~UdpReceiver
~UdpReceiver() noexcept
Definition: udpReceiver.cpp:52
rtctk::telRepub::UdpReceiver::UdpReceiver
UdpReceiver(uint16_t idx, MudpiProcessors const &processors, boost::asio::ip::udp::endpoint const &endpoint, numapp::NumaPolicies const &receive_thread_policies)
Creates UDP receiver.
Definition: udpReceiver.cpp:23
rtctk::telRepub::UdpReceiver::Disable
void Disable()
Disables processing UDP data from socket.
Definition: udpReceiver.cpp:116
error
void error(const char *msg)
Definition: main.cpp:38
rtctk::telRepub::UdpReceiver::Enable
void Enable()
Enables processing UDP data from socket.
Definition: udpReceiver.cpp:111