Diag-Client-Lib
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
doip_client::channel::tcp_channel::DoipTcpChannel Class Referencefinal

Class to manage a tcp channel as per DoIP protocol. More...

#include <doip_tcp_channel.h>

Collaboration diagram for doip_client::channel::tcp_channel::DoipTcpChannel:
Collaboration graph
[legend]

Public Types

using TcpMessagePtr = sockets::TcpSocketHandler::TcpMessagePtr
 Type alias for Tcp message pointer. More...
 

Public Member Functions

 DoipTcpChannel (std::string_view tcp_ip_address, std::uint16_t port_num, uds_transport::Connection &connection)
 Constructs an instance of TcpChannel. More...
 
 ~DoipTcpChannel ()=default
 Destruct an instance of TcpChannel. More...
 
void Start ()
 Function to start the channel. More...
 
void Stop ()
 Function to stop the channel. More...
 
bool IsConnectToHost ()
 Function to check if connected to host remote server. More...
 
uds_transport::UdsTransportProtocolMgr::ConnectionResult ConnectToHost (uds_transport::UdsMessageConstPtr message)
 Function to establish connection to remote host server. More...
 
uds_transport::UdsTransportProtocolMgr::DisconnectionResult DisconnectFromHost ()
 Function to disconnect from remote host server. More...
 
std::pair< uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtrIndicateMessage (uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, std::size_t size, uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, core_type::Span< std::uint8_t > payload_info)
 Function to indicate a start of reception of message. More...
 
uds_transport::UdsTransportProtocolMgr::TransmissionResult Transmit (uds_transport::UdsMessageConstPtr message)
 Function to transmit a valid Uds message. More...
 
void HandleMessage (uds_transport::UdsMessagePtr message)
 Function to Hands over a valid received Uds message to upper layer. More...
 
void ProcessReceivedTcpMessage (TcpMessagePtr tcp_rx_message)
 Function to process the received Tcp message from socket layer. More...
 

Private Types

using TcpSocketHandler = sockets::TcpSocketHandler
 Type alias for Tcp socket handler. More...
 

Private Attributes

TcpSocketHandler tcp_socket_handler_
 Store the tcp socket handler. More...
 
DoipTcpChannelHandler tcp_channel_handler_
 Store the doip channel handler. More...
 
uds_transport::Connectionconnection_
 Store the reference to doip connection. More...
 

Detailed Description

Class to manage a tcp channel as per DoIP protocol.

Definition at line 26 of file doip_tcp_channel.h.

Member Typedef Documentation

◆ TcpMessagePtr

Type alias for Tcp message pointer.

Definition at line 31 of file doip_tcp_channel.h.

◆ TcpSocketHandler

Type alias for Tcp socket handler.

Definition at line 137 of file doip_tcp_channel.h.

Constructor & Destructor Documentation

◆ DoipTcpChannel()

doip_client::channel::tcp_channel::DoipTcpChannel::DoipTcpChannel ( std::string_view  tcp_ip_address,
std::uint16_t  port_num,
uds_transport::Connection connection 
)

Constructs an instance of TcpChannel.

Parameters
[in]tcp_ip_addressThe local ip address
[in]port_numThe reference to tcp transport handler
[in]connectionThe reference to tcp transport handler

Definition at line 20 of file doip_tcp_channel.cpp.

21  : tcp_socket_handler_{tcp_ip_address, *this},
23  connection_{connection} {}
uds_transport::Connection & connection_
Store the reference to doip connection.
DoipTcpChannelHandler tcp_channel_handler_
Store the doip channel handler.
TcpSocketHandler tcp_socket_handler_
Store the tcp socket handler.

◆ ~DoipTcpChannel()

doip_client::channel::tcp_channel::DoipTcpChannel::~DoipTcpChannel ( )
default

Destruct an instance of TcpChannel.

Member Function Documentation

◆ ConnectToHost()

uds_transport::UdsTransportProtocolMgr::ConnectionResult doip_client::channel::tcp_channel::DoipTcpChannel::ConnectToHost ( uds_transport::UdsMessageConstPtr  message)

Function to establish connection to remote host server.

Parameters
[in]messageThe connection message
Returns
Connection result

Definition at line 39 of file doip_tcp_channel.cpp.

