BoostCommunication
template <typename IO_Object>
BoostCommunication

The BoostCommunication object that is used for actual read/write communication for all Connection objects

Functions
BoostCommunication
BoostCommunication(
std::unique_ptr<boost::asio::io_service> ioService,
std::unique_ptr<IO_Object> ioObj
)

Initializes the BoostCommunication object

Parameters
ioService
std::unique_ptr<boost::asio::io_service>

boost io_service

ioObj
std::unique_ptr<IO_Object>

boost io_object passed (Template)

~BoostCommunication
~BoostCommunication()

Destroys the BoostCommunication object

Variables
m_ioService
std::unique_ptr<boost::asio::io_service> m_ioService

Boost io_service needed in communication

m_ioObject
std::unique_ptr<IO_Object> m_ioObject

Boost io_object used to communicate (serial_port, ip::tcp::socket, etc.)

m_readBuffer
DataBuffer m_readBuffer

The DataBuffer to hold all the bytes read in

m_bufferWriter
BufferWriter m_bufferWriter

The BufferWriter used to write bytes to the DataBuffer

m_parseDataFunction
std::function<void(
DataBuffer&
)> m_parseDataFunction

The function to send all the read in data to. If null, the data will be thrown out.

m_parseFunctionMutex
std::recursive_mutex m_parseFunctionMutex

The mutex used to access/change the parse data function.

Functions
write
void write(
const std::vector<uint8&data
) const

Uses boost to write bytes to the io_object. Blocks until the write completes

Parameters
data
const std::vector<uint8>&

the bytes to be written

clearBuffer
void clearBuffer()

Clears the read buffer.

byteReadPos
std::size_t byteReadPos() const

Gets the read position from the byte buffer.

byteAppendPos
std::size_t byteAppendPos() const

Gets the append position from the byte buffer.

startReadLoop
void startReadLoop()

Starts the main read loop that reads in all data using boost

Returns

The ByteStream object holding the read in bytes

readSome
void readSome()

Performs the actual port read of bytes.

readLoopHandler
void readLoopHandler(
const boost::system::error_code &error,
std::size_t bytes_transferred
)

The read handler for the read loop, called when data comes in or the read operation has been canceled

Parameters
error
const boost::system::error_code&

boost error code

bytes_transferred
std::size_t

number of bytes read in

Exceptions
Error_Connection

I/O error occurred, the I/O service has been stopped

stopIoService
void stopIoService()

Stops the current boost::asio::io_service so no more reads or writes will happen

stopIoServiceError
void stopIoServiceError(
int errorCode
)

Stops the current boost::asio::io_service due to an error

setParseFunction
void setParseFunction(
std::function<void(DataBuffer&)> fn
)

Sets the function to be called when data is read in.

Parameters
fn
std::function<void(DataBuffer&)>

The function to set as the parser function.