#include <UUID.h>
Collaboration diagram for ACE_Utils::UUID_Generator:
Public Types | |
typedef ACE_UINT64 | UUID_time |
enum | { ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF } |
Public Member Functions | |
UUID_Generator () | |
~UUID_Generator () | |
void | init (void) |
void | generateUUID (UUID &, ACE_UINT16 version=0x0001, u_char variant=0x80) |
UUID * | generateUUID (ACE_UINT16 version=0x0001, u_char variant=0x80) |
ACE_SYNCH_MUTEX * | lock (void) |
void | lock (ACE_SYNCH_MUTEX *lock, bool release_lock) |
Set a new locking strategy and return the old one. | |
Private Member Functions | |
void | get_timestamp (UUID_time ×tamp) |
void | get_systemtime (UUID_time &timeNow) |
the Christian calendar). | |
Private Attributes | |
UUID_time | timeLast_ |
The system time when that last uuid was generated. | |
UUID_State | uuid_state_ |
The UUID generator persistent state. | |
ACE_SYNCH_MUTEX * | lock_ |
bool | destroy_lock_ |
|
Type to represent UTC as a count of 100 nanosecond intervals since 00:00:00.00, 15 October 1582. Definition at line 184 of file UUID.h. Referenced by generateUUID(), get_systemtime(), and get_timestamp(). |
|
Definition at line 166 of file UUID.h.
00166 {ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF}; |
|
Definition at line 349 of file UUID.cpp. References ACE_NEW, and ACE_SYNCH_MUTEX.
00350 : timeLast_ (0), 00351 destroy_lock_ (true) 00352 { 00353 ACE_NEW (lock_, 00354 ACE_SYNCH_MUTEX); 00355 } |
|
Definition at line 357 of file UUID.cpp. References destroy_lock_.
00358 { 00359 if (destroy_lock_) 00360 delete lock_; 00361 } |
|
Format timestamp, clockseq, and nodeID into a VI UUID. For generating UUID's with thread and process ids use variant=0xc0 Definition at line 448 of file UUID.cpp. References ACE_NEW_RETURN, and generateUUID().
00449 { 00450 UUID* uuid; 00451 ACE_NEW_RETURN (uuid, 00452 UUID, 00453 0); 00454 00455 this->generateUUID (*uuid, version, variant); 00456 return uuid; 00457 } |
|
Format timestamp, clockseq, and nodeID into an UUID of the specified version and variant. For generating UUID's with thread and process ids use variant=0xc0 Definition at line 406 of file UUID.cpp. References ACE_GUARD, ACE_SYNCH_MUTEX, ACE_Utils::UUID::clockSeqHiAndReserved(), ACE_Utils::UUID::clockSeqLow(), ACE_Utils::UUID_Generator::UUID_State::clockSequence, get_timestamp(), ACE_Utils::UUID_Generator::UUID_State::node, ACE_Utils::UUID::node(), ACE_Utils::UUID::pid(), ACE_OS::sprintf(), ACE_Utils::UUID::thr_id(), ACE_Utils::UUID::timeHiAndVersion(), ACE_Utils::UUID::timeLow(), ACE_Utils::UUID::timeMid(), ACE_Utils::UUID_Generator::UUID_State::timestamp, ACE_Thread_ID::to_string(), uuid_state_, and UUID_time. Referenced by generateUUID().
00407 { 00408 UUID_time timestamp; 00409 this->get_timestamp (timestamp); 00410 00411 00412 // Construct a Version 1 UUID with the information in the arguements. 00413 uuid.timeLow (static_cast<ACE_UINT32> (timestamp & 0xFFFFFFFF)); 00414 uuid.timeMid (static_cast<ACE_UINT16> ((timestamp >> 32) & 0xFFFF)); 00415 00416 00417 ACE_UINT16 tHAV = static_cast<ACE_UINT16> ((timestamp >> 48) & 0xFFFF); 00418 tHAV |= (version << 12); 00419 uuid.timeHiAndVersion (tHAV); 00420 00421 u_char cseqHAV; 00422 { 00423 ACE_GUARD (ACE_SYNCH_MUTEX, mon, *lock_); 00424 uuid.clockSeqLow (static_cast<u_char> (uuid_state_.clockSequence & 0xFF)); 00425 cseqHAV = static_cast<u_char> ((uuid_state_.clockSequence & 0x3f00) >> 8); 00426 uuid_state_.timestamp = timestamp; 00427 } 00428 00429 cseqHAV |= variant; 00430 uuid.clockSeqHiAndReserved (cseqHAV); 00431 uuid.node (&(uuid_state_.node)); 00432 00433 if (variant == 0xc0) 00434 { 00435 ACE_Thread_ID thread_id; 00436 char buf [BUFSIZ]; 00437 thread_id.to_string (buf); 00438 uuid.thr_id (buf); 00439 00440 ACE_OS::sprintf (buf, 00441 "%d", 00442 static_cast<int> (ACE_OS::getpid ())); 00443 uuid.pid (buf); 00444 } 00445 } |
|
the Christian calendar). Obtain the system time in UTC as a count of 100 nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to Definition at line 493 of file UUID.cpp. References ACE_INT64_LITERAL, ACE_UINT64, ACE_UINT64_LITERAL, ACE_OS::gettimeofday(), ACE_Time_Value::to_usec(), and UUID_time. Referenced by get_timestamp().
00494 { 00495 const UUID_time timeOffset = 00496 #if defined (ACE_LACKS_UNSIGNEDLONGLONG_T) 00497 ACE_U_LongLong (ACE_INT64_LITERAL (0x1B21DD213814000)); 00498 #elif defined (ACE_LACKS_LONGLONG_T) 00499 ACE_U_LongLong (0x13814000u, 0x1B21DD2u); 00500 #else 00501 ACE_UINT64_LITERAL (0x1B21DD213814000); 00502 #endif /* ACE_LACKS_UNSIGNEDLONGLONG_T */ 00503 00504 /// Get the time of day, convert to 100ns ticks then add the offset. 00505 ACE_Time_Value now = ACE_OS::gettimeofday(); 00506 ACE_UINT64 time; 00507 now.to_usec (time); 00508 time = time * 10; 00509 timestamp = time + timeOffset; 00510 } |
|
Obtain a UUID timestamp. Compensate for the fact that the time obtained from getSystem time has a resolution less than 100ns. Definition at line 462 of file UUID.cpp. References ACE_GUARD, ACE_SYNCH_MUTEX, ACE_UUID_CLOCK_SEQ_MASK, ACE_Utils::UUID_Generator::UUID_State::clockSequence, get_systemtime(), timeLast_, uuid_state_, and UUID_time. Referenced by generateUUID(), and init().
00463 { 00464 ACE_GUARD (ACE_SYNCH_MUTEX, mon, *lock_); 00465 00466 this->get_systemtime(timestamp); 00467 00468 // Account for the clock being set back. Increment the clock / 00469 // sequence. 00470 if (timestamp <= timeLast_) 00471 uuid_state_.clockSequence = static_cast<u_char> ((uuid_state_.clockSequence + 1) & ACE_UUID_CLOCK_SEQ_MASK); 00472 00473 // If the system time ticked since the last UUID was 00474 // generated. Set / the clock sequence back. 00475 else if (timestamp > timeLast_) 00476 uuid_state_.clockSequence = 0; 00477 00478 timeLast_ = timestamp; 00479 } |
|
Definition at line 364 of file UUID.cpp. References ACE_GUARD, ACE_SYNCH_MUTEX, get_timestamp(), ACE_OS::getmacaddress(), ACE_OS::memcpy(), ACE_Utils::UUID_Generator::UUID_State::node, ACE_OS::macaddr_node_t::node, ACE_Utils::UUID_node::nodeID(), ACE_Utils::UUID_node::NodeID, ACE_OS::rand(), timeLast_, ACE_Utils::UUID_Generator::UUID_State::timestamp, and uuid_state_.
00365 { 00366 ACE_OS::macaddr_node_t macaddress; 00367 int result = ACE_OS::getmacaddress (&macaddress); 00368 00369 UUID_node::NodeID nodeID; 00370 if (result != -1) 00371 { 00372 // ACE_DEBUG ((LM_DEBUG, 00373 // "%02X-%02X-%02X-%02X-%02X-%02X\n", 00374 // macaddress.node [0], 00375 // macaddress.node [1], 00376 // macaddress.node [2], 00377 // macaddress.node [3], 00378 // macaddress.node [4], 00379 // macaddress.node [5])); 00380 00381 ACE_OS::memcpy (&nodeID, 00382 macaddress.node, 00383 sizeof (nodeID)); 00384 } 00385 else 00386 { 00387 nodeID [0] = static_cast<u_char> (ACE_OS::rand()); 00388 nodeID [1] = static_cast<u_char> (ACE_OS::rand()); 00389 nodeID [2] = static_cast<u_char> (ACE_OS::rand()); 00390 nodeID [3] = static_cast<u_char> (ACE_OS::rand()); 00391 nodeID [4] = static_cast<u_char> (ACE_OS::rand()); 00392 nodeID [5] = static_cast<u_char> (ACE_OS::rand()); 00393 } 00394 00395 this->get_timestamp (timeLast_); 00396 00397 { 00398 ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, *lock_); 00399 uuid_state_.timestamp = timeLast_; 00400 uuid_state_.node.nodeID (nodeID); 00401 } 00402 } |
|
Set a new locking strategy and return the old one.
Definition at line 519 of file UUID.cpp. References destroy_lock_.
00521 { 00522 if (this->destroy_lock_) 00523 delete this->lock_; 00524 00525 this->lock_ = lock; 00526 this->destroy_lock_ = release_lock; 00527 } |
|
The locking strategy prevents multiple generators from accessing the UUID_state at the same time. Get the locking strategy. Definition at line 513 of file UUID.cpp.
00514 { 00515 return this->lock_; 00516 } |
|
Definition at line 221 of file UUID.h. Referenced by lock(), and ~UUID_Generator(). |
|
|
|
The system time when that last uuid was generated.
Definition at line 197 of file UUID.h. Referenced by get_timestamp(), and init(). |
|
The UUID generator persistent state.
Definition at line 218 of file UUID.h. Referenced by generateUUID(), get_timestamp(), and init(). |