diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2006-08-21 10:46:22 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2006-08-21 10:46:22 +0000 |
commit | b26cb3b8ff2017629f0982951036c8d3c90bf96d (patch) | |
tree | 383e4698acdfc1876f8c6cd070940c9e12c16153 /ACE | |
parent | 4e078b75c71935355a93f7d974bc7908617c3ba9 (diff) | |
download | ATCD-b26cb3b8ff2017629f0982951036c8d3c90bf96d.tar.gz |
Mon Aug 21 10:45:12 UTC 2006 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'ACE')
-rw-r--r-- | ACE/ChangeLog | 6 | ||||
-rw-r--r-- | ACE/ace/UUID.cpp | 176 | ||||
-rw-r--r-- | ACE/ace/UUID.h | 10 | ||||
-rw-r--r-- | ACE/ace/UUID.inl | 6 |
4 files changed, 110 insertions, 88 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index fb37912babe..570f6ca5ffa 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,9 @@ +Mon Aug 21 10:45:12 UTC 2006 Johnny Willemsen <jwillemsen@remedy.nl> + + * ace/UUID.{h,cpp,inl}: + Extended UUID to make it possible to assign a string to a UUID + to set it a new value. + Mon Aug 21 10:26:12 UTC 2006 Johnny Willemsen <jwillemsen@remedy.nl> * ace/UUID.{h,cpp,inl}: diff --git a/ACE/ace/UUID.cpp b/ACE/ace/UUID.cpp index 834c60e684e..bbd01437437 100644 --- a/ACE/ace/UUID.cpp +++ b/ACE/ace/UUID.cpp @@ -80,10 +80,91 @@ namespace ACE_Utils ACE_NEW (node_, UUID_node); + this->from_string_i (uuid_string); + } + + UUID::~UUID (void) + { + if (node_release_) + delete node_; + + if (as_string_ != 0) + delete as_string_; + } + + const ACE_CString* + UUID::to_string (void) + { + /// Only compute the string representation once. + if (as_string_ == 0) + { + // Get a buffer exactly the correct size. Use the nil UUID as a + // gauge. Don't forget the trailing nul. + size_t UUID_STRING_LENGTH = 36 + thr_id_.length () + pid_.length (); + char *buf; + + if ((thr_id_.length () != 0) && (pid_.length () != 0)) + { + UUID_STRING_LENGTH += 2; //for '-' + ACE_NEW_RETURN (buf, + char[UUID_STRING_LENGTH + 1], + 0); + + ACE_OS::sprintf(buf, + "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x-%s-%s", + this->timeLow_, + this->timeMid_, + this->timeHiAndVersion_, + this->clockSeqHiAndReserved_, + this->clockSeqLow_, + (this->node_->nodeID ()) [0], + (this->node_->nodeID ()) [1], + (this->node_->nodeID ()) [2], + (this->node_->nodeID ()) [3], + (this->node_->nodeID ()) [4], + (this->node_->nodeID ()) [5], + thr_id_.c_str (), + pid_.c_str () + ); + } + else + { + ACE_NEW_RETURN (buf, + char[UUID_STRING_LENGTH + 1], + 0); + + ACE_OS::sprintf (buf, + "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", + this->timeLow_, + this->timeMid_, + this->timeHiAndVersion_, + this->clockSeqHiAndReserved_, + this->clockSeqLow_, + (this->node_->nodeID ()) [0], + (this->node_->nodeID ()) [1], + (this->node_->nodeID ()) [2], + (this->node_->nodeID ()) [3], + (this->node_->nodeID ()) [4], + (this->node_->nodeID ()) [5] + ); + } + + ACE_NEW_RETURN (this->as_string_, + ACE_CString (buf, UUID_STRING_LENGTH), + 0); + delete [] buf; + } + + return as_string_; + } + + void + UUID::from_string_i (const ACE_CString& uuid_string) + { if (uuid_string.length() < NIL_UUID.to_string ()->length ()) { ACE_ERROR ((LM_ERROR, - "%N ACE_UUID::UUID - " + "%N ACE_UUID::from_string_i - " "IllegalArgument(incorrect string length)\n")); return; } @@ -132,7 +213,7 @@ namespace ACE_Utils if (nScanned != 11) { ACE_DEBUG ((LM_DEBUG, - "UUID::UUID - " + "UUID::from_string_i - " "IllegalArgument(invalid string representation)\n")); return; } @@ -159,7 +240,7 @@ namespace ACE_Utils if (nScanned != 12) { ACE_DEBUG ((LM_DEBUG, - "ACE_UUID::ACE_UUID - " + "ACE_UUID::from_string_i - " "IllegalArgument(invalid string representation)\n")); return; } @@ -181,7 +262,7 @@ namespace ACE_Utils if ((this->clockSeqHiAndReserved_ & 0xc0) != 0x80 && (this->clockSeqHiAndReserved_ & 0xc0) != 0xc0) { ACE_DEBUG ((LM_DEBUG, - "ACE_UUID_Impl::ACE_UUID_Impl - " + "ACE_UUID::from_string_i - " "IllegalArgument(unsupported variant)\n")); return; } @@ -194,7 +275,7 @@ namespace ACE_Utils (V1 & 0xF000) != 0x4000) { ACE_DEBUG ((LM_DEBUG, - "ACE_UUID::ACE_UUID - " + "ACE_UUID::from_string_i - " "IllegalArgument(unsupported version)\n")); return; } @@ -203,7 +284,7 @@ namespace ACE_Utils if (uuid_string.length() == NIL_UUID.to_string()->length()) { ACE_DEBUG ((LM_DEBUG, - "ACE_UUID::ACE_UUID - " + "ACE_UUID::from_string_i - " "IllegalArgument (Missing Thread and Process Id)\n")); return; } @@ -211,7 +292,7 @@ namespace ACE_Utils ssize_t pos = thr_pid_str.find ('-'); if (pos == -1) ACE_DEBUG ((LM_DEBUG, - "ACE_UUID::ACE_UUID - " + "ACE_UUID::from_string_i - " "IllegalArgument (Thread and Process Id format incorrect)\n")); this->thr_id_ = thr_pid_str.substr (0, pos); @@ -219,87 +300,12 @@ namespace ACE_Utils } } - UUID::~UUID (void) - { - if (node_release_) - delete node_; - - if (as_string_ != 0) - delete as_string_; - } - - const ACE_CString* - UUID::to_string (void) - { - /// Only compute the string representation once. - if (as_string_ == 0) - { - // Get a buffer exactly the correct size. Use the nil UUID as a - // gauge. Don't forget the trailing nul. - size_t UUID_STRING_LENGTH = 36 + thr_id_.length () + pid_.length (); - char *buf; - - if ((thr_id_.length () != 0) && (pid_.length () != 0)) - { - UUID_STRING_LENGTH += 2; //for '-' - ACE_NEW_RETURN (buf, - char[UUID_STRING_LENGTH + 1], - 0); - - ACE_OS::sprintf(buf, - "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x-%s-%s", - this->timeLow_, - this->timeMid_, - this->timeHiAndVersion_, - this->clockSeqHiAndReserved_, - this->clockSeqLow_, - (this->node_->nodeID ()) [0], - (this->node_->nodeID ()) [1], - (this->node_->nodeID ()) [2], - (this->node_->nodeID ()) [3], - (this->node_->nodeID ()) [4], - (this->node_->nodeID ()) [5], - thr_id_.c_str (), - pid_.c_str () - ); - } - else - { - ACE_NEW_RETURN (buf, - char[UUID_STRING_LENGTH + 1], - 0); - - ACE_OS::sprintf (buf, - "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", - this->timeLow_, - this->timeMid_, - this->timeHiAndVersion_, - this->clockSeqHiAndReserved_, - this->clockSeqLow_, - (this->node_->nodeID ()) [0], - (this->node_->nodeID ()) [1], - (this->node_->nodeID ()) [2], - (this->node_->nodeID ()) [3], - (this->node_->nodeID ()) [4], - (this->node_->nodeID ()) [5] - ); - } - - ACE_NEW_RETURN (this->as_string_, - ACE_CString (buf, UUID_STRING_LENGTH), - 0); - delete [] buf; - } - - return as_string_; - } - UUID_Generator::UUID_Generator () - : timeLast_ (0) + : timeLast_ (0), + destroy_lock_ (true) { ACE_NEW (lock_, ACE_SYNCH_MUTEX); - destroy_lock_ = 1; } UUID_Generator::~UUID_Generator() @@ -459,7 +465,7 @@ namespace ACE_Utils ACE_SYNCH_MUTEX* UUID_Generator::lock (ACE_SYNCH_MUTEX* lock, - int release_lock_) + bool release_lock_) { if (destroy_lock_) delete lock_; diff --git a/ACE/ace/UUID.h b/ACE/ace/UUID.h index ac0233b12ba..bc7eda72b6c 100644 --- a/ACE/ace/UUID.h +++ b/ACE/ace/UUID.h @@ -114,6 +114,9 @@ namespace ACE_Utils /// Returns a string representation of the UUID const ACE_CString* to_string (void); + /// Set the value using a string + void from_string (const ACE_CString& uuid_string); + static UUID NIL_UUID; /// Equality Operations @@ -127,6 +130,8 @@ namespace ACE_Utils //bool operator>= (const UUID &right) const; private: + void from_string_i (const ACE_CString& uuidString); + // Copy constructor and assignment operator were not implemented // correctly, so I removed their implementation as an easy solution. UUID (const UUID&); @@ -185,8 +190,7 @@ namespace ACE_Utils /// Set a new locking strategy and return the old one. ACE_SYNCH_MUTEX* lock (ACE_SYNCH_MUTEX*lock, - int release_lock); - + bool release_lock); private: @@ -215,7 +219,7 @@ namespace ACE_Utils UUID_State uuid_state_; ACE_SYNCH_MUTEX* lock_; - int destroy_lock_; + bool destroy_lock_; }; typedef ACE_Singleton<UUID_Generator, ACE_SYNCH_MUTEX> UUID_GENERATOR; diff --git a/ACE/ace/UUID.inl b/ACE/ace/UUID.inl index ad32012ecb4..d251facb3bd 100644 --- a/ACE/ace/UUID.inl +++ b/ACE/ace/UUID.inl @@ -108,6 +108,12 @@ namespace ACE_Utils this->pid_ = pid; } + ACE_INLINE void + UUID::from_string (const ACE_CString& uuidString) + { + this->from_string_i (uuidString); + } + //ACE_INLINE bool //UUID::operator == (const UUID &right) const //{ |