Diag-Client-Lib
vd_conversation.h
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 #ifndef DIAG_CLIENT_LIB_APPL_SRC_DCM_CONVERSATION_VD_CONVERSATION_H
9 #define DIAG_CLIENT_LIB_APPL_SRC_DCM_CONVERSATION_VD_CONVERSATION_H
10 
11 /* includes */
12 #include <chrono>
13 #include <mutex>
14 #include <string_view>
15 
16 #include "core/include/result.h"
25 
26 namespace diag {
27 namespace client {
28 namespace conversation {
29 
33 class VdConversation final : public Conversation {
34  private:
38  using PreselectionMode = std::uint8_t;
39 
43  using PreselectionValue = std::vector<std::uint8_t>;
44 
49 
53  using LogicalAddress = std::uint16_t;
54 
55  public:
63  VdConversation(std::string_view conversion_name, VDConversationType &conversion_identifier);
64 
68  VdConversation(const VdConversation &other) noexcept = delete;
69  VdConversation &operator=(const VdConversation &other) noexcept = delete;
70 
74  VdConversation(VdConversation &&other) noexcept = delete;
75  VdConversation &operator=(VdConversation &&other) noexcept = delete;
76 
80  ~VdConversation() override;
81 
85  void Startup() noexcept override;
86 
90  void Shutdown() noexcept override;
91 
97  void RegisterConnection(std::unique_ptr<::uds_transport::Connection> connection) noexcept override;
98 
104  ::uds_transport::ConversionHandler &GetConversationHandler() noexcept override;
105 
131  std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> IndicateMessage(
132  ::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr,
133  ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size,
134  ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind,
135  core_type::Span<std::uint8_t> payloadInfo) noexcept override;
136 
143  void HandleMessage(::uds_transport::UdsMessagePtr message) noexcept override;
144 
152  DiagClient::VehicleInfoResponseError>
153  SendVehicleIdentificationRequest(vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override;
154 
160 
161  private:
170  bool VerifyVehicleInfoRequest(PreselectionMode preselection_mode, std::uint8_t preselection_value_length);
171 
179  ::uds_transport::UdsMessagePtr message);
180 
188  vehicle_info::VehicleInfoListRequestType &vehicle_info_request);
189 
193  std::unique_ptr<::uds_transport::ConversionHandler> vd_conversion_handler_;
194 
198  std::string conversation_name_;
199 
203  std::string broadcast_address_;
204 
208  std::unique_ptr<::uds_transport::Connection> connection_ptr_;
209 
214 
219 };
220 
221 } // namespace conversation
222 } // namespace client
223 } // namespace diag
224 #endif // DIAG_CLIENT_LIB_APPL_SRC_DCM_CONVERSATION_VD_CONVERSATION_H
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
Class to manage Diagnostic Client.
Interface for diag client conversation.
Definition: conversation.h:24
Class to search for available diagnostic server over a network.
std::vector< std::uint8_t > PreselectionValue
Type alias of pre-selection value in terms of vector.
VdConversation(const VdConversation &other) noexcept=delete
Deleted copy assignment and copy constructor.
std::map< std::uint16_t, VehicleAddrInfoResponseStruct > vehicle_info_collection_
Store the vehicle info collection received till now.
::uds_transport::ConversionHandler & GetConversationHandler() noexcept override
Function to get the conversation handler from conversation object.
static std::pair< PreselectionMode, PreselectionValue > DeserializeVehicleInfoRequest(vehicle_info::VehicleInfoListRequestType &vehicle_info_request)
Function to deserialize the Vehicle Information request from user.
static std::pair< LogicalAddress, VehicleAddrInfoResponseStruct > DeserializeVehicleInfoResponse(::uds_transport::UdsMessagePtr message)
Function to deserialize the received Vehicle Identification Response/ Announcement.
~VdConversation() override
Destructs an instance of DmConversation.
std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr > 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 > payloadInfo) noexcept override
Function to indicate a start of reception of message.
VdConversation(std::string_view conversion_name, VDConversationType &conversion_identifier)
Constructs an instance of VdConversation.
VdConversation & operator=(VdConversation &&other) noexcept=delete
void Shutdown() noexcept override
Function to shutdown the DmConversation.
std::unique_ptr<::uds_transport::Connection > connection_ptr_
Store the underlying transport protocol connection object.
void RegisterConnection(std::unique_ptr<::uds_transport::Connection > connection) noexcept override
Function to register the conversation to underlying transport protocol handler.
VdConversation & operator=(const VdConversation &other) noexcept=delete
std::uint16_t LogicalAddress
Type alias of logical address.
std::unique_ptr<::uds_transport::ConversionHandler > vd_conversion_handler_
Store the vd conversation handler.
void Startup() noexcept override
Function to start the DmConversation.
bool VerifyVehicleInfoRequest(PreselectionMode preselection_mode, std::uint8_t preselection_value_length)
Function to verify the received vehicle info request.
vehicle_info::VehicleInfoMessageResponseUniquePtr GetDiagnosticServerList()
Function to get the list of available diagnostic server.
void HandleMessage(::uds_transport::UdsMessagePtr message) noexcept override
Function to Hands over a valid received Uds message.
core_type::Result< diag::client::vehicle_info::VehicleInfoMessageResponseUniquePtr, DiagClient::VehicleInfoResponseError > SendVehicleIdentificationRequest(vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override
Function to send vehicle identification request and get the Diagnostic Server list.
std::string conversation_name_
Store the conversation name.
std::uint8_t PreselectionMode
Type alias of pre-selection mode.
std::mutex vehicle_info_container_mutex_
Mutex to lock the vehicle info collection container.
std::string broadcast_address_
Store the broadcast Ip address of the conversation.
VdConversation(VdConversation &&other) noexcept=delete
Deleted move assignment and move constructor.
Span(T(&)[N]) -> Span< T, N >
VehicleAddrInfoRequest VehicleInfoListRequestType
Type alias of request storage type used while sending vehicle identification request.
std::unique_ptr< VehicleInfoMessage > VehicleInfoMessageResponseUniquePtr
The unique_ptr for Vehicle Identification Response Message.
std::string_view ProtocolKind
std::unique_ptr< UdsMessage > UdsMessagePtr
Definition: uds_message.h:71
uint32_t ChannelID
std::uint8_t Priority
Structure containing VD conversation type.
Structure containing available Vehicle Address Information.