RDMnet  0.3.0
Implementation of ANSI E1.33 (RDMnet)
View other versions:
ept_data.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_DATA_H_
24 #define RDMNET_CPP_MESSAGE_TYPES_EPT_DATA_H_
25 
26 #include <cstdint>
27 #include <vector>
28 #include "etcpal/cpp/uuid.h"
29 #include "rdmnet/message.h"
30 
31 namespace rdmnet
32 {
33 class SavedEptData;
34 
40 class EptData
41 {
42 public:
44  EptData() = delete;
46  EptData(const EptData& other) = delete;
48  EptData& operator=(const EptData& other) = delete;
49 
50  constexpr EptData(const RdmnetEptData& c_data) noexcept;
51 
52  constexpr etcpal::Uuid source_cid() const noexcept;
53  constexpr uint16_t manufacturer_id() const noexcept;
54  constexpr uint16_t protocol_id() const noexcept;
55  constexpr uint32_t sub_protocol() const noexcept;
56  constexpr const uint8_t* data() const noexcept;
57  constexpr size_t data_len() const noexcept;
58 
59  std::vector<uint8_t> CopyData() const;
60 
61  constexpr const RdmnetEptData& get() const noexcept;
62 
63  SavedEptData Save() const;
64 
65 private:
66  const RdmnetEptData& data_;
67 };
68 
76 {
77 public:
79  SavedEptData() = default;
80  SavedEptData(const RdmnetSavedEptData& c_data);
82  SavedEptData(const EptData& resp);
83  SavedEptData& operator=(const EptData& resp);
84 
85  const etcpal::Uuid& source_cid() const noexcept;
86  uint16_t manufacturer_id() const noexcept;
87  uint16_t protocol_id() const noexcept;
88  uint32_t sub_protocol() const noexcept;
89  const uint8_t* data() const noexcept;
90  size_t data_len() const noexcept;
91 
92  bool IsValid() const noexcept;
93 
94 private:
95  etcpal::Uuid source_cid_;
96  uint16_t manufacturer_id_;
97  uint16_t protocol_id_;
98  std::vector<uint8_t> data_;
99 };
100 
102 // EptData function definitions
104 
106 constexpr EptData::EptData(const RdmnetEptData& c_data) noexcept : data_(c_data)
107 {
108 }
109 
111 constexpr etcpal::Uuid EptData::source_cid() const noexcept
112 {
113  return data_.source_cid;
114 }
115 
117 constexpr uint16_t EptData::manufacturer_id() const noexcept
118 {
119  return data_.manufacturer_id;
120 }
121 
123 constexpr uint16_t EptData::protocol_id() const noexcept
124 {
125  return data_.protocol_id;
126 }
127 
130 constexpr uint32_t EptData::sub_protocol() const noexcept
131 {
132  return ((static_cast<uint32_t>(data_.manufacturer_id) << 16) | data_.protocol_id);
133 }
134 
136 constexpr const uint8_t* EptData::data() const noexcept
137 {
138  return data_.data;
139 }
140 
142 constexpr size_t EptData::data_len() const noexcept
143 {
144  return data_.data_len;
145 }
146 
150 {
151  if (data_.data && data_.data_len)
152  return std::vector<uint8_t>(data_.data, data_.data + data_.data_len);
153  else
154  return std::vector<uint8_t>{};
155 }
156 
158 constexpr const RdmnetEptData& EptData::get() const noexcept
159 {
160  return data_;
161 }
162 
166 {
167  return SavedEptData(*this);
168 }
169 
171 // SavedEptData function definitions
173 
176  : source_cid_(c_data.source_cid), manufacturer_id_(c_data.manufacturer_id), protocol_id_(c_data.protocol_id)
177 {
178  if (c_data.data && c_data.data_len)
179  data_.assign(c_data.data, c_data.data + c_data.data_len);
180 }
181 
184 {
185  source_cid_ = c_data.source_cid;
186  manufacturer_id_ = c_data.manufacturer_id;
187  protocol_id_ = c_data.protocol_id;
188  if (c_data.data && c_data.data_len)
189  data_.assign(c_data.data, c_data.data + c_data.data_len);
190  return *this;
191 }
192 
195  : source_cid_(resp.source_cid())
196  , manufacturer_id_(resp.manufacturer_id())
197  , protocol_id_(resp.protocol_id())
198  , data_(resp.CopyData())
199 {
200 }
201 
204 {
205  source_cid_ = resp.source_cid();
206  manufacturer_id_ = resp.manufacturer_id();
207  protocol_id_ = resp.protocol_id();
208  data_ = resp.CopyData();
209  return *this;
210 }
211 
213 inline const etcpal::Uuid& SavedEptData::source_cid() const noexcept
214 {
215  return source_cid_;
216 }
217 
219 inline uint16_t SavedEptData::manufacturer_id() const noexcept
220 {
221  return manufacturer_id_;
222 }
223 
225 inline uint16_t SavedEptData::protocol_id() const noexcept
226 {
227  return protocol_id_;
228 }
229 
232 inline uint32_t SavedEptData::sub_protocol() const noexcept
233 {
234  return ((static_cast<uint32_t>(manufacturer_id_) << 16) | protocol_id_);
235 }
236 
238 inline const uint8_t* SavedEptData::data() const noexcept
239 {
240  return data_.data();
241 }
242 
244 inline size_t SavedEptData::data_len() const noexcept
245 {
246  return data_.size();
247 }
248 
250 inline bool SavedEptData::IsValid() const noexcept
251 {
252  return (!source_cid_.IsNull() && !data_.empty());
253 }
254 
255 }; // namespace rdmnet
256 
257 #endif // RDMNET_CPP_MESSAGE_TYPES_EPT_DATA_H_
bool IsNull() const noexcept
An EPT data message received over RDMnet and delivered to an RDMnet callback function.
Definition: ept_data.h:41
std::vector< uint8_t > CopyData() const
Copy the data out of an EPT data message.
Definition: ept_data.h:149
constexpr const RdmnetEptData & get() const noexcept
Get a const reference to the underlying C type.
Definition: ept_data.h:158
EptData(const EptData &other)=delete
Not copyable - use Save() to create a copyable version.
constexpr const uint8_t * data() const noexcept
Get the data associated with this EPT message.
Definition: ept_data.h:136
EptData()=delete
Not default-constructible.
EptData & operator=(const EptData &other)=delete
Not copyable - use Save() to create a copyable version.
constexpr uint16_t manufacturer_id() const noexcept
Get the ESTA manufacturer ID that identifies the EPT sub-protocol.
Definition: ept_data.h:117
constexpr etcpal::Uuid source_cid() const noexcept
Get the CID of the EPT client that sent this data.
Definition: ept_data.h:111
constexpr size_t data_len() const noexcept
Get the length of the data associated with this EPT message.
Definition: ept_data.h:142
SavedEptData Save() const
Save this data message for later use from a different context.
Definition: ept_data.h:165
constexpr uint32_t sub_protocol() const noexcept
Get the full EPT sub-protocol identifier.
Definition: ept_data.h:130
constexpr uint16_t protocol_id() const noexcept
Get the protocol ID that identifies the EPT sub-protocol.
Definition: ept_data.h:123
An EPT data message received over RDMnet and saved for later processing.
Definition: ept_data.h:76
size_t data_len() const noexcept
Get the length of the data associated with this EPT message.
Definition: ept_data.h:244
uint32_t sub_protocol() const noexcept
Get the full EPT sub-protocol identifier.
Definition: ept_data.h:232
uint16_t manufacturer_id() const noexcept
Get the ESTA manufacturer ID that identifies the EPT sub-protocol.
Definition: ept_data.h:219
const uint8_t * data() const noexcept
Get the data associated with this EPT message.
Definition: ept_data.h:238
SavedEptData & operator=(const RdmnetSavedEptData &c_data)
Assign an instance of the C RdmnetSavedEptData type to an instance of this class.
Definition: ept_data.h:183
bool IsValid() const noexcept
Whether the values contained in this class are valid for an EPT data message.
Definition: ept_data.h:250
const etcpal::Uuid & source_cid() const noexcept
Get the CID of the EPT client that sent this data.
Definition: ept_data.h:213
SavedEptData()=default
Constructs an empty, invalid EPT data structure by default.
uint16_t protocol_id() const noexcept
Get the protocol ID that identifies the EPT sub-protocol.
Definition: ept_data.h:225
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 data message received by a local component.
Definition: message.h:270
An EPT data message received over RDMnet and saved for later processing.
Definition: message.h:291
EtcPalUuid source_cid
The CID of the EPT client that sent this data.
Definition: message.h:293
uint16_t protocol_id
The protocol ID that identifies the EPT sub-protocol.
Definition: message.h:297
const uint8_t * data
The data associated with this EPT message.
Definition: message.h:302
uint16_t manufacturer_id
The ESTA manufacturer ID that identifies the EPT sub-protocol.
Definition: message.h:295
size_t data_len
The length of the data associated with this EPT message.
Definition: message.h:304