Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef ACE_UUID_H
00015 #define ACE_UUID_H
00016 #include "ace/pre.h"
00017
00018 #include "ace/config-all.h"
00019
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif
00023
00024 #include "ace/Auto_Ptr.h"
00025 #include "ace/SString.h"
00026 #include "ace/Singleton.h"
00027 #include "ace/Synch_Traits.h"
00028
00029 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00030
00031 namespace ACE_Utils
00032 {
00033
00034
00035
00036
00037
00038 class ACE_Export UUID_Node
00039 {
00040 public:
00041
00042 enum {NODE_ID_SIZE = 6};
00043
00044
00045 typedef u_char Node_ID[NODE_ID_SIZE];
00046
00047
00048 Node_ID & node_ID (void);
00049
00050
00051
00052
00053 const Node_ID & node_ID (void) const;
00054
00055
00056 bool operator == (const UUID_Node & right) const;
00057
00058
00059 bool operator != (const UUID_Node & right) const;
00060
00061 private:
00062
00063 Node_ID node_ID_;
00064 };
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 class ACE_Export UUID
00085 {
00086 public:
00087
00088 enum { BINARY_SIZE = 16 };
00089
00090
00091 UUID (void);
00092
00093
00094 UUID (const ACE_CString& uuidString);
00095
00096 UUID (const UUID &right);
00097
00098
00099 ~UUID (void);
00100
00101 ACE_UINT32 time_low (void) const;
00102 void time_low (ACE_UINT32);
00103
00104 ACE_UINT16 time_mid (void) const;
00105 void time_mid (ACE_UINT16);
00106
00107 ACE_UINT16 time_hi_and_version (void) const;
00108 void time_hi_and_version (ACE_UINT16);
00109
00110 u_char clock_seq_hi_and_reserved (void) const;
00111 void clock_seq_hi_and_reserved (u_char);
00112
00113 u_char clock_seq_low (void) const;
00114 void clock_seq_low (u_char);
00115
00116 UUID_Node & node (void);
00117 const UUID_Node & node (void) const;
00118
00119 void node (const UUID_Node & node);
00120
00121 ACE_CString* thr_id (void);
00122 void thr_id (char*);
00123
00124 ACE_CString* pid (void);
00125 void pid (char*);
00126
00127
00128 const ACE_CString* to_string (void) const;
00129
00130
00131 void from_string (const ACE_CString& uuid_string);
00132
00133
00134 static const UUID NIL_UUID;
00135
00136
00137 bool operator == (const UUID &right) const;
00138 bool operator != (const UUID &right) const;
00139
00140
00141 unsigned long hash (void) const;
00142
00143
00144 const UUID & operator = (const UUID & rhs);
00145
00146 private:
00147
00148 void init (void);
00149
00150
00151
00152
00153
00154
00155 void from_string_i (const ACE_CString& uuid_string);
00156
00157
00158 struct data
00159 {
00160
00161 ACE_UINT32 time_low_;
00162
00163
00164 ACE_UINT16 time_mid_;
00165
00166
00167 ACE_UINT16 time_hi_and_version_;
00168
00169
00170 u_char clock_seq_hi_and_reserved_;
00171
00172
00173 u_char clock_seq_low_;
00174
00175
00176 UUID_Node node_;
00177 } uuid_;
00178
00179 ACE_CString thr_id_;
00180 ACE_CString pid_;
00181
00182
00183
00184 mutable ACE_Auto_Ptr <ACE_CString> as_string_;
00185 };
00186
00187
00188
00189
00190
00191
00192
00193 class ACE_Export UUID_Generator
00194 {
00195 public:
00196
00197 enum {ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF};
00198
00199
00200 UUID_Generator(void);
00201
00202
00203 ~UUID_Generator();
00204
00205
00206
00207 void init (void);
00208
00209
00210
00211
00212 void generate_UUID (UUID&, ACE_UINT16 version=0x0001, u_char variant=0x80);
00213
00214
00215
00216 UUID* generate_UUID (ACE_UINT16 version=0x0001, u_char variant=0x80);
00217
00218
00219
00220 typedef ACE_UINT64 UUID_Time;
00221
00222
00223
00224 ACE_SYNCH_MUTEX* lock (void);
00225
00226
00227 void lock (ACE_SYNCH_MUTEX* lock, bool release_lock);
00228
00229 private:
00230
00231 UUID_Time time_last_;
00232
00233
00234
00235 struct UUID_State
00236 {
00237 UUID_Time timestamp;
00238 UUID_Node node;
00239 ACE_UINT16 clock_sequence;
00240 };
00241
00242
00243
00244 void get_timestamp (UUID_Time& timestamp);
00245
00246
00247
00248
00249 void get_timestamp_and_clocksequence (UUID_Time& timestamp,
00250 ACE_UINT16& clockSequence);
00251
00252
00253
00254
00255 void get_systemtime( UUID_Time& timeNow);
00256
00257
00258 UUID_State uuid_state_;
00259
00260 ACE_SYNCH_MUTEX* lock_;
00261
00262 bool destroy_lock_;
00263
00264
00265 bool is_init_;
00266 };
00267
00268 typedef ACE_Singleton <ACE_Utils::UUID_Generator, ACE_SYNCH_MUTEX>
00269 UUID_GENERATOR;
00270 }
00271
00272 ACE_SINGLETON_DECLARE (ACE_Singleton, ACE_Utils::UUID_Generator, ACE_SYNCH_MUTEX)
00273
00274 ACE_END_VERSIONED_NAMESPACE_DECL
00275
00276 #if defined (__ACE_INLINE__)
00277 #include "ace/UUID.inl"
00278 #endif
00279
00280 #include "ace/post.h"
00281 #endif // ACE_UUID_H
00282