Go to the documentation of this file.
38 #ifndef ASYNC_COMM_COMM_H
39 #define ASYNC_COMM_COMM_H
41 #include <condition_variable>
49 #include <boost/asio.hpp>
50 #include <boost/function.hpp>
107 void send_bytes(
const uint8_t * src,
size_t len);
151 virtual void do_async_read(
const boost::asio::mutable_buffers_1 &buffer,
152 boost::function<
void(
const boost::system::error_code&,
size_t)> handler) = 0;
153 virtual void do_async_write(
const boost::asio::const_buffers_1 &buffer,
154 boost::function<
void(
const boost::system::error_code&,
size_t)> handler) = 0;
195 void async_read_end(
const boost::system::error_code& error,
size_t bytes_transferred);
198 void async_write_end(
const boost::system::error_code& error,
size_t bytes_transferred);
217 std::vector<std::reference_wrapper<CommListener>>
listeners_;
222 #endif // ASYNC_COMM_COMM_H
uint8_t data[READ_BUFFER_SIZE]
virtual void do_async_write(const boost::asio::const_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler)=0
uint8_t data[WRITE_BUFFER_SIZE]
std::list< WriteBuffer > write_queue_
MessageHandler & message_handler_
void send_byte(uint8_t data)
Send a single byte over the port.
void send_bytes(const uint8_t *src, size_t len)
Send bytes from a buffer over the port.
static constexpr size_t READ_BUFFER_SIZE
Abstract base class for an asynchronous communication port.
WriteBuffer(const uint8_t *buf, size_t len)
boost::asio::io_service io_service_
std::lock_guard< std::recursive_mutex > mutex_lock
const uint8_t * dpos() const
std::vector< std::reference_wrapper< CommListener > > listeners_
std::recursive_mutex write_mutex_
void async_write(bool check_write_state)
ReadBuffer(const uint8_t *buf, size_t len)
Comm(MessageHandler &message_handler=default_message_handler_)
Set up asynchronous communication base class.
std::list< ReadBuffer > read_queue_
Abstract base class for message handler.
void register_listener(CommListener &listener)
Register a listener for when bytes are received on the port.
static DefaultMessageHandler default_message_handler_
bool init()
Initializes and opens the port.
void close()
Closes the port.
uint8_t read_buffer_[READ_BUFFER_SIZE]
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.
void async_write_end(const boost::system::error_code &error, size_t bytes_transferred)
std::mutex mutex
mutex for synchronization between the main thread and callback thread
virtual void do_close()=0
std::function< void(const uint8_t *, size_t)> receive_callback_
Abstract base class for getting comm events via a listener interface.
std::thread callback_thread_
Default message handler that outputs to stdout and stderr.
static constexpr size_t WRITE_BUFFER_SIZE
void async_read_end(const boost::system::error_code &error, size_t bytes_transferred)
virtual void receive_callback(const uint8_t *buf, size_t size)=0
Callback for data received.
virtual void do_async_read(const boost::asio::mutable_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler)=0
std::condition_variable condition_variable_
std::condition_variable condition_variable
condition variable used to suspend main thread until all messages have been received back
std::mutex callback_mutex_
async_comm
Author(s):
autogenerated on Tue Mar 1 2022 23:49:04