RDMnet  0.3.0
Implementation of ANSI E1.33 (RDMnet)
View other versions:
ept_status.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************
16  * This file is a part of RDMnet. For more information, go to:
17  * https://github.com/ETCLabs/RDMnet
18  *****************************************************************************/
19 
22 
23 #ifndef RDMNET_CPP_MESSAGE_TYPES_EPT_STATUS_H_
24 #define RDMNET_CPP_MESSAGE_TYPES_EPT_STATUS_H_
25 
26 #include <string>
27 #include "etcpal/cpp/uuid.h"
28 #include "rdmnet/common.h"
29 #include "rdmnet/message.h"
30 
31 namespace rdmnet
32 {
33 class SavedEptStatus;
34 
40 class EptStatus
41 {
42 public:
44  EptStatus() = delete;
46  EptStatus(const EptStatus& other) = delete;
48  EptStatus& operator=(const EptStatus& other) = delete;
49  constexpr EptStatus(const RdmnetEptStatus& c_status);
50 
51  constexpr etcpal::Uuid source_cid() const noexcept;
52  constexpr ept_status_code_t status_code() const noexcept;
53  constexpr const char* status_c_str() const noexcept;
54  std::string status_string() const;
55 
56  const char* CodeToCString() const noexcept;
57  std::string CodeToString() const;
58  constexpr bool HasStatusString() const noexcept;
59 
60  constexpr const RdmnetEptStatus& get() const noexcept;
61 
62  SavedEptStatus Save() const;
63 
64 private:
65  const RdmnetEptStatus& status_;
66 };
67 
71 {
72 public:
74  SavedEptStatus() = default;
75  SavedEptStatus(const RdmnetSavedEptStatus& c_resp);
77  SavedEptStatus(const EptStatus& status);
78  SavedEptStatus& operator=(const EptStatus& status);
79 
80  const etcpal::Uuid& source_cid() const noexcept;
81  ept_status_code_t status_code() const noexcept;
82  const std::string& status_string() const noexcept;
83 
84  bool IsValid() const noexcept;
85  const char* CodeToCString() const noexcept;
86  std::string CodeToString() const;
87  bool HasStatusString() const noexcept;
88 
89 private:
90  etcpal::Uuid source_cid_;
91  ept_status_code_t status_code_;
92  std::string status_string_;
93 };
94 
96 // EptStatus function definitions
98 
100 constexpr EptStatus::EptStatus(const RdmnetEptStatus& c_status) : status_(c_status)
101 {
102 }
103 
105 constexpr etcpal::Uuid EptStatus::source_cid() const noexcept
106 {
107  return status_.source_cid;
108 }
109 
111 constexpr ept_status_code_t EptStatus::status_code() const noexcept
112 {
113  return status_.status_code;
114 }
115 
117 constexpr const char* EptStatus::status_c_str() const noexcept
118 {
119  return status_.status_string;
120 }
121 
124 {
125  return status_.status_string;
126 }
127 
129 inline const char* EptStatus::CodeToCString() const noexcept
130 {
131  return status_.status_string;
132 }
133 
136 {
137  return status_.status_string;
138 }
139 
141 constexpr bool EptStatus::HasStatusString() const noexcept
142 {
143  return (status_.status_string != nullptr);
144 }
145 
147 constexpr const RdmnetEptStatus& EptStatus::get() const noexcept
148 {
149  return status_;
150 }
151 
155 {
156  return SavedEptStatus(*this);
157 }
158 
160 // SavedEptStatus function definitions
162 
165  : source_cid_(c_status.source_cid), status_code_(c_status.status_code)
166 {
167  if (c_status.status_string)
168  status_string_.assign(c_status.status_string);
169 }
170 
173 {
174  source_cid_ = c_status.source_cid;
175  status_code_ = c_status.status_code;
176  if (c_status.status_string)
177  status_string_.assign(c_status.status_string);
178  return *this;
179 }
180 
183  : source_cid_(status.source_cid()), status_code_(status.status_code()), status_string_(status.status_string())
184 {
185 }
186 
189 {
190  source_cid_ = status.source_cid();
191  status_code_ = status.status_code();
192  status_string_ = status.status_string();
193  return *this;
194 }
195 
197 inline const etcpal::Uuid& SavedEptStatus::source_cid() const noexcept
198 {
199  return source_cid_;
200 }
201 
204 {
205  return status_code_;
206 }
207 
209 inline const std::string& SavedEptStatus::status_string() const noexcept
210 {
211  return status_string_;
212 }
213 
215 inline bool SavedEptStatus::IsValid() const noexcept
216 {
217  return !source_cid_.IsNull();
218 }
219 
221 inline const char* SavedEptStatus::CodeToCString() const noexcept
222 {
223  return rdmnet_ept_status_code_to_string(status_code_);
224 }
225 
228 {
229  return rdmnet_ept_status_code_to_string(status_code_);
230 }
231 
233 inline bool SavedEptStatus::HasStatusString() const noexcept
234 {
235  return !status_string_.empty();
236 }
237 }; // namespace rdmnet
238 
239 #endif // RDMNET_CPP_MESSAGE_TYPES_EPT_STATUS_H_
T assign(T... args)
bool IsNull() const noexcept
An EPT status message received over RDMnet and delivered to an RDMnet callback function.
Definition: ept_status.h:41
std::string status_string() const
Get the optional status string accompanying this status message.
Definition: ept_status.h:123
EptStatus & operator=(const EptStatus &other)=delete
Not copyable - use Save() to create a copyable version.
const char * CodeToCString() const noexcept
Convert the status message's code to a string representation.
Definition: ept_status.h:129
constexpr ept_status_code_t status_code() const noexcept
Get the EPT status code of this status message.
Definition: ept_status.h:111
constexpr const RdmnetEptStatus & get() const noexcept
Get a const reference to the underlying C type.
Definition: ept_status.h:147
constexpr bool HasStatusString() const noexcept
Determine whether the optional EPT status string is present.
Definition: ept_status.h:141
std::string CodeToString() const
Convert the status message's code to a string representation.
Definition: ept_status.h:135
SavedEptStatus Save() const
Save the data in this status message for later use from a different context.
Definition: ept_status.h:154
EptStatus()=delete
Not default-constructible.
constexpr etcpal::Uuid source_cid() const noexcept
Get the CID of the EPT client that sent this status message.
Definition: ept_status.h:105
constexpr const char * status_c_str() const noexcept
Get the optional status string accompanying this status message.
Definition: ept_status.h:117
EptStatus(const EptStatus &other)=delete
Not copyable - use Save() to create a copyable version.
An EPT status message received over RDMnet and saved for later processing.
Definition: ept_status.h:71
const etcpal::Uuid & source_cid() const noexcept
Get the CID of the EPT client that sent this EPT status message.
Definition: ept_status.h:197
std::string CodeToString() const
Convert the status message's code to a string representation.
Definition: ept_status.h:227
const char * CodeToCString() const noexcept
Convert the status message's code to a string representation.
Definition: ept_status.h:221
SavedEptStatus()=default
Constructs an empty, invalid EPT status by default.
SavedEptStatus & operator=(const RdmnetSavedEptStatus &c_resp)
Assign an instance of the C RdmnetSavedEptStatus type to an instance of this class.
Definition: ept_status.h:172
bool IsValid() const noexcept
Whether the values contained in this class are valid for an EPT status message.
Definition: ept_status.h:215
const std::string & status_string() const noexcept
Get the optional status string accompanying this status message.
Definition: ept_status.h:209
ept_status_code_t status_code() const noexcept
Get the EPT status code of this status message.
Definition: ept_status.h:203
bool HasStatusString() const noexcept
Determine whether the optional EPT status string is present.
Definition: ept_status.h:233
Functions and definitions common to all RDMnet API modules.
T empty(T... args)
const char * rdmnet_ept_status_code_to_string(ept_status_code_t code)
Get a string representation of an EPT status code.
Definition: common.c:250
ept_status_code_t
EPT status code definitions.
Definition: common.h:76
Basic types for parsed RDMnet messages.
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
An RDMnet EPT status message received by a local component.
Definition: message.h:309
An EPT status received over RDMnet and saved for later processing.
Definition: message.h:327
ept_status_code_t status_code
A status code that indicates the specific error or status condition.
Definition: message.h:331
const char * status_string
An optional implementation-defined status string to accompany this status message.
Definition: message.h:337
EtcPalUuid source_cid
The CID of the EPT client that sent this status message.
Definition: message.h:329