OpenDDS  Snapshot(2023/04/28-20:55)
RepoIdGenerator.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "DCPS/DdsDcps_pch.h"
9 
10 #include "RepoIdGenerator.h"
11 #include "RepoIdBuilder.h"
12 #include "ace/Log_Msg.h"
13 
15 namespace OpenDDS {
16 namespace DCPS {
17 
18 const unsigned int RepoIdGenerator::KeyBits = 24;
19 
20 const unsigned int RepoIdGenerator::KeyMask = (1 << KeyBits) - 1;
21 
22 RepoIdGenerator::RepoIdGenerator(long federation, long participant, EntityKind kind)
23  : kind_(kind)
24  , federation_(federation)
25  , participant_(participant)
26  , lastKey_(0)
27 {
28 }
29 
31 {
32 }
33 
34 GUID_t
35 RepoIdGenerator::next(bool builtin)
36 {
37  // Generate a new key value.
38  ++lastKey_;
39 
40  RepoIdBuilder builder;
41  builder.federationId(federation_);
42 
43  // Generate a Participant GUID value.
44  if (kind_ == KIND_PARTICIPANT) {
45 
46  // Rudimentary validity checking.
47  if (lastKey_ == 0) {
48  // We have rolled over and there can now exist objects with
49  // the same key.
51  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
52  ACE_TEXT("Exceeded Maximum number of participant keys!")
53  ACE_TEXT("Next key will be a duplicate!\n")));
54  }
55 
56  builder.participantId(lastKey_);
58 
59  // Generate an Entity GUID value.
60 
61  } else {
62 
63  // Rudimentary validity checking.
64  if ((lastKey_ & ~KeyMask) != 0) {
65  // We have rolled over and there can now exist objects with
66  // the same key.
68  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
69  ACE_TEXT("Exceeded Maximum number of entity keys!")
70  ACE_TEXT("Next key will be a duplicate!\n")));
71  }
72 
73  builder.participantId(participant_);
74  builder.entityKey(lastKey_);
75  builder.entityKind(kind_, builtin);
76  }
77 
78  return GUID_t(builder);
79 }
80 
81 void
83 {
84  if (key > lastKey_) {
85  lastKey_ = key;
86  }
87 }
88 
89 } // namespace DCPS
90 } // namespace OpenDDS
long participant_
Unique identifier for the DomainParticipant.
RepoIdGenerator(long federation, long participant=0, EntityKind kind=KIND_PARTICIPANT)
construct with at least a FederationId value.
#define ACE_ERROR(X)
ENTITYKIND_BUILTIN_PARTICIPANT.
Definition: GuidUtils.h:68
sequence< octet > key
static const unsigned int KeyBits
long federation_
Unique identifier for the repository.
const EntityId_t ENTITYID_PARTICIPANT
Definition: GuidUtils.h:37
static const unsigned int KeyMask
long lastKey_
Unique value for the EntityKey.
void entityKind(CORBA::Octet entityKind)
EntityKind kind_
Type of Entity to generate GUID values for.
void entityKey(long entityKey)
Definition: GuidBuilder.cpp:96
GUID_t next(bool builtin=false)
Obtain the next GUID_t value.
ACE_TEXT("TCP_Factory")
void entityId(EntityId_t entityId)
Definition: GuidBuilder.cpp:90
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
void participantId(long participantId)
void federationId(long federationId)
LM_ERROR
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28