Diag-Client-Lib
|
Class used to create a tcp socket for handling transmission and reception of tcp message from driver. More...
#include <tcp_client.h>
Public Types | |
enum class | TcpErrorCode : std::uint8_t { kOpenFailed , kBindingFailed , kGenericError } |
Tcp error code. More... | |
using | TcpHandlerRead = std::function< void(TcpMessagePtr)> |
Tcp function template used for reception. More... | |
Public Member Functions | |
TcpClientSocket (std::string_view local_ip_address, std::uint16_t local_port_num, TcpHandlerRead tcp_handler_read) | |
Constructs an instance of TcpClientSocket. More... | |
~TcpClientSocket () | |
Destruct an instance of TcpClientSocket. More... | |
core_type::Result< void, TcpErrorCode > | Open () |
Function to Open the socket. More... | |
core_type::Result< void, TcpErrorCode > | ConnectToHost (std::string_view host_ip_address, std::uint16_t host_port_num) |
Function to connect to remote ip address and port number. More... | |
core_type::Result< void, TcpErrorCode > | DisconnectFromHost () |
Function to Disconnect from host. More... | |
core_type::Result< void, TcpErrorCode > | Transmit (TcpMessageConstPtr tcp_message) |
Function to trigger transmission. More... | |
core_type::Result< void, TcpErrorCode > | Destroy () |
Function to destroy the socket. More... | |
Private Types | |
using | Tcp = boost::asio::ip::tcp |
Type alias for tcp protocol. More... | |
using | TcpSocket = Tcp::socket |
Type alias for tcp socket. More... | |
using | TcpIpAddress = boost::asio::ip::address |
Type alias for tcp ip address. More... | |
using | TcpErrorCodeType = boost::system::error_code |
Type alias for tcp error codes. More... | |
Private Member Functions | |
void | HandleMessage () |
Function to handle the reception of tcp message. More... | |
Private Attributes | |
std::string | local_ip_address_ |
Store local ip address. More... | |
std::uint16_t | local_port_num_ |
Store local port number. More... | |
boost::asio::io_context | io_context_ |
boost io context More... | |
TcpSocket | tcp_socket_ |
Store tcp socket. More... | |
std::atomic_bool | exit_request_ |
Flag to terminate the thread. More... | |
std::atomic_bool | running_ |
Flag to start the thread. More... | |
std::condition_variable | cond_var_ |
Conditional variable to block the thread. More... | |
std::thread | thread_ |
The thread itself. More... | |
std::mutex | mutex_ |
mutex to lock critical section More... | |
TcpHandlerRead | tcp_handler_read_ |
Store the handler. More... | |
Class used to create a tcp socket for handling transmission and reception of tcp message from driver.
Definition at line 26 of file tcp_client.h.
|
private |
Type alias for tcp protocol.
Definition at line 95 of file tcp_client.h.
|
private |
Type alias for tcp error codes.
Definition at line 110 of file tcp_client.h.
using boost_support::socket::tcp::TcpClientSocket::TcpHandlerRead = std::function<void(TcpMessagePtr)> |
Tcp function template used for reception.
Definition at line 36 of file tcp_client.h.
|
private |
Type alias for tcp ip address.
Definition at line 105 of file tcp_client.h.
|
private |
Type alias for tcp socket.
Definition at line 100 of file tcp_client.h.
|
strong |
Tcp error code.
Enumerator | |
---|---|
kOpenFailed | |
kBindingFailed | |
kGenericError |
Definition at line 31 of file tcp_client.h.
boost_support::socket::tcp::TcpClientSocket::TcpClientSocket | ( | std::string_view | local_ip_address, |
std::uint16_t | local_port_num, | ||
TcpHandlerRead | tcp_handler_read | ||
) |
Constructs an instance of TcpClientSocket.
[in] | local_ip_address | The local ip address |
[in] | local_port_num | The local port number |
[in] | tcp_handler_read | The handler to send received data to user |
Definition at line 19 of file tcp_client.cpp.
References cond_var_, exit_request_, HandleMessage(), mutex_, running_, and thread_.
boost_support::socket::tcp::TcpClientSocket::~TcpClientSocket | ( | ) |
Destruct an instance of TcpClientSocket.
Definition at line 48 of file tcp_client.cpp.
References cond_var_, exit_request_, running_, and thread_.
core_type::Result< void, TcpClientSocket::TcpErrorCode > boost_support::socket::tcp::TcpClientSocket::ConnectToHost | ( | std::string_view | host_ip_address, |
std::uint16_t | host_port_num | ||
) |
Function to connect to remote ip address and port number.
[in] | host_ip_address | The host ip address |
[in] | host_port_num | The host port number |
Definition at line 94 of file tcp_client.cpp.
References cond_var_, boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), kGenericError, mutex_, running_, and tcp_socket_.
core_type::Result< void, TcpClientSocket::TcpErrorCode > boost_support::socket::tcp::TcpClientSocket::Destroy | ( | ) |
Function to destroy the socket.
Definition at line 165 of file tcp_client.cpp.
References kGenericError, and tcp_socket_.
core_type::Result< void, TcpClientSocket::TcpErrorCode > boost_support::socket::tcp::TcpClientSocket::DisconnectFromHost | ( | ) |
Function to Disconnect from host.
Definition at line 122 of file tcp_client.cpp.
References boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), kGenericError, running_, and tcp_socket_.
|
private |
Function to handle the reception of tcp message.
Definition at line 173 of file tcp_client.cpp.
References boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), boost_support::socket::tcp::kDoipheadrSize, running_, tcp_handler_read_, and tcp_socket_.
Referenced by TcpClientSocket().
core_type::Result< void, TcpClientSocket::TcpErrorCode > boost_support::socket::tcp::TcpClientSocket::Open | ( | ) |
Function to Open the socket.
Definition at line 55 of file tcp_client.cpp.
References boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), kBindingFailed, kGenericError, kOpenFailed, local_ip_address_, local_port_num_, and tcp_socket_.
core_type::Result< void, TcpClientSocket::TcpErrorCode > boost_support::socket::tcp::TcpClientSocket::Transmit | ( | TcpMessageConstPtr | tcp_message | ) |
Function to trigger transmission.
[in] | tcp_message | The tcp message to be transmitted |
Definition at line 142 of file tcp_client.cpp.
References boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), kGenericError, and tcp_socket_.
|
private |
Conditional variable to block the thread.
Definition at line 145 of file tcp_client.h.
Referenced by ConnectToHost(), TcpClientSocket(), and ~TcpClientSocket().
|
private |
Flag to terminate the thread.
Definition at line 135 of file tcp_client.h.
Referenced by TcpClientSocket(), and ~TcpClientSocket().
|
private |
boost io context
Definition at line 125 of file tcp_client.h.
|
private |
|
private |
|
private |
mutex to lock critical section
Definition at line 155 of file tcp_client.h.
Referenced by ConnectToHost(), and TcpClientSocket().
|
private |
Flag to start the thread.
Definition at line 140 of file tcp_client.h.
Referenced by ConnectToHost(), DisconnectFromHost(), HandleMessage(), TcpClientSocket(), and ~TcpClientSocket().
|
private |
|
private |
Store tcp socket.
Definition at line 130 of file tcp_client.h.
Referenced by ConnectToHost(), Destroy(), DisconnectFromHost(), HandleMessage(), Open(), and Transmit().
|
private |
The thread itself.
Definition at line 150 of file tcp_client.h.
Referenced by TcpClientSocket(), and ~TcpClientSocket().