FREEDM DGI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CECNHandler.hpp
Go to the documentation of this file.
1 
24 #include <boost/asio.hpp>
25 #include <boost/system/error_code.hpp>
26 
27 #include "CGlobalConfiguration.hpp"
28 
29 namespace freedm {
30 namespace broker {
31 
33 {
34 public:
35  static CECNHandler& Instance();
36 
38  void Start(boost::asio::ip::udp::endpoint& endpoint);
39 
41  void Stop();
42 
44  boost::asio::ip::udp::socket& GetSocket() { return m_socket; };
45 
46  // Schedules listening for the next message
47  void ScheduleListen();
48 
49 private:
51  CECNHandler();
52 
54  void HandleRead(const boost::system::error_code& e, std::size_t bytes_transferred);
55 
57  boost::array<char, CGlobalConfiguration::MAX_PACKET_SIZE> m_buffer;
58 
60  boost::asio::ip::udp::socket m_socket;
61 
63  boost::asio::ip::udp::endpoint m_recv_from;
64 };
65 
66 }
67 }
static CECNHandler & Instance()
Definition: CECNHandler.cpp:66
CECNHandler()
Private constructor for the singleton instance.
Definition: CECNHandler.cpp:56
boost::asio::ip::udp::endpoint m_recv_from
Endpoint for incoming message.
Definition: CECNHandler.hpp:63
boost::asio::ip::udp::socket & GetSocket()
Gets the listener socket.
Definition: CECNHandler.hpp:44
void ScheduleListen()
Definition: CECNHandler.cpp:186
void Start(boost::asio::ip::udp::endpoint &endpoint)
Bind the listener to the specified endpoint and listen for datagrams.
Definition: CECNHandler.cpp:80
boost::array< char, CGlobalConfiguration::MAX_PACKET_SIZE > m_buffer
Buffer for incoming data.
Definition: CECNHandler.hpp:57
Definition: CECNHandler.hpp:32
boost::asio::ip::udp::socket m_socket
Socket for the CConnection.
Definition: CECNHandler.hpp:60
void Stop()
Stop any current async read and close the socket.
Definition: CECNHandler.cpp:100
void HandleRead(const boost::system::error_code &e, std::size_t bytes_transferred)
Handle completion of a read operation.
Definition: CECNHandler.cpp:124