OpenDDS  Snapshot(2023/04/28-20:55)
GuidUtils.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_GUIDUTILS_H
7 #define OPENDDS_DCPS_GUIDUTILS_H
8 
9 #include "dcps_export.h"
10 #include "PoolAllocator.h"
11 #include "Serializer.h"
12 #include "Hash.h"
13 #include "Util.h"
14 
15 #include <dds/DdsDcpsGuidC.h>
16 #include <dds/DdsDcpsInfoUtilsC.h>
17 
18 #ifndef OPENDDS_SAFETY_PROFILE
19 # include <iosfwd>
20 #endif
21 #include <cstring>
22 
24 
25 namespace OpenDDS {
26 namespace DCPS {
27 
28 /// Vendor Id value specified for OCI is used for OpenDDS.
29 const GuidVendorId_t VENDORID_OCI = {0x01, 0x03};
30 
31 /// Nil value for the GUID prefix (participant identifier).
33 
34 ///@{
35 /// Entity Id values specified in Version 2.1 of RTPS specification.
36 const EntityId_t ENTITYID_UNKNOWN = {{0x00, 0x00, 0x00}, 0x00};
37 const EntityId_t ENTITYID_PARTICIPANT = {{0x00, 0x00, 0x01}, 0xc1};
38 const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_WRITER = {{0x00, 0x00, 0x02}, 0xc2};
39 const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_READER = {{0x00, 0x00, 0x02}, 0xc7};
40 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER = {{0x00, 0x00, 0x03}, 0xc2};
41 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER = {{0x00, 0x00, 0x03}, 0xc7};
42 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER = {{0x00, 0x00, 0x04}, 0xc2};
43 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER = {{0x00, 0x00, 0x04}, 0xc7};
44 const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER = {{0x00, 0x01, 0x00}, 0xc2};
45 const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER = {{0x00, 0x01, 0x00}, 0xc7};
48 ///@}
49 
50 ///@{
51 /// XTypes Type Lookup Service
52 const EntityId_t ENTITYID_TL_SVC_REQ_WRITER = {{0x00, 0x03, 0x00}, 0xc3};
53 const EntityId_t ENTITYID_TL_SVC_REQ_READER = {{0x00, 0x03, 0x00}, 0xc4};
54 const EntityId_t ENTITYID_TL_SVC_REPLY_WRITER = {{0x00, 0x03, 0x01}, 0xc3};
55 const EntityId_t ENTITYID_TL_SVC_REPLY_READER = {{0x00, 0x03, 0x01}, 0xc4};
56 ///@}
57 
58 /// Nil value for GUID.
59 const GUID_t GUID_UNKNOWN = { { 0 }, { { 0 }, 0 } };
60 
61 /**
62  * Identifies the kinds of entities used in a GUID.
63  *
64  * See dds/DdsDcpsGuid.idl for the values these map to.
65  */
66 enum EntityKind {
67  KIND_UNKNOWN, ///< ENTITYKIND_USER_UNKNOWN and ENTITYKIND_BUILTIN_UNKNOWN
68  KIND_PARTICIPANT, ///< ENTITYKIND_BUILTIN_PARTICIPANT
69  KIND_USER_WRITER, ///< ENTITYKIND_USER_WRITER_WITH_KEY and ENTITYKIND_USER_WRITER_NO_KEY
70  KIND_USER_READER, ///< ENTITYKIND_USER_READER_WITH_KEY and ENTITYKIND_USER_READER_NO_KEY
71  KIND_USER_TOPIC, ///< ENTITYKIND_OPENDDS_TOPIC
72  KIND_BUILTIN_WRITER, ///< ENTITYKIND_BUILTIN_WRITER_WITH_KEY and ENTITYKIND_USER_WRITER_NO_KEY
73  KIND_BUILTIN_READER, ///< ENTITYKIND_BUILTIN_READER_WITH_KEY and ENTITYKIND_USER_READER_NO_KEY
74  KIND_BUILTIN_TOPIC, ///< ENTITYKIND_BUILTIN_TOPIC
75  KIND_PUBLISHER, ///< Publisher (OpenDDS-specific)
76  KIND_SUBSCRIBER, ///< Subscriber (OpenDDS-specific)
77  KIND_USER ///< For creating custom GUIDs for things that are not DDS entities (OpenDDS-specific)
78 };
79 
80 inline bool operator<(const GUID_t& lhs, const GUID_t& rhs)
81 {
82  return mem_cmp(lhs, rhs) < 0;
83 }
84 
86  static bool entity_less(const EntityId_t& v1, const EntityId_t& v2)
87  {
88  return mem_cmp(v1, v2) < 0;
89  }
90 
91  bool operator()(const GUID_t& v1, const GUID_t& v2) const
92  {
93  return v1 < v2;
94  }
95 };
96 
98  bool operator()(const EntityId_t& v1, const EntityId_t& v2) const
99  {
100  return mem_cmp(v1, v2) < 0;
101  }
102 };
103 
106  const DDS::BuiltinTopicKey_t& v2) const
107  {
108  return mem_cmp(v1, v2) < 0;
109  }
110 };
111 
112 typedef OPENDDS_SET_CMP(GUID_t, GUID_tKeyLessThan) GuidSet;
113 typedef GuidSet RepoIdSet;
114 
115 const size_t guid_cdr_size = 16;
116 
117 #ifndef OPENDDS_SAFETY_PROFILE
118 inline bool
119 operator==(const GUID_t& lhs, const GUID_t& rhs)
120 {
121  return mem_cmp(lhs, rhs) == 0;
122 }
123 
124 inline bool
125 operator!=(const GUID_t& lhs, const GUID_t& rhs)
126 {
127  return !(lhs == rhs);
128 }
129 #endif
130 
131 OpenDDS_Dcps_Export inline
132 bool equal_guid_prefixes(const GuidPrefix_t& lhs, const GuidPrefix_t& rhs)
133 {
134  return mem_cmp(lhs, rhs) == 0;
135 }
136 
137 OpenDDS_Dcps_Export inline
138 bool equal_guid_prefixes(const GUID_t& lhs, const GUID_t& rhs)
139 {
140  return equal_guid_prefixes(lhs.guidPrefix, rhs.guidPrefix);
141 }
142 
143 #ifndef OPENDDS_SAFETY_PROFILE
144 inline bool
145 operator==(const EntityId_t& lhs, const EntityId_t& rhs)
146 {
147  return mem_cmp(lhs, rhs) == 0;
148 }
149 
150 inline bool
151 operator!=(const EntityId_t& lhs, const EntityId_t& rhs)
152 {
153  return !(lhs == rhs);
154 }
155 #endif
156 
157 inline void assign(EntityId_t& dest, const EntityId_t& src)
158 {
159  std::memcpy(&dest, &src, sizeof(EntityId_t));
160 }
161 
162 inline void assign(EntityKey_t& dest, unsigned src)
163 {
164  dest[0] = static_cast<CORBA::Octet>(src);
165  dest[1] = static_cast<CORBA::Octet>(src >> 8);
166  dest[2] = static_cast<CORBA::Octet>(src >> 16);
167 }
168 
170 to_string(const GUID_t& guid);
171 
173 to_string(const EntityId_t& entityId);
174 
175 #ifndef OPENDDS_SAFETY_PROFILE
176 // Serialize to ASCII Hex string: "xxxx.xxxx.xxxx.xxxx"
177 OpenDDS_Dcps_Export std::ostream&
178 operator<<(std::ostream& os, const GUID_t& rhs);
179 
180 // Deserialize from ASCII Hex string: "xxxx.xxxx.xxxx.xxxx"
181 OpenDDS_Dcps_Export std::istream&
182 operator>>(std::istream& is, GUID_t& rhs);
183 #endif
184 
185 inline void assign(GuidPrefix_t& dest, const GuidPrefix_t& src)
186 {
187  std::memcpy(&dest[0], &src[0], sizeof(GuidPrefix_t));
188 }
189 
190 inline void assign(GUID_t& dest, const GUID_t& src)
191 {
192  std::memcpy(&dest, &src, sizeof(GUID_t));
193 }
194 
195 inline void assign(DDS::OctetArray16& dest, const GUID_t& src)
196 {
197  std::memcpy(&dest[0], &src, sizeof(src));
198 }
199 
200 inline GUID_t make_id(const GuidPrefix_t& prefix, const EntityId_t& entity)
201 {
202  GUID_t id;
203  assign(id.guidPrefix, prefix);
204  id.entityId = entity;
205  return id;
206 }
207 
208 inline GUID_t make_id(const GUID_t& participant_id, const EntityId_t& entity)
209 {
210  GUID_t id = participant_id;
211  id.entityId = entity;
212  return id;
213 }
214 
215 OpenDDS_Dcps_Export inline
217 {
218  return make_id(prefix, ENTITYID_PARTICIPANT);
219 }
220 
221 OpenDDS_Dcps_Export inline
223 {
224  return make_part_guid(guid.guidPrefix);
225 }
226 
227 OpenDDS_Dcps_Export inline
229 {
230  return make_id(prefix, ENTITYID_UNKNOWN);
231 }
232 
233 OpenDDS_Dcps_Export inline
235 {
236  return make_unknown_guid(guid.guidPrefix);
237 }
238 
240 void intersect(const GuidSet& a, const GuidSet& b, GuidSet& result);
241 
242 OpenDDS_Dcps_Export inline
244 {
246  std::memcpy(key.value, &guid, sizeof(key.value));
247  return key;
248 }
249 
250 OpenDDS_Dcps_Export inline
252 {
253  GUID_t id;
254  std::memcpy(&id, key.value, sizeof(id));
255  return id;
256 }
257 
261 
262  GuidPair(const GUID_t& local, const GUID_t& remote)
263  : local(local)
264  , remote(remote)
265  {
266  }
267 
268  int cmp(const GuidPair& other) const
269  {
270  const int local_cmp = mem_cmp(local, other.local);
271  return local_cmp == 0 ? mem_cmp(remote, other.remote) : local_cmp;
272  }
273 
274  bool operator<(const GuidPair& other) const
275  {
276  return cmp(other) < 0;
277  }
278 };
279 
280 } // namespace DCPS
281 } // namespace OpenDDS
282 
284 
285 #if defined ACE_HAS_CPP11
286 OPENDDS_OOAT_STD_HASH(OpenDDS::DCPS::GUID_t, OpenDDS_Dcps_Export);
287 #endif
288 
289 #endif /* OPENDDS_DDS_DCPS_GUIDUTILS_H */
bool operator<(const GuidPair &other) const
Definition: GuidUtils.h:274
const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_READER
Definition: GuidUtils.h:39
octet GuidVendorId_t[2]
Definition: DdsDcpsGuid.idl:16
ENTITYKIND_BUILTIN_PARTICIPANT.
Definition: GuidUtils.h:68
const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER
Definition: GuidUtils.h:43
const GUID_t GUID_UNKNOWN
Nil value for GUID.
Definition: GuidUtils.h:59
ENTITYKIND_BUILTIN_WRITER_WITH_KEY and ENTITYKIND_USER_WRITER_NO_KEY.
Definition: GuidUtils.h:72
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
sequence< octet > key
bool operator()(const GUID_t &v1, const GUID_t &v2) const
Definition: GuidUtils.h:91
const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_READER
Definition: GuidUtils.h:47
const EntityId_t ENTITYID_TL_SVC_REQ_WRITER
Definition: GuidUtils.h:52
const size_t guid_cdr_size
Definition: GuidUtils.h:115
GuidSet RepoIdSet
Definition: GuidUtils.h:113
const EntityId_t ENTITYID_TL_SVC_REPLY_READER
Definition: GuidUtils.h:55
For creating custom GUIDs for things that are not DDS entities (OpenDDS-specific) ...
Definition: GuidUtils.h:77
OpenDDS_Dcps_Export GUID_t make_unknown_guid(const GuidPrefix_t &prefix)
Definition: GuidUtils.h:228
key GuidPrefix_t guidPrefix
Definition: DdsDcpsGuid.idl:58
int mem_cmp(const T &a, const T &b)
Definition: Util.h:227
octet EntityKey_t[3]
Definition: DdsDcpsGuid.idl:22
bool operator==(const DisjointSequence::OrderedRanges< T > &a, const DisjointSequence::OrderedRanges< T > &b)
ENTITYKIND_USER_WRITER_WITH_KEY and ENTITYKIND_USER_WRITER_NO_KEY.
Definition: GuidUtils.h:69
int cmp(const GuidPair &other) const
Definition: GuidUtils.h:268
ENTITYKIND_BUILTIN_TOPIC.
Definition: GuidUtils.h:74
#define OPENDDS_STRING
const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER
Definition: GuidUtils.h:44
const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER
Definition: GuidUtils.h:45
const EntityId_t ENTITYID_PARTICIPANT
Definition: GuidUtils.h:37
ENTITYKIND_OPENDDS_TOPIC.
Definition: GuidUtils.h:71
ACE_CDR::Boolean operator<<(Serializer &serializer, CoherentChangeControl &value)
Marshal/Insertion into a buffer.
ENTITYKIND_USER_READER_WITH_KEY and ENTITYKIND_USER_READER_NO_KEY.
Definition: GuidUtils.h:70
bool operator()(const DDS::BuiltinTopicKey_t &v1, const DDS::BuiltinTopicKey_t &v2) const
Definition: GuidUtils.h:105
typedef OPENDDS_SET_CMP(GUID_t, GUID_tKeyLessThan) GuidSet
const EntityId_t ENTITYID_TL_SVC_REQ_READER
Definition: GuidUtils.h:53
GuidPair(const GUID_t &local, const GUID_t &remote)
Definition: GuidUtils.h:262
const EntityId_t ENTITYID_TL_SVC_REPLY_WRITER
Definition: GuidUtils.h:54
Publisher (OpenDDS-specific)
Definition: GuidUtils.h:75
const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER
Definition: GuidUtils.h:40
ENTITYKIND_USER_UNKNOWN and ENTITYKIND_BUILTIN_UNKNOWN.
Definition: GuidUtils.h:67
bool operator()(const EntityId_t &v1, const EntityId_t &v2) const
Definition: GuidUtils.h:98
Subscriber (OpenDDS-specific)
Definition: GuidUtils.h:76
OpenDDS_Dcps_Export GUID_t make_part_guid(const GuidPrefix_t &prefix)
Definition: GuidUtils.h:216
bool operator!=(const GUID_t &lhs, const GUID_t &rhs)
Definition: GuidUtils.h:125
const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER
Definition: GuidUtils.h:42
OpenDDS_Dcps_Export bool equal_guid_prefixes(const GuidPrefix_t &lhs, const GuidPrefix_t &rhs)
Definition: GuidUtils.h:132
const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_WRITER
Definition: GuidUtils.h:38
octet GuidPrefix_t[12]
Definition: DdsDcpsGuid.idl:19
ACE_CDR::Octet Octet
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
static bool entity_less(const EntityId_t &v1, const EntityId_t &v2)
Definition: GuidUtils.h:86
void intersect(const GuidSet &a, const GuidSet &b, GuidSet &result)
Definition: GuidUtils.cpp:60
ACE_CDR::Boolean operator>>(Serializer &serializer, CoherentChangeControl &value)
const GuidPrefix_t GUIDPREFIX_UNKNOWN
Nil value for the GUID prefix (participant identifier).
Definition: GuidUtils.h:32
const char * to_string(MessageId value)
void assign(EntityId_t &dest, const EntityId_t &src)
Definition: GuidUtils.h:157
const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER
Definition: GuidUtils.h:41
GUID_t make_id(const GuidPrefix_t &prefix, const EntityId_t &entity)
Definition: GuidUtils.h:200
const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER
Definition: GuidUtils.h:46
OpenDDS_Dcps_Export GUID_t bit_key_to_guid(const DDS::BuiltinTopicKey_t &key)
Definition: GuidUtils.h:251
const EntityId_t ENTITYID_UNKNOWN
Definition: GuidUtils.h:36
const GuidVendorId_t VENDORID_OCI
Vendor Id value specified for OCI is used for OpenDDS.
Definition: GuidUtils.h:29
OpenDDS_Dcps_Export DDS::BuiltinTopicKey_t guid_to_bit_key(const GUID_t &guid)
Definition: GuidUtils.h:243
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
ENTITYKIND_BUILTIN_READER_WITH_KEY and ENTITYKIND_USER_READER_NO_KEY.
Definition: GuidUtils.h:73
key EntityId_t entityId
Definition: DdsDcpsGuid.idl:59
bool operator<(const GUID_t &lhs, const GUID_t &rhs)
Definition: GuidUtils.h:80
octet OctetArray16[16]