RDMnet  0.3.0
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 <string>
29 #include <utility>
30 #include <vector>
31 #include "etcpal/cpp/uuid.h"
32 #include "rdm/cpp/uid.h"
33 #include "rdmnet/common.h"
34 #include "rdmnet/message.h"
35 
36 namespace rdmnet
37 {
41 {
42  DynamicUidMapping() = default;
45 
46  constexpr bool IsOk() const noexcept;
47  const char* CodeToCString() const noexcept;
48  std::string CodeToString() const;
49 
53  rdm::Uid uid;
56 };
57 
59 inline DynamicUidMapping::DynamicUidMapping(const RdmnetDynamicUidMapping& c_mapping)
60  : status_code(c_mapping.status_code), uid(c_mapping.uid), rid(c_mapping.rid)
61 {
62 }
63 
66 {
67  status_code = c_mapping.status_code;
68  uid = c_mapping.uid;
69  rid = c_mapping.rid;
70  return *this;
71 }
72 
75 constexpr bool DynamicUidMapping::IsOk() const noexcept
76 {
78 }
79 
81 inline const char* DynamicUidMapping::CodeToCString() const noexcept
82 {
84 }
85 
88 {
90 }
91 
98 {
99 public:
106 
107  constexpr DynamicUidAssignmentList(const RdmnetDynamicUidAssignmentList& c_list) noexcept;
108 
110 
111  constexpr bool more_coming() const noexcept;
112  constexpr const RdmnetDynamicUidMapping* raw_mapping_array() const noexcept;
113  constexpr size_t raw_mapping_array_size() const noexcept;
114 
115 private:
116  const RdmnetDynamicUidAssignmentList& list_;
117 };
118 
121  : list_(c_list)
122 {
123 }
124 
130 {
132  to_return.reserve(list_.num_mappings);
133  std::transform(list_.mappings, list_.mappings + list_.num_mappings, std::back_inserter(to_return),
134  [](const RdmnetDynamicUidMapping& mapping) { return DynamicUidMapping(mapping); });
135  return to_return;
136 }
137 
144 constexpr bool DynamicUidAssignmentList::more_coming() const noexcept
145 {
146  return list_.more_coming;
147 }
148 
151 {
152  return list_.mappings;
153 }
154 
156 constexpr size_t DynamicUidAssignmentList::raw_mapping_array_size() const noexcept
157 {
158  return list_.num_mappings;
159 }
160 }; // namespace rdmnet
161 
162 #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:98
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:156
DynamicUidAssignmentList()=delete
Not default-constructible.
DynamicUidAssignmentList(const DynamicUidAssignmentList &other)=delete
Not copyable - use GetMappings() to copy out the data.
std::vector< DynamicUidMapping > GetMappings() const
Copy out the list of dynamic UID mappings.
Definition: dynamic_uid.h:129
constexpr bool more_coming() const noexcept
This message contains a partial list.
Definition: dynamic_uid.h:144
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:150
DynamicUidAssignmentList & operator=(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:392
rdmnet_dynamic_uid_status_t
Dynamic UID Status Codes for the BrokerDynamicUidMapping struct.
Definition: common.h:134
@ kRdmnetDynamicUidStatusOk
The Dynamic UID Mapping was fetched or assigned successfully.
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)
A list of mappings from dynamic UIDs to responder IDs received from an RDMnet broker.
Definition: message.h:245
bool more_coming
This message contains a partial list.
Definition: message.h:256
size_t num_mappings
The size of the mappings array.
Definition: message.h:249
RdmnetDynamicUidMapping * mappings
An array of dynamic UID mappings.
Definition: message.h:247
A mapping from a dynamic UID to a responder ID (RID).
Definition: message.h:234
EtcPalUuid rid
The corresponding RID to which the dynamic UID is mapped.
Definition: message.h:240
RdmUid uid
The dynamic UID.
Definition: message.h:238
rdmnet_dynamic_uid_status_t status_code
The response code - indicates whether the broker was able to assign or look up dynamic UID.
Definition: message.h:236
A mapping from a dynamic UID to a responder ID (RID).
Definition: dynamic_uid.h:41
etcpal::Uuid rid
The corresponding RID to which the dynamic UID is mapped.
Definition: dynamic_uid.h:55
std::string CodeToString() const
Convert the mapping status code to a string representation.
Definition: dynamic_uid.h:87
rdm::Uid uid
The dynamic UID.
Definition: dynamic_uid.h:53
const char * CodeToCString() const noexcept
Convert the mapping status code to a string representation.
Definition: dynamic_uid.h:81
constexpr bool IsOk() const noexcept
Whether a DynamicUidMapping has a status code of OK.
Definition: dynamic_uid.h:75
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:51
DynamicUidMapping & operator=(const RdmnetDynamicUidMapping &c_mapping)
Assign an instance of the C RdmnetDynamicUidMapping type to an instance of this class.
Definition: dynamic_uid.h:65
T transform(T... args)