FREEDM DGI
CListener.hpp
Go to the documentation of this file.
1 
24 #ifndef CLISTENER_HPP
25 #define CLISTENER_HPP
26 
27 #include "CGlobalConfiguration.hpp"
28 
29 #include <boost/asio.hpp>
30 #include <boost/array.hpp>
31 #include <boost/noncopyable.hpp>
32 #include <boost/shared_ptr.hpp>
33 
34 namespace freedm {
35  namespace broker {
36 
37 class CBroker;
38 class CConnectionManager;
39 
41 class CListener
42  : private boost::noncopyable
43 {
44 public:
46  static CListener& Instance();
47 
49  void Start(boost::asio::ip::udp::endpoint& endpoint);
50 
52  void Stop();
53 
55  boost::asio::ip::udp::socket& GetSocket() { return m_socket; };
56 private:
58  CListener();
59 
61  void HandleRead(const boost::system::error_code& e, std::size_t bytes_transferred);
62 
64  void ScheduleListen();
65 
67  boost::array<char, CGlobalConfiguration::MAX_PACKET_SIZE> m_buffer;
68 
70  boost::asio::ip::udp::socket m_socket;
71 
73  boost::asio::ip::udp::endpoint m_recv_from;
74 };
75 
76 
77  } // namespace broker
78 } // namespace freedm
79 
80 #endif // CCONNECTION_HPP
boost::array< char, CGlobalConfiguration::MAX_PACKET_SIZE > m_buffer
Buffer for incoming data.
Definition: CListener.hpp:67
Represents a single CListener from a client.
Definition: CListener.hpp:41
CListener()
Private constructor for the singleton instance.
Definition: CListener.cpp:63
boost::asio::ip::udp::socket m_socket
Socket for the CConnection.
Definition: CListener.hpp:70
boost::asio::ip::udp::endpoint m_recv_from
Endpoint for incoming message.
Definition: CListener.hpp:73
void Stop()
Stop any current async read and close the socket.
Definition: CListener.cpp:101
void HandleRead(const boost::system::error_code &e, std::size_t bytes_transferred)
Handle completion of a read operation.
Definition: CListener.cpp:127
static CListener & Instance()
Access the singleton instance of the CListener.
Definition: CListener.cpp:73
void Start(boost::asio::ip::udp::endpoint &endpoint)
Bind the listener to the specified endpoint and listen for datagrams.
Definition: CListener.cpp:87
General FREEDM Namespace.
Definition: CBroker.cpp:53
void ScheduleListen()
Asynchronously listen for a new message.
Definition: CListener.cpp:201
boost::asio::ip::udp::socket & GetSocket()
Gets the listener socket.
Definition: CListener.hpp:55