Diag-Client-Lib
uds_message.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 DIAGNOSTIC_CLIENT_LIB_LIB_UDS_TRANSPORT_LAYER_API_UDS_TRANSPORT_UDS_MESSAGE_H
9 #define DIAGNOSTIC_CLIENT_LIB_LIB_UDS_TRANSPORT_LAYER_API_UDS_TRANSPORT_UDS_MESSAGE_H
10 
11 #include <cstdint>
12 #include <map>
13 #include <string_view>
14 
16 
17 namespace uds_transport {
18 
19 class UdsMessage {
20  public:
21  // type for UDS source and target addresses
22  using Address = std::uint16_t;
23  // Ip address
24  using IpAddress = std::string_view;
25  // Port Number
26  using PortNumber = std::uint16_t;
27  // Type for the meta information attached to a UdsMessage
28  using MetaInfoMap = std::map<std::string, std::string>;
29  // type of target address in UdsMessage
30  enum class TargetAddressType : std::uint8_t { kPhysical = 0U, kFunctional = 1U };
31 
32  // ctor
33  UdsMessage() = default;
34 
35  UdsMessage(const UdsMessage &other) = default;
36  UdsMessage(UdsMessage &&other) noexcept = default;
37  UdsMessage &operator=(const UdsMessage &other) = default;
38  UdsMessage &operator=(UdsMessage &&other) noexcept = default;
39 
40  // dtor
41  inline virtual ~UdsMessage() = default;
42 
43  // add new metaInfo to this message.
44  virtual void AddMetaInfo(std::shared_ptr<const MetaInfoMap> meta_info) = 0;
45 
46  // Get the UDS message data starting with the SID (A_Data as per ISO)
47  virtual const ByteVector &GetPayload() const = 0;
48 
49  // return the underlying buffer for write access
50  virtual ByteVector &GetPayload() = 0;
51 
52  // Get the source address of the uds message.
53  virtual Address GetSa() const noexcept = 0;
54 
55  // Get the target address of the uds message.
56  virtual Address GetTa() const noexcept = 0;
57 
58  // Get the target address type (phys/func) of the uds message.
59  virtual TargetAddressType GetTaType() const noexcept = 0;
60 
61  // Get Host Ip address
62  virtual IpAddress GetHostIpAddress() const noexcept = 0;
63 
64  // Get Host port number
65  virtual PortNumber GetHostPortNumber() const noexcept = 0;
66 };
67 
68 // This is the unique_ptr for constant UdsMessages
69 using UdsMessageConstPtr = std::unique_ptr<const UdsMessage>;
70 // This is the unique_ptr for UdsMessages
71 using UdsMessagePtr = std::unique_ptr<UdsMessage>;
72 
73 } // namespace uds_transport
74 #endif // DIAGNOSTIC_CLIENT_LIB_LIB_UDS_TRANSPORT_LAYER_API_UDS_TRANSPORT_UDS_MESSAGE_H
virtual IpAddress GetHostIpAddress() const noexcept=0
std::string_view IpAddress
Definition: uds_message.h:24
UdsMessage & operator=(UdsMessage &&other) noexcept=default
virtual void AddMetaInfo(std::shared_ptr< const MetaInfoMap > meta_info)=0
virtual Address GetTa() const noexcept=0
UdsMessage & operator=(const UdsMessage &other)=default
virtual Address GetSa() const noexcept=0
UdsMessage(const UdsMessage &other)=default
virtual ~UdsMessage()=default
virtual const ByteVector & GetPayload() const =0
std::map< std::string, std::string > MetaInfoMap
Definition: uds_message.h:28
std::uint16_t PortNumber
Definition: uds_message.h:26
virtual PortNumber GetHostPortNumber() const noexcept=0
virtual ByteVector & GetPayload()=0
UdsMessage(UdsMessage &&other) noexcept=default
virtual TargetAddressType GetTaType() const noexcept=0
std::unique_ptr< const UdsMessage > UdsMessageConstPtr
Definition: uds_message.h:69
std::unique_ptr< UdsMessage > UdsMessagePtr
Definition: uds_message.h:71
std::vector< std::uint8_t > ByteVector