VISR  0.11.1
Versatile Interactive Scene Renderer
udp_receiver.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_LIBRCL_UDP_RECEIVER_HPP_INCLUDED
4 #define VISR_LIBRCL_UDP_RECEIVER_HPP_INCLUDED
5 
6 #include "export_symbols.hpp"
7 
8 #include <libvisr/constants.hpp>
11 
14 
15 #include <boost/array.hpp>
16 #include <boost/asio/io_service.hpp>
17 #include <boost/asio/ip/udp.hpp>
18 #include <boost/thread/thread.hpp>
19 
20 #include <memory>
21 #include <string>
22 #include <deque>
23 
24 namespace visr
25 {
26 namespace rcl
27 {
28 
35 class VISR_RCL_LIBRARY_SYMBOL UdpReceiver: public AtomicComponent
36 {
37 public:
38  enum class Mode
39  {
40  Synchronous,
42  Asynchronous,
44  ExternalServiceObject
46  };
47 
48  static std::size_t const cMaxMessageLength = 65536;
49 
56  explicit UdpReceiver( SignalFlowContext const & context,
57  char const * name,
58  CompositeComponent * parent = nullptr );
59 
63  ~UdpReceiver();
64 
73  void setup( std::size_t port, Mode mode, boost::asio::io_service* externalIoService = nullptr );
74 
78  void process() override;
79 
80 private:
81  void handleReceiveData( const boost::system::error_code& error,
82  std::size_t numBytesTransferred );
83 
84  Mode mMode;
85 
89  boost::asio::io_service* mIoService;
90 
95  std::unique_ptr<boost::asio::io_service> mIoServiceInstance;
96 
97 
98  std::unique_ptr<boost::asio::ip::udp::socket> mSocket;
99 
100  boost::asio::ip::udp::endpoint mRemoteEndpoint;
101 
102  boost::array<char, cMaxMessageLength> mReceiveBuffer;
103 
104  std::unique_ptr<boost::asio::io_service::work> mIoServiceWork;
105 
110  std::deque< pml::StringParameter > mInternalMessageBuffer;
111 
112  std::unique_ptr< boost::thread > mServiceThread;
113 
114  boost::mutex mMutex;
115 
117 };
118 
119 } // namespace rcl
120 } // namespace visr
121 
122 #endif // #ifndef VISR_LIBRCL_UDP_RECEIVER_HPP_INCLUDED
Definition: udp_receiver.hpp:35
Definition: options.cpp:10
Definition: atomic_component.hpp:21
Definition: composite_component.hpp:29
Definition: signal_flow_context.hpp:15
Mode
Definition: udp_receiver.hpp:38