3 //=============================================================================
7 * $Id: UUID.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Andrew T. Finnel <andrew@activesol.net>
10 * @author Yamuna Krishnmaurthy <yamuna@oomworks.com>
12 //=============================================================================
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/config-all.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/SString.h"
25 #include "ace/Singleton.h"
26 #include "ace/Synch_Traits.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 /// Class to hold a MAC address
33 class ACE_Export UUID_Node
40 enum {NODE_ID_SIZE
= 6};
41 typedef u_char Node_ID
[NODE_ID_SIZE
];
43 Node_ID
&node_ID (void);
44 void node_ID (Node_ID
&);
46 ///// Equality Operations
47 bool operator == (const UUID_Node
& right
) const;
48 bool operator != (const UUID_Node
& right
) const;
50 ///// Relational Operations
51 //bool operator < (const UUID_Node& right) const;
60 * ACE_UUID represents a Universally Unique IDentifier (UUID) as
61 * described in (the expired) INTERNET-DRAFT specification entitled
62 * UUIDs and GUIDs. All instances of UUID are of the time-based
63 * variety. That is, the version number part of the timeHiAndVersion
66 * The default constructor creates a nil UUID.
68 * UUIDs have value semantics. In addition, they may be compared for
69 * ordering and equality.
71 * Additionally in this implementation provisions have been made to include
72 * process and thread ids to make the UUIDs more unique. The variant 0xc0
73 * has been added to facilitate this.
82 /// Constructs a UUID from a string representation.
83 UUID (const ACE_CString
& uuidString
);
85 UUID (const UUID
&right
);
90 ACE_UINT32
time_low (void) const;
91 void time_low (ACE_UINT32
);
93 ACE_UINT16
time_mid (void) const;
94 void time_mid (ACE_UINT16
);
96 ACE_UINT16
time_hi_and_version (void) const;
97 void time_hi_and_version (ACE_UINT16
);
99 u_char
clock_seq_hi_and_reserved (void) const;
100 void clock_seq_hi_and_reserved (u_char
);
102 u_char
clock_seq_low (void) const;
103 void clock_seq_low (u_char
);
105 UUID_Node
* node (void) const;
106 void node (UUID_Node
*);
108 ACE_CString
* thr_id (void);
111 ACE_CString
* pid (void);
114 /// Returns a string representation of the UUID
115 const ACE_CString
* to_string (void);
117 /// Set the value using a string
118 void from_string (const ACE_CString
& uuid_string
);
120 static UUID NIL_UUID
;
122 /// Equality Operations
123 bool operator== (const UUID
&right
) const;
124 bool operator!= (const UUID
&right
) const;
126 /// Relational Operations
127 //bool operator< (const UUID &right) const;
128 //bool operator> (const UUID &right) const;
129 //bool operator<= (const UUID &right) const;
130 //bool operator>= (const UUID &right) const;
133 void from_string_i (const ACE_CString
& uuid_string
);
135 UUID
& operator= (const UUID
&);
137 /// Data Members for Class Attributes
138 ACE_UINT32 time_low_
;
139 ACE_UINT16 time_mid_
;
140 ACE_UINT16 time_hi_and_version_
;
141 u_char clock_seq_hi_and_reserved_
;
142 u_char clock_seq_low_
;
148 /// The string representation of the UUID. This is created and
149 /// updated only on demand.
150 ACE_CString
*as_string_
;
154 * @class ACE_UUID_Generator
156 * Singleton class that generates UUIDs.
159 class ACE_Export UUID_Generator
163 enum {ACE_UUID_CLOCK_SEQ_MASK
= 0x3FFF};
170 /// Format timestamp, clockseq, and nodeID into an UUID of the
171 /// specified version and variant. For generating UUID's with
172 /// thread and process ids use variant=0xc0
173 void generate_UUID (UUID
&, ACE_UINT16 version
=0x0001, u_char variant
=0x80);
175 /// Format timestamp, clockseq, and nodeID into a VI UUID. For
176 /// generating UUID's with thread and process ids use variant=0xc0
177 UUID
* generate_UUID (ACE_UINT16 version
=0x0001, u_char variant
=0x80);
179 /// Type to represent UTC as a count of 100 nanosecond intervals
180 /// since 00:00:00.00, 15 October 1582.
181 typedef ACE_UINT64 UUID_Time
;
183 /// The locking strategy prevents multiple generators from accessing
184 /// the UUID_state at the same time. Get the locking strategy.
185 ACE_SYNCH_MUTEX
* lock (void);
187 /// Set a new locking strategy and return the old one.
188 void lock (ACE_SYNCH_MUTEX
* lock
,
193 /// The system time when that last uuid was generated.
194 UUID_Time time_last_
;
196 /// Type to contain the UUID generator persistent state. This will
197 /// be kept in memory mapped shared memory
202 ACE_UINT16 clock_sequence
;
205 /// Obtain a UUID timestamp. Compensate for the fact that the time
206 /// obtained from getSystem time has a resolution less than 100ns.
207 void get_timestamp (UUID_Time
& timestamp
);
209 /// Obtain a UUID timestamp and clock sequence. Compensate for the
210 /// fact that the time obtained from getSystem time has a
211 /// resolution less than 100ns.
212 void get_timestamp_and_clocksequence (UUID_Time
& timestamp
,
213 ACE_UINT16
& clockSequence
);
215 /// Obtain the system time in UTC as a count of 100 nanosecond intervals
216 /// since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to
217 /// the Christian calendar).
218 void get_systemtime( UUID_Time
& timeNow
);
220 /// The UUID generator persistent state.
221 UUID_State uuid_state_
;
223 ACE_SYNCH_MUTEX
* lock_
;
227 typedef ACE_Singleton
<UUID_Generator
, ACE_SYNCH_MUTEX
> UUID_GENERATOR
;
231 ACE_END_VERSIONED_NAMESPACE_DECL
233 #if defined (__ACE_INLINE__)
234 #include "ace/UUID.inl"
235 #endif /* __ACE_INLINE__ */
237 #include /**/ "ace/post.h"