A asynchronous tcp client. More...
#include <AsyncTCPClient.h>
Public Types | |
typedef boost::function< void(const sick::datastructure::PacketBuffer &)> | PacketHandler |
Typedef to a function referencing a packet handler. This can be passed to the class and therefore be called on processing the data. More... | |
Public Member Functions | |
AsyncTCPClient (const PacketHandler &packet_handler, boost::asio::io_service &io_service, const boost::asio::ip::address_v4 &server_ip, const uint16_t &server_port) | |
Constructor of the asynchronous tcp client. More... | |
void | doConnect () |
Establishes a connection from the host to the sensor. More... | |
void | doDisconnect () |
Disconnects the host from the sensor. More... | |
void | doSendAndReceive (const std::vector< uint8_t > &sendBuffer) |
Start a cycle of sensing a command and waiting got the return. More... | |
void | initiateReceive () |
Initiates the listening for a message from the server. More... | |
void | setPacketHandler (const PacketHandler &packet_handler) |
Sets the packet handler function. More... | |
virtual | ~AsyncTCPClient () |
The destructor of the asynchronous tcp client. More... | |
Private Member Functions | |
AsyncTCPClient (AsyncTCPClient &) | |
void | handleReceive (const boost::system::error_code &error, const std::size_t &bytes_transferred) |
void | handleSendAndReceive (const boost::system::error_code &error, const std::size_t &bytes_transferred) |
void | startReceive () |
Private Attributes | |
boost::condition | m_connect_condition |
boost::mutex | m_connect_mutex |
boost::asio::io_service & | m_io_service |
std::shared_ptr< boost::asio::io_service::work > | m_io_work_ptr |
PacketHandler | m_packet_handler |
datastructure::PacketBuffer::ArrayBuffer | m_recv_buffer |
boost::asio::ip::tcp::endpoint | m_remote_endpoint |
std::thread | m_service_thread |
boost::mutex | m_socket_mutex |
std::shared_ptr< boost::asio::ip::tcp::socket > | m_socket_ptr |
A asynchronous tcp client.
Responsible to handle the connection to an IP-address and a port. Transfers the data to the specified target and receives the answer. The answer will be passed to a packet handler.
Definition at line 62 of file AsyncTCPClient.h.
typedef boost::function<void(const sick::datastructure::PacketBuffer&)> sick::communication::AsyncTCPClient::PacketHandler |
Typedef to a function referencing a packet handler. This can be passed to the class and therefore be called on processing the data.
Definition at line 69 of file AsyncTCPClient.h.
sick::communication::AsyncTCPClient::AsyncTCPClient | ( | const PacketHandler & | packet_handler, |
boost::asio::io_service & | io_service, | ||
const boost::asio::ip::address_v4 & | server_ip, | ||
const uint16_t & | server_port | ||
) |
Constructor of the asynchronous tcp client.
packet_handler | Function which handles the packets on processing. |
io_service | The boost io_service instance. |
server_ip | The IP address of the server to connect to. |
server_port | The port on the server to connect to. |
Definition at line 39 of file AsyncTCPClient.cpp.
|
virtual |
The destructor of the asynchronous tcp client.
Definition at line 61 of file AsyncTCPClient.cpp.
|
private |
void sick::communication::AsyncTCPClient::doConnect | ( | ) |
Establishes a connection from the host to the sensor.
Definition at line 88 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::doDisconnect | ( | ) |
Disconnects the host from the sensor.
Definition at line 63 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::doSendAndReceive | ( | const std::vector< uint8_t > & | sendBuffer | ) |
Start a cycle of sensing a command and waiting got the return.
sendBuffer | The telegram which will be sent to the server. |
Definition at line 108 of file AsyncTCPClient.cpp.
|
private |
Definition at line 157 of file AsyncTCPClient.cpp.
|
private |
Definition at line 140 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::initiateReceive | ( | ) |
Initiates the listening for a message from the server.
Definition at line 122 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::setPacketHandler | ( | const PacketHandler & | packet_handler | ) |
Sets the packet handler function.
packet_handler | The new packet handler function. |
Definition at line 135 of file AsyncTCPClient.cpp.
|
private |
Definition at line 155 of file AsyncTCPClient.cpp.
|
private |
Definition at line 129 of file AsyncTCPClient.h.
|
private |
Definition at line 130 of file AsyncTCPClient.h.
|
private |
Definition at line 124 of file AsyncTCPClient.h.
|
private |
Definition at line 123 of file AsyncTCPClient.h.
|
private |
Definition at line 121 of file AsyncTCPClient.h.
|
private |
Definition at line 119 of file AsyncTCPClient.h.
|
private |
Definition at line 126 of file AsyncTCPClient.h.
|
private |
Definition at line 127 of file AsyncTCPClient.h.
|
private |
Definition at line 131 of file AsyncTCPClient.h.
|
private |
Definition at line 125 of file AsyncTCPClient.h.