#include <UUID.h>
Collaboration diagram for ACE_Utils::UUID_Generator:
Public Types | |
typedef ACE_UINT64 | UUID_Time |
ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF | |
enum | { ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF } |
Public Member Functions | |
UUID_Generator () | |
~UUID_Generator () | |
void | init (void) |
void | generate_UUID (UUID &, ACE_UINT16 version=0x0001, u_char variant=0x80) |
UUID * | generate_UUID (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_timestamp_and_clocksequence (UUID_Time ×tamp, ACE_UINT16 &clockSequence) |
void | get_systemtime (UUID_Time &timeNow) |
the Christian calendar). | |
Private Attributes | |
UUID_Time | time_last_ |
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_ |
Classes | |
struct | UUID_State |
Definition at line 159 of file UUID.h.
anonymous enum |
ACE_Utils::UUID_Generator::UUID_Generator | ( | ) |
Definition at line 343 of file UUID.cpp.
References ACE_NEW, ACE_SYNCH_MUTEX, and lock_.
00344 : time_last_ (0), 00345 destroy_lock_ (true) 00346 { 00347 ACE_NEW (lock_, 00348 ACE_SYNCH_MUTEX); 00349 }
ACE_Utils::UUID_Generator::~UUID_Generator | ( | ) |
Definition at line 351 of file UUID.cpp.
References destroy_lock_, and lock_.
00352 { 00353 if (destroy_lock_) 00354 delete lock_; 00355 }
UUID * ACE_Utils::UUID_Generator::generate_UUID | ( | ACE_UINT16 | version = 0x0001 , |
|
u_char | variant = 0x80 | |||
) |
Format timestamp, clockseq, and nodeID into a VI UUID. For generating UUID's with thread and process ids use variant=0xc0
Definition at line 440 of file UUID.cpp.
References ACE_NEW_RETURN, and generate_UUID().
00441 { 00442 UUID* uuid; 00443 ACE_NEW_RETURN (uuid, 00444 UUID, 00445 0); 00446 00447 this->generate_UUID (*uuid, version, variant); 00448 return uuid; 00449 }
void ACE_Utils::UUID_Generator::generate_UUID | ( | UUID & | , | |
ACE_UINT16 | version = 0x0001 , |
|||
u_char | variant = 0x80 | |||
) |
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 399 of file UUID.cpp.
References ACE_Utils::UUID::clock_seq_hi_and_reserved(), ACE_Utils::UUID::clock_seq_low(), get_timestamp_and_clocksequence(), ACE_OS::getpid(), 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::time_hi_and_version(), ACE_Utils::UUID::time_low(), ACE_Utils::UUID::time_mid(), ACE_Utils::UUID_Generator::UUID_State::timestamp, ACE::timestamp(), ACE_Thread_ID::to_string(), and uuid_state_.
Referenced by generate_UUID().
00401 { 00402 UUID_Time timestamp; 00403 ACE_UINT16 clock_sequence; 00404 00405 this->get_timestamp_and_clocksequence (timestamp, 00406 clock_sequence); 00407 00408 // Construct a Version 1 UUID with the information in the arguements. 00409 uuid.time_low (static_cast<ACE_UINT32> (timestamp & 0xFFFFFFFF)); 00410 uuid.time_mid (static_cast<ACE_UINT16> ((timestamp >> 32) & 0xFFFF)); 00411 00412 ACE_UINT16 tHAV = static_cast<ACE_UINT16> ((timestamp >> 48) & 0xFFFF); 00413 tHAV |= (version << 12); 00414 uuid.time_hi_and_version (tHAV); 00415 00416 u_char cseqHAV; 00417 uuid.clock_seq_low (static_cast<u_char> (clock_sequence & 0xFF)); 00418 cseqHAV = static_cast<u_char> ((clock_sequence & 0x3f00) >> 8); 00419 uuid_state_.timestamp = timestamp; 00420 00421 cseqHAV |= variant; 00422 uuid.clock_seq_hi_and_reserved (cseqHAV); 00423 uuid.node (& (uuid_state_.node)); 00424 00425 if (variant == 0xc0) 00426 { 00427 ACE_Thread_ID thread_id; 00428 char buf [BUFSIZ]; 00429 thread_id.to_string (buf); 00430 uuid.thr_id (buf); 00431 00432 ACE_OS::sprintf (buf, 00433 "%d", 00434 static_cast<int> (ACE_OS::getpid ())); 00435 uuid.pid (buf); 00436 } 00437 }
void ACE_Utils::UUID_Generator::get_systemtime | ( | UUID_Time & | timeNow | ) | [private] |
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
Get the time of day, convert to 100ns ticks then add the offset.
Definition at line 511 of file UUID.cpp.
References ACE_INT64_LITERAL, ACE_UINT64_LITERAL, ACE_OS::gettimeofday(), ACE_OS::time(), and ACE_Time_Value::to_usec().
Referenced by get_timestamp(), and get_timestamp_and_clocksequence().
00512 { 00513 const UUID_Time timeOffset = 00514 #if defined (ACE_LACKS_UNSIGNEDLONGLONG_T) 00515 ACE_U_LongLong (ACE_INT64_LITERAL (0x1B21DD213814000)); 00516 #elif defined (ACE_LACKS_LONGLONG_T) 00517 ACE_U_LongLong (0x13814000u, 0x1B21DD2u); 00518 #else 00519 ACE_UINT64_LITERAL (0x1B21DD213814000); 00520 #endif /* ACE_LACKS_UNSIGNEDLONGLONG_T */ 00521 00522 /// Get the time of day, convert to 100ns ticks then add the offset. 00523 ACE_Time_Value now = ACE_OS::gettimeofday (); 00524 ACE_UINT64 time; 00525 now.to_usec (time); 00526 time = time * 10; 00527 timestamp = time + timeOffset; 00528 }
void ACE_Utils::UUID_Generator::get_timestamp | ( | UUID_Time & | timestamp | ) | [private] |
Obtain a UUID timestamp. Compensate for the fact that the time obtained from getSystem time has a resolution less than 100ns.
Definition at line 454 of file UUID.cpp.
References ACE_GUARD, ACE_SYNCH_MUTEX, ACE_UUID_CLOCK_SEQ_MASK, ACE_Utils::UUID_Generator::UUID_State::clock_sequence, get_systemtime(), lock_, time_last_, and uuid_state_.
Referenced by init().
00455 { 00456 ACE_GUARD (ACE_SYNCH_MUTEX, mon, *lock_); 00457 00458 this->get_systemtime (timestamp); 00459 00460 // Account for the clock being set back. Increment the clock / 00461 // sequence. 00462 if (timestamp <= time_last_) 00463 { 00464 uuid_state_.clock_sequence = static_cast<ACE_UINT16> 00465 ((uuid_state_.clock_sequence + 1) & ACE_UUID_CLOCK_SEQ_MASK); 00466 } 00467 // If the system time ticked since the last UUID was 00468 // generated. Set / the clock sequence back. 00469 else if (timestamp > time_last_) 00470 { 00471 uuid_state_.clock_sequence = 0; 00472 } 00473 00474 time_last_ = timestamp; 00475 }
void ACE_Utils::UUID_Generator::get_timestamp_and_clocksequence | ( | UUID_Time & | timestamp, | |
ACE_UINT16 & | clockSequence | |||
) | [private] |
Obtain a UUID timestamp and clock sequence. Compensate for the fact that the time obtained from getSystem time has a resolution less than 100ns.
Definition at line 478 of file UUID.cpp.
References ACE_GUARD, ACE_SYNCH_MUTEX, ACE_UUID_CLOCK_SEQ_MASK, ACE_Utils::UUID_Generator::UUID_State::clock_sequence, get_systemtime(), lock_, time_last_, and uuid_state_.
Referenced by generate_UUID().
00480 { 00481 ACE_GUARD (ACE_SYNCH_MUTEX, mon, *lock_); 00482 00483 this->get_systemtime (timestamp); 00484 00485 // Account for the clock being set back. Increment the clock / 00486 // sequence. 00487 if (timestamp <= time_last_) 00488 uuid_state_.clock_sequence = static_cast<ACE_UINT16> ((uuid_state_.clock_sequence + 1) & ACE_UUID_CLOCK_SEQ_MASK); 00489 00490 // If the system time ticked since the last UUID was 00491 // generated. Set / the clock sequence back. 00492 else if (timestamp > time_last_) 00493 uuid_state_.clock_sequence = 0; 00494 00495 time_last_ = timestamp; 00496 clock_sequence = uuid_state_.clock_sequence; 00497 }
void ACE_Utils::UUID_Generator::init | ( | void | ) |
Definition at line 358 of file UUID.cpp.
References ACE_GUARD, ACE_SYNCH_MUTEX, get_timestamp(), ACE_OS::getmacaddress(), lock_, ACE_OS::memcpy(), ACE_Utils::UUID_Generator::UUID_State::node, ACE_OS::macaddr_node_t::node, ACE_Utils::UUID_Node::node_ID(), ACE_OS::rand(), time_last_, ACE_Utils::UUID_Generator::UUID_State::timestamp, and uuid_state_.
00359 { 00360 ACE_OS::macaddr_node_t macaddress; 00361 int result = ACE_OS::getmacaddress (&macaddress); 00362 00363 UUID_Node::Node_ID node_id; 00364 if (result != -1) 00365 { 00366 // ACE_DEBUG ((LM_DEBUG, 00367 // "%02X-%02X-%02X-%02X-%02X-%02X\n", 00368 // macaddress.node [0], 00369 // macaddress.node [1], 00370 // macaddress.node [2], 00371 // macaddress.node [3], 00372 // macaddress.node [4], 00373 // macaddress.node [5])); 00374 00375 ACE_OS::memcpy (&node_id, 00376 macaddress.node, 00377 sizeof (node_id)); 00378 } 00379 else 00380 { 00381 node_id [0] = static_cast<u_char> (ACE_OS::rand ()); 00382 node_id [1] = static_cast<u_char> (ACE_OS::rand ()); 00383 node_id [2] = static_cast<u_char> (ACE_OS::rand ()); 00384 node_id [3] = static_cast<u_char> (ACE_OS::rand ()); 00385 node_id [4] = static_cast<u_char> (ACE_OS::rand ()); 00386 node_id [5] = static_cast<u_char> (ACE_OS::rand ()); 00387 } 00388 00389 this->get_timestamp (time_last_); 00390 00391 { 00392 ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, *lock_); 00393 uuid_state_.timestamp = time_last_; 00394 uuid_state_.node.node_ID (node_id); 00395 } 00396 }
void ACE_Utils::UUID_Generator::lock | ( | ACE_SYNCH_MUTEX * | lock, | |
bool | release_lock | |||
) |
Set a new locking strategy and return the old one.
Definition at line 537 of file UUID.cpp.
References destroy_lock_, and lock_.
00539 { 00540 if (this->destroy_lock_) 00541 delete this->lock_; 00542 00543 this->lock_ = lock; 00544 this->destroy_lock_ = release_lock; 00545 }
ACE_SYNCH_MUTEX * ACE_Utils::UUID_Generator::lock | ( | void | ) |
bool ACE_Utils::UUID_Generator::destroy_lock_ [private] |
ACE_SYNCH_MUTEX* ACE_Utils::UUID_Generator::lock_ [private] |
Definition at line 223 of file UUID.h.
Referenced by get_timestamp(), get_timestamp_and_clocksequence(), init(), lock(), UUID_Generator(), and ~UUID_Generator().
The system time when that last uuid was generated.
Definition at line 194 of file UUID.h.
Referenced by get_timestamp(), get_timestamp_and_clocksequence(), and init().
The UUID generator persistent state.
Definition at line 221 of file UUID.h.
Referenced by generate_UUID(), get_timestamp(), get_timestamp_and_clocksequence(), and init().