00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #include "dds/DdsDcpsGuidC.h" 00009 #include "dds/DCPS/RTPS/rtps_export.h" 00010 00011 #include "ace/Basic_Types.h" 00012 #include "ace/Thread_Mutex.h" 00013 00014 namespace OpenDDS { 00015 namespace RTPS { 00016 00017 /** 00018 * Generate GuidPrefix_t values for use with RTPS 00019 * Also see GuidConverter.h in dds/DCPS 00020 * 0 GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS) 00021 * 1 GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS) 00022 * 2 GUID_t.guidPrefix[ 2] == MAC Address 00023 * 3 GUID_t.guidPrefix[ 3] == MAC Address 00024 * 4 GUID_t.guidPrefix[ 4] == MAC Address 00025 * 5 GUID_t.guidPrefix[ 5] == MAC Address 00026 * 6 GUID_t.guidPrefix[ 6] == MAC Address 00027 * 7 GUID_t.guidPrefix[ 7] == MAC Address 00028 * 8 GUID_t.guidPrefix[ 8] == Process ID (MS byte) 00029 * 9 GUID_t.guidPrefix[ 9] == Process ID (LS byte) 00030 * 10 GUID_t.guidPrefix[10] == Counter (MS byte) 00031 * 11 GUID_t.guidPrefix[11] == Counter (LS byte) 00032 * 00033 */ 00034 class OpenDDS_Rtps_Export GuidGenerator { 00035 public: 00036 /// Borrowed from ACE::UUID_Node, definition of the 00037 /// MAC address holder type 00038 00039 enum {NODE_ID_SIZE = 6}; 00040 typedef unsigned char Node_ID[NODE_ID_SIZE]; 00041 00042 /// Default constructor - initializes pid and MAC address values 00043 GuidGenerator(); 00044 00045 /// populate a GUID container with a unique ID. This will increment 00046 /// the counter, and use a lock (if compiled with MT ACE) while 00047 /// doing so. 00048 void populate(DCPS::GUID_t& container); 00049 00050 private: 00051 ACE_UINT16 getCount(); 00052 00053 Node_ID node_id_; 00054 pid_t pid_; 00055 ACE_Thread_Mutex counter_lock_; 00056 ACE_UINT16 counter_; 00057 }; 00058 00059 } // namespace RTPS 00060 } // namespace OpenDDS