40  {
43 
44  uds_transport::UdsMessage::IpAddress const kHostIpAddress{message->GetHostIpAddress()};
45  uds_transport::UdsMessage::PortNumber const kHostPortNumber{message->GetHostPortNumber()};
46  // Initiate connecting to server
47  if (tcp_socket_handler_.ConnectToHost(kHostIpAddress, kHostPortNumber)) {
48  // Once connected, Send routing activation req and get response
49  ret_val = tcp_channel_handler_.SendRoutingActivationRequest(std::move(message));
50  } else { // failure
51  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError(
52  __FILE__, __LINE__, __func__, [&kHostIpAddress, &kHostPortNumber](std::stringstream &msg) {
53  msg << "Doip Tcp socket connect failed for remote endpoints : "
54  << "<Ip: " << kHostIpAddress << ", Port: " << kHostPortNumber << ">";
55  });
56  }
57  return ret_val;
58 }
auto SendRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
Function to send routing activation request.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Definition: logger.h:20
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.
std::string_view IpAddress
Definition: uds_message.h:24
std::uint16_t PortNumber
Definition: uds_message.h:26

References doip_client::sockets::TcpSocketHandler::ConnectToHost(), doip_client::logger::DoipClientLogger::GetDiagClientLogger(), uds_transport::UdsTransportProtocolMgr::kConnectionFailed, doip_client::channel::tcp_channel::DoipTcpChannelHandler::SendRoutingActivationRequest(), tcp_channel_handler_, and tcp_socket_handler_.

Referenced by doip_client::connection::DoipTcpConnection::ConnectToHost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DisconnectFromHost()

uds_transport::UdsTransportProtocolMgr::DisconnectionResult doip_client::channel::tcp_channel::DoipTcpChannel::DisconnectFromHost ( )

Function to disconnect from remote host server.

Returns
Disconnection result

Definition at line 60 of file doip_tcp_channel.cpp.

References doip_client::sockets::TcpSocketHandler::DisconnectFromHost(), doip_client::channel::tcp_channel::DoipTcpChannelHandler::IsRoutingActivated(), uds_transport::UdsTransportProtocolMgr::kDisconnectionFailed, uds_transport::UdsTransportProtocolMgr::kDisconnectionOk, doip_client::channel::tcp_channel::DoipTcpChannelHandler::Reset(), tcp_channel_handler_, and tcp_socket_handler_.

Referenced by doip_client::connection::DoipTcpConnection::DisconnectFromHost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleMessage()

void doip_client::channel::tcp_channel::DoipTcpChannel::HandleMessage ( uds_transport::UdsMessagePtr  message)

Function to Hands over a valid received Uds message to upper layer.

Parameters
[in]messageThe Uds message ptr (unique_ptr semantics) with the request. Ownership of the UdsMessage is given back to the conversation here

Definition at line 102 of file doip_tcp_channel.cpp.

102  {
103  connection_.HandleMessage(std::move(message));
104 }
virtual void HandleMessage(UdsMessagePtr message)=0
Function to Hands over a valid received Uds message.

References connection_, and uds_transport::Connection::HandleMessage().

Here is the call graph for this function:

◆ IndicateMessage()

std::pair< uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr > doip_client::channel::tcp_channel::DoipTcpChannel::IndicateMessage ( uds_transport::UdsMessage::Address  source_addr,
uds_transport::UdsMessage::Address  target_addr,
uds_transport::UdsMessage::TargetAddressType  type,
uds_transport::ChannelID  channel_id,
std::size_t  size,
uds_transport::Priority  priority,
uds_transport::ProtocolKind  protocol_kind,
core_type::Span< std::uint8_t >  payload_info 
)

Function to indicate a start of reception of message.

This is called to indicate the reception of new message by underlying transport protocol handler

Parameters
[in]source_addrThe UDS source address of message
[in]target_addrThe UDS target address of message
[in]typeThe indication whether its is phys/func request
[in]channel_idThe transport protocol channel on which message start happened
[in]sizeThe size in bytes of the UdsMessage starting from SID
[in]priorityThe priority of the given message, used for prioritization of conversations
[in]protocol_kindThe identifier of protocol kind associated to message
[in]payload_infoThe view onto the first received payload bytes, if any. This view shall be used only within this function call. It is recommended that the TP provides at least the first two bytes of the request message, so the DM can identify a functional TesterPresent
Returns
std::pair< IndicationResult, UdsMessagePtr > The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned to the handler to get filled

Definition at line 93 of file doip_tcp_channel.cpp.

97  {
98  return connection_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, protocol_kind,
99  payload_info);
100 }
virtual std::pair< UdsTransportProtocolMgr::IndicationResult, UdsMessagePtr > IndicateMessage(UdsMessage::Address source_addr, UdsMessage::Address target_addr, UdsMessage::TargetAddressType type, ChannelID channel_id, std::size_t size, Priority priority, ProtocolKind protocol_kind, core_type::Span< std::uint8_t > payload_info)=0
Function to indicate a start of reception of message.

References connection_, and uds_transport::Connection::IndicateMessage().

Here is the call graph for this function:

◆ IsConnectToHost()

