LCOV - code coverage report
Current view: top level - DCPS - GuidConverter.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 94 34.0 %
Date: 2023-04-30 01:32:43 Functions: 7 18 38.9 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #include <DCPS/DdsDcps_pch.h> // Only the _pch include should start with DCPS/
       7             : 
       8             : #include "GuidConverter.h"
       9             : 
      10             : #include <dds/DdsDcpsGuidTypeSupportImpl.h>
      11             : 
      12             : #include <ace/ACE.h>
      13             : #include <ace/OS_NS_stdio.h>
      14             : 
      15             : #ifdef DDS_HAS_WCHAR
      16             : #  include <sstream>
      17             : #endif
      18             : 
      19             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      20             : 
      21             : namespace OpenDDS {
      22             : namespace DCPS {
      23             : 
      24           7 : GuidConverter::GuidConverter(const GUID_t& guid)
      25           7 :   : guid_(guid)
      26           7 : {}
      27             : 
      28           7 : GuidConverter::~GuidConverter()
      29           7 : {}
      30             : 
      31             : long
      32           2 : GuidConverter::checksum() const
      33             : {
      34           2 :   return ACE::crc32(reinterpret_cast<const void*>(&guid_), sizeof(guid_));
      35             : }
      36             : 
      37             : long
      38           1 : GuidConverter::vendorId() const
      39             : {
      40           1 :   return guid_.guidPrefix[0] << 8
      41           1 :          | guid_.guidPrefix[1];
      42             : }
      43             : 
      44             : long
      45           1 : GuidConverter::entityId() const
      46             : {
      47           1 :   return entityKey() << 8
      48           1 :          | guid_.entityId.entityKind;
      49             : }
      50             : 
      51             : long
      52           2 : GuidConverter::entityKey() const
      53             : {
      54           2 :   return guid_.entityId.entityKey[0] << 16
      55           2 :          | guid_.entityId.entityKey[1] << 8
      56           2 :          | guid_.entityId.entityKey[2];
      57             : }
      58             : 
      59             : EntityKind
      60           0 : GuidConverter::entityKind() const
      61             : {
      62           0 :   switch (guid_.entityId.entityKind) {
      63           0 :   case ENTITYKIND_OPENDDS_TOPIC:
      64           0 :     return KIND_USER_TOPIC;
      65             : 
      66           0 :   case ENTITYKIND_BUILTIN_TOPIC:
      67           0 :     return KIND_BUILTIN_TOPIC;
      68             : 
      69           0 :   case ENTITYKIND_USER_READER_NO_KEY:
      70             :   case ENTITYKIND_USER_READER_WITH_KEY:
      71           0 :     return KIND_USER_READER;
      72             : 
      73           0 :   case ENTITYKIND_USER_WRITER_NO_KEY:
      74             :   case ENTITYKIND_USER_WRITER_WITH_KEY:
      75             :   case ENTITYKIND_OPENDDS_NIL_WRITER:
      76           0 :     return KIND_USER_WRITER;
      77             : 
      78           0 :   case ENTITYKIND_BUILTIN_READER_NO_KEY:
      79             :   case ENTITYKIND_BUILTIN_READER_WITH_KEY:
      80           0 :     return KIND_BUILTIN_READER;
      81             : 
      82           0 :   case ENTITYKIND_BUILTIN_WRITER_NO_KEY:
      83             :   case ENTITYKIND_BUILTIN_WRITER_WITH_KEY:
      84           0 :     return KIND_BUILTIN_WRITER;
      85             : 
      86           0 :   case ENTITYKIND_BUILTIN_PARTICIPANT:
      87           0 :     return KIND_PARTICIPANT;
      88             : 
      89           0 :   case ENTITYKIND_OPENDDS_PUBLISHER:
      90           0 :     return KIND_PUBLISHER;
      91             : 
      92           0 :   case ENTITYKIND_OPENDDS_SUBSCRIBER:
      93           0 :     return KIND_SUBSCRIBER;
      94             : 
      95           0 :   case ENTITYKIND_OPENDDS_USER:
      96           0 :     return KIND_USER;
      97             : 
      98           0 :   case ENTITYKIND_USER_UNKNOWN:
      99             :   case ENTITYKIND_BUILTIN_UNKNOWN:
     100             :   default:
     101           0 :     return KIND_UNKNOWN;
     102             :   }
     103             : }
     104             : 
     105           0 : bool GuidConverter::isBuiltinDomainEntity() const
     106             : {
     107           0 :   switch (guid_.entityId.entityKind) {
     108             : 
     109           0 :   case ENTITYKIND_BUILTIN_READER_NO_KEY:
     110             :   case ENTITYKIND_BUILTIN_READER_WITH_KEY:
     111             :   case ENTITYKIND_BUILTIN_WRITER_NO_KEY:
     112             :   case ENTITYKIND_BUILTIN_WRITER_WITH_KEY:
     113             :   case ENTITYKIND_BUILTIN_TOPIC:
     114           0 :     return true;
     115             : 
     116           0 :   default:
     117           0 :     return false;
     118             :   }
     119             : }
     120             : 
     121           0 : bool GuidConverter::isUserDomainEntity() const
     122             : {
     123           0 :   switch (guid_.entityId.entityKind) {
     124             : 
     125           0 :   case ENTITYKIND_USER_READER_NO_KEY:
     126             :   case ENTITYKIND_USER_READER_WITH_KEY:
     127             :   case ENTITYKIND_USER_WRITER_NO_KEY:
     128             :   case ENTITYKIND_USER_WRITER_WITH_KEY:
     129             :   case ENTITYKIND_OPENDDS_TOPIC:
     130           0 :     return true;
     131             : 
     132           0 :   default:
     133           0 :     return false;
     134             :   }
     135             : }
     136             : 
     137           0 : bool GuidConverter::isWriter() const
     138             : {
     139           0 :   EntityKind kind = entityKind();
     140           0 :   return kind == KIND_USER_WRITER || kind == KIND_BUILTIN_WRITER;
     141             : }
     142             : 
     143           0 : bool GuidConverter::isReader() const
     144             : {
     145           0 :   EntityKind kind = entityKind();
     146           0 :   return kind == KIND_USER_READER || kind == KIND_BUILTIN_READER;
     147             : }
     148             : 
     149           0 : bool GuidConverter::isTopic() const
     150             : {
     151           0 :   EntityKind kind = entityKind();
     152           0 :   return kind == KIND_USER_TOPIC || kind == KIND_BUILTIN_TOPIC;
     153             : }
     154             : 
     155           0 : GuidConverter::operator OPENDDS_STRING() const
     156             : {
     157           0 :   OPENDDS_STRING ret(to_string(guid_));
     158           0 :   ret += "(";
     159           0 :   ret += to_dds_string((unsigned long) checksum(), true);
     160           0 :   ret += ")";
     161           0 :   return ret;
     162           0 : }
     163             : 
     164             : #ifdef DDS_HAS_WCHAR
     165           0 : GuidConverter::operator std::wstring() const
     166             : {
     167           0 :   std::wostringstream os;
     168           0 :   const OPENDDS_STRING guid_str(to_string(guid_));
     169           0 :   os << guid_str.c_str() << "(" << std::hex << checksum() << ")";
     170           0 :   return os.str();
     171           0 : }
     172             : #endif
     173             : 
     174             : #ifndef OPENDDS_SAFETY_PROFILE
     175             : 
     176             : std::ostream&
     177           0 : operator<<(std::ostream& os, const GuidConverter& rhs)
     178             : {
     179           0 :   return os << OPENDDS_STRING(rhs);
     180             : }
     181             : 
     182             : #ifdef DDS_HAS_WCHAR
     183             : std::wostream&
     184           0 : operator<<(std::wostream& os, const GuidConverter& rhs)
     185             : {
     186           0 :   return os << std::wstring(rhs);
     187             : }
     188             : #endif //DDS_HAS_WCHAR
     189             : #endif //OPENDDS_SAFETY_PROFILE
     190             : 
     191             : OPENDDS_STRING
     192           2 : GuidConverter::uniqueParticipantId() const
     193             : {
     194             :   char id[64];
     195           2 :   ACE_OS::snprintf(id, sizeof id,
     196             :           "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
     197           2 :           guid_.guidPrefix[ 0],
     198           2 :           guid_.guidPrefix[ 1],
     199           2 :           guid_.guidPrefix[ 2],
     200           2 :           guid_.guidPrefix[ 3],
     201           2 :           guid_.guidPrefix[ 4],
     202           2 :           guid_.guidPrefix[ 5],
     203           2 :           guid_.guidPrefix[ 6],
     204           2 :           guid_.guidPrefix[ 7],
     205           2 :           guid_.guidPrefix[ 8],
     206           2 :           guid_.guidPrefix[ 9],
     207           2 :           guid_.guidPrefix[10],
     208           2 :           guid_.guidPrefix[11]);
     209           2 :   return id;
     210             : }
     211             : 
     212             : } // namespace DCPS
     213             : } // namespace OpenDDS
     214             : 
     215             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16