OpenDDS  Snapshot(2023/04/28-20:55)
RepoIdGenerator.h
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 #ifndef OPENDDS_DCPS_REPOIDGENERATOR_H
9 #define OPENDDS_DCPS_REPOIDGENERATOR_H
10 
11 #include "tao/Basic_Types.h"
12 
13 #include "dds/DdsDcpsInfoUtilsC.h"
14 #include "dds/DdsDcpsGuidC.h"
15 
16 #include "GuidUtils.h"
17 
18 #include "dcps_export.h"
19 
21 namespace OpenDDS {
22 namespace DCPS {
23 
24 /**
25  * @class RepoIdGenerator
26  *
27  * @brief Create RepoId values for use within DDS.
28  *
29  * Internal to the OpenDDS repository, the Repository Identifiers that
30  * uniquely identify all DDS Entities within the service managed by this
31  * (and other federated) repositories consist of GUID values.
32  *
33  * These GUID (Global Unique IDentifiers) values are based on the RTPS
34  * specification (formal/08-04-09) GUID_t values. They use the same
35  * structure. The VendorId value is applied in the first 2 bytes of the
36  * prefix. The remainder of the Participant Id value is composed of the
37  * OpenDDS specific Federation Id value (the identifier of the repository
38  * where the Entity was created) and a DomainParticipant identifier within
39  * that repository. In addition to the standard EntityKind values,
40  * the EntityKind byte has an added value of ENTITYKIND_OPENDDS_TOPIC
41  * allowed to permit the use of GUID values for Topic entities as well.
42  * This is an OpenDDS specific extension.
43  *
44  * The EntityKey field is used to distinguish Topics, Publications and
45  * Subscriptions within a single Participant. Each of these is within
46  * its own number (address) space. The EntityKind byte will ensure that
47  * identical EntityKey values of these different types will not conflict
48  * in the final GUID value.
49  *
50  * Values are generated using the specified FederationId and
51  * DomainParticipant identifiers. The EntityKey for a type is
52  * incremented each time a value is generated.
53  *
54  * The ability to reset the last used value is provided to allow the
55  * reloading of Entities from persistent storage without inducing
56  * conflicts with newly created Entities. This is a simplistic mechanism
57  * and requires that all information from the persistent storage be
58  * processed *prior* to any new Entities being created within the
59  * repository. After this processing is complete, the last used value
60  * should be reset to ensure that any new values will not conflict with
61  * the restored values.
62  *
63  * NOTE: This mechanism does not work well for values that have wrapped
64  * around the 24 bit EntityKey space. It is possible to extend the
65  * current mapping to overflow into the two '0' bytes (2 and 3)
66  * with the Key value number (address) space to increase the
67  * possible unique identifiers if this becomes an issue. Doing
68  * that would alleviate the need to manage an arena of Key values.
69  *
70  * Even though each Domain could have a separate GUID (address) space,
71  * since we do not currently include the domain value within the GUID
72  * mapping, all domains within a repository will use the same generator
73  * instance to ensure no conflicting GUID values. This will restrict the
74  * total number of DomainParticipants within *all* domains of a
75  * repository to be within the 32 bit (2**32) DomainParticipant address
76  * space. It is likely that other limits will be exceeded before this
77  * one is approached.
78  *
79  * The current mapping of meanings to the GUID component values is:
80  *
81  * Content:
82  * | VendorId| 0 | 0 | FederationId | DomainParticpant | EntityKey |Kind|
83  * GUID_t bytes:
84  * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
85  * GuidPrefix_t GUID_t.guidPrefix bytes:
86  * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
87  * EntityId_t GUID_t.entityId bytes: | 0 | 1 | 2 | 3 |
88  * EntityKey_t GUID_t.entityId.entityKey bytes: | 0 | 1 | 2 |
89  *
90  * Where the VendorId value used for OpenDDS is defined in GuidUtils.h
91  */
93 public:
94  static const unsigned int KeyBits;
95 
96  static const unsigned int KeyMask;
97 
98  /**
99  * @brief construct with at least a FederationId value.
100  *
101  * @param federation identifier for the repository.
102  * @param participant identifier for the participant.
103  * @param kind type of Entities to generate Id values for.
104  * @return GUID_t generated unique identifier value.
105  *
106  * If the @c kind is KIND_PARTICIPANT then the generator will generate
107  * Participant RepoId values. Otherwise it will generate the specified
108  * type of Entity values within the specified Participant.
109  */
111  long federation,
112  long participant = 0,
114 
115  virtual ~RepoIdGenerator();
116 
117  /// Obtain the next GUID_t value.
118  GUID_t next(bool builtin = false);
119 
120  /**
121  * Set the minimum of the last key (or participant) value used.
122  *
123  * @param key the smallest value that the last generated key can be
124  *
125  * If the supplied @c key value is larger than the actual last
126  * generated key value, the new key value replaces the old one.
127  */
128  void last(long key);
129 
130 private:
131  /// Type of Entity to generate GUID values for.
133 
134  /// Unique identifier for the repository.
136 
137  /// Unique identifier for the DomainParticipant.
139 
140  /// Unique value for the EntityKey.
141  long lastKey_;
142 };
143 
144 } // namespace DCPS
145 } // namespace OpenDDS
147 
148 #endif /* REPOIDGENERATOR_H */
long participant_
Unique identifier for the DomainParticipant.
ENTITYKIND_BUILTIN_PARTICIPANT.
Definition: GuidUtils.h:68
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
sequence< octet > key
static const unsigned int KeyBits
long federation_
Unique identifier for the repository.
static const unsigned int KeyMask
Create RepoId values for use within DDS.
long lastKey_
Unique value for the EntityKey.
EntityKind kind_
Type of Entity to generate GUID values for.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28