Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
async_comm::UDP Class Reference

Asynchronous communication class for a UDP socket. More...

#include <udp.h>

Inheritance diagram for async_comm::UDP:
Inheritance graph
[legend]

Public Member Functions

 UDP (std::string bind_host=DEFAULT_BIND_HOST, uint16_t bind_port=DEFAULT_BIND_PORT, std::string remote_host=DEFAULT_REMOTE_HOST, uint16_t remote_port=DEFAULT_REMOTE_PORT, MessageHandler &message_handler=default_message_handler_)
 Bind a UDP socket. More...
 
 ~UDP ()
 
- Public Member Functions inherited from async_comm::Comm
void close ()
 Closes the port. More...
 
 Comm (MessageHandler &message_handler=default_message_handler_)
 Set up asynchronous communication base class. More...
 
bool init ()
 Initializes and opens the port. More...
 
void register_listener (CommListener &listener)
 Register a listener for when bytes are received on the port. More...
 
void register_receive_callback (std::function< void(const uint8_t *, size_t)> fun)
 Register a callback function for when bytes are received on the port. More...
 
void send_byte (uint8_t data)
 Send a single byte over the port. More...
 
void send_bytes (const uint8_t *src, size_t len)
 Send bytes from a buffer over the port. More...
 
virtual ~Comm ()
 

Private Member Functions

void do_async_read (const boost::asio::mutable_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler) override
 
void do_async_write (const boost::asio::const_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler) override
 
void do_close () override
 
bool do_init () override
 
bool is_open () override
 

Private Attributes

boost::asio::ip::udp::endpoint bind_endpoint_
 
std::string bind_host_
 
uint16_t bind_port_
 
boost::asio::ip::udp::endpoint remote_endpoint_
 
std::string remote_host_
 
uint16_t remote_port_
 
boost::asio::ip::udp::socket socket_
 

Static Private Attributes

static constexpr auto DEFAULT_BIND_HOST = "localhost"
 
static constexpr uint16_t DEFAULT_BIND_PORT = 16140
 
static constexpr auto DEFAULT_REMOTE_HOST = "localhost"
 
static constexpr uint16_t DEFAULT_REMOTE_PORT = 16145
 

Additional Inherited Members

- Protected Attributes inherited from async_comm::Comm
boost::asio::io_service io_service_
 
MessageHandlermessage_handler_
 
- Static Protected Attributes inherited from async_comm::Comm
static DefaultMessageHandler default_message_handler_
 
static constexpr size_t READ_BUFFER_SIZE = 1024
 
static constexpr size_t WRITE_BUFFER_SIZE = 1024
 

Detailed Description

Asynchronous communication class for a UDP socket.

Definition at line 56 of file udp.h.

Constructor & Destructor Documentation

async_comm::UDP::UDP ( std::string  bind_host = DEFAULT_BIND_HOST,
uint16_t  bind_port = DEFAULT_BIND_PORT,
std::string  remote_host = DEFAULT_REMOTE_HOST,
uint16_t  remote_port = DEFAULT_REMOTE_PORT,
MessageHandler message_handler = default_message_handler_ 
)

Bind a UDP socket.

Parameters
bind_hostThe bind host where this application is listening (usually "localhost")
bind_portThe bind port where this application is listening
remote_hostThe remote host to communicate with
remote_portThe port on the remote host
message_handlerCustom message handler, or omit for default handler

Definition at line 48 of file udp.cpp.

async_comm::UDP::~UDP ( )

Definition at line 59 of file udp.cpp.

Member Function Documentation

void async_comm::UDP::do_async_read ( const boost::asio::mutable_buffers_1 &  buffer,
boost::function< void(const boost::system::error_code &, size_t)>  handler 
)
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 104 of file udp.cpp.

void async_comm::UDP::do_async_write ( const boost::asio::const_buffers_1 &  buffer,
boost::function< void(const boost::system::error_code &, size_t)>  handler 
)
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 110 of file udp.cpp.

void async_comm::UDP::do_close ( )
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 99 of file udp.cpp.

bool async_comm::UDP::do_init ( )
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 69 of file udp.cpp.

bool async_comm::UDP::is_open ( )
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 64 of file udp.cpp.

Member Data Documentation

boost::asio::ip::udp::endpoint async_comm::UDP::bind_endpoint_
private

Definition at line 93 of file udp.h.

std::string async_comm::UDP::bind_host_
private

Definition at line 86 of file udp.h.

uint16_t async_comm::UDP::bind_port_
private

Definition at line 87 of file udp.h.

constexpr auto async_comm::UDP::DEFAULT_BIND_HOST = "localhost"
staticprivate

Definition at line 73 of file udp.h.

constexpr uint16_t async_comm::UDP::DEFAULT_BIND_PORT = 16140
staticprivate

Definition at line 74 of file udp.h.

constexpr auto async_comm::UDP::DEFAULT_REMOTE_HOST = "localhost"
staticprivate

Definition at line 75 of file udp.h.

constexpr uint16_t async_comm::UDP::DEFAULT_REMOTE_PORT = 16145
staticprivate

Definition at line 76 of file udp.h.

boost::asio::ip::udp::endpoint async_comm::UDP::remote_endpoint_
private

Definition at line 94 of file udp.h.

std::string async_comm::UDP::remote_host_
private

Definition at line 89 of file udp.h.

uint16_t async_comm::UDP::remote_port_
private

Definition at line 90 of file udp.h.

boost::asio::ip::udp::socket async_comm::UDP::socket_
private

Definition at line 92 of file udp.h.


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


async_comm
Author(s):
autogenerated on Fri May 14 2021 02:35:38