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/PoolAllocator.h" 00010 #include "dds/DCPS/RTPS/rtps_export.h" 00011 00012 #include "ace/Basic_Types.h" 00013 #include "ace/Thread_Mutex.h" 00014 00015 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00016 00017 namespace OpenDDS { 00018 namespace RTPS { 00019 00020 /** 00021 * Generate GuidPrefix_t values for use with RTPS 00022 * Also see GuidConverter.h in dds/DCPS 00023 * 0 GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS) 00024 * 1 GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS) 00025 * 2 GUID_t.guidPrefix[ 2] == MAC Address 00026 * 3 GUID_t.guidPrefix[ 3] == MAC Address 00027 * 4 GUID_t.guidPrefix[ 4] == MAC Address 00028 * 5 GUID_t.guidPrefix[ 5] == MAC Address 00029 * 6 GUID_t.guidPrefix[ 6] == MAC Address 00030 * 7 GUID_t.guidPrefix[ 7] == MAC Address 00031 * 8 GUID_t.guidPrefix[ 8] == Process ID (MS byte) 00032 * 9 GUID_t.guidPrefix[ 9] == Process ID (LS byte) 00033 * 10 GUID_t.guidPrefix[10] == Counter (MS byte) 00034 * 11 GUID_t.guidPrefix[11] == Counter (LS byte) 00035 * 00036 */ 00037 class OpenDDS_Rtps_Export GuidGenerator { 00038 public: 00039 GuidGenerator(); 00040 00041 /// override the MAC address to use a specific network interface 00042 /// instead of just the first (non-loopback) interface 00043 int interfaceName(const char* interface); 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 enum {NODE_ID_SIZE = 6}; 00052 00053 /// Borrowed from ACE::UUID_Node, definition of the 00054 /// MAC address holder type 00055 typedef unsigned char Node_ID[NODE_ID_SIZE]; 00056 00057 ACE_UINT16 getCount(); 00058 00059 Node_ID node_id_; 00060 pid_t pid_; 00061 ACE_Thread_Mutex counter_lock_; 00062 ACE_UINT16 counter_; 00063 OPENDDS_STRING interface_name_; 00064 }; 00065 00066 } // namespace RTPS 00067 } // namespace OpenDDS 00068 00069 OPENDDS_END_VERSIONED_NAMESPACE_DECL