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. | |
Public Member Functions | |
AsyncTCPClient (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. | |
void | doConnect () |
Establishes a connection from the host to the sensor. | |
void | doDisconnect () |
Disconnects the host from the sensor. | |
void | doSendAndReceive (const sick::datastructure::PacketBuffer::VectorBuffer &sendBuffer) |
Start a cycle of sensing a command and waiting got the return. | |
void | initiateReceive () |
Initiates the listening for a message from the server. | |
void | setPacketHandler (const PacketHandler &packet_handler) |
Sets the packet handler function. | |
virtual | ~AsyncTCPClient () |
The destructor of the asynchronous tcp client. | |
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 | ( | 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.
sick::communication::AsyncTCPClient::~AsyncTCPClient | ( | ) | [virtual] |
The destructor of the asynchronous tcp client.
Definition at line 62 of file AsyncTCPClient.cpp.
sick::communication::AsyncTCPClient::AsyncTCPClient | ( | AsyncTCPClient & | ) | [private] |
Establishes a connection from the host to the sensor.
Definition at line 89 of file AsyncTCPClient.cpp.
Disconnects the host from the sensor.
Definition at line 64 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::doSendAndReceive | ( | const sick::datastructure::PacketBuffer::VectorBuffer & | 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 109 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::handleReceive | ( | const boost::system::error_code & | error, |
const std::size_t & | bytes_transferred | ||
) | [private] |
Definition at line 159 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::handleSendAndReceive | ( | const boost::system::error_code & | error, |
const std::size_t & | bytes_transferred | ||
) | [private] |
Definition at line 142 of file AsyncTCPClient.cpp.
Initiates the listening for a message from the server.
Definition at line 124 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 137 of file AsyncTCPClient.cpp.
void sick::communication::AsyncTCPClient::startReceive | ( | ) | [private] |
Definition at line 157 of file AsyncTCPClient.cpp.
boost::condition sick::communication::AsyncTCPClient::m_connect_condition [private] |
Definition at line 129 of file AsyncTCPClient.h.
boost::mutex sick::communication::AsyncTCPClient::m_connect_mutex [private] |
Definition at line 130 of file AsyncTCPClient.h.
boost::asio::io_service& sick::communication::AsyncTCPClient::m_io_service [private] |
Definition at line 124 of file AsyncTCPClient.h.
std::shared_ptr<boost::asio::io_service::work> sick::communication::AsyncTCPClient::m_io_work_ptr [private] |
Definition at line 123 of file AsyncTCPClient.h.
Definition at line 121 of file AsyncTCPClient.h.
datastructure::PacketBuffer::ArrayBuffer sick::communication::AsyncTCPClient::m_recv_buffer [private] |
Definition at line 119 of file AsyncTCPClient.h.
boost::asio::ip::tcp::endpoint sick::communication::AsyncTCPClient::m_remote_endpoint [private] |
Definition at line 126 of file AsyncTCPClient.h.
std::thread sick::communication::AsyncTCPClient::m_service_thread [private] |
Definition at line 127 of file AsyncTCPClient.h.
boost::mutex sick::communication::AsyncTCPClient::m_socket_mutex [private] |
Definition at line 131 of file AsyncTCPClient.h.
std::shared_ptr<boost::asio::ip::tcp::socket> sick::communication::AsyncTCPClient::m_socket_ptr [private] |
Definition at line 125 of file AsyncTCPClient.h.