VISR  0.11.8
Versatile Interactive Scene Renderer
udp_sender.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_SENDER_HPP_INCLUDED
4 #define VISR_LIBRCL_UDP_SENDER_HPP_INCLUDED
5 
6 #include "export_symbols.hpp"
7 
9 #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 
23 namespace visr
24 {
25 namespace rcl
26 {
27 
33 class VISR_RCL_LIBRARY_SYMBOL UdpSender: public AtomicComponent
34 {
35 public:
36  enum class Mode
37  {
38  Synchronous,
39  Asynchronous,
40  ExternalServiceObject
41  };
42 
43  static std::size_t const cMaxMessageLength = 8192;
44 
57  explicit UdpSender( SignalFlowContext const & context,
58  char const * name,
59  CompositeComponent * parent,
60  std::size_t sendPort,
61  std::string const & receiverAddress,
62  std::size_t receiverPort,
63  Mode mode, boost::asio::io_service* externalIoService = nullptr );
64 
68  virtual ~UdpSender();
69 
73  void process() override;
74 
75 private:
80  void handleSentData( const boost::system::error_code& error,
81  std::size_t numBytesTransferred );
82 
83  Mode mMode;
84 
88  boost::asio::io_service* mIoService;
89 
94  std::unique_ptr<boost::asio::io_service> mIoServiceInstance;
95 
96  std::unique_ptr<boost::asio::ip::udp::socket> mSocket;
97 
98  boost::asio::ip::udp::endpoint mRemoteEndpoint;
99 
100 // boost::array<char, cMaxMessageLength> mSendBufferBuffer;
101 
102  std::unique_ptr<boost::asio::io_service::work> mIoServiceWork;
103 
108  std::deque< pml::StringParameter > mInternalMessageBuffer;
109 
110  std::unique_ptr< boost::thread > mServiceThread;
111 
112  boost::mutex mMutex;
113 
115 };
116 
117 } // namespace rcl
118 } // namespace visr
119 
120 #endif // #ifndef VISR_LIBRCL_UDP_SENDER_HPP_INCLUDED
Mode
Definition: udp_sender.hpp:36
Definition: options.cpp:10
Definition: atomic_component.hpp:21
Definition: udp_sender.hpp:33
Definition: composite_component.hpp:29
Definition: signal_flow_context.hpp:15