FREEDM DGI
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
freedm::broker::CListener Class Reference

Represents a single CListener from a client.

#include <CListener.hpp>

Inheritance diagram for freedm::broker::CListener:

Public Member Functions

boost::asio::ip::udp::socket & GetSocket ()
 Gets the listener socket. More...
 
void Start (boost::asio::ip::udp::endpoint &endpoint)
 Bind the listener to the specified endpoint and listen for datagrams. More...
 
void Stop ()
 Stop any current async read and close the socket. More...
 

Static Public Member Functions

static CListenerInstance ()
 Access the singleton instance of the CListener. More...
 

Private Member Functions

 CListener ()
 Private constructor for the singleton instance. More...
 
void HandleRead (const boost::system::error_code &e, std::size_t bytes_transferred)
 Handle completion of a read operation. More...
 
void ScheduleListen ()
 Asynchronously listen for a new message. More...
 

Private Attributes

boost::array< char, CGlobalConfiguration::MAX_PACKET_SIZEm_buffer
 Buffer for incoming data. More...
 
boost::asio::ip::udp::endpoint m_recv_from
 Endpoint for incoming message. More...
 
boost::asio::ip::udp::socket m_socket
 Socket for the CConnection. More...
 

Constructor & Destructor Documentation

freedm::broker::CListener::CListener ( )
private

CListener::CListener

Description:
Constructor. Creates the socket that will be used to listen for incoming messages.
Precondition:
None.
Postcondition:
A socket is created using the Broker's io service.

Member Function Documentation

boost::asio::ip::udp::socket& freedm::broker::CListener::GetSocket ( )
inline
void freedm::broker::CListener::HandleRead ( const boost::system::error_code &  e,
std::size_t  bytes_transferred 
)
private

CListener::HandleRead

Description:
The callback which accepts messages from the remote sender.
Parameters
eThe errorcode if any associated.
bytes_transferredThe size of the datagram being read.
Precondition:
The connection has had start called and some message has been placed in the buffer by the receive call.
Postcondition:
The message is scheduled for delivery by the dispatcher to one or more modules. The message has been processed by the CConnection that manages messages between this process and the sender. ScheduleListen() is waiting for another datagram to arrive.

We can make the remote host from the endpoint:

Make sure the hostname is registered:

Get the pointer to the connection:

CListener & freedm::broker::CListener::Instance ( )
static

CListener::Instance

Description:
Access the singleton instance of the CListener
void freedm::broker::CListener::ScheduleListen ( )
private

CListener::ScheduleListen

Description:
Makes a call to the Broker's ioservice and requests that the HandleRead function is called when a datagram arrives on the Listener's socket.
Precondition:
The m_socket is bound to an endpoint
Postcondition:
HandleRead will be called when a datagram arrives at the socket
void freedm::broker::CListener::Start ( boost::asio::ip::udp::endpoint &  endpoint)

CListener::Start

Description:
Causes the listener to start listening for new messages
Precondition:
endpoint is a valid endpoint for the lister to listen on
Postcondition:
The listener is not listening for incoming messages on the socket bound to endpoint
Parameters
endpointthe endpoint for the listener to listen on
void freedm::broker::CListener::Stop ( )

CListener::Stop

Description:
Closes the listening socket.
Precondition:
None
Postcondition:
The socket used to listen for messages is closed.

Member Data Documentation

boost::array<char, CGlobalConfiguration::MAX_PACKET_SIZE> freedm::broker::CListener::m_buffer
private
boost::asio::ip::udp::endpoint freedm::broker::CListener::m_recv_from
private
boost::asio::ip::udp::socket freedm::broker::CListener::m_socket
private

The documentation for this class was generated from the following files: