OpenDDS  Snapshot(2023/04/28-20:55)
GuidConverter.cpp
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 #include <DCPS/DdsDcps_pch.h> // Only the _pch include should start with DCPS/
7 
8 #include "GuidConverter.h"
9 
10 #include <dds/DdsDcpsGuidTypeSupportImpl.h>
11 
12 #include <ace/ACE.h>
13 #include <ace/OS_NS_stdio.h>
14 
15 #ifdef DDS_HAS_WCHAR
16 # include <sstream>
17 #endif
18 
20 
21 namespace OpenDDS {
22 namespace DCPS {
23 
25  : guid_(guid)
26 {}
27 
29 {}
30 
31 long
33 {
34  return ACE::crc32(reinterpret_cast<const void*>(&guid_), sizeof(guid_));
35 }
36 
37 long
39 {
40  return guid_.guidPrefix[0] << 8
41  | guid_.guidPrefix[1];
42 }
43 
44 long
46 {
47  return entityKey() << 8
49 }
50 
51 long
53 {
54  return guid_.entityId.entityKey[0] << 16
55  | guid_.entityId.entityKey[1] << 8
57 }
58 
61 {
62  switch (guid_.entityId.entityKind) {
64  return KIND_USER_TOPIC;
65 
67  return KIND_BUILTIN_TOPIC;
68 
71  return KIND_USER_READER;
72 
76  return KIND_USER_WRITER;
77 
80  return KIND_BUILTIN_READER;
81 
84  return KIND_BUILTIN_WRITER;
85 
87  return KIND_PARTICIPANT;
88 
90  return KIND_PUBLISHER;
91 
93  return KIND_SUBSCRIBER;
94 
96  return KIND_USER;
97 
100  default:
101  return KIND_UNKNOWN;
102  }
103 }
104 
106 {
107  switch (guid_.entityId.entityKind) {
108 
114  return true;
115 
116  default:
117  return false;
118  }
119 }
120 
122 {
123  switch (guid_.entityId.entityKind) {
124 
130  return true;
131 
132  default:
133  return false;
134  }
135 }
136 
138 {
139  EntityKind kind = entityKind();
140  return kind == KIND_USER_WRITER || kind == KIND_BUILTIN_WRITER;
141 }
142 
144 {
145  EntityKind kind = entityKind();
146  return kind == KIND_USER_READER || kind == KIND_BUILTIN_READER;
147 }
148 
150 {
151  EntityKind kind = entityKind();
152  return kind == KIND_USER_TOPIC || kind == KIND_BUILTIN_TOPIC;
153 }
154 
155 GuidConverter::operator OPENDDS_STRING() const
156 {
158  ret += "(";
159  ret += to_dds_string((unsigned long) checksum(), true);
160  ret += ")";
161  return ret;
162 }
163 
164 #ifdef DDS_HAS_WCHAR
165 GuidConverter::operator std::wstring() const
166 {
167  std::wostringstream os;
168  const OPENDDS_STRING guid_str(to_string(guid_));
169  os << guid_str.c_str() << "(" << std::hex << checksum() << ")";
170  return os.str();
171 }
172 #endif
173 
174 #ifndef OPENDDS_SAFETY_PROFILE
175 
176 std::ostream&
177 operator<<(std::ostream& os, const GuidConverter& rhs)
178 {
179  return os << OPENDDS_STRING(rhs);
180 }
181 
182 #ifdef DDS_HAS_WCHAR
183 std::wostream&
184 operator<<(std::wostream& os, const GuidConverter& rhs)
185 {
186  return os << std::wstring(rhs);
187 }
188 #endif //DDS_HAS_WCHAR
189 #endif //OPENDDS_SAFETY_PROFILE
190 
193 {
194  char id[64];
195  ACE_OS::snprintf(id, sizeof id,
196  "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
197  guid_.guidPrefix[ 0],
198  guid_.guidPrefix[ 1],
199  guid_.guidPrefix[ 2],
200  guid_.guidPrefix[ 3],
201  guid_.guidPrefix[ 4],
202  guid_.guidPrefix[ 5],
203  guid_.guidPrefix[ 6],
204  guid_.guidPrefix[ 7],
205  guid_.guidPrefix[ 8],
206  guid_.guidPrefix[ 9],
207  guid_.guidPrefix[10],
208  guid_.guidPrefix[11]);
209  return id;
210 }
211 
212 } // namespace DCPS
213 } // namespace OpenDDS
214 
const octet ENTITYKIND_BUILTIN_TOPIC
Definition: DdsDcpsGuid.idl:37
const octet ENTITYKIND_BUILTIN_WRITER_WITH_KEY
Definition: DdsDcpsGuid.idl:33
ENTITYKIND_BUILTIN_PARTICIPANT.
Definition: GuidUtils.h:68
const octet ENTITYKIND_OPENDDS_SUBSCRIBER
Definition: DdsDcpsGuid.idl:46
ENTITYKIND_BUILTIN_WRITER_WITH_KEY and ENTITYKIND_USER_WRITER_NO_KEY.
Definition: GuidUtils.h:72
bool isReader() const
Returns true if the GUID represents a reader entity.
int snprintf(char *buf, size_t maxlen, const char *format,...) ACE_GCC_FORMAT_ATTRIBUTE(printf
String to_dds_string(unsigned short to_convert)
bool isUserDomainEntity() const
Returns true if the GUID represents a user defined type domain entity.
const octet ENTITYKIND_OPENDDS_NIL_WRITER
Definition: DdsDcpsGuid.idl:53
For creating custom GUIDs for things that are not DDS entities (OpenDDS-specific) ...
Definition: GuidUtils.h:77
key GuidPrefix_t guidPrefix
Definition: DdsDcpsGuid.idl:58
const octet ENTITYKIND_BUILTIN_WRITER_NO_KEY
Definition: DdsDcpsGuid.idl:34
EntityKind entityKind() const
Extract the EntityKind value.
ENTITYKIND_USER_WRITER_WITH_KEY and ENTITYKIND_USER_WRITER_NO_KEY.
Definition: GuidUtils.h:69
Conversion processing and value testing utilities for RTPS GUID_t types.
Definition: GuidConverter.h:62
GuidConverter(const GUID_t &guid)
Construct from a GUID_t.
ENTITYKIND_BUILTIN_TOPIC.
Definition: GuidUtils.h:74
const octet ENTITYKIND_USER_UNKNOWN
Definition: DdsDcpsGuid.idl:39
long checksum() const
Calculate the CRC32 checksum.
const octet ENTITYKIND_USER_READER_WITH_KEY
Definition: DdsDcpsGuid.idl:43
#define OPENDDS_STRING
ENTITYKIND_OPENDDS_TOPIC.
Definition: GuidUtils.h:71
const octet ENTITYKIND_OPENDDS_USER
Definition: DdsDcpsGuid.idl:50
ACE_CDR::Boolean operator<<(Serializer &serializer, CoherentChangeControl &value)
Marshal/Insertion into a buffer.
const octet ENTITYKIND_OPENDDS_TOPIC
Definition: DdsDcpsGuid.idl:49
long entityKey() const
Extract the EntityKey value.
ENTITYKIND_USER_READER_WITH_KEY and ENTITYKIND_USER_READER_NO_KEY.
Definition: GuidUtils.h:70
key EntityKey_t entityKey
Definition: DdsDcpsGuid.idl:27
const octet ENTITYKIND_BUILTIN_PARTICIPANT
Definition: DdsDcpsGuid.idl:32
Publisher (OpenDDS-specific)
Definition: GuidUtils.h:75
const octet ENTITYKIND_USER_WRITER_NO_KEY
Definition: DdsDcpsGuid.idl:41
ENTITYKIND_USER_UNKNOWN and ENTITYKIND_BUILTIN_UNKNOWN.
Definition: GuidUtils.h:67
const octet ENTITYKIND_OPENDDS_PUBLISHER
Definition: DdsDcpsGuid.idl:47
bool isTopic() const
Returns true if the GUID represents a topic entity.
OPENDDS_STRING uniqueParticipantId() const
const octet ENTITYKIND_BUILTIN_UNKNOWN
Definition: DdsDcpsGuid.idl:31
bool isBuiltinDomainEntity() const
Returns true if the GUID represents a builtin type domain entity.
Subscriber (OpenDDS-specific)
Definition: GuidUtils.h:76
ACE_UINT32 crc32(const char *str)
long entityId() const
Extract the EntityId value.
const octet ENTITYKIND_USER_WRITER_WITH_KEY
Definition: DdsDcpsGuid.idl:40
virtual ~GuidConverter()
Virtual destructor (this is a base class).
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
const char * to_string(MessageId value)
const octet ENTITYKIND_USER_READER_NO_KEY
Definition: DdsDcpsGuid.idl:42
bool isWriter() const
Returns true if the GUID represents a writer entity.
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
const octet ENTITYKIND_BUILTIN_READER_NO_KEY
Definition: DdsDcpsGuid.idl:35
const octet ENTITYKIND_BUILTIN_READER_WITH_KEY
Definition: DdsDcpsGuid.idl:36
long vendorId() const
Extract the VendorId value.
key EntityId_t entityId
Definition: DdsDcpsGuid.idl:59