OpenDDS  Snapshot(2023/04/28-20:55)
GuidConverter.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_GUIDCONVERTER_H
9 #define OPENDDS_DCPS_GUIDCONVERTER_H
10 
11 #include "dcps_export.h"
12 #include "Definitions.h"
13 #include "SafetyProfileStreams.h"
14 #include "PoolAllocator.h"
15 #include "GuidUtils.h"
16 
17 #include <dds/DdsDcpsGuidC.h>
18 
20 
21 namespace OpenDDS {
22 namespace DCPS {
23 
24 /**
25  * @class GuidConverter
26  *
27  * @brief Conversion processing and value testing utilities for RTPS
28  * GUID_t types.
29  *
30  * This class encapsulates the conversion of a GUID_t value to and from
31  * other types used within OpenDDS. This class handles opaque GUID_t values
32  * only. For specific access, the appropriate subclass must instead be used.
33  *
34  * Since the GUID_t type is formed of octets in network order, we do all
35  * processing byte by byte to avoid any endian issues.
36  *
37  * Currently the GUID_t is mapped from various internal values.
38  * These mappings are:
39  *
40  * byte structure reference content
41  * ---- --------------------- --------------------------
42  * 0 GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS)
43  * 1 GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS)
44  * 2 GUID_t.guidPrefix[ 2] == 0x00
45  * 3 GUID_t.guidPrefix[ 3] == 0x00
46  *
47  * 4 GUID_t.guidPrefix[ 4] == <private> (MS byte)
48  * 5 GUID_t.guidPrefix[ 5] == <private>
49  * 6 GUID_t.guidPrefix[ 6] == <private>
50  * 7 GUID_t.guidPrefix[ 7] == <private> (LS byte)
51  *
52  * 8 GUID_t.guidPrefix[ 8] == <private> (MS byte)
53  * 9 GUID_t.guidPrefix[ 9] == <private>
54  * 10 GUID_t.guidPrefix[10] == <private>
55  * 11 GUID_t.guidPrefix[11] == <private> (LS byte)
56  *
57  * 12 GUID_t.entityId.entityKey[ 0] == entity id[0] (MS byte)
58  * 13 GUID_t.entityId.entityKey[ 1] == entity id[1]
59  * 14 GUID_t.entityId.entityKey[ 2] == entity id[2] (LS byte)
60  * 15 GUID_t.entityId.entityKind == entity kind
61  */
63 public:
64  /// Construct from a GUID_t.
65  GuidConverter(const GUID_t& guid);
66 
67  /// Virtual destructor (this is a base class).
68  virtual ~GuidConverter();
69 
70  /// Calculate the CRC32 checksum.
71  long checksum() const;
72 
73  /// Extract the VendorId value.
74  long vendorId() const;
75 
76  /// Extract the EntityId value.
77  long entityId() const;
78 
79  /// Extract the EntityKey value.
80  long entityKey() const;
81 
82  /// Extract the EntityKind value.
83  EntityKind entityKind() const;
84 
85  /// Returns true if the GUID represents a builtin type domain entity.
86  bool isBuiltinDomainEntity() const;
87 
88  /// Returns true if the GUID represents a user defined type domain entity.
89  bool isUserDomainEntity() const;
90 
91  /// Returns true if the GUID represents a writer entity.
92  bool isWriter() const;
93 
94  /// Returns true if the GUID represents a reader entity.
95  bool isReader() const;
96 
97  /// Returns true if the GUID represents a topic entity.
98  bool isTopic() const;
99 
100  /// Convert to diagnostic string.
101  operator OPENDDS_STRING() const;
102 #ifdef DDS_HAS_WCHAR
103  operator std::wstring() const;
104 #endif
105 
106  OPENDDS_STRING uniqueParticipantId() const;
107 
108 protected:
109  const GUID_t guid_;
110 };
111 
113  explicit LogGuid(const GUID_t& id)
114  : conv_(GuidConverter(id)) {}
115  explicit LogGuid(const GuidPrefix_t& prefix)
116  : conv_(GuidConverter(make_part_guid(prefix)))
117  {
118  }
119  const char* c_str() const { return conv_.c_str(); }
121 };
122 
123 #ifndef OPENDDS_SAFETY_PROFILE
124 OpenDDS_Dcps_Export std::ostream&
125 operator<<(std::ostream& os, const OpenDDS::DCPS::GuidConverter& rhs);
126 
127 #ifdef DDS_HAS_WCHAR
128 OpenDDS_Dcps_Export std::wostream&
129 operator<<(std::wostream& os, const OpenDDS::DCPS::GuidConverter& rhs);
130 #endif //DDS_HAS_WCHAR
131 #endif //OPENDDS_SAFETY_PROFILE
132 
133 } // namespace DCPS
134 } // namespace OpenDDS
135 
137 
138 #endif /* DCPS_GUIDCONVERTER_H */
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
const char * c_str() const
Conversion processing and value testing utilities for RTPS GUID_t types.
Definition: GuidConverter.h:62
#define OPENDDS_STRING
ACE_CDR::Boolean operator<<(Serializer &serializer, CoherentChangeControl &value)
Marshal/Insertion into a buffer.
LogGuid(const GUID_t &id)
LogGuid(const GuidPrefix_t &prefix)
OPENDDS_STRING conv_
OpenDDS_Dcps_Export GUID_t make_part_guid(const GuidPrefix_t &prefix)
Definition: GuidUtils.h:216
octet GuidPrefix_t[12]
Definition: DdsDcpsGuid.idl:19
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28