Diag-Client-Lib
doip_transport_protocol_handler.cpp
Go to the documentation of this file.
1 /* Diagnostic Client library
2  * Copyright (C) 2024 Avijit Dey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
9 
10 #include "common/logger.h"
12 
13 namespace doip_client {
14 namespace transport_protocol_handler {
15 
17  UdsTransportProtocolHandlerId const handler_id,
18  uds_transport::UdsTransportProtocolMgr const &transport_protocol_mgr)
19  : uds_transport::UdsTransportProtocolHandler(handler_id, transport_protocol_mgr),
20  doip_connection_mgr_{} {}
21 
23 
26 }
27 
29 
31 
32 std::unique_ptr<uds_transport::Connection> DoipTransportProtocolHandler::CreateTcpConnection(
33  uds_transport::ConversionHandler &conversation, std::string_view tcp_ip_address, std::uint16_t port_num) {
35  __FILE__, __LINE__, __func__, [tcp_ip_address](std::stringstream &msg) {
36  msg << "Doip Tcp protocol requested with local endpoint : "
37  << "<Tcp: " << tcp_ip_address << ">";
38  });
39  return doip_connection_mgr_.FindOrCreateTcpConnection(conversation, tcp_ip_address, port_num);
40 }
41 
42 std::unique_ptr<uds_transport::Connection> DoipTransportProtocolHandler::CreateUdpConnection(
43  uds_transport::ConversionHandler &conversation, std::string_view udp_ip_address, std::uint16_t port_num) {
45  __FILE__, __LINE__, __func__, [udp_ip_address](std::stringstream &msg) {
46  msg << "Doip Udp protocol requested with local endpoint : "
47  << "<Udp: " << udp_ip_address << ">";
48  });
49  return doip_connection_mgr_.FindOrCreateUdpConnection(conversation, udp_ip_address, port_num);
50 }
51 } // namespace transport_protocol_handler
52 } // namespace doip_client
std::unique_ptr< uds_transport::Connection > FindOrCreateTcpConnection(uds_transport::ConversionHandler const &conversation, std::string_view tcp_ip_address, std::uint16_t port_num)
Function to find or create a new Tcp connection.
std::unique_ptr< uds_transport::Connection > FindOrCreateUdpConnection(uds_transport::ConversionHandler const &conversation, std::string_view udp_ip_address, std::uint16_t port_num)
Function to find or create a new Udp connection.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Definition: logger.h:20
DoipTransportProtocolHandler(UdsTransportProtocolHandlerId handler_id, uds_transport::UdsTransportProtocolMgr const &transport_protocol_mgr)
Constructs an instance of DoipTransportProtocolHandler.
connection::DoipConnectionManager doip_connection_mgr_
Store Doip Connection manager.
std::unique_ptr< uds_transport::Connection > CreateTcpConnection(uds_transport::ConversionHandler &conversation, std::string_view tcp_ip_address, std::uint16_t port_num) override
Function to create a new Tcp connection.
std::unique_ptr< uds_transport::Connection > CreateUdpConnection(uds_transport::ConversionHandler &conversion_handler, std::string_view udp_ip_address, std::uint16_t port_num) override
Function to create a new Udp connection.
InitializationResult Initialize() override
Function to initialize the handler.
uds_transport::UdsTransportProtocolHandler::UdsTransportProtocolHandlerId UdsTransportProtocolHandlerId
Type alias for handler id.
~DoipTransportProtocolHandler() final
Destruct an instance of DoipTransportProtocolHandler.
Class to manage reception from transport protocol handler to connection handler.
InitializationResult
Definitions of different initialization result.