RDMnet  HEAD (unstable)
Implementation of ANSI E1.33 (RDMnet)
View other versions:
dynamic_uid.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_DYNAMIC_UID_H_
24 #define RDMNET_CPP_MESSAGE_TYPES_DYNAMIC_UID_H_
25 
26 #include <algorithm>
27 #include <cstddef>
28 #include <iterator>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 #include "etcpal/cpp/uuid.h"
33 #include "rdm/cpp/uid.h"
34 #include "rdmnet/common.h"
35 #include "rdmnet/message.h"
36 
37 namespace rdmnet
38 {
42 {
43  DynamicUidMapping() = default;
46 
47  constexpr bool IsOk() const noexcept;
48  const char* CodeToCString() const noexcept;
49  std::string CodeToString() const;
50 
54  rdm::Uid uid;
57 };
58 
60 inline DynamicUidMapping::DynamicUidMapping(const RdmnetDynamicUidMapping& c_mapping)
61  : status_code(c_mapping.status_code), uid(c_mapping.uid), rid(c_mapping.rid)
62 {
63 }
64 
67 {
68  status_code = c_mapping.status_code;
69  uid = c_mapping.uid;
70  rid = c_mapping.rid;
71  return *this;
72 }
73 
76 constexpr bool DynamicUidMapping::IsOk() const noexcept
77 {
79 }
80 
82 inline const char* DynamicUidMapping::CodeToCString() const noexcept
83 {
85 }
86 
89 {
91 }
92 
99 {
100 public:
107 
108  constexpr DynamicUidAssignmentList(const RdmnetDynamicUidAssignmentList& c_list) noexcept;
109 
111 
112  constexpr bool more_coming() const noexcept;
113  constexpr const RdmnetDynamicUidMapping* raw_mapping_array() const noexcept;
114  constexpr size_t raw_mapping_array_size() const noexcept;
115 
116 private:
117  const RdmnetDynamicUidAssignmentList& list_;
118 };
119 
122  : list_(c_list)
123 {
124 }
125 
131 {
133  to_return.reserve(list_.num_mappings);
134  std::transform(list_.mappings, list_.mappings + list_.num_mappings, std::back_inserter(to_return),
135  [](const RdmnetDynamicUidMapping& mapping) { return DynamicUidMapping(mapping); });
136  return to_return;
137 }
138 
145 constexpr bool DynamicUidAssignmentList::more_coming() const noexcept
146 {
147  return list_.more_coming;
148 }
149 
152 {
153  return list_.mappings;
154 }
155 
157 constexpr size_t DynamicUidAssignmentList::raw_mapping_array_size() const noexcept
158 {
159  return list_.num_mappings;
160 }
161 }; // namespace rdmnet
162 
163 #endif // RDMNET_CPP_MESSAGE_TYPES_DYNAMIC_UID_H_
T back_inserter(T... args)
A list of mappings from dynamic UIDs to responder IDs received from an RDMnet broker.
Definition: dynamic_uid.h:99
DynamicUidAssignmentList()=delete
Not default-constructible.
constexpr const RdmnetDynamicUidMapping * raw_mapping_array() const noexcept
Get a pointer to the raw array of dynamic UID mapping C structures.
Definition: dynamic_uid.h:151
constexpr size_t raw_mapping_array_size() const noexcept
Get the size of the raw array of dynamic UID mapping C structures.
Definition: dynamic_uid.h:157
constexpr bool more_coming() const noexcept
This message contains a partial list.
Definition: dynamic_uid.h:145
std::vector< DynamicUidMapping > GetMappings() const
Copy out the list of dynamic UID mappings.
Definition: dynamic_uid.h:130
DynamicUidAssignmentList & operator=(const DynamicUidAssignmentList &other)=delete
Not copyable - use GetMappings() to copy out the data.
DynamicUidAssignmentList(const DynamicUidAssignmentList &other)=delete
Not copyable - use GetMappings() to copy out the data.
Functions and definitions common to all RDMnet API modules.
const char * rdmnet_dynamic_uid_status_to_string(rdmnet_dynamic_uid_status_t code)
Get a string description of an RDMnet Dynamic UID status code.
Definition: common.c:466
rdmnet_dynamic_uid_status_t
Definition: common.h:134
@ kRdmnetDynamicUidStatusOk
Definition: common.h:136
Basic types for parsed RDMnet messages.
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
T reserve(T... args)
Definition: message.h:246
RdmnetDynamicUidMapping * mappings
Definition: message.h:248
bool more_coming
Definition: message.h:257
size_t num_mappings
Definition: message.h:250
Definition: message.h:235
EtcPalUuid rid
Definition: message.h:241
rdmnet_dynamic_uid_status_t status_code
Definition: message.h:237
RdmUid uid
Definition: message.h:239
A mapping from a dynamic UID to a responder ID (RID).
Definition: dynamic_uid.h:42
constexpr bool IsOk() const noexcept
Whether a DynamicUidMapping has a status code of OK.
Definition: dynamic_uid.h:76
rdm::Uid uid
The dynamic UID.
Definition: dynamic_uid.h:54
etcpal::Uuid rid
The corresponding RID to which the dynamic UID is mapped.
Definition: dynamic_uid.h:56
std::string CodeToString() const
Convert the mapping status code to a string representation.
Definition: dynamic_uid.h:88
DynamicUidMapping & operator=(const RdmnetDynamicUidMapping &c_mapping)
Assign an instance of the C RdmnetDynamicUidMapping type to an instance of this class.
Definition: dynamic_uid.h:66
rdmnet_dynamic_uid_status_t status_code
The response code - indicating whether the broker was able to assign or look up this dynamic UID.
Definition: dynamic_uid.h:52
const char * CodeToCString() const noexcept
Convert the mapping status code to a string representation.
Definition: dynamic_uid.h:82
T transform(T... args)