OpenDDS  Snapshot(2023/04/28-20:55)
GuidGenerator.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 #ifndef OPENDDS_DCPS_RTPS_GUIDGENERATOR_H
8 #define OPENDDS_DCPS_RTPS_GUIDGENERATOR_H
9 
10 #if !defined (ACE_LACKS_PRAGMA_ONCE)
11 #pragma once
12 #endif /* ACE_LACKS_PRAGMA_ONCE */
13 
14 #include "dds/DdsDcpsGuidC.h"
15 #include "dds/DCPS/PoolAllocator.h"
16 #include "rtps_export.h"
17 
18 #include "ace/Basic_Types.h"
19 #include "ace/Thread_Mutex.h"
20 
22 
23 namespace OpenDDS {
24  namespace RTPS {
25 
26 /**
27  * Generate GuidPrefix_t values for use with RTPS
28  * Also see GuidConverter.h in dds/DCPS
29  * 0 GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS)
30  * 1 GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS)
31  * 2 GUID_t.guidPrefix[ 2] == MAC Address
32  * 3 GUID_t.guidPrefix[ 3] == MAC Address
33  * 4 GUID_t.guidPrefix[ 4] == MAC Address
34  * 5 GUID_t.guidPrefix[ 5] == MAC Address
35  * 6 GUID_t.guidPrefix[ 6] == MAC Address
36  * 7 GUID_t.guidPrefix[ 7] == MAC Address
37  * 8 GUID_t.guidPrefix[ 8] == Process ID (MS byte)
38  * 9 GUID_t.guidPrefix[ 9] == Process ID (LS byte)
39  * 10 GUID_t.guidPrefix[10] == Counter (MS byte)
40  * 11 GUID_t.guidPrefix[11] == Counter (LS byte)
41  *
42  */
44 public:
45  GuidGenerator();
46 
47  /// override the MAC address to use a specific network interface
48  /// instead of just the first (non-loopback) interface
49  int interfaceName(const char* nic);
50 
51  /// populate a GUID container with a unique ID. This will increment
52  /// the counter, and use a lock (if compiled with MT ACE) while
53  /// doing so.
54  void populate(DCPS::GUID_t& container);
55 
56  // In a test case, for just examining the counter, pass false. Otherwise exclude the parameter.
57  ACE_UINT16 getCount(bool doIncrement = true);
58 
59 private:
60  enum {NODE_ID_SIZE = 6};
61 
62  /// Borrowed from ACE::UUID_Node, definition of the
63  /// MAC address holder type
64  typedef unsigned char Node_ID[NODE_ID_SIZE];
65 
66  Node_ID node_id_;
67  pid_t pid_;
69  ACE_UINT16 counter_;
71 };
72 
73 } // namespace RTPS
74 } // namespace OpenDDS
75 
77 
78 #endif
ACE_Thread_Mutex counter_lock_
Definition: GuidGenerator.h:68
#define OPENDDS_STRING
OPENDDS_STRING interface_name_
Definition: GuidGenerator.h:70
#define OpenDDS_Rtps_Export
Definition: rtps_export.h:23
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28