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 namespace OpenDDS {
00020 namespace DCPS {
00021 
00022 Data_Types_Register::Data_Types_Register()
00023 {
00024 }
00025 
00026 Data_Types_Register::~Data_Types_Register()
00027 {
00028 }
00029 
00030 Data_Types_Register*
00031 Data_Types_Register::instance()
00032 {
00033   return ACE_Singleton<Data_Types_Register, ACE_SYNCH_MUTEX>::instance();
00034 }
00035 
00036 DDS::ReturnCode_t Data_Types_Register::register_type(
00037   DDS::DomainParticipant_ptr domain_participant,
00038   const char* type_name,
00039   TypeSupport_ptr the_type)
00040 {
00041   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
00042 
00043   TypeSupportMap& tsm = participants_[domain_participant];
00044   const TypeSupport_var typeSupport = TypeSupport::_duplicate(the_type);
00045 
00046   TypeSupportMap::iterator iter = tsm.find(type_name);
00047   if (iter == tsm.end()) {
00048     tsm[type_name] = typeSupport;
00049     return DDS::RETCODE_OK;
00050   }
00051 
00052   if (std::strcmp(typeSupport->_interface_repository_id(),
00053                   iter->second->_interface_repository_id()) == 0) {
00054     return DDS::RETCODE_OK;
00055   }
00056 
00057   return DDS::RETCODE_ERROR;
00058 }
00059 
00060 DDS::ReturnCode_t Data_Types_Register::unregister_participant(
00061   DDS::DomainParticipant_ptr domain_participant)
00062 {
00063   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, DDS::RETCODE_ERROR);
00064   participants_.erase(domain_participant);
00065   return DDS::RETCODE_OK;
00066 }
00067 
00068 TypeSupport_ptr Data_Types_Register::lookup(
00069   DDS::DomainParticipant_ptr domain_participant,
00070   const char* type_name) const
00071 {
00072   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, lock_, 0);
00073 
00074   ParticipantMap::const_iterator iter1 = participants_.find(domain_participant);
00075   if (iter1 == participants_.end()) {
00076     return 0;
00077   }
00078 
00079   TypeSupportMap::const_iterator iter2 = iter1->second.find(type_name);
00080   if (iter2 == iter1->second.end()) {
00081     return 0;
00082   }
00083 
00084   TypeSupport_var typeSupport = iter2->second;
00085   return typeSupport._retn();
00086 }
00087 
00088 } // namespace DCPS
00089 } // namespace OpenDDS
00090 

Generated on Fri Feb 12 20:05:25 2016 for OpenDDS by  doxygen 1.4.7