Diag-Client-Lib
|
Class used to create a tcp socket for handling transmission and reception of tcp message from driver. More...
#include <tcp_socket_handler.h>
Public Types | |
enum class | SocketHandlerState : std::uint8_t { kSocketOffline = 0U , kSocketOnline = 1U , kSocketConnected = 2U , kSocketDisconnected = 4U } |
Definitions of different socket state. More... | |
using | TcpMessage = boost_support::socket::tcp::TcpMessage |
Type alias for Tcp message. More... | |
using | TcpMessagePtr = boost_support::socket::tcp::TcpMessagePtr |
Type alias for Tcp message pointer. More... | |
using | TcpMessageConstPtr = boost_support::socket::tcp::TcpMessageConstPtr |
Type alias for Tcp message const pointer. More... | |
using | TcpChannel = channel::tcp_channel::DoipTcpChannel |
Type alias for Tcp message. More... | |
Public Member Functions | |
TcpSocketHandler (std::string_view local_ip_address, TcpChannel &channel) | |
Constructs an instance of TcpSocketHandler. More... | |
~TcpSocketHandler ()=default | |
Destruct an instance of TcpSocketHandler. More... | |
void | Start () |
Function to start the socket handler. More... | |
void | Stop () |
Function to stop the socket handler. More... | |
core_type::Result< void > | 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 > | DisconnectFromHost () |
Function to disconnect from remote host if already connected. More... | |
core_type::Result< void > | Transmit (TcpMessageConstPtr tcp_message) |
Function to transmit the provided tcp message. More... | |
SocketHandlerState | GetSocketHandlerState () const |
Function to get the current state of socket handler. More... | |
Private Types | |
using | TcpSocket = boost_support::socket::tcp::TcpClientSocket |
Type alias for tcp client socket. More... | |
Private Attributes | |
std::string | local_ip_address_ |
Store the local ip address. More... | |
std::uint16_t | local_port_num_ |
Store the local port number. More... | |
std::optional< TcpSocket > | tcp_socket_ |
Store the socket object. More... | |
TcpChannel & | channel_ |
Store the reference to tcp channel. More... | |
std::atomic< SocketHandlerState > | state_ |
Store the state of handler. More... | |
Class used to create a tcp socket for handling transmission and reception of tcp message from driver.
Definition at line 32 of file tcp_socket_handler.h.
Type alias for Tcp message.
Definition at line 62 of file tcp_socket_handler.h.
Type alias for Tcp message.
Definition at line 47 of file tcp_socket_handler.h.
using doip_client::sockets::TcpSocketHandler::TcpMessageConstPtr = boost_support::socket::tcp::TcpMessageConstPtr |
Type alias for Tcp message const pointer.
Definition at line 57 of file tcp_socket_handler.h.
using doip_client::sockets::TcpSocketHandler::TcpMessagePtr = boost_support::socket::tcp::TcpMessagePtr |
Type alias for Tcp message pointer.
Definition at line 52 of file tcp_socket_handler.h.
|
private |
Type alias for tcp client socket.
Definition at line 122 of file tcp_socket_handler.h.
|
strong |
Definitions of different socket state.
Enumerator | |
---|---|
kSocketOffline | Socket offline state |
kSocketOnline | Socket online state |
kSocketConnected | Socket connected to remote server |
kSocketDisconnected | Socket disconnected from remote server |
Definition at line 37 of file tcp_socket_handler.h.
doip_client::sockets::TcpSocketHandler::TcpSocketHandler | ( | std::string_view | local_ip_address, |
TcpChannel & | channel | ||
) |
Constructs an instance of TcpSocketHandler.
[in] | local_ip_address | The local ip address |
[in] | channel | The reference to tcp transport handler |
Definition at line 19 of file tcp_socket_handler.cpp.
|
default |
Destruct an instance of TcpSocketHandler.
core_type::Result< void > doip_client::sockets::TcpSocketHandler::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 37 of file tcp_socket_handler.cpp.
References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), doip_client::error_domain::kGenericError, kSocketConnected, kSocketOnline, doip_client::error_domain::MakeErrorCode(), state_, and tcp_socket_.
Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::ConnectToHost().
core_type::Result< void > doip_client::sockets::TcpSocketHandler::DisconnectFromHost | ( | ) |
Function to disconnect from remote host if already connected.
Definition at line 57 of file tcp_socket_handler.cpp.
References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), doip_client::error_domain::kGenericError, kSocketConnected, kSocketDisconnected, kSocketOffline, doip_client::error_domain::MakeErrorCode(), state_, and tcp_socket_.
Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::DisconnectFromHost(), and Stop().
TcpSocketHandler::SocketHandlerState doip_client::sockets::TcpSocketHandler::GetSocketHandlerState | ( | ) | const |
Function to get the current state of socket handler.
Definition at line 90 of file tcp_socket_handler.cpp.
References state_.
Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::IsConnectToHost().
void doip_client::sockets::TcpSocketHandler::Start | ( | ) |
Function to start the socket handler.
Definition at line 26 of file tcp_socket_handler.cpp.
References channel_, local_ip_address_, local_port_num_, doip_client::channel::tcp_channel::DoipTcpChannel::ProcessReceivedTcpMessage(), and tcp_socket_.
Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::Start().
void doip_client::sockets::TcpSocketHandler::Stop | ( | ) |
Function to stop the socket handler.
Definition at line 32 of file tcp_socket_handler.cpp.
References DisconnectFromHost(), kSocketOffline, state_, and tcp_socket_.
Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::Stop().
core_type::Result< void > doip_client::sockets::TcpSocketHandler::Transmit | ( | TcpMessageConstPtr | tcp_message | ) |
Function to transmit the provided tcp message.
[in] | tcp_message | The tcp message |
Definition at line 77 of file tcp_socket_handler.cpp.
References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), doip_client::error_domain::kGenericError, kSocketConnected, doip_client::error_domain::MakeErrorCode(), state_, and tcp_socket_.
|
private |
Store the reference to tcp channel.
Definition at line 142 of file tcp_socket_handler.h.
Referenced by Start().
|
private |
Store the local ip address.
Definition at line 127 of file tcp_socket_handler.h.
Referenced by Start().
|
private |
Store the local port number.
Definition at line 132 of file tcp_socket_handler.h.
Referenced by Start().
|
private |
Store the state of handler.
Definition at line 147 of file tcp_socket_handler.h.
Referenced by ConnectToHost(), DisconnectFromHost(), GetSocketHandlerState(), Stop(), and Transmit().
|
private |
Store the socket object.
Definition at line 137 of file tcp_socket_handler.h.
Referenced by ConnectToHost(), DisconnectFromHost(), Start(), Stop(), and Transmit().