Registered_Data_Types.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 
00010 #include "Registered_Data_Types.h"
00011 
00012 #include "dds/DCPS/Util.h"
00013 #include "dds/DdsDcpsDomainC.h"
00014 
00015 #include "ace/Singleton.h"
00016 
00017 #include <cstring>
00018 
00019 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 namespace OpenDDS {
00022 namespace DCPS {
00023 
00024 Data_Types_Register::Data_Types_Register()
00025 {
00026 }
00027 
00028 Data_Types_Register::~Data_Types_Register()
00029 {
00030 }
00031 
00032 Data_Types_Register*
00033 Data_Types_Register::instance()
00034 {
00035   return ACE_Singleton<Data_Types_Register, ACE_SYNCH_MUTEX>::instance();
00036 }
00037 
00038 DDS::ReturnCode_t Data_Types_Register::register_type(
00039   DDS::DomainParticipant_ptr domain_participant,
00040   const char* type_name,
00041   TypeSupport_ptr the_type)
00042 {
00043   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
00044 
00045   TypeSupportMap& tsm = participants_[domain_participant];
00046   const TypeSupport_var typeSupport = TypeSupport::_duplicate(the_type);
00047 
00048   TypeSupportMap::iterator iter = tsm.find(type_name);
00049   if (iter == tsm.end()) {
00050     tsm[type_name] = typeSupport;
00051     return DDS::RETCODE_OK;
00052   }
00053 
00054   if (std::strcmp(typeSupport->_interface_repository_id(),
00055                   iter->second->_interface_repository_id()) == 0) {
00056     return DDS::RETCODE_OK;
00057   }
00058 
00059   return DDS::RETCODE_ERROR;
00060 }
00061 
00062 DDS::ReturnCode_t Data_Types_Register::unregister_type(
00063     DDS::DomainParticipant_ptr domain_participant,
00064     const char* type_name,
00065     TypeSupport_ptr the_type)
00066 {
00067   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
00068 
00069   TypeSupportMap& tsm = participants_[domain_participant];
00070 
00071   TypeSupportMap::iterator iter = tsm.find(type_name);
00072   if (iter == tsm.end()) {
00073     // Not in the map, can't delete
00074     return DDS::RETCODE_ERROR;
00075   }
00076   else {
00077     if (std::strcmp(the_type->_interface_repository_id(), iter->second->_interface_repository_id()) == 0) {
00078       tsm.erase(iter);
00079       return DDS::RETCODE_OK;
00080     }
00081     else {
00082       return DDS::RETCODE_ERROR;
00083     }
00084   }
00085 }
00086 
00087 DDS::ReturnCode_t Data_Types_Register::unregister_participant(
00088   DDS::DomainParticipant_ptr domain_participant)
00089 {
00090   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
00091   participants_.erase(domain_participant);
00092   return DDS::RETCODE_OK;
00093 }
00094 
00095 TypeSupport_ptr Data_Types_Register::lookup(
00096   DDS::DomainParticipant_ptr domain_participant,
00097   const char* type_name) const
00098 {
00099   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, 0);
00100 
00101   ParticipantMap::const_iterator iter1 = participants_.find(domain_participant);
00102   if (iter1 == participants_.end()) {
00103     return 0;
00104   }
00105 
00106   TypeSupportMap::const_iterator iter2 = iter1->second.find(type_name);
00107   if (iter2 == iter1->second.end()) {
00108     return 0;
00109   }
00110 
00111   TypeSupport_var typeSupport = iter2->second;
00112   return typeSupport._retn();
00113 }
00114 
00115 } // namespace DCPS
00116 } // namespace OpenDDS
00117 
00118 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1