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 namespace OpenDDS {
00026 namespace DCPS {
00027
00028
00029 const GuidVendorId_t VENDORID_OCI = { 0x01, 0x03 };
00030
00031
00032 const GuidPrefix_t GUIDPREFIX_UNKNOWN = { 0 };
00033
00034
00035 const EntityId_t ENTITYID_UNKNOWN = { {0x00,0x00,0x00}, 0x00};
00036 const EntityId_t ENTITYID_PARTICIPANT = { {0x00,0x00,0x01}, 0xc1};
00037 const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_WRITER = { {0x00,0x00,0x02}, 0xc2};
00038 const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_READER = { {0x00,0x00,0x02}, 0xc7};
00039 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER = { {0x00,0x00,0x03}, 0xc2};
00040 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER = { {0x00,0x00,0x03}, 0xc7};
00041 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER = { {0x00,0x00,0x04}, 0xc2};
00042 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER = { {0x00,0x00,0x04}, 0xc7};
00043 const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER = { {0x00,0x01,0x00}, 0xc2};
00044 const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER = { {0x00,0x01,0x00}, 0xc7};
00045 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER = { {0x00,0x02,0x00}, 0xc2};
00046 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_READER = { {0x00,0x02,0x00}, 0xc7};
00047
00048
00049 const GUID_t GUID_UNKNOWN = { {0,0,0,0,0,0,0,0,0,0,0,0}, { {0,0,0}, 0} };
00050
00051
00052 enum EntityKind {
00053 KIND_UNKNOWN,
00054 KIND_PARTICIPANT,
00055 KIND_WRITER,
00056 KIND_READER,
00057 KIND_TOPIC,
00058
00059 KIND_PUBLISHER,
00060 KIND_SUBSCRIBER,
00061 KIND_USER
00062 };
00063
00064 struct OpenDDS_Dcps_Export GUID_tKeyLessThan {
00065 static bool entity_less(const EntityId_t& v1, const EntityId_t& v2)
00066 {
00067 if (v1.entityKey[2] < v2.entityKey[2]) return true;
00068 if (v2.entityKey[2] < v1.entityKey[2]) return false;
00069 if (v1.entityKey[1] < v2.entityKey[1]) return true;
00070 if (v2.entityKey[1] < v1.entityKey[1]) return false;
00071 if (v1.entityKey[0] < v2.entityKey[0]) return true;
00072 if (v2.entityKey[0] < v1.entityKey[0]) return false;
00073 if (v1.entityKind < v2.entityKind) return true;
00074 if (v2.entityKind < v1.entityKind) return false;
00075 return false;
00076 }
00077
00078 bool operator()(const GUID_t& v1, const GUID_t& v2) const
00079 {
00080 if (v1.guidPrefix[11] < v2.guidPrefix[11]) return true;
00081 if (v2.guidPrefix[11] < v1.guidPrefix[11]) return false;
00082 if (v1.guidPrefix[10] < v2.guidPrefix[10]) return true;
00083 if (v2.guidPrefix[10] < v1.guidPrefix[10]) return false;
00084 if (v1.guidPrefix[ 9] < v2.guidPrefix[ 9]) return true;
00085 if (v2.guidPrefix[ 9] < v1.guidPrefix[ 9]) return false;
00086 if (v1.guidPrefix[ 8] < v2.guidPrefix[ 8]) return true;
00087 if (v2.guidPrefix[ 8] < v1.guidPrefix[ 8]) return false;
00088 if (v1.guidPrefix[ 7] < v2.guidPrefix[ 7]) return true;
00089 if (v2.guidPrefix[ 7] < v1.guidPrefix[ 7]) return false;
00090 if (v1.guidPrefix[ 6] < v2.guidPrefix[ 6]) return true;
00091 if (v2.guidPrefix[ 6] < v1.guidPrefix[ 6]) return false;
00092 if (v1.guidPrefix[ 5] < v2.guidPrefix[ 5]) return true;
00093 if (v2.guidPrefix[ 5] < v1.guidPrefix[ 5]) return false;
00094 if (v1.guidPrefix[ 4] < v2.guidPrefix[ 4]) return true;
00095 if (v2.guidPrefix[ 4] < v1.guidPrefix[ 4]) return false;
00096 if (v1.guidPrefix[ 3] < v2.guidPrefix[ 3]) return true;
00097 if (v2.guidPrefix[ 3] < v1.guidPrefix[ 3]) return false;
00098 if (v1.guidPrefix[ 2] < v2.guidPrefix[ 2]) return true;
00099 if (v2.guidPrefix[ 2] < v1.guidPrefix[ 2]) return false;
00100 if (v1.guidPrefix[ 1] < v2.guidPrefix[ 1]) return true;
00101 if (v2.guidPrefix[ 1] < v1.guidPrefix[ 1]) return false;
00102 if (v1.guidPrefix[ 0] < v2.guidPrefix[ 0]) return true;
00103 if (v2.guidPrefix[ 0] < v1.guidPrefix[ 0]) return false;
00104 return entity_less(v1.entityId, v2.entityId);
00105 }
00106 };
00107
00108 typedef OPENDDS_SET_CMP(RepoId, GUID_tKeyLessThan) RepoIdSet;
00109
00110 inline size_t
00111 gen_max_marshaled_size(const GUID_t&)
00112 {
00113 return 16;
00114 }
00115
00116 #ifndef OPENDDS_SAFETY_PROFILE
00117 inline bool
00118 operator==(const GUID_t& lhs, const GUID_t& rhs)
00119 {
00120 GUID_tKeyLessThan lessThan;
00121 return !lessThan(lhs, rhs) && !lessThan(rhs, lhs);
00122 }
00123
00124 inline bool
00125 operator!=(const GUID_t& lhs, const GUID_t& rhs)
00126 {
00127 return !(lhs == rhs);
00128 }
00129 #endif
00130
00131 struct GuidPrefixEqual {
00132
00133 bool
00134 operator() (const GuidPrefix_t& lhs, const GuidPrefix_t& rhs) const
00135 {
00136 return std::memcmp(&lhs, &rhs, sizeof(GuidPrefix_t)) == 0;
00137 }
00138 };
00139
00140 #ifndef OPENDDS_SAFETY_PROFILE
00141 inline bool
00142 operator==(const EntityId_t& lhs, const EntityId_t& rhs)
00143 {
00144 return !GUID_tKeyLessThan::entity_less(lhs, rhs)
00145 && !GUID_tKeyLessThan::entity_less(rhs, lhs);
00146 }
00147
00148 inline bool
00149 operator!=(const EntityId_t& lhs, const EntityId_t& rhs)
00150 {
00151 return !(lhs == rhs);
00152 }
00153 #endif
00154
00155 struct EntityIdConverter {
00156 EntityIdConverter (const unsigned char o[4])
00157 {
00158 std::memcpy(&entityId, &o, sizeof(EntityId_t));
00159 }
00160
00161 operator EntityId_t() const { return entityId; }
00162
00163 EntityId_t entityId;
00164 };
00165
00166 OpenDDS_Dcps_Export OPENDDS_STRING
00167 to_string(const GUID_t& guid);
00168
00169 #ifndef OPENDDS_SAFETY_PROFILE
00170
00171 OpenDDS_Dcps_Export std::ostream&
00172 operator<<(std::ostream& os, const GUID_t& rhs);
00173
00174
00175 OpenDDS_Dcps_Export std::istream&
00176 operator>>(std::istream& is, GUID_t& rhs);
00177 #endif
00178 }
00179 }
00180
00181 #endif