RepoIdGenerator.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"
00009 
00010 #include "RepoIdGenerator.h"
00011 #include "dds/DCPS/RepoIdBuilder.h"
00012 #include "ace/Log_Msg.h"
00013 
00014 const unsigned RepoIdGenerator::KeyBits = 24;
00015 
00016 const unsigned RepoIdGenerator::KeyMask = (1 << KeyBits) - 1;
00017 
00018 RepoIdGenerator::RepoIdGenerator(
00019   long                      federation,
00020   long                      participant,
00021   OpenDDS::DCPS::EntityKind kind) : kind_(kind),
00022     federation_(federation),
00023     participant_(participant),
00024     lastKey_(0)
00025 {
00026 }
00027 
00028 RepoIdGenerator::~RepoIdGenerator()
00029 {
00030 }
00031 
00032 OpenDDS::DCPS::RepoId
00033 RepoIdGenerator::next()
00034 {
00035   // Generate a new key value.
00036   ++this->lastKey_;
00037 
00038   OpenDDS::DCPS::RepoIdBuilder builder;
00039   builder.federationId(federation_);
00040 
00041   // Generate a Participant GUID value.
00042   if (this->kind_ == OpenDDS::DCPS::KIND_PARTICIPANT) {
00043 
00044     // Rudimentary validity checking.
00045     if (this->lastKey_ == 0) {
00046       // We have rolled over and there can now exist objects with
00047       // the same key.
00048       ACE_ERROR((LM_ERROR,
00049                  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
00050                  ACE_TEXT("Exceeded Maximum number of participant keys!")
00051                  ACE_TEXT("Next key will be a duplicate!\n")));
00052     }
00053 
00054     builder.participantId(lastKey_);
00055     builder.entityId(OpenDDS::DCPS::ENTITYID_PARTICIPANT);
00056 
00057     // Generate an Entity GUID value.
00058 
00059   } else {
00060 
00061     // Rudimentary validity checking.
00062     if ((this->lastKey_ & ~KeyMask) != 0) {
00063       // We have rolled over and there can now exist objects with
00064       // the same key.
00065       ACE_ERROR((LM_ERROR,
00066                  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
00067                  ACE_TEXT("Exceeded Maximum number of entity keys!")
00068                  ACE_TEXT("Next key will be a duplicate!\n")));
00069     }
00070 
00071     builder.participantId(participant_);
00072     builder.entityKey(lastKey_);
00073     builder.entityKind(kind_);
00074   }
00075 
00076   return OpenDDS::DCPS::RepoId(builder);
00077 }
00078 
00079 void
00080 RepoIdGenerator::last(long key)
00081 {
00082   if (key > this->lastKey_) {
00083     this->lastKey_ = key;
00084   }
00085 }

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