41 #include <boost/bind.hpp> 49 shutdown_requested_(false),
50 write_in_progress_(false)
119 boost::asio::placeholders::error,
120 boost::asio::placeholders::bytes_transferred));
127 std::cerr << error.message() << std::endl;
156 boost::asio::placeholders::error,
157 boost::asio::placeholders::bytes_transferred));
164 std::cerr << error.message() << std::endl;
177 buffer.
pos += bytes_transferred;
191 std::list<ReadBuffer> local_queue;
206 local_queue.splice(local_queue.end(),
read_queue_);
213 while (!local_queue.empty())
217 local_queue.pop_front();
std::thread callback_thread_
virtual void do_async_read(const boost::asio::mutable_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler)=0
static constexpr size_t WRITE_BUFFER_SIZE
boost::asio::io_service io_service_
uint8_t read_buffer_[READ_BUFFER_SIZE]
void async_read_end(const boost::system::error_code &error, size_t bytes_transferred)
void send_bytes(const uint8_t *src, size_t len)
Send bytes from a buffer over the port.
bool init()
Initializes and opens the port.
std::lock_guard< std::recursive_mutex > mutex_lock
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.
std::list< WriteBuffer > write_queue_
std::recursive_mutex write_mutex_
void async_write(bool check_write_state)
void close()
Closes the port.
const uint8_t * dpos() const
static constexpr size_t READ_BUFFER_SIZE
void async_write_end(const boost::system::error_code &error, size_t bytes_transferred)
std::condition_variable condition_variable_
std::list< ReadBuffer > read_queue_
std::function< void(const uint8_t *, size_t)> receive_callback_
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[READ_BUFFER_SIZE]
std::mutex callback_mutex_
virtual void do_close()=0