OpenDDS::RTPS::GuidGenerator Class Reference

#include <GuidGenerator.h>

List of all members.

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_


Detailed Description

Generate GuidPrefix_t values for use with RTPS Also see GuidConverter.h in dds/DCPS 0 GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS) 1 GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS) 2 GUID_t.guidPrefix[ 2] == MAC Address 3 GUID_t.guidPrefix[ 3] == MAC Address 4 GUID_t.guidPrefix[ 4] == MAC Address 5 GUID_t.guidPrefix[ 5] == MAC Address 6 GUID_t.guidPrefix[ 6] == MAC Address 7 GUID_t.guidPrefix[ 7] == MAC Address 8 GUID_t.guidPrefix[ 8] == Process ID (MS byte) 9 GUID_t.guidPrefix[ 9] == Process ID (LS byte) 10 GUID_t.guidPrefix[10] == Counter (MS byte) 11 GUID_t.guidPrefix[11] == Counter (LS byte)

Definition at line 34 of file GuidGenerator.h.


Member Typedef Documentation

typedef unsigned char OpenDDS::RTPS::GuidGenerator::Node_ID[NODE_ID_SIZE]

Definition at line 40 of file GuidGenerator.h.


Member Enumeration Documentation

anonymous enum

Borrowed from ACE::UUID_Node, definition of the MAC address holder type

Enumerator:
NODE_ID_SIZE 

Definition at line 39 of file GuidGenerator.h.

00039 {NODE_ID_SIZE = 6};


Constructor & Destructor Documentation

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 }


Member Function Documentation

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 }


Member Data Documentation

ACE_UINT16 OpenDDS::RTPS::GuidGenerator::counter_ [private]

Definition at line 56 of file GuidGenerator.h.

Referenced by getCount().

ACE_Thread_Mutex OpenDDS::RTPS::GuidGenerator::counter_lock_ [private]

Definition at line 55 of file GuidGenerator.h.

Node_ID OpenDDS::RTPS::GuidGenerator::node_id_ [private]

Definition at line 53 of file GuidGenerator.h.

Referenced by GuidGenerator(), and populate().

pid_t OpenDDS::RTPS::GuidGenerator::pid_ [private]

Definition at line 54 of file GuidGenerator.h.

Referenced by GuidGenerator(), and populate().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:48 2016 for OpenDDS by  doxygen 1.4.7