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/SString.h"
00025 #include "ace/Singleton.h"
00026 #include "ace/Synch_Traits.h"
00027
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029
00030 namespace ACE_Utils
00031 {
00032
00033 class ACE_Export UUID_node
00034 {
00035 public:
00036
00037
00038 UUID_node (void);
00039
00040 enum {NODE_ID_SIZE = 6};
00041 typedef u_char NodeID[NODE_ID_SIZE];
00042
00043 NodeID& nodeID (void);
00044 void nodeID (NodeID&);
00045
00046
00047
00048
00049
00050
00051
00052
00053 private:
00054 NodeID nodeID_;
00055 };
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 class ACE_Export UUID
00078 {
00079 public:
00080
00081
00082 UUID (void);
00083
00084
00085 UUID (const ACE_CString& uuidString);
00086
00087
00088 ~UUID (void);
00089
00090 ACE_UINT32 timeLow (void);
00091 void timeLow (ACE_UINT32);
00092
00093 ACE_UINT16 timeMid (void);
00094 void timeMid (ACE_UINT16);
00095
00096 ACE_UINT16 timeHiAndVersion (void);
00097 void timeHiAndVersion (ACE_UINT16);
00098
00099 u_char clockSeqHiAndReserved (void);
00100 void clockSeqHiAndReserved (u_char);
00101
00102 u_char clockSeqLow (void);
00103 void clockSeqLow (u_char);
00104
00105 UUID_node* node (void);
00106 void node (UUID_node*);
00107
00108 ACE_CString* thr_id (void);
00109 void thr_id (char*);
00110
00111 ACE_CString* pid (void);
00112 void pid (char*);
00113
00114
00115 const ACE_CString* to_string (void);
00116
00117 static UUID NIL_UUID;
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 private:
00130
00131
00132 UUID (const UUID&);
00133 UUID& operator= (const UUID&);
00134
00135
00136 ACE_UINT32 timeLow_;
00137 ACE_UINT16 timeMid_;
00138 ACE_UINT16 timeHiAndVersion_;
00139 u_char clockSeqHiAndReserved_;
00140 u_char clockSeqLow_;
00141 UUID_node* node_;
00142 int node_release_;
00143 ACE_CString thr_id_;
00144 ACE_CString pid_;
00145
00146
00147
00148 ACE_CString *as_string_;
00149 };
00150
00151
00152
00153
00154
00155
00156
00157
00158 class ACE_Export UUID_Generator
00159 {
00160 public:
00161
00162 enum {ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF};
00163
00164 UUID_Generator();
00165 ~UUID_Generator();
00166
00167 void init (void);
00168
00169
00170
00171
00172 void generateUUID (UUID&, ACE_UINT16 version=0x0001, u_char variant=0x80);
00173
00174
00175
00176 UUID* generateUUID (ACE_UINT16 version=0x0001, u_char variant=0x80);
00177
00178
00179
00180 typedef ACE_UINT64 UUID_time;
00181
00182
00183
00184 ACE_SYNCH_MUTEX* lock (void);
00185
00186
00187 ACE_SYNCH_MUTEX* lock (ACE_SYNCH_MUTEX*lock,
00188 int release_lock);
00189
00190
00191 private:
00192
00193
00194 UUID_time timeLast_;
00195
00196
00197
00198 struct UUID_State
00199 {
00200 UUID_time timestamp;
00201 UUID_node node;
00202 ACE_UINT16 clockSequence;
00203 };
00204
00205
00206
00207 void get_timestamp (UUID_time& timestamp);
00208
00209
00210
00211
00212 void get_systemtime( UUID_time& timeNow);
00213
00214
00215 UUID_State uuid_state_;
00216
00217 ACE_SYNCH_MUTEX* lock_;
00218 int destroy_lock_;
00219 };
00220
00221 typedef ACE_Singleton<UUID_Generator, ACE_SYNCH_MUTEX> UUID_GENERATOR;
00222
00223 }
00224
00225 ACE_END_VERSIONED_NAMESPACE_DECL
00226
00227 #if defined (__ACE_INLINE__)
00228 #include "ace/UUID.inl"
00229 #endif
00230
00231 #include "ace/post.h"
00232 #endif // ACE_UUID_H