GuidUtils.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
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 /// Vendor Id value specified for OCI is used for OpenDDS.
00029 const GuidVendorId_t VENDORID_OCI = { 0x01, 0x03 };
00030 
00031 /// Nil value for the GUID prefix (participant identifier).
00032 const GuidPrefix_t GUIDPREFIX_UNKNOWN = { 0 };
00033 
00034 /// Entity Id values specified in Version 2.1 of RTPS specification.
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 /// Nil value for GUID.
00049 const GUID_t GUID_UNKNOWN = { {0,0,0,0,0,0,0,0,0,0,0,0}, { {0,0,0}, 0} };
00050 
00051 /// Summary kinds of entities within the service.
00052 enum EntityKind {     // EntityId_t.entityKind value(s)
00053   KIND_UNKNOWN,       // 0x3f & 0x00 (and all other unspecified values)
00054   KIND_PARTICIPANT,   // 0x3f & 0x01
00055   KIND_WRITER,        // 0x3f & 0x02 | 0x3f & 0x03
00056   KIND_READER,        // 0x3f & 0x04 | 0x3f & 0x07
00057   KIND_TOPIC,         // 0x3f & 0x05
00058 
00059   KIND_PUBLISHER,     // OpenDDS specific Publisher Guid values
00060   KIND_SUBSCRIBER,    // OpenDDS specific Subscriber Guid values
00061   KIND_USER           // OpenDDS specific other Guid values
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 // Serialize to ASCII Hex string: "xxxx.xxxx.xxxx.xxxx"
00171 OpenDDS_Dcps_Export std::ostream&
00172 operator<<(std::ostream& os, const GUID_t& rhs);
00173 
00174 // Deserialize from ASCII Hex string: "xxxx.xxxx.xxxx.xxxx"
00175 OpenDDS_Dcps_Export std::istream&
00176 operator>>(std::istream& is, GUID_t& rhs);
00177 #endif
00178 } // namespace DCPS
00179 } // namespace OpenDDS
00180 
00181 #endif /* GUIDUTILS_H */

Generated on Fri Feb 12 20:05:23 2016 for OpenDDS by  doxygen 1.4.7