GuidConverter.cpp

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 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 
00010 #include "GuidConverter.h"
00011 #include "dds/DdsDcpsGuidTypeSupportImpl.h"
00012 
00013 #include "ace/ACE.h"
00014 #include "ace/OS_NS_stdio.h"
00015 
00016 namespace OpenDDS {
00017 namespace DCPS {
00018 
00019 GuidConverter::GuidConverter(const GUID_t& guid)
00020   : guid_(guid)
00021 {}
00022 
00023 GuidConverter::~GuidConverter()
00024 {}
00025 
00026 long
00027 GuidConverter::checksum() const
00028 {
00029   return ACE::crc32(reinterpret_cast<const void*>(&guid_), sizeof(guid_));
00030 }
00031 
00032 long
00033 GuidConverter::vendorId() const
00034 {
00035   return guid_.guidPrefix[0] << 8
00036          | guid_.guidPrefix[1];
00037 }
00038 
00039 long
00040 GuidConverter::entityId() const
00041 {
00042   return entityKey() << 8
00043          | guid_.entityId.entityKind;
00044 }
00045 
00046 long
00047 GuidConverter::entityKey() const
00048 {
00049   return guid_.entityId.entityKey[0] << 16
00050          | guid_.entityId.entityKey[1] << 8
00051          | guid_.entityId.entityKey[2];
00052 }
00053 
00054 EntityKind
00055 GuidConverter::entityKind() const
00056 {
00057   switch (guid_.entityId.entityKind) {
00058   case ENTITYKIND_OPENDDS_TOPIC:
00059     return KIND_TOPIC;
00060 
00061   case ENTITYKIND_USER_READER_NO_KEY:
00062   case ENTITYKIND_USER_READER_WITH_KEY:
00063   case ENTITYKIND_BUILTIN_READER_NO_KEY:
00064   case ENTITYKIND_BUILTIN_READER_WITH_KEY:
00065     return KIND_READER;
00066 
00067   case ENTITYKIND_USER_WRITER_NO_KEY:
00068   case ENTITYKIND_USER_WRITER_WITH_KEY:
00069   case ENTITYKIND_BUILTIN_WRITER_NO_KEY:
00070   case ENTITYKIND_BUILTIN_WRITER_WITH_KEY:
00071   case ENTITYKIND_OPENDDS_NIL_WRITER:
00072     return KIND_WRITER;
00073 
00074   case ENTITYKIND_BUILTIN_PARTICIPANT:
00075     return KIND_PARTICIPANT;
00076 
00077   case ENTITYKIND_OPENDDS_PUBLISHER:
00078     return KIND_PUBLISHER;
00079 
00080   case ENTITYKIND_OPENDDS_SUBSCRIBER:
00081     return KIND_SUBSCRIBER;
00082 
00083   case ENTITYKIND_OPENDDS_USER:
00084     return KIND_USER;
00085 
00086   case ENTITYKIND_USER_UNKNOWN:
00087   case ENTITYKIND_BUILTIN_UNKNOWN:
00088   default:
00089     return KIND_UNKNOWN;
00090   }
00091 }
00092 
00093 GuidConverter::operator OPENDDS_STRING() const
00094 {
00095 
00096   OPENDDS_STRING ret(to_string(guid_));
00097   ret += "(";
00098   ret += to_dds_string((unsigned long) checksum(), true);
00099   ret += ")";
00100 
00101   return ret;
00102 }
00103 
00104 #ifdef DDS_HAS_WCHAR
00105 GuidConverter::operator std::wstring() const
00106 {
00107   std::wostringstream os;
00108 
00109   os << guid_ << "(" << std::hex << checksum() << ")";
00110 
00111   return os.str();
00112 }
00113 #endif
00114 
00115 #ifndef OPENDDS_SAFETY_PROFILE
00116 
00117 std::ostream&
00118 operator<<(std::ostream& os, const GuidConverter& rhs)
00119 {
00120   return os << OPENDDS_STRING(rhs);
00121 }
00122 
00123 #ifdef DDS_HAS_WCHAR
00124 std::wostream&
00125 operator<<(std::wostream& os, const GuidConverter& rhs)
00126 {
00127   return os << std::wstring(rhs);
00128 }
00129 #endif //DDS_HAS_WCHAR
00130 #endif //OPENDDS_SAFETY_PROFILE
00131 
00132 OPENDDS_STRING
00133 GuidConverter::uniqueId() const
00134 {
00135   char id[64];
00136   ACE_OS::snprintf(id, sizeof id,
00137           "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
00138           guid_.guidPrefix[ 0],
00139           guid_.guidPrefix[ 1],
00140           guid_.guidPrefix[ 2],
00141           guid_.guidPrefix[ 3],
00142           guid_.guidPrefix[ 4],
00143           guid_.guidPrefix[ 5],
00144           guid_.guidPrefix[ 6],
00145           guid_.guidPrefix[ 7],
00146           guid_.guidPrefix[ 8],
00147           guid_.guidPrefix[ 9],
00148           guid_.guidPrefix[10],
00149           guid_.guidPrefix[11]);
00150   return id;
00151 }
00152 
00153 } // namespace DCPS
00154 } // namespace OpenDDS
00155 

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