#include <GuidGenerator.h>
Public Types | |
typedef unsigned char | Node_ID [NODE_ID_SIZE] |
NODE_ID_SIZE = 6 | |
enum | { NODE_ID_SIZE = 6 } |
Public Member Functions | |
GuidGenerator () | |
Default constructor - initializes pid and MAC address values. | |
void | populate (DCPS::GUID_t &container) |
Private Member Functions | |
ACE_UINT16 | getCount () |
Private Attributes | |
Node_ID | node_id_ |
pid_t | pid_ |
ACE_Thread_Mutex | counter_lock_ |
ACE_UINT16 | counter_ |
Definition at line 34 of file GuidGenerator.h.
typedef unsigned char OpenDDS::RTPS::GuidGenerator::Node_ID[NODE_ID_SIZE] |
Definition at line 40 of file GuidGenerator.h.
anonymous enum |
Borrowed from ACE::UUID_Node, definition of the MAC address holder type
Definition at line 39 of file GuidGenerator.h.
00039 {NODE_ID_SIZE = 6};
OpenDDS::RTPS::GuidGenerator::GuidGenerator | ( | ) |
Default constructor - initializes pid and MAC address values.
Definition at line 22 of file GuidGenerator.cpp.
References node_id_, NODE_ID_SIZE, and pid_.
00023 : pid_(ACE_OS::getpid()), 00024 counter_(0) 00025 { 00026 00027 if (pid_ == -1) { 00028 unsigned seed = static_cast<unsigned>(ACE_OS::gettimeofday().usec()); 00029 pid_ = static_cast<pid_t>(ACE_OS::rand_r(&seed)); 00030 } 00031 00032 ACE_OS::macaddr_node_t macaddress; 00033 const int result = ACE_OS::getmacaddress(&macaddress); 00034 00035 if (-1 != result) { 00036 ACE_OS::memcpy(node_id_, macaddress.node, NODE_ID_SIZE); 00037 } else { 00038 node_id_[0] = static_cast<unsigned char>(ACE_OS::rand()); 00039 node_id_[1] = static_cast<unsigned char>(ACE_OS::rand()); 00040 node_id_[2] = static_cast<unsigned char>(ACE_OS::rand()); 00041 node_id_[3] = static_cast<unsigned char>(ACE_OS::rand()); 00042 node_id_[4] = static_cast<unsigned char>(ACE_OS::rand()); 00043 node_id_[5] = static_cast<unsigned char>(ACE_OS::rand()); 00044 } 00045 }
ACE_UINT16 OpenDDS::RTPS::GuidGenerator::getCount | ( | ) | [private] |
Definition at line 48 of file GuidGenerator.cpp.
References counter_.
Referenced by populate().
00049 { 00050 ACE_Guard<ACE_SYNCH_MUTEX> guard(this->counter_lock_); 00051 return counter_++; 00052 }
void OpenDDS::RTPS::GuidGenerator::populate | ( | DCPS::GUID_t & | container | ) |
populate a GUID container with a unique ID. This will increment the counter, and use a lock (if compiled with MT ACE) while doing so.
Definition at line 55 of file GuidGenerator.cpp.
References getCount(), OpenDDS::DCPS::GUID_t::guidPrefix, node_id_, NODE_ID_SIZE, pid_, and OpenDDS::DCPS::VENDORID_OCI.
Referenced by OpenDDS::RTPS::RtpsDiscovery::add_domain_participant().
00056 { 00057 container.guidPrefix[0] = DCPS::VENDORID_OCI[0]; 00058 container.guidPrefix[1] = DCPS::VENDORID_OCI[1]; 00059 00060 ACE_UINT16 count = this->getCount(); 00061 ACE_OS::memcpy(&container.guidPrefix[2], node_id_, NODE_ID_SIZE); 00062 container.guidPrefix[8] = static_cast<CORBA::Octet>(this->pid_ >> 8); 00063 container.guidPrefix[9] = static_cast<CORBA::Octet>(this->pid_ & 0xFF); 00064 container.guidPrefix[10] = static_cast<CORBA::Octet>(count >> 8); 00065 container.guidPrefix[11] = static_cast<CORBA::Octet>(count & 0xFF); 00066 }
ACE_UINT16 OpenDDS::RTPS::GuidGenerator::counter_ [private] |
ACE_Thread_Mutex OpenDDS::RTPS::GuidGenerator::counter_lock_ [private] |
Definition at line 55 of file GuidGenerator.h.
pid_t OpenDDS::RTPS::GuidGenerator::pid_ [private] |