bool doip_client::channel::tcp_channel::DoipTcpChannel::IsConnectToHost ( )

Function to check if connected to host remote server.

Returns
True if connection, False otherwise

Definition at line 35 of file doip_tcp_channel.cpp.

References doip_client::sockets::TcpSocketHandler::GetSocketHandlerState(), doip_client::sockets::TcpSocketHandler::kSocketConnected, and tcp_socket_handler_.

Referenced by doip_client::connection::DoipTcpConnection::IsConnectToHost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessReceivedTcpMessage()

void doip_client::channel::tcp_channel::DoipTcpChannel::ProcessReceivedTcpMessage ( TcpMessagePtr  tcp_rx_message)

Function to process the received Tcp message from socket layer.

Parameters
[in]tcp_rx_messageThe Tcp message ptr (unique_ptr semantics) with the request. Ownership of the UdsMessage is given back to the channel here

Definition at line 73 of file doip_tcp_channel.cpp.

73  {
74  tcp_channel_handler_.HandleMessage(std::move(tcp_rx_message));
75 }
void HandleMessage(TcpMessagePtr tcp_rx_message) noexcept
Function to process the received message.

References doip_client::channel::tcp_channel::DoipTcpChannelHandler::HandleMessage(), and tcp_channel_handler_.

Referenced by doip_client::sockets::TcpSocketHandler::Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Start()

void doip_client::channel::tcp_channel::DoipTcpChannel::Start ( )

Function to start the channel.

Definition at line 25 of file doip_tcp_channel.cpp.

25  {
28 }
void Start()
Function to start the socket handler.

References doip_client::channel::tcp_channel::DoipTcpChannelHandler::Start(), doip_client::sockets::TcpSocketHandler::Start(), tcp_channel_handler_, and tcp_socket_handler_.

Referenced by doip_client::connection::DoipTcpConnection::Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stop()

void doip_client::channel::tcp_channel::DoipTcpChannel::Stop ( )

Function to stop the channel.

Definition at line 30 of file doip_tcp_channel.cpp.

30  {
33 }
void Stop()
Function to stop the socket handler.

References doip_client::channel::tcp_channel::DoipTcpChannelHandler::Stop(), doip_client::sockets::TcpSocketHandler::Stop(), tcp_channel_handler_, and tcp_socket_handler_.

Referenced by doip_client::connection::DoipTcpConnection::Stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Transmit()

uds_transport::UdsTransportProtocolMgr::TransmissionResult doip_client::channel::tcp_channel::DoipTcpChannel::Transmit ( uds_transport::UdsMessageConstPtr  message)

Function to transmit a valid Uds message.

Parameters
[in]messageThe Uds message ptr (unique_ptr semantics) with the request.

Definition at line 77 of file doip_tcp_channel.cpp.

78  {
81  // Routing activation should be active before sending diag request
83  ret_val = tcp_channel_handler_.SendDiagnosticRequest(std::move(message));
84  } else {
85  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError(
86  __FILE__, __LINE__, __func__,
87  [](std::stringstream &msg) { msg << "Routing Activation required, please connect to server first"; });
88  }
89  return ret_val;
90 }
auto SendDiagnosticRequest(uds_transport::UdsMessageConstPtr diagnostic_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to send diagnostic request.

References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), doip_client::channel::tcp_channel::DoipTcpChannelHandler::IsRoutingActivated(), uds_transport::UdsTransportProtocolMgr::kTransmitFailed, doip_client::channel::tcp_channel::DoipTcpChannelHandler::SendDiagnosticRequest(), and tcp_channel_handler_.

Referenced by doip_client::connection::DoipTcpConnection::Transmit().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ connection_

uds_transport::Connection& doip_client::channel::tcp_channel::DoipTcpChannel::connection_
private

Store the reference to doip connection.

Definition at line 152 of file doip_tcp_channel.h.

Referenced by HandleMessage(), and IndicateMessage().

◆ tcp_channel_handler_

DoipTcpChannelHandler doip_client::channel::tcp_channel::DoipTcpChannel::tcp_channel_handler_
private

Store the doip channel handler.

Definition at line 147 of file doip_tcp_channel.h.

Referenced by ConnectToHost(), DisconnectFromHost(), ProcessReceivedTcpMessage(), Start(), Stop(), and Transmit().

◆ tcp_socket_handler_

TcpSocketHandler doip_client::channel::tcp_channel::DoipTcpChannel::tcp_socket_handler_
private

Store the tcp socket handler.

Definition at line 142 of file doip_tcp_channel.h.

Referenced by ConnectToHost(), DisconnectFromHost(), IsConnectToHost(), Start(), and Stop().


The documentation for this class was generated from the following files: