00001
00002
00003
00004
00005
00006
00007
00008 #ifndef GUIDUTILS_H
00009 #define GUIDUTILS_H
00010
00011 #include "dds/DdsDcpsGuidC.h"
00012 #include "dds/DdsDcpsInfoUtilsC.h"
00013 #include "dds/DCPS/PoolAllocator.h"
00014
00015 #include "dcps_export.h"
00016
00017 #include "tao/Basic_Types.h"
00018
00019 #ifndef OPENDDS_SAFETY_PROFILE
00020 #include <iosfwd>
00021 #endif
00022
00023 #include <cstring>
00024
00025 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 namespace OpenDDS {
00028 namespace DCPS {
00029
00030
00031 const GuidVendorId_t VENDORID_OCI = { 0x01, 0x03 };
00032
00033
00034 const GuidPrefix_t GUIDPREFIX_UNKNOWN = { 0 };
00035
00036
00037
00038 const EntityId_t ENTITYID_UNKNOWN = { {0x00,0x00,0x00}, 0x00};
00039 const EntityId_t ENTITYID_PARTICIPANT = { {0x00,0x00,0x01}, 0xc1};
00040 const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_WRITER = { {0x00,0x00,0x02}, 0xc2};
00041 const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_READER = { {0x00,0x00,0x02}, 0xc7};
00042 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER = { {0x00,0x00,0x03}, 0xc2};
00043 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER = { {0x00,0x00,0x03}, 0xc7};
00044 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER = { {0x00,0x00,0x04}, 0xc2};
00045 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER = { {0x00,0x00,0x04}, 0xc7};
00046 const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER = { {0x00,0x01,0x00}, 0xc2};
00047 const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER = { {0x00,0x01,0x00}, 0xc7};
00048 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER = { {0x00,0x02,0x00}, 0xc2};
00049 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_READER = { {0x00,0x02,0x00}, 0xc7};
00050
00051
00052
00053 const GUID_t GUID_UNKNOWN = { { 0 }, { { 0 }, 0 } };
00054
00055
00056
00057
00058
00059
00060 enum EntityKind {
00061
00062
00063 KIND_UNKNOWN,
00064
00065 KIND_PARTICIPANT,
00066
00067
00068 KIND_WRITER,
00069
00070 KIND_READER,
00071
00072 KIND_TOPIC,
00073
00074
00075 KIND_BUILTIN_WRITER,
00076
00077 KIND_BUILTIN_READER,
00078
00079 KIND_BUILTIN_TOPIC,
00080
00081
00082 KIND_PUBLISHER,
00083
00084 KIND_SUBSCRIBER,
00085
00086 KIND_USER
00087 };
00088
00089 struct OpenDDS_Dcps_Export GUID_tKeyLessThan {
00090 static bool entity_less(const EntityId_t& v1, const EntityId_t& v2)
00091 {
00092 if (v1.entityKey[2] < v2.entityKey[2]) return true;
00093 if (v2.entityKey[2] < v1.entityKey[2]) return false;
00094 if (v1.entityKey[1] < v2.entityKey[1]) return true;
00095 if (v2.entityKey[1] < v1.entityKey[1]) return false;
00096 if (v1.entityKey[0] < v2.entityKey[0]) return true;
00097 if (v2.entityKey[0] < v1.entityKey[0]) return false;
00098 if (v1.entityKind < v2.entityKind) return true;
00099 if (v2.entityKind < v1.entityKind) return false;
00100 return false;
00101 }
00102
00103 bool operator()(const GUID_t& v1, const GUID_t& v2) const
00104 {
00105 if (v1.guidPrefix[11] < v2.guidPrefix[11]) return true;
00106 if (v2.guidPrefix[11] < v1.guidPrefix[11]) return false;
00107 if (v1.guidPrefix[10] < v2.guidPrefix[10]) return true;
00108 if (v2.guidPrefix[10] < v1.guidPrefix[10]) return false;
00109 if (v1.guidPrefix[ 9] < v2.guidPrefix[ 9]) return true;
00110 if (v2.guidPrefix[ 9] < v1.guidPrefix[ 9]) return false;
00111 if (v1.guidPrefix[ 8] < v2.guidPrefix[ 8]) return true;
00112 if (v2.guidPrefix[ 8] < v1.guidPrefix[ 8]) return false;
00113 if (v1.guidPrefix[ 7] < v2.guidPrefix[ 7]) return true;
00114 if (v2.guidPrefix[ 7] < v1.guidPrefix[ 7]) return false;
00115 if (v1.guidPrefix[ 6] < v2.guidPrefix[ 6]) return true;
00116 if (v2.guidPrefix[ 6] < v1.guidPrefix[ 6]) return false;
00117 if (v1.guidPrefix[ 5] < v2.guidPrefix[ 5]) return true;
00118 if (v2.guidPrefix[ 5] < v1.guidPrefix[ 5]) return false;
00119 if (v1.guidPrefix[ 4] < v2.guidPrefix[ 4]) return true;
00120 if (v2.guidPrefix[ 4] < v1.guidPrefix[ 4]) return false;
00121 if (v1.guidPrefix[ 3] < v2.guidPrefix[ 3]) return true;
00122 if (v2.guidPrefix[ 3] < v1.guidPrefix[ 3]) return false;
00123 if (v1.guidPrefix[ 2] < v2.guidPrefix[ 2]) return true;
00124 if (v2.guidPrefix[ 2] < v1.guidPrefix[ 2]) return false;
00125 if (v1.guidPrefix[ 1] < v2.guidPrefix[ 1]) return true;
00126 if (v2.guidPrefix[ 1] < v1.guidPrefix[ 1]) return false;
00127 if (v1.guidPrefix[ 0] < v2.guidPrefix[ 0]) return true;
00128 if (v2.guidPrefix[ 0] < v1.guidPrefix[ 0]) return false;
00129 return entity_less(v1.entityId, v2.entityId);
00130 }
00131 };
00132
00133 typedef OPENDDS_SET_CMP(RepoId, GUID_tKeyLessThan) RepoIdSet;
00134
00135 inline size_t
00136 gen_max_marshaled_size(const GUID_t&)
00137 {
00138 return 16;
00139 }
00140
00141 #ifndef OPENDDS_SAFETY_PROFILE
00142 inline bool
00143 operator==(const GUID_t& lhs, const GUID_t& rhs)
00144 {
00145 GUID_tKeyLessThan lessThan;
00146 return !lessThan(lhs, rhs) && !lessThan(rhs, lhs);
00147 }
00148
00149 inline bool
00150 operator!=(const GUID_t& lhs, const GUID_t& rhs)
00151 {
00152 return !(lhs == rhs);
00153 }
00154 #endif
00155
00156 struct GuidPrefixEqual {
00157
00158 bool
00159 operator() (const GuidPrefix_t& lhs, const GuidPrefix_t& rhs) const
00160 {
00161 return std::memcmp(&lhs, &rhs, sizeof(GuidPrefix_t)) == 0;
00162 }
00163 };
00164
00165 #ifndef OPENDDS_SAFETY_PROFILE
00166 inline bool
00167 operator==(const EntityId_t& lhs, const EntityId_t& rhs)
00168 {
00169 return !GUID_tKeyLessThan::entity_less(lhs, rhs)
00170 && !GUID_tKeyLessThan::entity_less(rhs, lhs);
00171 }
00172
00173 inline bool
00174 operator!=(const EntityId_t& lhs, const EntityId_t& rhs)
00175 {
00176 return !(lhs == rhs);
00177 }
00178 #endif
00179
00180 struct EntityIdConverter {
00181 explicit EntityIdConverter(const unsigned char (&o)[4])
00182 {
00183 std::memcpy(&entityId, o, sizeof(EntityId_t));
00184 }
00185
00186 operator EntityId_t() const { return entityId; }
00187
00188 EntityId_t entityId;
00189 };
00190
00191 OpenDDS_Dcps_Export OPENDDS_STRING
00192 to_string(const GUID_t& guid);
00193
00194 #ifndef OPENDDS_SAFETY_PROFILE
00195
00196 OpenDDS_Dcps_Export std::ostream&
00197 operator<<(std::ostream& os, const GUID_t& rhs);
00198
00199
00200 OpenDDS_Dcps_Export std::istream&
00201 operator>>(std::istream& is, GUID_t& rhs);
00202 #endif
00203 }
00204 }
00205
00206 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00207
00208 #endif