Diag-Client-Lib
doip_error_domain.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 
9 /* includes */
11 
13 
14 namespace doip_client {
15 namespace error_domain {
16 namespace {
17 
21 constexpr core_type::ErrorDomain::IdType unique_identifier{0x5000000000000001};
22 
27 
28 auto ConvertErrorCodeToString(core_type::ErrorDomain::CodeType error_code) noexcept -> std::string {
29  std::string result{};
30  DoipErrorErrc const doip_error_code{error_code};
31 
32  switch (doip_error_code) {
34  result = "InitializationFailed";
35  break;
37  result = "DeInitializationFailed";
38  break;
40  result = "SocketError";
41  break;
43  result = "GenericError";
44  break;
45  }
46  return result;
47 }
48 
49 } // namespace
50 
52 
53 const char* DoipErrorDomain::Name() const noexcept { return domain_name_.c_str(); }
54 
56  message_.clear();
57  message_ = ConvertErrorCodeToString(error_code);
58  return message_.c_str();
59 }
60 
63 }
64 
65 } // namespace error_domain
66 } // namespace doip_client
Encapsulation of an error code. An ErrorCode contains a raw error code value and an error domain....
Definition: error_code.h:22
std::int32_t CodeType
Type alias for a domain-specific error code value.
Definition: error_domain.h:30
std::uint8_t SupportDataType
Type alias type for vendor-specific supplementary data.
Definition: error_domain.h:35
std::uint64_t IdType
Type alias for a unique ErrorDomain identifier type.
Definition: error_domain.h:25
Definition of Doip Client Error domain.
DoipErrorDomain() noexcept
Default constructor.
const std::string domain_name_
Store the error domain name.
const char * Message(CodeType error_code) noexcept override
Return a textual representation of the given error code.
const char * Name() const noexcept override
Return the name of this error domain.
constexpr core_type::ErrorDomain::IdType unique_identifier
Store the unique identifier of this domain.
auto ConvertErrorCodeToString(core_type::ErrorDomain::CodeType error_code) noexcept -> std::string
core_type::ErrorCode MakeErrorCode(DoipErrorErrc, core_type::ErrorDomain::SupportDataType data) noexcept
Create a new ErrorCode within DoipErrorDomain.
DoipErrorErrc
Definition of error code in Doip Client.