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 namespace OpenDDS {
00030 namespace DCPS {
00031 
00032 GuidBuilder::GuidBuilder()
00033   : guid_cxx_(create())
00034   , guid_(guid_cxx_)
00035 {
00036 }
00037 
00038 GuidBuilder::GuidBuilder(GUID_t& guid)
00039   : guid_cxx_()
00040   , guid_(guid)
00041 {
00042 }
00043 
00044 GuidBuilder::~GuidBuilder()
00045 {
00046 }
00047 
00048 GUID_t
00049 GuidBuilder::create()
00050 {
00051   GUID_t guid = {
00052     { VENDORID_OCI[0],
00053       VENDORID_OCI[1],
00054       0,
00055       0,
00056       0,
00057       0,
00058       0,
00059       0,
00060       0,
00061       0,
00062       0,
00063       0
00064     }, ENTITYID_UNKNOWN
00065   };
00066   return guid;
00067 }
00068 
00069 void
00070 GuidBuilder::guidPrefix0(long p0)
00071 {
00072   fill_guid(guid_.guidPrefix, p0, 4);
00073 }
00074 
00075 void
00076 GuidBuilder::guidPrefix1(long p1)
00077 {
00078   fill_guid(guid_.guidPrefix + 4, p1, 4);
00079 }
00080 
00081 void
00082 GuidBuilder::guidPrefix2(long p2)
00083 {
00084   fill_guid(guid_.guidPrefix + 8, p2, 4);
00085 }
00086 
00087 void
00088 GuidBuilder::entityId(EntityId_t entityId)
00089 {
00090   guid_.entityId = entityId;
00091 }
00092 
00093 void
00094 GuidBuilder::entityKey(long entityKey)
00095 {
00096   fill_guid(guid_.entityId.entityKey, entityKey, 3);
00097 }
00098 
00099 void
00100 GuidBuilder::entityKind(CORBA::Octet entityKind)
00101 {
00102   guid_.entityId.entityKind = entityKind;
00103 }
00104 
00105 void
00106 GuidBuilder::entityKind(EntityKind kind)
00107 {
00108   switch (kind) {
00109   case KIND_WRITER:
00110     guid_.entityId.entityKind =
00111       ENTITYKIND_USER_WRITER_WITH_KEY;
00112     break;
00113 
00114   case KIND_READER:
00115     guid_.entityId.entityKind =
00116       ENTITYKIND_USER_READER_WITH_KEY;
00117     break;
00118 
00119   case KIND_TOPIC:
00120     guid_.entityId.entityKind =
00121       ENTITYKIND_OPENDDS_TOPIC;
00122     break;
00123 
00124   // OpenDDS specific Publisher Guid values
00125   case KIND_PUBLISHER:
00126     guid_.entityId.entityKind =
00127       ENTITYKIND_OPENDDS_PUBLISHER;
00128     break;
00129 
00130   // OpenDDS specific Subscriber Guid values
00131   case KIND_SUBSCRIBER:
00132     guid_.entityId.entityKind =
00133       ENTITYKIND_OPENDDS_SUBSCRIBER;
00134     break;
00135 
00136   // OpenDDS specific other Guid values
00137   case KIND_USER:
00138     guid_.entityId.entityKind =
00139       ENTITYKIND_OPENDDS_USER;
00140     break;
00141 
00142   default:
00143     guid_.entityId.entityKind =
00144       ENTITYKIND_USER_UNKNOWN;
00145   }
00146 }
00147 
00148 } // namespace DCPS
00149 } // namespace OpenDDS

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