Example #1
0
void EDPSimplePUBListener::onNewCacheChangeAdded(RTPSReader* /*reader*/, const CacheChange_t* const change_in)
{
	const char* const CLASS_NAME = "EDPSimplePUBListener";
	const char* const METHOD_NAME = "onNewCacheChangeAdded";
	CacheChange_t* change = (CacheChange_t*)change_in;
	//boost::lock_guard<boost::recursive_mutex> guard(*this->mp_SEDP->mp_PubReader.first->getMutex());
	logInfo(RTPS_EDP,"");
	if(!computeKey(change))
	{
		logWarning(RTPS_EDP,"Received change with no Key");
	}
	if(change->kind == ALIVE)
	{
		//LOAD INFORMATION IN TEMPORAL WRITER PROXY DATA
		WriterProxyData writerProxyData;
		CDRMessage_t tempMsg;
		tempMsg.msg_endian = change->serializedPayload.encapsulation == PL_CDR_BE ? BIGEND:LITTLEEND;
		tempMsg.length = change->serializedPayload.length;
		memcpy(tempMsg.buffer,change->serializedPayload.data,tempMsg.length);
		if(writerProxyData.readFromCDRMessage(&tempMsg))
		{
			change->instanceHandle = writerProxyData.m_key;
			if(writerProxyData.m_guid.guidPrefix == mp_SEDP->mp_RTPSParticipant->getGuid().guidPrefix)
			{
				logInfo(RTPS_EDP,"Message from own RTPSParticipant, ignoring",C_CYAN);
				mp_SEDP->mp_PubReader.second->remove_change(change);
				return;
			}
			//LOOK IF IS AN UPDATED INFORMATION
			WriterProxyData* wdata = nullptr;
			ParticipantProxyData* pdata = nullptr;
			if(this->mp_SEDP->mp_PDP->addWriterProxyData(&writerProxyData,true,&wdata,&pdata)) //ADDED NEW DATA
			{
				//CHECK the locators:
				if(wdata->m_unicastLocatorList.empty() && wdata->m_multicastLocatorList.empty())
				{
					wdata->m_unicastLocatorList = pdata->m_defaultUnicastLocatorList;
					wdata->m_multicastLocatorList = pdata->m_defaultMulticastLocatorList;
				}
				wdata->m_isAlive = true;
				mp_SEDP->pairingWriterProxy(wdata);
			}
			else if(pdata == nullptr) //RTPSParticipant NOT FOUND
			{
				logWarning(RTPS_EDP,"Received message from UNKNOWN RTPSParticipant, removing");
				this->mp_SEDP->mp_PubReader.second->remove_change(change);
				return;
			}
			else //NOT ADDED BECAUSE IT WAS ALREADY THERE
			{
				boost::lock_guard<boost::recursive_mutex> guard(*mp_SEDP->mp_PubReader.second->getMutex());
				for(auto ch = mp_SEDP->mp_PubReader.second->changesBegin();
						ch!=mp_SEDP->mp_PubReader.second->changesEnd();++ch)
				{
					if((*ch)->instanceHandle == change->instanceHandle &&
							(*ch)->sequenceNumber < change->sequenceNumber)
						mp_SEDP->mp_PubReader.second->remove_change(*ch);
				}
				wdata->update(&writerProxyData);
				mp_SEDP->pairingWriterProxy(wdata);
			}
		}
	}
	else
	{
		//REMOVE WRITER FROM OUR READERS:
		logInfo(RTPS_EDP,"Disposed Remote Writer, removing...",C_CYAN);
		GUID_t auxGUID = iHandle2GUID(change->instanceHandle);
		mp_SEDP->mp_PubReader.second->remove_change(change);
		this->mp_SEDP->removeWriterProxy(auxGUID);
	}
	return;
}
Example #2
0
void PDPSimpleListener::onNewCacheChangeAdded(RTPSReader* reader, const CacheChange_t* const change_in)
{
    CacheChange_t* change = (CacheChange_t*)(change_in);
    logInfo(RTPS_PDP,"SPDP Message received");
    if(change->instanceHandle == c_InstanceHandle_Unknown)
    {
        if(!this->getKey(change))
        {
            logWarning(RTPS_PDP,"Problem getting the key of the change, removing");
            this->mp_SPDP->mp_SPDPReaderHistory->remove_change(change);
            return;
        }
    }
    if(change->kind == ALIVE)
    {
        //LOAD INFORMATION IN TEMPORAL RTPSParticipant PROXY DATA
        ParticipantProxyData participant_data;
        CDRMessage_t msg;
        msg.msg_endian = change->serializedPayload.encapsulation == PL_CDR_BE ? BIGEND:LITTLEEND;
        msg.length = change->serializedPayload.length;
        memcpy(msg.buffer,change->serializedPayload.data,msg.length);
        if(participant_data.readFromCDRMessage(&msg))
        {
            //AFTER CORRECTLY READING IT
            //CHECK IF IS THE SAME RTPSParticipant
            change->instanceHandle = participant_data.m_key;
            if(participant_data.m_guid == mp_SPDP->getRTPSParticipant()->getGuid())
            {
                logInfo(RTPS_PDP,"Message from own RTPSParticipant, removing");
                this->mp_SPDP->mp_SPDPReaderHistory->remove_change(change);
                return;
            }

            // At this point we can release reader lock.
            reader->getMutex()->unlock();

            //LOOK IF IS AN UPDATED INFORMATION
            ParticipantProxyData* pdata = nullptr;
            std::unique_lock<std::recursive_mutex> lock(*mp_SPDP->getMutex());
            for (auto it = mp_SPDP->m_participantProxies.begin();
                    it != mp_SPDP->m_participantProxies.end();++it)
            {
                if(participant_data.m_key == (*it)->m_key)
                {
                    pdata = (*it);
                    break;
                }
            }

            RTPSParticipantDiscoveryInfo info;
            info.m_guid = participant_data.m_guid;
            info.m_RTPSParticipantName = participant_data.m_participantName;
            info.m_propertyList = participant_data.m_properties.properties;
            info.m_userData = participant_data.m_userData;

            if(pdata == nullptr)
            {
                info.m_status = DISCOVERED_RTPSPARTICIPANT;
                //IF WE DIDNT FOUND IT WE MUST CREATE A NEW ONE
                pdata = new ParticipantProxyData(participant_data);
                pdata->isAlive = true;
                pdata->mp_leaseDurationTimer = new RemoteParticipantLeaseDuration(mp_SPDP,
                        pdata,
                        TimeConv::Time_t2MilliSecondsDouble(pdata->m_leaseDuration));
                pdata->mp_leaseDurationTimer->restart_timer();
                this->mp_SPDP->m_participantProxies.push_back(pdata);
                lock.unlock();

                mp_SPDP->assignRemoteEndpoints(&participant_data);
                mp_SPDP->announceParticipantState(false);
            }
            else
            {
                info.m_status = CHANGED_QOS_RTPSPARTICIPANT;
                pdata->updateData(participant_data);
                pdata->isAlive = true;
                lock.unlock();

                if(mp_SPDP->m_discovery.use_STATIC_EndpointDiscoveryProtocol)
                    mp_SPDP->mp_EDP->assignRemoteEndpoints(participant_data);
            }

            if(this->mp_SPDP->getRTPSParticipant()->getListener()!=nullptr)
                this->mp_SPDP->getRTPSParticipant()->getListener()->onRTPSParticipantDiscovery(
                        this->mp_SPDP->getRTPSParticipant()->getUserRTPSParticipant(),
                        info);

            // Take again the reader lock
            reader->getMutex()->lock();
        }
    }
    else
    {
        GUID_t guid;
        iHandle2GUID(guid, change->instanceHandle);

        if(this->mp_SPDP->removeRemoteParticipant(guid))
        {
            if(this->mp_SPDP->getRTPSParticipant()->getListener()!=nullptr)
            {
                RTPSParticipantDiscoveryInfo info;
                info.m_status = REMOVED_RTPSPARTICIPANT;
                info.m_guid = guid;
                if(this->mp_SPDP->getRTPSParticipant()->getListener()!=nullptr)
                    this->mp_SPDP->getRTPSParticipant()->getListener()->onRTPSParticipantDiscovery(
                            this->mp_SPDP->getRTPSParticipant()->getUserRTPSParticipant(),
                            info);
            }
        }
    }

    //Remove change form history.
    this->mp_SPDP->mp_SPDPReaderHistory->remove_change(change);

    return;
}