-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathde_tahifi_lists_errors.hh
More file actions
193 lines (170 loc) · 5.26 KB
/
de_tahifi_lists_errors.hh
File metadata and controls
193 lines (170 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Copyright (C) 2015, 2016, 2017, 2019, 2022 T+A elektroakustik GmbH & Co. KG
*
* This file is part of T+A Streaming Board D-Bus interfaces (T+A-D-Bus).
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef DE_TAHIFI_LISTS_ERRORS_HH
#define DE_TAHIFI_LISTS_ERRORS_HH
#include <cinttypes>
class ListError
{
public:
#ifndef DE_TAHIFI_LISTS_ERRORS_ENUM_NAME
#define DE_TAHIFI_LISTS_ERRORS_ENUM_NAME Code
#endif /* !DE_TAHIFI_LISTS_ERRORS_ENUM_NAME */
#ifndef DE_TAHIFI_LISTS_ERRORS_ENUM_VALUE
#define DE_TAHIFI_LISTS_ERRORS_ENUM_VALUE(V) V
#endif /* !DE_TAHIFI_LISTS_ERRORS_ENUM_VALUE */
#include "de_tahifi_lists_errors.h"
private:
/*!
* String representations of the error codes.
*
* \attention
* This array must be sorted according to the values in the
* #ListError::Code enum and it must match its size.
*
* \attention
* This array must be explicitly instantiated in some C++ file,
* otherwise the linker will bail out with an error. Copy the
* following definition to some implementation file so that the linker
* can take it from there:
* \code constexpr const char *ListError::names_[]; \endcode
*/
static constexpr const char *names_[] =
{
"OK",
"INTERNAL",
"INTERRUPTED",
"INVALID_ID",
"PHYSICAL_MEDIA_IO",
"NET_IO",
"PROTOCOL",
"AUTHENTICATION",
"INCONSISTENT",
"NOT_SUPPORTED",
"PERMISSION_DENIED",
"INVALID_URI",
"BUSY_500",
"BUSY_1000",
"BUSY_1500",
"BUSY_3000",
"BUSY_5000",
"BUSY",
"OUT_OF_RANGE",
"EMPTY",
"OVERFLOWN",
"UNDERFLOWN",
"INVALID_STREAM_URL",
"INVALID_STRBO_URL",
"NOT_FOUND",
};
static_assert(sizeof(names_) / sizeof(names_[0]) == static_cast<std::size_t>(ListError::Code::LAST_ERROR_CODE) + 1U,
"Mismatch between error codes enum and error strings");
Code error_code_;
public:
constexpr explicit ListError(Code error_code = Code::OK) throw():
error_code_(error_code)
{}
constexpr explicit ListError(unsigned int error_code) throw():
error_code_(raw_to_code(error_code))
{}
constexpr Code get() const noexcept
{
return error_code_;
}
constexpr uint8_t get_raw_code() const noexcept { return uint8_t(error_code_); }
ListError &operator=(Code code) noexcept
{
error_code_ = code;
return *this;
}
constexpr bool operator==(Code code) const noexcept
{
return error_code_ == code;
}
constexpr bool operator!=(Code code) const noexcept
{
return !(*this == code);
}
constexpr bool operator==(const ListError &other) const noexcept
{
return *this == other.error_code_;
}
constexpr bool failed() const noexcept
{
return *this != Code::OK;
}
constexpr bool busy() const noexcept
{
switch(error_code_)
{
case Code::BUSY:
case Code::BUSY_500:
case Code::BUSY_1000:
case Code::BUSY_1500:
case Code::BUSY_3000:
case Code::BUSY_5000:
return true;
case Code::OK:
case Code::INTERNAL:
case Code::INTERRUPTED:
case Code::INVALID_ID:
case Code::PHYSICAL_MEDIA_IO:
case Code::NET_IO:
case Code::PROTOCOL:
case Code::AUTHENTICATION:
case Code::INCONSISTENT:
case Code::NOT_SUPPORTED:
case Code::PERMISSION_DENIED:
case Code::INVALID_URI:
case Code::OUT_OF_RANGE:
case Code::EMPTY:
case Code::OVERFLOWN:
case Code::UNDERFLOWN:
case Code::INVALID_STREAM_URL:
case Code::INVALID_STRBO_URL:
case Code::NOT_FOUND:
break;
}
return false;
}
constexpr static Code raw_to_code(unsigned int raw_error_code)
{
return (raw_error_code <= Code::LAST_ERROR_CODE)
? Code(raw_error_code)
: Code::INTERNAL;
}
constexpr static const char *code_to_string(Code error)
{
return error < sizeof(names_) / sizeof(names_[0])
? names_[error]
: "***Invalid ListError code***";
}
constexpr const char *to_string() const
{
return ListError::code_to_string(error_code_);
}
};
template <typename T>
static T& operator<<(T& os, const ::ListError &error)
{
os << "ListError::Code::" << error.to_string();
return os;
}
#endif /* !DE_TAHIFI_LISTS_ERRORS_HH */