Diag-Client-Lib
diagnostic_client_conversation.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 <memory>
11 
13 #include "src/dcm/dcm_client.h"
14 
15 namespace diag {
16 namespace client {
17 namespace conversation {
18 
20  public:
26  explicit DiagClientConversationImpl(std::string_view conversation_name) noexcept
27  : internal_conversation_{dcm::GetConversationManager().GetDiagnosticClientConversation(conversation_name)} {}
28 
32  ~DiagClientConversationImpl() noexcept = default;
33 
38  void Startup() noexcept { internal_conversation_.Startup(); }
39 
45  void Shutdown() noexcept { internal_conversation_.Shutdown(); }
46 
56  ConnectResult ConnectToDiagServer(std::uint16_t target_address, IpAddress host_ip_addr) noexcept {
57  return internal_conversation_.ConnectToDiagServer(target_address, host_ip_addr);
58  }
59 
66 
77  uds_message::UdsRequestMessageConstPtr message) noexcept {
78  return internal_conversation_.SendDiagnosticRequest(std::move(message));
79  }
80 
81  private:
86 };
87 
88 DiagClientConversation::DiagClientConversation(std::string_view conversation_name) noexcept
89  : diag_client_conversation_impl_{std::make_unique<DiagClientConversationImpl>(conversation_name)} {}
90 
92 
93 void DiagClientConversation::Startup() noexcept { diag_client_conversation_impl_->Startup(); }
94 
96 
98  std::uint16_t target_address, DiagClientConversation::IpAddress host_ip_addr) noexcept {
99  return diag_client_conversation_impl_->ConnectToDiagServer(target_address, host_ip_addr);
100 }
101 
103  return diag_client_conversation_impl_->DisconnectFromDiagServer();
104 }
105 
108  return diag_client_conversation_impl_->SendDiagnosticRequest(std::move(message));
109 }
110 
111 } // namespace conversation
112 } // namespace client
113 } // namespace diag
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
Interface for diag client conversation.
Definition: conversation.h:24
virtual ConnectResult ConnectToDiagServer(std::uint16_t, IpAddress) noexcept
Function to connect to Diagnostic Server.
Definition: conversation.h:101
virtual void Shutdown() noexcept=0
Function to shutdown the Conversation.
virtual DisconnectResult DisconnectFromDiagServer() noexcept
Function to disconnect from Diagnostic Server.
Definition: conversation.h:108
virtual Result< uds_message::UdsResponseMessagePtr, DiagError > SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr) noexcept
Function to send Diagnostic Request and get Diagnostic Response.
Definition: conversation.h:158
virtual void Startup() noexcept=0
Function to start the Conversation.
DisconnectResult DisconnectFromDiagServer() noexcept
Function to disconnect from Diagnostic Server.
void Startup() noexcept
Function to startup the Diagnostic Client Conversation.
~DiagClientConversationImpl() noexcept=default
Destructor an instance of DiagClientConversationImpl.
DiagClientConversationImpl(std::string_view conversation_name) noexcept
Constructor an instance of DiagClientConversationImpl.
Result< uds_message::UdsResponseMessagePtr, DiagClientConversation::DiagError > SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr message) noexcept
Function to send Diagnostic Request and get Diagnostic Response.
ConnectResult ConnectToDiagServer(std::uint16_t target_address, IpAddress host_ip_addr) noexcept
Function to connect to Diagnostic Server.
void Shutdown() noexcept
Function to shutdown the Diagnostic Client Conversation.
Conversation class to establish connection with a Diagnostic Server.
Result< uds_message::UdsResponseMessagePtr, DiagError > SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr message) noexcept
Function to send Diagnostic Request and get Diagnostic Response.
DiagClientConversation(std::string_view conversation_name) noexcept
Constructor an instance of DiagClientConversation.
uds_message::UdsMessage::IpAddress IpAddress
Type alias of ip address type.
ConnectResult ConnectToDiagServer(std::uint16_t target_address, IpAddress host_ip_addr) noexcept
Function to connect to Diagnostic Server using Target address and IP address of the server.
void Startup() noexcept
Function to startup the Diagnostic Client Conversation.
~DiagClientConversation() noexcept
Destructor an instance of DiagClientConversation -Conversation-Destruction.
void Shutdown() noexcept
Function to shutdown the Diagnostic Client Conversation.
DisconnectResult DisconnectFromDiagServer() noexcept
Function to disconnect from Diagnostic Server.
std::unique_ptr< DiagClientConversationImpl > diag_client_conversation_impl_
Unique pointer to diag client conversation implementation.
auto GetConversationManager() noexcept -> conversation_manager::ConversationManager &
Function to get the reference to conversation manager.
Definition: dcm_client.cpp:83
std::unique_ptr< const UdsMessage > UdsRequestMessageConstPtr
Type alias of unique_ptr for constant UdsRequestMessage.