RDMnet  0.3.0
Implementation of ANSI E1.33 (RDMnet)
View other versions:
rpt_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_RPT_STATUS_H_
24 #define RDMNET_CPP_MESSAGE_TYPES_RPT_STATUS_H_
25 
26 #include <cstdint>
27 #include <string>
28 #include "rdm/cpp/uid.h"
29 #include "rdmnet/common.h"
30 #include "rdmnet/message.h"
31 
32 namespace rdmnet
33 {
34 class SavedRptStatus;
35 
41 class RptStatus
42 {
43 public:
45  RptStatus() = delete;
46  constexpr RptStatus(const RdmnetRptStatus& c_status);
47 
48  constexpr rdm::Uid source_uid() const noexcept;
49  constexpr uint16_t source_endpoint() const noexcept;
50  constexpr uint32_t seq_num() const noexcept;
51 
52  constexpr rpt_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 RdmnetRptStatus& get() const noexcept;
61 
62  SavedRptStatus Save() const;
63 
64 private:
65  const RdmnetRptStatus& status_;
66 };
67 
71 {
72 public:
74  SavedRptStatus() = default;
75  SavedRptStatus(const RdmnetSavedRptStatus& c_status);
76  SavedRptStatus& operator=(const RdmnetSavedRptStatus& c_status);
77  SavedRptStatus(const RptStatus& status);
78  SavedRptStatus& operator=(const RptStatus& status);
79 
80  const rdm::Uid& source_uid() const noexcept;
81  uint16_t source_endpoint() const noexcept;
82  uint32_t seq_num() const noexcept;
83 
84  rpt_status_code_t status_code() const noexcept;
85  const std::string& status_string() const noexcept;
86 
87  bool IsValid() const noexcept;
88  const char* CodeToCString() const noexcept;
89  std::string CodeToString() const;
90  bool HasStatusString() const noexcept;
91 
92 private:
93  rdm::Uid source_uid_;
94  uint16_t source_endpoint_{E133_NULL_ENDPOINT};
95  uint32_t seq_num_{0};
96  rpt_status_code_t status_code_{};
97  std::string status_string_;
98 };
99 
101 // RptStatus function definitions
103 
105 constexpr RptStatus::RptStatus(const RdmnetRptStatus& c_status) : status_(c_status)
106 {
107 }
108 
110 constexpr rdm::Uid RptStatus::source_uid() const noexcept
111 {
112  return status_.source_uid;
113 }
114 
116 constexpr uint16_t RptStatus::source_endpoint() const noexcept
117 {
118  return status_.source_endpoint;
119 }
120 
122 constexpr uint32_t RptStatus::seq_num() const noexcept
123 {
124  return status_.seq_num;
125 }
126 
128 constexpr rpt_status_code_t RptStatus::status_code() const noexcept
129 {
130  return status_.status_code;
131 }
132 
134 constexpr const char* RptStatus::status_c_str() const noexcept
135 {
136  return status_.status_string;
137 }
138 
141 {
142  return status_.status_string;
143 }
144 
146 inline const char* RptStatus::CodeToCString() const noexcept
147 {
149 }
150 
153 {
155 }
156 
158 constexpr bool RptStatus::HasStatusString() const noexcept
159 {
160  return (status_.status_string != nullptr);
161 }
162 
164 constexpr const RdmnetRptStatus& RptStatus::get() const noexcept
165 {
166  return status_;
167 }
168 
172 {
173  return SavedRptStatus(*this);
174 }
175 
177 // SavedRptStatus function definitions
179 
182  : source_uid_(c_status.source_uid)
183  , source_endpoint_(c_status.source_endpoint)
184  , seq_num_(c_status.seq_num)
185  , status_code_(c_status.status_code)
186 {
187  if (c_status.status_string)
188  status_string_.assign(c_status.status_string);
189 }
190 
193 {
194  source_uid_ = c_status.source_uid;
195  source_endpoint_ = c_status.source_endpoint;
196  seq_num_ = c_status.seq_num;
197  status_code_ = c_status.status_code;
198  if (c_status.status_string)
199  status_string_.assign(c_status.status_string);
200  return *this;
201 }
202 
205  : source_uid_(status.source_uid())
206  , source_endpoint_(status.source_endpoint())
207  , seq_num_(status.seq_num())
208  , status_code_(status.status_code())
209  , status_string_(status.status_string())
210 {
211 }
212 
215 {
216  source_uid_ = status.source_uid();
217  source_endpoint_ = status.source_endpoint();
218  seq_num_ = status.seq_num();
219  status_code_ = status.status_code();
220  status_string_ = status.status_string();
221  return *this;
222 }
223 
225 inline const rdm::Uid& SavedRptStatus::source_uid() const noexcept
226 {
227  return source_uid_;
228 }
229 
231 inline uint16_t SavedRptStatus::source_endpoint() const noexcept
232 {
233  return source_endpoint_;
234 }
235 
237 inline uint32_t SavedRptStatus::seq_num() const noexcept
238 {
239  return seq_num_;
240 }
241 
244 {
245  return status_code_;
246 }
247 
249 inline const std::string& SavedRptStatus::status_string() const noexcept
250 {
251  return status_string_;
252 }
253 
255 inline bool SavedRptStatus::IsValid() const noexcept
256 {
257  return seq_num_ != 0;
258 }
259 
261 inline const char* SavedRptStatus::CodeToCString() const noexcept
262 {
263  return rdmnet_rpt_status_code_to_string(status_code_);
264 }
265 
268 {
269  return rdmnet_rpt_status_code_to_string(status_code_);
270 }
271 
273 inline bool SavedRptStatus::HasStatusString() const noexcept
274 {
275  return !status_string_.empty();
276 }
277 
278 }; // namespace rdmnet
279 
280 #endif // RDMNET_CPP_MESSAGE_TYPES_RPT_STATUS_H_
T assign(T... args)
An RPT status message received over RDMnet and delivered to an RDMnet callback function.
Definition: rpt_status.h:42
constexpr const char * status_c_str() const noexcept
Get the optional status string accompanying this status message.
Definition: rpt_status.h:134
RptStatus()=delete
Not default-constructible.
SavedRptStatus Save() const
Save the data in this status message for later use from a different context.
Definition: rpt_status.h:171
constexpr uint16_t source_endpoint() const noexcept
Get the endpoint from which this RPT status message was sent.
Definition: rpt_status.h:116
const char * CodeToCString() const noexcept
Convert the status message's code to a string representation.
Definition: rpt_status.h:146
constexpr rdm::Uid source_uid() const noexcept
Get the UID of the RDMnet component that sent this RPT status message.
Definition: rpt_status.h:110
constexpr uint32_t seq_num() const noexcept
Get the RDMnet sequence number of this RPT status message, for matching with a corresponding command.
Definition: rpt_status.h:122
constexpr rpt_status_code_t status_code() const noexcept
Get the RPT status code of this status message.
Definition: rpt_status.h:128
constexpr bool HasStatusString() const noexcept
Determine whether the optional RPT status string is present.
Definition: rpt_status.h:158
std::string status_string() const
Get the optional status string accompanying this status message.
Definition: rpt_status.h:140
std::string CodeToString() const
Convert the status message's code to a string representation.
Definition: rpt_status.h:152
constexpr const RdmnetRptStatus & get() const noexcept
Get a const reference to the underlying C type.
Definition: rpt_status.h:164
An RPT status message received over RDMnet and saved for later processing.
Definition: rpt_status.h:71
SavedRptStatus & operator=(const RdmnetSavedRptStatus &c_status)
Assign an instance of the C RdmnetSavedRptStatus type to an instance of this class.
Definition: rpt_status.h:192
bool HasStatusString() const noexcept
Determine whether the optional RPT status string is present.
Definition: rpt_status.h:273
SavedRptStatus()=default
Constructs an empty, invalid RPT status by default.
bool IsValid() const noexcept
Whether the values contained in this class are valid for an RPT Status message.
Definition: rpt_status.h:255
std::string CodeToString() const
Convert the status message's code to a string representation.
Definition: rpt_status.h:267
const rdm::Uid & source_uid() const noexcept
Get the UID of the RDMnet component that sent this RPT status message.
Definition: rpt_status.h:225
const std::string & status_string() const noexcept
Get the optional status string accompanying this status message.
Definition: rpt_status.h:249
uint32_t seq_num() const noexcept
Get the RDMnet sequence number of this RPT status message, for matching with a corresponding command.
Definition: rpt_status.h:237
uint16_t source_endpoint() const noexcept
Get the endpoint from which this RPT status message was sent.
Definition: rpt_status.h:231
rpt_status_code_t status_code() const noexcept
Get the RPT status code of this status message.
Definition: rpt_status.h:243
const char * CodeToCString() const noexcept
Convert the status message's code to a string representation.
Definition: rpt_status.h:261
Functions and definitions common to all RDMnet API modules.
T empty(T... args)
const char * rdmnet_rpt_status_code_to_string(rpt_status_code_t code)
Get a string representation of an RPT status code.
Definition: common.c:231
rpt_status_code_t
RPT status code definitions.
Definition: common.h:53
Basic types for parsed RDMnet messages.
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
An RDMnet RPT status message received by a local component.
Definition: message.h:193
RdmUid source_uid
The UID of the RDMnet component that sent this status message.
Definition: message.h:195
const char * status_string
An optional implementation-defined status string to accompany this status message.
Definition: message.h:203
uint32_t seq_num
The sequence number of the status message, for matching with a corresponding command.
Definition: message.h:199
uint16_t source_endpoint
The endpoint from which the status message was sent.
Definition: message.h:197
rpt_status_code_t status_code
A status code that indicates the specific error or status condition.
Definition: message.h:201
An RPT status received over RDMnet and saved for later processing.
Definition: message.h:215
uint16_t source_endpoint
The endpoint from which the status message was sent.
Definition: message.h:219
uint32_t seq_num
The sequence number of the status message, for matching with a corresponding command.
Definition: message.h:221
char * status_string
An optional implementation-defined status string to accompany this status message.
Definition: message.h:229
RdmUid source_uid
The UID of the RDMnet component that sent this status message.
Definition: message.h:217
rpt_status_code_t status_code
A status code that indicates the specific error or status condition.
Definition: message.h:223