GuidBuilder.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 "GuidBuilder.h"
00011 
00012 #ifndef __ACE_INLINE__
00013 # include "GuidBuilder.inl"
00014 #endif /* __ACE_INLINE__ */
00015 
00016 namespace {
00017 
00018 inline void
00019 fill_guid(CORBA::Octet* begin, long value, std::size_t len)
00020 {
00021   for (std::size_t i = 0; i < len; ++i) {
00022     size_t shift = (len - i - 1) << 3;
00023     begin[i] = static_cast<CORBA::Octet>(0xff & (value >> shift));
00024   }
00025 }
00026 
00027 } // namespace
00028 
00029 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00030 
00031 namespace OpenDDS {
00032 namespace DCPS {
00033 
00034 GuidBuilder::GuidBuilder()
00035   : guid_cxx_(create())
00036   , guid_(guid_cxx_)
00037 {
00038 }
00039 
00040 GuidBuilder::GuidBuilder(GUID_t& guid)
00041   : guid_cxx_()
00042   , guid_(guid)
00043 {
00044 }
00045 
00046 GuidBuilder::~GuidBuilder()
00047 {
00048 }
00049 
00050 GUID_t
00051 GuidBuilder::create()
00052 {
00053   GUID_t guid = {
00054     { VENDORID_OCI[0],
00055       VENDORID_OCI[1],
00056       0,
00057       0,
00058       0,
00059       0,
00060       0,
00061       0,
00062       0,
00063       0,
00064       0,
00065       0
00066     }, ENTITYID_UNKNOWN
00067   };
00068   return guid;
00069 }
00070 
00071 void
00072 GuidBuilder::guidPrefix0(long p0)
00073 {
00074   fill_guid(guid_.guidPrefix, p0, 4);
00075 }
00076 
00077 void
00078 GuidBuilder::guidPrefix1(long p1)
00079 {
00080   fill_guid(guid_.guidPrefix + 4, p1, 4);
00081 }
00082 
00083 void
00084 GuidBuilder::guidPrefix2(long p2)
00085 {
00086   fill_guid(guid_.guidPrefix + 8, p2, 4);
00087 }
00088 
00089 void
00090 GuidBuilder::entityId(EntityId_t entityId)
00091 {
00092   guid_.entityId = entityId;
00093 }
00094 
00095 void
00096 GuidBuilder::entityKey(long entityKey)
00097 {
00098   fill_guid(guid_.entityId.entityKey, entityKey, 3);
00099 }
00100 
00101 void
00102 GuidBuilder::entityKind(CORBA::Octet entityKind)
00103 {
00104   guid_.entityId.entityKind = entityKind;
00105 }
00106 
00107 void
00108 GuidBuilder::entityKind(EntityKind kind, bool makeBuiltin)
00109 {
00110   switch (kind) {
00111 
00112   // User Entities
00113 
00114   case KIND_WRITER:
00115     guid_.entityId.entityKind = makeBuiltin ?
00116       ENTITYKIND_BUILTIN_WRITER_WITH_KEY : ENTITYKIND_USER_WRITER_WITH_KEY;
00117     break;
00118 
00119   case KIND_READER:
00120     guid_.entityId.entityKind = makeBuiltin ?
00121       ENTITYKIND_BUILTIN_READER_WITH_KEY : ENTITYKIND_USER_READER_WITH_KEY;
00122     break;
00123 
00124   case KIND_TOPIC:
00125     guid_.entityId.entityKind = makeBuiltin ?
00126       ENTITYKIND_BUILTIN_TOPIC : ENTITYKIND_OPENDDS_TOPIC;
00127     break;
00128 
00129   // Builtin Entities
00130 
00131   case KIND_BUILTIN_WRITER:
00132     guid_.entityId.entityKind = ENTITYKIND_BUILTIN_WRITER_WITH_KEY;
00133     break;
00134 
00135   case KIND_BUILTIN_READER:
00136     guid_.entityId.entityKind = ENTITYKIND_BUILTIN_READER_WITH_KEY;
00137     break;
00138 
00139   case KIND_BUILTIN_TOPIC:
00140     guid_.entityId.entityKind = ENTITYKIND_BUILTIN_TOPIC;
00141     break;
00142 
00143   // OpenDDS specific Publisher Guid values
00144   case KIND_PUBLISHER:
00145     guid_.entityId.entityKind =
00146       ENTITYKIND_OPENDDS_PUBLISHER;
00147     break;
00148 
00149   // OpenDDS specific Subscriber Guid values
00150   case KIND_SUBSCRIBER:
00151     guid_.entityId.entityKind =
00152       ENTITYKIND_OPENDDS_SUBSCRIBER;
00153     break;
00154 
00155   // OpenDDS specific other Guid values
00156   case KIND_USER:
00157     guid_.entityId.entityKind =
00158       ENTITYKIND_OPENDDS_USER;
00159     break;
00160 
00161   default:
00162     guid_.entityId.entityKind =
00163       ENTITYKIND_USER_UNKNOWN;
00164   }
00165 }
00166 
00167 } // namespace DCPS
00168 } // namespace OpenDDS
00169 
00170 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1