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