00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef DCPS_GUIDCONVERTER_H 00009 #define DCPS_GUIDCONVERTER_H 00010 00011 #include "tao/Basic_Types.h" 00012 00013 #include "dds/DdsDcpsGuidC.h" 00014 00015 #include "GuidUtils.h" 00016 00017 #include "dcps_export.h" 00018 #include "dds/DCPS/Definitions.h" 00019 #include "dds/DCPS/SafetyProfileStreams.h" 00020 #include "dds/DCPS/PoolAllocator.h" 00021 00022 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00023 00024 namespace OpenDDS { 00025 namespace DCPS { 00026 00027 /** 00028 * @class GuidConverter 00029 * 00030 * @brief Conversion processing and value testing utilities for RTPS 00031 * GUID_t types. 00032 * 00033 * This class encapsulates the conversion of a GUID_t value to and from 00034 * other types used within OpenDDS. This class handles opaque GUID_t values 00035 * only. For specific access, the appropriate subclass must instead be used. 00036 * 00037 * Since the GUID_t type is formed of octets in network order, we do all 00038 * processing byte by byte to avoid any endian issues. 00039 * 00040 * Currently the GUID_t is mapped from various internal values. 00041 * These mappings are: 00042 * 00043 * byte structure reference content 00044 * ---- --------------------- -------------------------- 00045 * 0 GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS) 00046 * 1 GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS) 00047 * 2 GUID_t.guidPrefix[ 2] == 0x00 00048 * 3 GUID_t.guidPrefix[ 3] == 0x00 00049 * 00050 * 4 GUID_t.guidPrefix[ 4] == <private> (MS byte) 00051 * 5 GUID_t.guidPrefix[ 5] == <private> 00052 * 6 GUID_t.guidPrefix[ 6] == <private> 00053 * 7 GUID_t.guidPrefix[ 7] == <private> (LS byte) 00054 * 00055 * 8 GUID_t.guidPrefix[ 8] == <private> (MS byte) 00056 * 9 GUID_t.guidPrefix[ 9] == <private> 00057 * 10 GUID_t.guidPrefix[10] == <private> 00058 * 11 GUID_t.guidPrefix[11] == <private> (LS byte) 00059 * 00060 * 12 GUID_t.entityId.entityKey[ 0] == entity id[0] (MS byte) 00061 * 13 GUID_t.entityId.entityKey[ 1] == entity id[1] 00062 * 14 GUID_t.entityId.entityKey[ 2] == entity id[2] (LS byte) 00063 * 15 GUID_t.entityId.entityKind == entity kind 00064 */ 00065 class OpenDDS_Dcps_Export GuidConverter { 00066 public: 00067 /// Construct from a GUID_t. 00068 GuidConverter(const GUID_t& guid); 00069 00070 /// Virtual destructor (this is a base class). 00071 virtual ~GuidConverter(); 00072 00073 /// Calculate the CRC32 checksum. 00074 long checksum() const; 00075 00076 /// Extract the VendorId value. 00077 long vendorId() const; 00078 00079 /// Extract the EntityId value. 00080 long entityId() const; 00081 00082 /// Extract the EntityKey value. 00083 long entityKey() const; 00084 00085 /// Extract the EntityKind value. 00086 EntityKind entityKind() const; 00087 00088 /// Returns true if the GUID represents a builtin type domain entity. 00089 bool isBuiltinDomainEntity() const; 00090 00091 /// Returns true if the GUID represents a user defined type domain entity. 00092 bool isUserDomainEntity() const; 00093 00094 /// Returns true if the GUID represents a writer entity. 00095 bool isWriter() const; 00096 00097 /// Returns true if the GUID represents a reader entity. 00098 bool isReader() const; 00099 00100 /// Returns true if the GUID represents a topic entity. 00101 bool isTopic() const; 00102 00103 /// Convert to diagnostic string. 00104 operator OPENDDS_STRING() const; 00105 #ifdef DDS_HAS_WCHAR 00106 operator std::wstring() const; 00107 #endif 00108 00109 OPENDDS_STRING uniqueId() const; 00110 00111 protected: 00112 const GUID_t guid_; 00113 }; 00114 00115 struct OpenDDS_Dcps_Export LogGuid { 00116 explicit LogGuid(const GUID_t& id) 00117 : conv_(GuidConverter(id)) {} 00118 const char* c_str() const { return conv_.c_str(); } 00119 OPENDDS_STRING conv_; 00120 }; 00121 00122 #ifndef OPENDDS_SAFETY_PROFILE 00123 OpenDDS_Dcps_Export std::ostream& 00124 operator<<(std::ostream& os, const OpenDDS::DCPS::GuidConverter& rhs); 00125 00126 #ifdef DDS_HAS_WCHAR 00127 OpenDDS_Dcps_Export std::wostream& 00128 operator<<(std::wostream& os, const OpenDDS::DCPS::GuidConverter& rhs); 00129 #endif //DDS_HAS_WCHAR 00130 #endif //OPENDDS_SAFETY_PROFILE 00131 00132 } // namespace 00133 } // namespace 00134 00135 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00136 00137 #endif /* DCPS_GUIDCONVERTER_H */