Handles Asynchronous I/O reading and writing. More...
#include <async_worker.h>
Public Types | |
typedef boost::mutex | Mutex |
typedef boost::mutex::scoped_lock | ScopedLock |
Public Member Functions | |
AsyncWorker (boost::shared_ptr< StreamT > stream, boost::shared_ptr< boost::asio::io_service > io_service, std::size_t buffer_size=8192) | |
Construct an Asynchronous I/O worker. | |
bool | isOpen () const |
Whether or not the I/O stream is open. | |
bool | send (const unsigned char *data, const unsigned int size) |
Send the data bytes via the I/O stream. | |
void | setCallback (const Callback &callback) |
Set the callback function which handles input messages. | |
void | setRawDataCallback (const Callback &callback) |
Set the callback function which handles raw data. | |
void | wait (const boost::posix_time::time_duration &timeout) |
Wait for incoming messages. | |
virtual | ~AsyncWorker () |
Protected Member Functions | |
void | doClose () |
Close the I/O stream. | |
void | doRead () |
Read the input stream. | |
void | doWrite () |
Send all the data in the output buffer. | |
void | readEnd (const boost::system::error_code &, std::size_t) |
Process messages read from the input stream. | |
Protected Attributes | |
boost::shared_ptr< boost::thread > | background_thread_ |
std::vector< unsigned char > | in_ |
The input buffer. | |
std::size_t | in_buffer_size_ |
boost::shared_ptr < boost::asio::io_service > | io_service_ |
The I/O service. | |
std::vector< unsigned char > | out_ |
The output buffer. | |
Callback | read_callback_ |
Callback function to handle received messages. | |
boost::condition | read_condition_ |
Mutex | read_mutex_ |
Lock for the input buffer. | |
bool | stopping_ |
Whether or not the I/O service is closed. | |
boost::shared_ptr< StreamT > | stream_ |
The I/O stream. | |
Callback | write_callback_ |
Callback function to handle raw data. | |
boost::condition | write_condition_ |
Mutex | write_mutex_ |
Lock for the output buffer. |
Handles Asynchronous I/O reading and writing.
Definition at line 51 of file async_worker.h.
typedef boost::mutex ublox_gps::AsyncWorker< StreamT >::Mutex |
Definition at line 53 of file async_worker.h.
typedef boost::mutex::scoped_lock ublox_gps::AsyncWorker< StreamT >::ScopedLock |
Definition at line 54 of file async_worker.h.
ublox_gps::AsyncWorker< StreamT >::AsyncWorker | ( | boost::shared_ptr< StreamT > | stream, |
boost::shared_ptr< boost::asio::io_service > | io_service, | ||
std::size_t | buffer_size = 8192 |
||
) |
Construct an Asynchronous I/O worker.
stream | the stream for th I/O service |
io_service | the I/O service |
buffer_size | the size of the input and output buffers |
Definition at line 138 of file async_worker.h.
ublox_gps::AsyncWorker< StreamT >::~AsyncWorker | ( | ) | [virtual] |
Definition at line 155 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::doClose | ( | ) | [protected] |
Close the I/O stream.
Definition at line 252 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::doRead | ( | ) | [protected] |
Read the input stream.
Definition at line 204 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::doWrite | ( | ) | [protected] |
Send all the data in the output buffer.
Definition at line 181 of file async_worker.h.
bool ublox_gps::AsyncWorker< StreamT >::isOpen | ( | ) | const [inline, virtual] |
Whether or not the I/O stream is open.
Implements ublox_gps::Worker.
Definition at line 91 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::readEnd | ( | const boost::system::error_code & | error, |
std::size_t | bytes_transfered | ||
) | [protected] |
Process messages read from the input stream.
error_code | an error code for read failures |
the | number of bytes received |
Definition at line 215 of file async_worker.h.
bool ublox_gps::AsyncWorker< StreamT >::send | ( | const unsigned char * | data, |
const unsigned int | size | ||
) | [virtual] |
Send the data bytes via the I/O stream.
data | the buffer of data bytes to send |
size | the size of the buffer |
Implements ublox_gps::Worker.
Definition at line 162 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::setCallback | ( | const Callback & | callback | ) | [inline, virtual] |
Set the callback function which handles input messages.
callback | the read callback which handles received messages |
Implements ublox_gps::Worker.
Definition at line 71 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::setRawDataCallback | ( | const Callback & | callback | ) | [inline, virtual] |
Set the callback function which handles raw data.
callback | the write callback which handles raw data |
Implements ublox_gps::Worker.
Definition at line 77 of file async_worker.h.
void ublox_gps::AsyncWorker< StreamT >::wait | ( | const boost::posix_time::time_duration & | timeout | ) | [virtual] |
Wait for incoming messages.
timeout | the maximum time to wait |
Implements ublox_gps::Worker.
Definition at line 263 of file async_worker.h.
boost::shared_ptr<boost::thread> ublox_gps::AsyncWorker< StreamT >::background_thread_ [protected] |
thread for the I/O service
Definition at line 129 of file async_worker.h.
std::vector<unsigned char> ublox_gps::AsyncWorker< StreamT >::in_ [protected] |
The input buffer.
Definition at line 121 of file async_worker.h.
std::size_t ublox_gps::AsyncWorker< StreamT >::in_buffer_size_ [protected] |
number of bytes currently in the input buffer
Definition at line 122 of file async_worker.h.
boost::shared_ptr<boost::asio::io_service> ublox_gps::AsyncWorker< StreamT >::io_service_ [protected] |
The I/O service.
Definition at line 117 of file async_worker.h.
std::vector<unsigned char> ublox_gps::AsyncWorker< StreamT >::out_ [protected] |
The output buffer.
Definition at line 127 of file async_worker.h.
Callback ublox_gps::AsyncWorker< StreamT >::read_callback_ [protected] |
Callback function to handle received messages.
Definition at line 131 of file async_worker.h.
boost::condition ublox_gps::AsyncWorker< StreamT >::read_condition_ [protected] |
Definition at line 120 of file async_worker.h.
Mutex ublox_gps::AsyncWorker< StreamT >::read_mutex_ [protected] |
Lock for the input buffer.
Definition at line 119 of file async_worker.h.
bool ublox_gps::AsyncWorker< StreamT >::stopping_ [protected] |
Whether or not the I/O service is closed.
Definition at line 134 of file async_worker.h.
boost::shared_ptr<StreamT> ublox_gps::AsyncWorker< StreamT >::stream_ [protected] |
The I/O stream.
Definition at line 116 of file async_worker.h.
Callback ublox_gps::AsyncWorker< StreamT >::write_callback_ [protected] |
Callback function to handle raw data.
Definition at line 132 of file async_worker.h.
boost::condition ublox_gps::AsyncWorker< StreamT >::write_condition_ [protected] |
Definition at line 126 of file async_worker.h.
Mutex ublox_gps::AsyncWorker< StreamT >::write_mutex_ [protected] |
Lock for the output buffer.
Definition at line 125 of file async_worker.h.