LCOV - code coverage report
Current view: top level - DCPS - GuidConverter.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 6 0.0 %
Date: 2023-04-30 01:32:43 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *
       4             :  * Distributed under the OpenDDS License.
       5             :  * See: http://www.opendds.org/license.html
       6             :  */
       7             : 
       8             : #ifndef OPENDDS_DCPS_GUIDCONVERTER_H
       9             : #define OPENDDS_DCPS_GUIDCONVERTER_H
      10             : 
      11             : #include "dcps_export.h"
      12             : #include "Definitions.h"
      13             : #include "SafetyProfileStreams.h"
      14             : #include "PoolAllocator.h"
      15             : #include "GuidUtils.h"
      16             : 
      17             : #include <dds/DdsDcpsGuidC.h>
      18             : 
      19             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      20             : 
      21             : namespace OpenDDS {
      22             : namespace DCPS {
      23             : 
      24             : /**
      25             :  * @class GuidConverter
      26             :  *
      27             :  * @brief Conversion processing and value testing utilities for RTPS
      28             :  *        GUID_t types.
      29             :  *
      30             :  * This class encapsulates the conversion of a GUID_t value to and from
      31             :  * other types used within OpenDDS.  This class handles opaque GUID_t values
      32             :  * only.  For specific access, the appropriate subclass must instead be used.
      33             :  *
      34             :  * Since the GUID_t type is formed of octets in network order, we do all
      35             :  * processing byte by byte to avoid any endian issues.
      36             :  *
      37             :  * Currently the GUID_t is mapped from various internal values.
      38             :  * These mappings are:
      39             :  *
      40             :  * byte  structure reference     content
      41             :  * ---- ---------------------    --------------------------
      42             :  *   0  GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS)
      43             :  *   1  GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS)
      44             :  *   2  GUID_t.guidPrefix[ 2] == 0x00
      45             :  *   3  GUID_t.guidPrefix[ 3] == 0x00
      46             :  *
      47             :  *   4  GUID_t.guidPrefix[ 4] == <private> (MS byte)
      48             :  *   5  GUID_t.guidPrefix[ 5] == <private>
      49             :  *   6  GUID_t.guidPrefix[ 6] == <private>
      50             :  *   7  GUID_t.guidPrefix[ 7] == <private> (LS byte)
      51             :  *
      52             :  *   8  GUID_t.guidPrefix[ 8] == <private> (MS byte)
      53             :  *   9  GUID_t.guidPrefix[ 9] == <private>
      54             :  *  10  GUID_t.guidPrefix[10] == <private>
      55             :  *  11  GUID_t.guidPrefix[11] == <private> (LS byte)
      56             :  *
      57             :  *  12  GUID_t.entityId.entityKey[ 0] == entity id[0] (MS byte)
      58             :  *  13  GUID_t.entityId.entityKey[ 1] == entity id[1]
      59             :  *  14  GUID_t.entityId.entityKey[ 2] == entity id[2] (LS byte)
      60             :  *  15  GUID_t.entityId.entityKind    == entity kind
      61             :  */
      62             : class OpenDDS_Dcps_Export GuidConverter {
      63             : public:
      64             :   /// Construct from a GUID_t.
      65             :   GuidConverter(const GUID_t& guid);
      66             : 
      67             :   /// Virtual destructor (this is a base class).
      68             :   virtual ~GuidConverter();
      69             : 
      70             :   /// Calculate the CRC32 checksum.
      71             :   long checksum() const;
      72             : 
      73             :   /// Extract the VendorId value.
      74             :   long vendorId() const;
      75             : 
      76             :   /// Extract the EntityId value.
      77             :   long entityId() const;
      78             : 
      79             :   /// Extract the EntityKey value.
      80             :   long entityKey() const;
      81             : 
      82             :   /// Extract the EntityKind value.
      83             :   EntityKind entityKind() const;
      84             : 
      85             :   /// Returns true if the GUID represents a builtin type domain entity.
      86             :   bool isBuiltinDomainEntity() const;
      87             : 
      88             :   /// Returns true if the GUID represents a user defined type domain entity.
      89             :   bool isUserDomainEntity() const;
      90             : 
      91             :   /// Returns true if the GUID represents a writer entity.
      92             :   bool isWriter() const;
      93             : 
      94             :   /// Returns true if the GUID represents a reader entity.
      95             :   bool isReader() const;
      96             : 
      97             :   /// Returns true if the GUID represents a topic entity.
      98             :   bool isTopic() const;
      99             : 
     100             :   /// Convert to diagnostic string.
     101             :   operator OPENDDS_STRING() const;
     102             : #ifdef DDS_HAS_WCHAR
     103             :   operator std::wstring() const;
     104             : #endif
     105             : 
     106             :   OPENDDS_STRING uniqueParticipantId() const;
     107             : 
     108             : protected:
     109             :   const GUID_t guid_;
     110             : };
     111             : 
     112             : struct OpenDDS_Dcps_Export LogGuid {
     113           0 :   explicit LogGuid(const GUID_t& id)
     114           0 :     : conv_(GuidConverter(id)) {}
     115           0 :   explicit LogGuid(const GuidPrefix_t& prefix)
     116           0 :     : conv_(GuidConverter(make_part_guid(prefix)))
     117             :   {
     118           0 :   }
     119           0 :   const char* c_str() const { return conv_.c_str(); }
     120             :   OPENDDS_STRING conv_;
     121             : };
     122             : 
     123             : #ifndef OPENDDS_SAFETY_PROFILE
     124             : OpenDDS_Dcps_Export std::ostream&
     125             : operator<<(std::ostream& os, const OpenDDS::DCPS::GuidConverter& rhs);
     126             : 
     127             : #ifdef DDS_HAS_WCHAR
     128             : OpenDDS_Dcps_Export std::wostream&
     129             : operator<<(std::wostream& os, const OpenDDS::DCPS::GuidConverter& rhs);
     130             : #endif //DDS_HAS_WCHAR
     131             : #endif //OPENDDS_SAFETY_PROFILE
     132             : 
     133             : } // namespace DCPS
     134             : } // namespace OpenDDS
     135             : 
     136             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     137             : 
     138             : #endif /* DCPS_GUIDCONVERTER_H */

Generated by: LCOV version 1.16