LCOV - code coverage report
Current view: top level - DCPS - Registered_Data_Types.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 46 47.8 %
Date: 2023-04-30 01:32:43 Functions: 4 7 57.1 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *
       4             :  * Distributed under the OpenDDS License.
       5             :  * See: http://www.opendds.org/license.html
       6             :  */
       7             : 
       8             : #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
       9             : 
      10             : #include "Registered_Data_Types.h"
      11             : 
      12             : #include "Util.h"
      13             : #include "dds/DdsDcpsDomainC.h"
      14             : 
      15             : #include "ace/Singleton.h"
      16             : 
      17             : #include <cstring>
      18             : 
      19             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      20             : 
      21             : namespace OpenDDS {
      22             : namespace DCPS {
      23             : 
      24           1 : Data_Types_Register::Data_Types_Register()
      25             : {
      26           1 : }
      27             : 
      28           0 : Data_Types_Register::~Data_Types_Register()
      29             : {
      30           0 : }
      31             : 
      32             : Data_Types_Register*
      33         108 : Data_Types_Register::instance()
      34             : {
      35         108 :   return ACE_Singleton<Data_Types_Register, ACE_SYNCH_MUTEX>::instance();
      36             : }
      37             : 
      38          54 : DDS::ReturnCode_t Data_Types_Register::register_type(
      39             :   DDS::DomainParticipant_ptr domain_participant,
      40             :   const char* type_name,
      41             :   TypeSupport_ptr the_type)
      42             : {
      43          54 :   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
      44             : 
      45          54 :   TypeSupportMap& tsm = participants_[domain_participant];
      46          54 :   const TypeSupport_var typeSupport = TypeSupport::_duplicate(the_type);
      47             : 
      48          54 :   TypeSupportMap::iterator iter = tsm.find(type_name);
      49          54 :   if (iter == tsm.end()) {
      50          54 :     tsm[type_name] = typeSupport;
      51          54 :     return DDS::RETCODE_OK;
      52             :   }
      53             : 
      54           0 :   if (std::strcmp(typeSupport->_interface_repository_id(),
      55           0 :                   iter->second->_interface_repository_id()) == 0) {
      56           0 :     return DDS::RETCODE_OK;
      57             :   }
      58             : 
      59           0 :   return DDS::RETCODE_ERROR;
      60          54 : }
      61             : 
      62          54 : DDS::ReturnCode_t Data_Types_Register::unregister_type(
      63             :     DDS::DomainParticipant_ptr domain_participant,
      64             :     const char* type_name,
      65             :     TypeSupport_ptr the_type)
      66             : {
      67          54 :   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
      68             : 
      69          54 :   TypeSupportMap& tsm = participants_[domain_participant];
      70             : 
      71          54 :   TypeSupportMap::iterator iter = tsm.find(type_name);
      72          54 :   if (iter == tsm.end()) {
      73             :     // Not in the map, can't delete
      74           0 :     return DDS::RETCODE_ERROR;
      75             :   }
      76             :   else {
      77          54 :     if (std::strcmp(the_type->_interface_repository_id(), iter->second->_interface_repository_id()) == 0) {
      78          54 :       tsm.erase(iter);
      79          54 :       return DDS::RETCODE_OK;
      80             :     }
      81             :     else {
      82           0 :       return DDS::RETCODE_ERROR;
      83             :     }
      84             :   }
      85          54 : }
      86             : 
      87           0 : DDS::ReturnCode_t Data_Types_Register::unregister_participant(
      88             :   DDS::DomainParticipant_ptr domain_participant)
      89             : {
      90           0 :   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
      91           0 :   participants_.erase(domain_participant);
      92           0 :   return DDS::RETCODE_OK;
      93           0 : }
      94             : 
      95           0 : TypeSupport_ptr Data_Types_Register::lookup(
      96             :   DDS::DomainParticipant_ptr domain_participant,
      97             :   const char* type_name) const
      98             : {
      99           0 :   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, 0);
     100             : 
     101           0 :   ParticipantMap::const_iterator iter1 = participants_.find(domain_participant);
     102           0 :   if (iter1 == participants_.end()) {
     103           0 :     return 0;
     104             :   }
     105             : 
     106           0 :   TypeSupportMap::const_iterator iter2 = iter1->second.find(type_name);
     107           0 :   if (iter2 == iter1->second.end()) {
     108           0 :     return 0;
     109             :   }
     110             : 
     111           0 :   TypeSupport_var typeSupport = iter2->second;
     112           0 :   return typeSupport._retn();
     113           0 : }
     114             : 
     115             : } // namespace DCPS
     116             : } // namespace OpenDDS
     117             : 
     118             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16