Diag-Client-Lib
dcm_client.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  */
8 /* includes */
9 #include "src/dcm/dcm_client.h"
10 
11 #include <optional>
12 
13 #include "src/common/logger.h"
14 
15 namespace diag {
16 namespace client {
17 namespace dcm {
18 namespace {
19 
23 std::optional<std::reference_wrapper<conversation_manager::ConversationManager>> conversation_manager_ref{};
24 
25 } // namespace
26 
27 // string representing of vehicle discovery conversation name
28 constexpr std::string_view VehicleDiscoveryConversation{"VehicleDiscovery"};
29 
31  : DiagnosticManager{},
32  uds_transport_protocol_mgr_{std::make_unique<uds_transport::UdsTransportProtocolManager>()},
33  conversation_mgr_{std::move(dcm_client_config), *uds_transport_protocol_mgr_},
34  vehicle_discovery_conversation_{conversation_mgr_.GetDiagnosticClientConversation(VehicleDiscoveryConversation)} {
35  // make the conversation manager reference available externally
37 }
38 
39 DCMClient::~DCMClient() noexcept = default;
40 
41 void DCMClient::Initialize() noexcept {
42  // start Conversation Manager
43  conversation_mgr_.Startup();
44  // start all the udsTransportProtocol Layer
45  uds_transport_protocol_mgr_->Startup();
46  // start Vehicle Discovery
47  vehicle_discovery_conversation_.Startup();
48 
50  __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Dcm Client Initialized"; });
51 }
52 
53 void DCMClient::Run() noexcept {
54  // run udsTransportProtocol layer
57  __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Dcm Client is ready to serve"; });
58 }
59 
60 void DCMClient::Shutdown() noexcept {
61  // shutdown Vehicle Discovery
63  // shutdown udsTransportProtocol layer
64  uds_transport_protocol_mgr_->Shutdown();
65  // shutdown Conversation Manager
67 
69  __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Dcm Client Shutdown completed"; });
70 }
71 
73  std::string_view conversation_name) noexcept {
74  return conversation::DiagClientConversation{conversation_name};
75 }
76 
79  diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept {
80  return vehicle_discovery_conversation_.SendVehicleIdentificationRequest(vehicle_info_request);
81 }
82 
83 auto GetConversationManager() noexcept -> conversation_manager::ConversationManager & {
85  logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogFatal(
86  __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; });
87  }
88  return conversation_manager_ref.value();
89 }
90 
91 } // namespace dcm
92 } // namespace client
93 } // namespace diag
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
virtual void Shutdown() noexcept=0
Function to shutdown the Conversation.
Conversation class to establish connection with a Diagnostic Server.
void Shutdown() noexcept
Function to shutdown the ConversationManager.
Class to create Diagnostic Manager Client functionality.
Definition: dcm_client.h:26
std::unique_ptr< uds_transport::UdsTransportProtocolManager > uds_transport_protocol_mgr_
Stores the uds transport protocol manager.
Definition: dcm_client.h:91
DCMClient(config_parser::DcmClientConfig dcm_client_config)
Constructs an instance of DCMClient.
Definition: dcm_client.cpp:30
void Shutdown() noexcept override
Function to shutdown the DCMClient.
Definition: dcm_client.cpp:60
conversation_manager::ConversationManager conversation_mgr_
Stores the conversation manager instance.
Definition: dcm_client.h:96
void Run() noexcept override
Function to run DCMClient.
Definition: dcm_client.cpp:53
~DCMClient() noexcept override
Destructs an instance of DCMClient.
conversation::DiagClientConversation GetDiagnosticClientConversation(std::string_view conversation_name) noexcept override
Function to get required diag client conversation object based on conversation name.
Definition: dcm_client.cpp:72
conversation::Conversation & vehicle_discovery_conversation_
Store the conversation for vehicle discovery.
Definition: dcm_client.h:101
core_type::Result< diag::client::vehicle_info::VehicleInfoMessageResponseUniquePtr, DiagClient::VehicleInfoResponseError > SendVehicleIdentificationRequest(diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override
Function to send vehicle identification request and get the Diagnostic Server list.
Definition: dcm_client.cpp:78
static auto GetDiagClientLogger() noexcept -> DiagClientLogger &
Get the diag client logger instance.
Definition: logger.h:32
std::optional< std::reference_wrapper< conversation_manager::ConversationManager > > conversation_manager_ref
Store the conversation manager reference optionally.
Definition: dcm_client.cpp:23
auto GetConversationManager() noexcept -> conversation_manager::ConversationManager &
Function to get the reference to conversation manager.
Definition: dcm_client.cpp:83
constexpr std::string_view VehicleDiscoveryConversation
Definition: dcm_client.cpp:28