summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryamuna <yamuna@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-07-02 05:35:29 +0000
committeryamuna <yamuna@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-07-02 05:35:29 +0000
commita1b28ebdf0c3d172cdcfaf6845f4fb04d1fc6f5d (patch)
tree507876b595dfd462c110e948b4bcaee9a15b167e
parent12480d7935cf06f8738f97e4bbe98b1a7e411b94 (diff)
downloadATCD-a1b28ebdf0c3d172cdcfaf6845f4fb04d1fc6f5d.tar.gz
*** empty log message ***
-rw-r--r--ace/UUID.cpp421
-rw-r--r--ace/UUID.h266
-rw-r--r--ace/UUID.i209
-rwxr-xr-xace/UUIDTest.cpp4
4 files changed, 461 insertions, 439 deletions
diff --git a/ace/UUID.cpp b/ace/UUID.cpp
index d976a55be57..6c638d729da 100644
--- a/ace/UUID.cpp
+++ b/ace/UUID.cpp
@@ -7,49 +7,71 @@
#include <rpc.h>
#include <rpcdce.h>
-#if !defined (__ACE_INLINE__)
-#include "ace/UUID.i"
-#endif /* __ACE_INLINE__ */
+UUID_node::UUID_Node (void)
+{
+ for (int i = 0; i < 6; i++)
+ {
+ nodeID_ [i] = 0;
+ }
+}
+
+UUID_node::NodeID&
+UUID_node::nodeID (void)
+{
+ return nodeID_;
+}
+
+void
+UUID_node::nodeID (NodeID& nodeID)
+{
+
+
+ nodeID_ [0] = nodeID [0];
+ nodeID_ [1] = nodeID [1];
+ nodeID_ [2] = nodeID [2];
+ nodeID_ [3] = nodeID [3];
+ nodeID_ [4] = nodeID [4];
+ nodeID_ [5] = nodeID [5];
+}
ACE_UUID ACE_UUID::NIL_UUID;
+/*
ACE_UUID::UUID_t nil_uuid_t =
{0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}};
+*/
-/**
- * Construct a nil UUID. Such a UUID has every one of it's data elements set
- * to zero. Also, since the nil UUID representation is shared by all instances
- * of nil UUID (there is just one) we can just go ahead and pre-compute the
- * string representation.
- */
+/// Construct a nil UUID. Such a UUID has every one of it's data
+/// elements set to zero.
ACE_UUID::ACE_UUID()
- : uuid_ (nil_uuid_t),
+ : timeLow_ (0),
+ timeMid_ (0),
+ timeHiAndVersion_ (0),
+ clockSeqHiAndReserved_ (0),
+ clockSeqLow_ (0),
as_string_ (0)
{
}
ACE_UUID::ACE_UUID(const ACE_UUID &right)
- : uuid_ (nil_uuid_t)
-{
- *this = right;
-}
-
-/**
- * I dont really understand why we need this constructor.
- * Maybe someone will find a use for it.
- */
-ACE_UUID::ACE_UUID (const ACE_UUID::UUID_t &uuid)
- : uuid_ (uuid),
+ : timeLow_ (0),
+ timeMid_ (0),
+ timeHiAndVersion_ (0),
+ clockSeqHiAndReserved_ (0),
+ clockSeqLow_ (0),
as_string_ (0)
{
+ *this = right;
}
-/**
- * Construct a UUID from a string representation
- * of an UUID.
- */
+/// Construct a UUID from a string representation of an UUID.
ACE_UUID::ACE_UUID (const ACE_SString& uuid_string)
- : uuid_ (nil_uuid_t)
+ : timeLow_ (0),
+ timeMid_ (0),
+ timeHiAndVersion_ (0),
+ clockSeqHiAndReserved_ (0),
+ clockSeqLow_ (0),
+ as_string_ (0)
{
ACE_TRACE ("ACE_UUID::ACE_UUID");
@@ -60,23 +82,19 @@ ACE_UUID::ACE_UUID (const ACE_SString& uuid_string)
"IllegalArgument(incorrect string length)"));
}
- // Special case for the nil UUID.
+ /// Special case for the nil UUID.
if (uuid_string == *NIL_UUID.to_string())
{
- uuid_ = NIL_UUID.uuid_;
+ *this = NIL_UUID;
return;
}
- /**
- * @note sscanf is known only to read into longs or ints so
- * we have to go through this mess.
- */
long timeLow;
int timeMid;
int timeHiAndVersion;
int clockSeqHiAndReserved;
int clockSeqLow;
- int node[ACE_UUID::UUID_node_t::NODE_ID_SIZE];
+ int node [UUID_node::NODE_ID_SIZE];
// This might seem quite strange seeing as this is ACE, but it
// seems to be a bit difficult to write a facade for ::sscanf because
@@ -96,11 +114,11 @@ ACE_UUID::ACE_UUID (const ACE_SString& uuid_string)
&node[2],
&node[3],
&node[4],
- &node[5]);
+ &node[5]
+ );
#else
- int nScanned = ::sscanf(
- uuid_string.c_str(),
+ int nScanned = ::sscanf(uuid_string.c_str(),
"%8x-%4x-%4x-%2x%2x-%2x%2x%2x%2x%2x%2x",
&timeLow,
&timeMid,
@@ -112,7 +130,8 @@ ACE_UUID::ACE_UUID (const ACE_SString& uuid_string)
&node[2],
&node[3],
&node[4],
- &node[5]);
+ &node[5]
+ );
#endif
if (nScanned != 11)
@@ -122,30 +141,34 @@ ACE_UUID::ACE_UUID (const ACE_SString& uuid_string)
"IllegalArgument(invalid string representation)"));
}
- uuid_.timeLow = ACE_static_cast (ACE_UINT32, timeLow);
- uuid_.timeMid = ACE_static_cast (ACE_UINT16, timeMid);
- uuid_.timeHiAndVersion = ACE_static_cast (ACE_UINT16, timeHiAndVersion);
- uuid_.clockSeqHiAndReserved = ACE_static_cast (u_char , clockSeqHiAndReserved);
- uuid_.clockSeqLow = ACE_static_cast (u_char , clockSeqLow);
- uuid_.node.nodeID[0] = ACE_static_cast (u_char , node[0]);
- uuid_.node.nodeID[1] = ACE_static_cast (u_char , node[1]);
- uuid_.node.nodeID[2] = ACE_static_cast (u_char , node[2]);
- uuid_.node.nodeID[3] = ACE_static_cast (u_char , node[3]);
- uuid_.node.nodeID[4] = ACE_static_cast (u_char , node[4]);
- uuid_.node.nodeID[5] = ACE_static_cast (u_char , node[5]);
+ this->timeLow_ = ACE_static_cast (ACE_UINT32, timeLow);
+ this->timeMid_ = ACE_static_cast (ACE_UINT16, timeMid);
+ this->timeHiAndVersion_ = ACE_static_cast (ACE_UINT16, timeHiAndVersion);
+ this->clockSeqHiAndReserved_ = ACE_static_cast (u_char , clockSeqHiAndReserved);
+ this->clockSeqLow_ = ACE_static_cast (u_char , clockSeqLow);
+
+ UUID_node::NodeID nodeID;
+ nodeID [0] = ACE_static_cast (u_char , node[0]);
+ nodeID [1] = ACE_static_cast (u_char , node[1]);
+ nodeID [2] = ACE_static_cast (u_char , node[2]);
+ nodeID [3] = ACE_static_cast (u_char , node[3]);
+ nodeID [4] = ACE_static_cast (u_char , node[4]);
+ nodeID [5] = ACE_static_cast (u_char , node[5]);
+
+ this->node_->nodeID (nodeID);
// Support varient 10- only
- if ((uuid_.clockSeqHiAndReserved & 0xc0) != 0x80)
+ if ((this->clockSeqHiAndReserved_ & 0xc0) != 0x80)
{
ACE_DEBUG ((LM_DEBUG,
"ACE_UUID_Impl::ACE_UUID_Impl - "
"IllegalArgument(unsupported variant)"));
}
-
- // Support versions 1, 3, and 4 only
- if (((uuid_.timeHiAndVersion & 0xF000) != 0x1000) &&
- ((uuid_.timeHiAndVersion & 0xF000) != 0x3000) &&
- ((uuid_.timeHiAndVersion & 0xF000) != 0x4000))
+
+ /// Support versions 1, 3, and 4 only
+ if (((this->timeHiAndVersion & 0xF000) != 0x1000) &&
+ ((this->timeHiAndVersion & 0xF000) != 0x3000) &&
+ ((this->timeHiAndVersion & 0xF000) != 0x4000))
{
ACE_DEBUG ((LM_DEBUG,
"ACE_UUID::ACE_UUID - "
@@ -160,41 +183,34 @@ ACE_UUID::~ACE_UUID()
const ACE_SString*
ACE_UUID::to_string (void)
{
- // Only compute the string representation once.
+ /// Only compute the string representation once.
if (as_string_ == 0)
{
- // Note. It would be nice to use ACE_SStringstream for this. But, for
- // compatability with gcc we must used std::sprintf. Fix this when all
- // supported platforms implement ACE_SStringstream.
-
// Get a buffer exactly the correct size. Use the nil UUID as a gauge.
// Don't forget the trailing nul.
- int UUID_STRING_LENGTH = 36 + uuid_.thr_id->length () + uuid_.pid->length () + 2;
- //char buf [UUID_STRING_LENGTH + 1];
+ int UUID_STRING_LENGTH = 36; ///+ uuid_.thr_id->length () + uuid_.pid->length ();
+
char *buf;
ACE_NEW_RETURN (buf,
char[UUID_STRING_LENGTH + 1],
0);
- /**
- * We know that the node id is 6 in length as we define it and so does the
- * standard.
- */
ACE_OS::sprintf(buf,
- "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%s-%s-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
- uuid_.timeLow,
- uuid_.timeMid,
- uuid_.timeHiAndVersion,
- uuid_.clockSeqHiAndReserved,
- uuid_.clockSeqLow,
- uuid_.thr_id->c_str (),
- uuid_.pid->c_str (),
- uuid_.node.nodeID[0],
- uuid_.node.nodeID[1],
- uuid_.node.nodeID[2],
- uuid_.node.nodeID[3],
- uuid_.node.nodeID[4],
- uuid_.node.nodeID[5]);
+ //"%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%s-%s-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
+ "%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_,
+ // uuid_.thr_id->c_str (),
+ // uuid_.pid->c_str (),
+ (this->node_->nodeID ()) [0],
+ (this->node_->nodeID ()) [1],
+ (this->node_->nodeID ()) [2],
+ (this->node_->nodeID ()) [3],
+ (this->node_->nodeID ()) [4],
+ (this->node_->nodeID ()) [5]);
this->as_string_ = new ACE_SString (buf, UUID_STRING_LENGTH + 1);
}
@@ -202,62 +218,24 @@ ACE_UUID::to_string (void)
return as_string_;
}
-
-// ACE_UUID_Generator*
-// ACE_UUID_Generator::instance()
-// {
-// return ACE_Singleton< ACE_UUID_Generator, ACE_SYNCH_MUTEX >::instance();
-// }
-
ACE_UUID_Generator::ACE_UUID_Generator(void)
- : timeLast(0),
+ : timeLast_ (0),
lock_ (0)
{
-
- ACE_OS::macaddr_node_t macaddress;
- int result =
- ACE_OS::getmacaddress (&macaddress);
-
- if (result != -1)
- {
- ACE_DEBUG ((LM_DEBUG,
- "%02X-%02X-%02X-%02X-%02X-%02X\n",
- macaddress.node [0],
- macaddress.node [1],
- macaddress.node [2],
- macaddress.node [3],
- macaddress.node [4],
- macaddress.node [5]));
-
- ACE_OS::memcpy (uuid_state_.node.nodeID,
- macaddress.node,
- sizeof (uuid_state_.node.nodeID));
- }
- else
- {
- // Generate random node. This is pretty bad, but until
- // ACE has a strong prng, this is what we can do.
- uuid_state_.node.nodeID[0] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[1] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[2] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[3] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[4] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[5] = static_cast<u_char>(ACE_OS::rand());
- }
-
- getTimestamp(timeLast);
- uuid_state_.timestamp = timeLast;
}
-ACE_UUID_Generator::ACE_UUID_Generator(ACE_Lock* lock)
- : timeLast(0),
- lock_ (lock)
-{
-
- ACE_OS::macaddr_node_t macaddress;
+ACE_UUID_Generator::~ACE_UUID_Generator()
+{
+}
+
+void
+ACE_UUID_Generator::init (void)
+{
+ ACE_OS::macaddr_node_t macaddress;
int result =
ACE_OS::getmacaddress (&macaddress);
-
+
+ UUID_node::NodeID nodeID;
if (result != -1)
{
ACE_DEBUG ((LM_DEBUG,
@@ -268,56 +246,86 @@ ACE_UUID_Generator::ACE_UUID_Generator(ACE_Lock* lock)
macaddress.node [3],
macaddress.node [4],
macaddress.node [5]));
-
- ACE_OS::memcpy (uuid_state_.node.nodeID,
+
+
+ ACE_OS::memcpy (&nodeID,
macaddress.node,
- sizeof (uuid_state_.node.nodeID));
+ sizeof (nodeID));
+
+
+
}
else
{
// Generate random node. This is pretty bad, but until
// ACE has a strong prng, this is what we can do.
- uuid_state_.node.nodeID[0] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[1] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[2] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[3] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[4] = static_cast<u_char>(ACE_OS::rand());
- uuid_state_.node.nodeID[5] = static_cast<u_char>(ACE_OS::rand());
+ nodeID [0] = static_cast<u_char>(ACE_OS::rand());
+ nodeID [1] = static_cast<u_char>(ACE_OS::rand());
+ nodeID [2] = static_cast<u_char>(ACE_OS::rand());
+ nodeID [3] = static_cast<u_char>(ACE_OS::rand());
+ nodeID [4] = static_cast<u_char>(ACE_OS::rand());
+ nodeID [5] = static_cast<u_char>(ACE_OS::rand());
}
+
+ uuid_state_.node.nodeID (nodeID);
+
+
+ ACE_DEBUG ((LM_DEBUG,
+ "%02X-%02X-%02X-%02X-%02X-%02X\n",
+ (uuid_state_.node.nodeID ()) [0],
+ (uuid_state_.node.nodeID ()) [1],
+ (uuid_state_.node.nodeID ()) [2],
+ (uuid_state_.node.nodeID ()) [3],
+ (uuid_state_.node.nodeID ()) [4],
+ (uuid_state_.node.nodeID ()) [5]));
if (lock_ != 0)
{
ACE_GUARD (ACE_Lock, mon, *lock_);
- getTimestamp(timeLast);
- uuid_state_.timestamp = timeLast;
+ this->get_timestamp (timeLast_);
+ uuid_state_.timestamp = timeLast_;
}
else
{
- getTimestamp(timeLast);
- uuid_state_.timestamp = timeLast;
+ this->get_timestamp (timeLast_);
+ uuid_state_.timestamp = timeLast_;
}
-}
-ACE_UUID_Generator::~ACE_UUID_Generator()
-{
}
+
void
-ACE_UUID_Generator::generateV1(ACE_UUID::UUID_t& uuid)
+ACE_UUID_Generator::generateUUID (ACE_UUID& uuid)
{
- UUID_time_t timestamp;
- getTimestamp(timestamp);
+ UUID_time timestamp;
+ this->get_timestamp (timestamp);
// Construct a Version 1 UUID with the information in the arguements.
- uuid.timeLow = ACE_static_cast (ACE_UINT32, timestamp & 0xFFFFFFFF);
- uuid.timeMid = ACE_static_cast(ACE_UINT16, (timestamp >> 32) & 0xFFFF);
- uuid.timeHiAndVersion = ACE_static_cast (ACE_UINT16, (timestamp >> 48) & 0xFFFF);
- uuid.timeHiAndVersion |= (1 << 12);
- uuid.clockSeqLow = uuid_state_.clockSequence & 0xFF;
- uuid.clockSeqHiAndReserved = (uuid_state_.clockSequence & 0x3f00) >> 8;
- uuid.clockSeqHiAndReserved |= 0x80;
- uuid.node = uuid_state_.node;
+ uuid.timeLow (ACE_static_cast (ACE_UINT32, timestamp & 0xFFFFFFFF));
+ uuid.timeMid (ACE_static_cast(ACE_UINT16, (timestamp >> 32) & 0xFFFF));
+
+ ACE_UINT16 tHAV = ACE_static_cast (ACE_UINT16, (timestamp >> 48) & 0xFFFF);
+ tHAV |= (1 << 12);
+ uuid.timeHiAndVersion (tHAV);
+
+ u_char cseqHAV = (uuid_state_.clockSequence & 0x3f00) >> 8;
+ cseqHAV |= 0x80;
+
+ if (lock_ != 0)
+ {
+ ACE_GUARD (ACE_Lock, mon, *lock_);
+ uuid.clockSeqLow (uuid_state_.clockSequence & 0xFF);
+ uuid.clockSeqHiAndReserved (cseqHAV);
+ }
+ else
+ {
+ uuid.clockSeqLow (uuid_state_.clockSequence & 0xFF);
+ uuid.clockSeqHiAndReserved (cseqHAV);
+ }
+
+ uuid.node (&(uuid_state_.node));
+ /*
ACE_thread_t thr_id = ACE_OS::thr_self ();
ACE_hthread_t thr_handle;
ACE_OS::thr_self (thr_handle);
@@ -332,6 +340,7 @@ ACE_UUID_Generator::generateV1(ACE_UUID::UUID_t& uuid)
ACE_static_cast (int, ACE_OS::getpid ()));
uuid.pid = new ACE_CString (buf);
+ */
if (lock_ != 0)
{
@@ -342,59 +351,27 @@ ACE_UUID_Generator::generateV1(ACE_UUID::UUID_t& uuid)
uuid_state_.timestamp = timestamp;
}
-ACE_UUID
-ACE_UUID_Generator::generateUUID ()
+ACE_UUID*
+ACE_UUID_Generator::generateUUID (void)
{
- ACE_UUID::UUID_t uuid;
- generateV1 (uuid);
- return uuid;
-}
+ ACE_UUID* uuid;
+ ACE_NEW_RETURN (uuid,
+ ACE_UUID,
+ 0);
-/*
-void
-ACE_UUID_Generator::getTimestamp( UUID_time_t& timestamp)
-{
- UUID_time_t timeNow;
-
- while (1)
- {
- get_system_time(timeNow);
-
- // If the system time ticked since the last UUID was generated
- if (timeLast != timeNow)
- {
- // reset the count of uuids generated with this clock reading
- uuidsThisTick = 0;
- timeLast = timeNow;
- break;
- }
-
- if (uuidsThisTick < UUIDS_PER_TICK)
- {
- ++uuidsThisTick;
- break;
- }
- // Otherwise, we've generated our quota of uuids this tick; spin.
- }
-
- timestamp = timeNow + uuidsThisTick;
+ this->generateUUID (*uuid);
+ return uuid;
}
-*/
-/**
- * Obtain a new timestamp. If UUID's are being generated
- * to quickly this method will 'spin' until enough time
- * has elapsed.
- */
+/// Obtain a new timestamp. If UUID's are being generated to quickly
+/// this method will 'spin' until enough time has elapsed.
void
-ACE_UUID_Generator::getTimestamp ( UUID_time_t& timestamp)
+ACE_UUID_Generator::get_timestamp (UUID_time& timestamp)
{
- this->get_system_time(timestamp);
+ this->get_systemtime(timestamp);
- /**
- * Account for the clock being set back. Increment the clock sequence.
- */
- if (timestamp <= time_last_)
+ /// Account for the clock being set back. Increment the clock sequence.
+ if (timestamp <= timeLast_)
{
if (lock_ != 0)
{
@@ -406,10 +383,9 @@ ACE_UUID_Generator::getTimestamp ( UUID_time_t& timestamp)
uuid_state_.clockSequence = (uuid_state_.clockSequence + 1) & ACE_UUID_CLOCK_SEQ_MASK;
}
}
- /**
- * If the system time ticked since the last UUID was generated. Set the clock sequence back.
- */
- else if (timestamp > time_last_)
+
+ /// If the system time ticked since the last UUID was generated. Set the clock sequence back.
+ else if (timestamp > timeLast_)
{
if (lock_ != 0)
{
@@ -422,7 +398,7 @@ ACE_UUID_Generator::getTimestamp ( UUID_time_t& timestamp)
}
}
- time_last_ = timestamp;
+ timeLast_ = timestamp;
}
/**
@@ -436,39 +412,20 @@ ACE_UUID_Generator::getTimestamp ( UUID_time_t& timestamp)
* This adds up, in days: (17+30+31+365*17+4)+(365*300+73)+(365*70+17) or
* 122192928000000000U (0x1B21DD213814000) 100 ns ticks.
*/
-/*
void
-ACE_UUID_Generator::get_system_time (UUID_time_t& timestamp)
+ACE_UUID_Generator::get_systemtime(UUID_time& timestamp)
{
- const UUID_time_t timeOffset = 0x1B21DD213814000;
+ const UUID_time timeOffset = 0x1B21DD213814000;
- // Get the time of day, convert to 100ns ticks then add the offset.
+ /// Get the time of day, convert to 100ns ticks then add the offset.
ACE_Time_Value now = ACE_OS::gettimeofday();
- UUID_time_t time = now.sec() * 10000000 + now.usec() * 10;
+ UUID_time time = now.sec() * 10000000 + now.usec() * 10;
timestamp = time + timeOffset;
}
-*/
-/**
- * ACE_Time_Value is in POSIX time, seconds since Jan 1, 1970. UUIDs use
- * time in 100ns ticks since 15 October 1582. The difference is:
- * 15 Oct 1582 - 1 Jan 1600: 17 days in Oct, 30 in Nov, 31 in Dec +
- * 17 years and 4 leap days (1584, 88, 92 and 96)
- * 1 Jan 1600 - 1 Jan 1900: 3 centuries + 73 leap days ( 25 in 17th cent.
- * and 24 each in 18th and 19th centuries)
- * 1 Jan 1900 - 1 Jan 1970: 70 years + 17 leap days.
- * This adds up, in days: (17+30+31+365*17+4)+(365*300+73)+(365*70+17) or
- * 122192928000000000U (0x1B21DD213814000) 100 ns ticks.
-*/
-void
-ACE_UUID_Generator::get_system_time(UUID_time_t& timestamp)
-{
- const UUID_time_t timeOffset = 0x1B21DD213814000;
- // Get the time of day, convert to 100ns ticks then add the offset.
- ACE_Time_Value now = ACE_OS::gettimeofday();
- UUID_time_t time = now.sec() * 10000000 + now.usec() * 10;
- timestamp = time + timeOffset;
-}
+#if !defined (__ACE_INLINE__)
+#include "ace/UUID.i"
+#endif /* __ACE_INLINE__ */
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Singleton<ACE_UUID_Generator, ACE_SYNCH_MUTEX>;
diff --git a/ace/UUID.h b/ace/UUID.h
index f972aaed8fc..78ea7b6700e 100644
--- a/ace/UUID.h
+++ b/ace/UUID.h
@@ -10,6 +10,30 @@
//typedef unsigned char Octet;
class ACE_Lock;
+/// Class to hold a MAC address
+class ACE_Export UUID_node
+{
+ public:
+
+ UUID_Node (void);
+
+ typedef enum {NODE_ID_SIZE = 6};
+ typedef u_char NodeID[NODE_ID_SIZE];
+
+ NodeID& nodeID (void);
+ void nodeID (NodeID&);
+
+ /*
+ bool operator == (const UUID_node_t& right) const;
+ bool operator != (const UUID_node_t& right) const;
+ bool operator < (const UUID_node_t& right) const;
+ */
+
+ private:
+ NodeID nodeID_;
+};
+
+
/**
* @class ACE_UUID
*
@@ -33,93 +57,87 @@ class ACE_Lock;
class ACE_Export ACE_UUID
{
public:
+
+ ACE_UUID(void);
+
+ /// Copy constructor
+ ACE_UUID(const ACE_UUID &right);
- /**
- * Type to hold a MAC address
- */
- struct UUID_node_t
- {
- typedef enum {NODE_ID_SIZE = 6};
- typedef u_char NodeID[NODE_ID_SIZE];
- bool operator == (const UUID_node_t& right) const;
- bool operator != (const UUID_node_t& right) const;
- bool operator < (const UUID_node_t& right) const;
- NodeID nodeID;
- };
+ /// Constructs a UUID from a string representation.
+ ACE_UUID (const ACE_SString& uuidString);
- struct UUID_t
- {
- // Data Members for Class Attributes
- ACE_UINT32 timeLow;
- ACE_UINT16 timeMid;
- ACE_UINT16 timeHiAndVersion;
- u_char clockSeqHiAndReserved;
- u_char clockSeqLow;
- ACE_CString* thr_id;
- ACE_CString* pid;
- UUID_node_t node;
- };
+ ~ACE_UUID(void);
- ACE_UUID(void);
+ /// Data Members for Class Attributes
+ ACE_UINT32 timeLow (void);
+ void timeLow (ACE_UINT32);
- /**
- * Copy constructor
- */
- ACE_UUID(const ACE_UUID &right);
+ ACE_UINT16 timeMid (void);
+ void timeMid (ACE_UINT16);
- /**
- * Construct a UUID based on a UUID_t
- */
- ACE_UUID (const UUID_t& newUUID);
+ ACE_UINT16 timeHiAndVersion (void);
+ void timeHiAndVersion (ACE_UINT16);
- /**
- * Constructs a UUID from a string representation.
- */
- ACE_UUID (const ACE_SString& uuidString);
+ u_char clockSeqHiAndReserved (void);
+ void clockSeqHiAndReserved (u_char);
- ~ACE_UUID(void);
+ u_char clockSeqLow (void);
+ void clockSeqLow (u_char);
+
+ UUID_node* node (void);
+ void node (UUID_node*);
+
+ /// Returns a string representation of the UUID.
+ const ACE_SString* to_string (void);
+
+ static ACE_UUID NIL_UUID;
- /**
- * Assignment Operation
- */
+ /*
+ /// Assignment Operation
ACE_UUID & operator=(const ACE_UUID &right);
- /**
- * Equality Operations
- */
+ /// Equality Operations
bool operator==(const ACE_UUID &right) const;
bool operator!=(const ACE_UUID &right) const;
- /**
- * Relational Operations
- */
+ /// Relational Operations
bool operator< (const ACE_UUID &right) const;
bool operator> (const ACE_UUID &right) const;
bool operator<=(const ACE_UUID &right) const;
bool operator>=(const ACE_UUID &right) const;
-
- /**
- * Returns a string representation of the UUID. Internally,
- * the string representation, which is contained in as
- * String, is only computed if this operation is called.
- * Once the representation is computed it can never change.
- */
- const ACE_SString* to_string (void);
-
- static ACE_UUID NIL_UUID;
-
+ */
private:
- /**
- * The string representation of the UUID. This is created
- * and updated only on demand.
- */
- //mutable ACE_SString asString;
+
+ /// Data Members for Class Attributes
+ ACE_UINT32 timeLow_;
+ ACE_UINT16 timeMid_;
+ ACE_UINT16 timeHiAndVersion_;
+ u_char clockSeqHiAndReserved_;
+ u_char clockSeqLow_;
+ UUID_node* node_;
+
+ /// The string representation of the UUID. This is created */
+ /// and updated only on demand.
ACE_SString *as_string_;
-
- // This ACE_UUID_Impl's representation of the UUID
- UUID_t uuid_;
};
+
+/* class ACE_UUID_Ext: public ACE_UUID */
+/* { */
+/* public: */
+/* ACE_UUID_Ext (void); */
+/* ~ACE_UUID_Ext (void); */
+
+/* ACE_CString* thr_id (void); */
+
+/* ACE_CString* pid (void); */
+
+/* private: */
+/* ACE_CString* thr_id_; */
+/* ACE_CString* pid_; */
+//};
+
+
/**
* @class ACE_UUID_Generator
* Singleton class that generates UUIDs.
@@ -128,98 +146,68 @@ class ACE_Export ACE_UUID_Generator
{
public:
- enum { ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF };
-
- // Format timestamp, clockseq, and nodeID into a VI UUID.
- void generateV1(ACE_UUID::UUID_t&);
+ enum {ACE_UUID_CLOCK_SEQ_MASK = 0x3FFF};
- // Format timestamp, clockseq, and nodeID into a VI UUID.
- ACE_UUID generateUUID (void);
+ void init (void);
- /**
- * Type to represent UTC as a count of 100 nanosecond intervals since
- * 00:00:00.00, 15 October 1582.
- */
- typedef ACE_UINT64 UUID_time_t;
+ /// Format timestamp, clockseq, and nodeID into a VI UUID.
+ void generateUUID(ACE_UUID&);
+
+ /// Format timestamp, clockseq, and nodeID into a VI UUID.
+ ACE_UUID* generateUUID (void);
+
+ /// Type to represent UTC as a count of 100 nanosecond intervals since
+ /// 00:00:00.00, 15 October 1582.
+ typedef ACE_UINT64 UUID_time;
ACE_UUID_Generator(void);
- ACE_UUID_Generator(ACE_Lock* lock);
~ACE_UUID_Generator();
-
- /**
- * The locking strategy prevents multiple generators
- * from accessing the UUID_state at the same time.
- * Get the locking strategy.
- */
- ACE_Lock *lock (void);
+ /// The locking strategy prevents multiple generators
+ /// from accessing the UUID_state at the same time.
+ /// Get the locking strategy.
+ ACE_Lock* lock (void);
- /**
- * Set a new locking strategy and return the hold one.
- */
- ACE_Lock *lock (ACE_Lock *lock);
+ /// Set a new locking strategy and return the hold one.
+ ACE_Lock* lock (ACE_Lock *lock);
private:
- /**
- * The maximum number of uuids that can be generated per tick of the
- * system clock. This number should be the number of 100ns ticks of the
- * actual resolution of the system's clock.
- */
- enum { UUIDS_PER_TICK = 1000 };
-
- /**
- * The number of uuids generated in this process since the last clock
- * tick. Value never exceeds uuidsPerTick - 1.
- */
- ACE_UINT32 uuidsThisTick;
-
- /**
- * The system time when that last uuid was generated.
- */
- UUID_time_t timeLast;
-
- /**
- * Type to map to contain the UUID generator persistent state. This
- * will be kept in memory mapped shared memory
- */
- struct UUID_state
+ /// The maximum number of uuids that can be generated per tick of the
+ /// system clock. This number should be the number of 100ns ticks of the
+ /// actual resolution of the system's clock.
+ enum {UUIDS_PER_TICK = 1000};
+
+ /// The number of uuids generated in this process since the last clock
+ /// tick. Value never exceeds uuidsPerTick - 1.
+ ACE_UINT32 uuidsThisTick_;
+
+ /// The system time when that last uuid was generated.
+ UUID_time timeLast_;
+
+ /// Type to map to contain the UUID generator persistent state. This
+ /// will be kept in memory mapped shared memory
+ struct UUID_State
{
- UUID_time_t timestamp;
- ACE_UUID::UUID_node_t node;
+ UUID_time timestamp;
+ UUID_node node;
ACE_UINT16 clockSequence;
};
- /**
- * Obtain a UUID timestamp. Compensate for the fact that the time
- * obtained from getSystem time has a resolution less than 100ns.
- */
- void getTimestamp( UUID_time_t& timestamp);
-
- /**
- * 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
- * the Christian calendar).
- */
- void get_system_time( UUID_time_t& timeNow);
+ /// Obtain a UUID timestamp. Compensate for the fact that the time
+ /// obtained from getSystem time has a resolution less than 100ns.
+ void get_timestamp (UUID_time& timestamp);
+ /// 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
+ /// the Christian calendar).
+ void get_systemtime( UUID_time& timeNow);
- /**
- * The system time when that last uuid was generated.
- */
- UUID_time_t time_last_;
-
- /**
- * The UUID generator persistent state.
- */
- UUID_state uuid_state_;
+ /// The UUID generator persistent state.
+ UUID_State uuid_state_;
ACE_Lock* lock_;
-
- // No value semantics
- //ACE_UNIMPLEMENTED_FUNC (ACE_UUID_Generator( const ACE_UUID_Generator&))
- // ACE_UNIMPLEMENTED_FUNC (ACE_UUID_Generator& operator=( const ACE_UUID_Generator&))
};
typedef ACE_Singleton <ACE_UUID_Generator, ACE_SYNCH_MUTEX> ACE_UUID_GENERATOR;
diff --git a/ace/UUID.i b/ace/UUID.i
index d5a2e4a2f12..ee514aad882 100644
--- a/ace/UUID.i
+++ b/ace/UUID.i
@@ -1,103 +1,178 @@
//$Id$
// -*- C++ -*-
-ACE_INLINE ACE_UUID &
-ACE_UUID::operator=(const ACE_UUID &right)
+/// Data Members for Class Attributes
+ACE_INLINE ACE_UINT32
+ACE_UUID::timeLow (void)
{
- uuid_ = right.uuid_;
- return *this;
+ return this->timeLow_;
}
-ACE_INLINE bool
-ACE_UUID::operator==(const ACE_UUID &right) const
+ACE_INLINE void
+ACE_UUID::timeLow (ACE_UINT32 timelow)
{
- if ((uuid_.timeLow != right.uuid_.timeLow) ||
- (uuid_.timeMid != right.uuid_.timeMid) ||
- (uuid_.timeHiAndVersion != right.uuid_.timeHiAndVersion) ||
- (uuid_.clockSeqHiAndReserved != right.uuid_.clockSeqHiAndReserved) ||
- (uuid_.clockSeqLow != right.uuid_.clockSeqLow))
- {
- return false;
- }
-
- if (uuid_.node != right.uuid_.node)
- {
- return false;
- }
-
- return true;
+ this->timeLow_ = timelow;
}
-ACE_INLINE bool
-ACE_UUID::operator!=(const ACE_UUID &right) const
+ACE_INLINE ACE_UINT16
+ACE_UUID::timeMid (void)
{
- return !(*this == right);
+ return this->timeMid_;
}
-ACE_INLINE bool
-ACE_UUID::operator<(const ACE_UUID &right) const
+ACE_INLINE void
+ACE_UUID::timeMid (ACE_UINT16 time_mid)
{
- if ((uuid_.timeLow < right.uuid_.timeLow) ||
- (uuid_.timeMid < right.uuid_.timeMid) ||
- (uuid_.timeHiAndVersion < right.uuid_.timeHiAndVersion) ||
- (uuid_.clockSeqHiAndReserved < right.uuid_.clockSeqHiAndReserved) ||
- (uuid_.clockSeqLow < right.uuid_.clockSeqLow))
- {
- return true;
- }
-
- if (uuid_.node < right.uuid_.node)
- {
- return true;
- }
+ this->timeMid_ = time_mid;
+}
- return false;
+ACE_INLINE ACE_UINT16
+ACE_UUID::timeHiAndVersion (void)
+{
+ return this->timeHiAndVersion_;
}
-ACE_INLINE bool
-ACE_UUID::operator>(const ACE_UUID &right) const
+ACE_INLINE void
+ACE_UUID::timeHiAndVersion (ACE_UINT16 timeHiAndVersion)
{
- return right < *this;
+ this->timeHiAndVersion_ = timeHiAndVersion;
}
-ACE_INLINE bool
-ACE_UUID::operator<=(const ACE_UUID &right) const
+ACE_INLINE u_char
+ACE_UUID::clockSeqHiAndReserved (void)
{
- return !(*this > right);
+ return this->clockSeqHiAndReserved_;
}
-ACE_INLINE bool
-ACE_UUID::operator>=(const ACE_UUID &right) const
+ACE_INLINE void
+ACE_UUID::clockSeqHiAndReserved (u_char clockSeqHiAndReserved)
{
- return !(*this < right);
+ this->clockSeqHiAndReserved_ = clockSeqHiAndReserved;
}
-ACE_INLINE bool
-ACE_UUID::UUID_node_t::operator == (const ACE_UUID::UUID_node_t& right) const
+ACE_INLINE u_char
+ACE_UUID::clockSeqLow (void)
{
- for (size_t i = 0; i < (sizeof(nodeID) / sizeof(nodeID[0])); ++i)
- {
- if (nodeID[i] != right.nodeID[i])
- {
- return false;
- }
- }
- return true;
+ return this->clockSeqLow_;
}
-ACE_INLINE bool
-ACE_UUID::UUID_node_t::operator != (const ACE_UUID::UUID_node_t& right) const
+ACE_INLINE void
+ACE_UUID::clockSeqLow (u_char clockSeqLow)
{
- return !(*this == right);
+ this->clockSeqLow_ = clockSeqLow;
}
-ACE_INLINE bool
-ACE_UUID::UUID_node_t::operator < (const ACE_UUID::UUID_node_t& right) const
+ACE_INLINE UUID_node*
+ACE_UUID::node (void)
{
+ return this->node_;
+}
+
+ACE_INLINE void
+ACE_UUID::node (UUID_node* node)
+{
+ this->node_ = node;
+}
+
+/*
+ ACE_INLINE ACE_UUID&
+ ACE_UUID::operator=(const ACE_UUID &right)
+ {
+ *this = right;
+ return *this;
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::operator==(const ACE_UUID &right) const
+ {
+ if ((timeLow_ != right.timeLow ()) ||
+ (this->timeMid () != right.timeMid ()) ||
+ (this->timeHiAndVersion () != right.timeHiAndVersion ()) ||
+ (this->clockSeqHiAndReserved () != right.clockSeqHiAndReserved ()) ||
+ (this->clockSeqLow () != right.clockSeqLow ()))
+ {
+ return false;
+ }
+
+ if (this->node () != right.node ())
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::operator!=(const ACE_UUID &right) const
+ {
+ return !(*this == right);
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::operator<(const ACE_UUID &right) const
+ {
+ if ((uuid_.timeLow < right.uuid_.timeLow) ||
+ (uuid_.timeMid < right.uuid_.timeMid) ||
+ (uuid_.timeHiAndVersion < right.uuid_.timeHiAndVersion) ||
+ (uuid_.clockSeqHiAndReserved < right.uuid_.clockSeqHiAndReserved) ||
+ (uuid_.clockSeqLow < right.uuid_.clockSeqLow))
+ {
+ return true;
+ }
+
+ if (uuid_.node < right.uuid_.node)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::operator>(const ACE_UUID &right) const
+ {
+ return right < *this;
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::operator<=(const ACE_UUID &right) const
+ {
+ return !(*this > right);
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::operator>=(const ACE_UUID &right) const
+ {
+ return !(*this < right);
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::UUID_node_t::operator == (const ACE_UUID::UUID_node_t& right) const
+ {
+ for (size_t i = 0; i < (sizeof(nodeID) / sizeof(nodeID[0])); ++i)
+ {
+ if (nodeID[i] != right.nodeID[i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::UUID_node_t::operator != (const ACE_UUID::UUID_node_t& right) const
+ {
+ return !(*this == right);
+ }
+
+ ACE_INLINE bool
+ ACE_UUID::UUID_node_t::operator < (const ACE_UUID::UUID_node_t& right) const
+ {
for (size_t i = 0; i < (sizeof( nodeID) / sizeof( nodeID[0])); ++i)
- if (nodeID[i] < right.nodeID[i])
- return true;
+ if (nodeID[i] < right.nodeID[i])
+ return true;
return false;
-}
+ }
+*/
diff --git a/ace/UUIDTest.cpp b/ace/UUIDTest.cpp
index a63532a2612..94264cd04d5 100755
--- a/ace/UUIDTest.cpp
+++ b/ace/UUIDTest.cpp
@@ -47,9 +47,11 @@ int Tester::test()
// return -1;
// if (test2() == -1)
// return -1;
+ ACE_UUID_GENERATOR::instance ()->init ();
+
ACE_DEBUG ((LM_DEBUG,
"%s\n",
- ACE_UUID_GENERATOR::instance ()->generateUUID ().to_string ()->c_str ()));
+ ACE_UUID_GENERATOR::instance ()->generateUUID ()->to_string ()->c_str ()));
return 0;
}