Example #1
0
void PeriodicHeartbeat::event(EventCode code, const char* msg)
{
	const char* const METHOD_NAME = "event";
	if(code == EVENT_SUCCESS)
	{
		SequenceNumber_t firstSeq, lastSeq;
		LocatorList_t locList;
		bool unacked_changes = false;
		{//BEGIN PROTECTION
			boost::lock_guard<boost::recursive_mutex> guardW(*mp_SFW->getMutex());
			std::vector<ChangeForReader_t*> unack;
			for(std::vector<ReaderProxy*>::iterator it = mp_SFW->matchedReadersBegin();
					it!=mp_SFW->matchedReadersEnd();++it)
			{
				unack.clear();
				if(!unacked_changes)
				{
					(*it)->unacked_changes(&unack);
					if(!unack.empty())
					{
						unacked_changes= true;
					}
				}
				locList.push_back((*it)->m_att.endpoint.unicastLocatorList);
				locList.push_back((*it)->m_att.endpoint.multicastLocatorList);
			}
			firstSeq = mp_SFW->get_seq_num_min();
			lastSeq = mp_SFW->get_seq_num_max();
		}
		if(unacked_changes)
		{
			if(firstSeq != c_SequenceNumber_Unknown && lastSeq != c_SequenceNumber_Unknown && lastSeq >= firstSeq)
			{
				mp_SFW->incrementHBCount();
				CDRMessage::initCDRMsg(&m_periodic_hb_msg);
				RTPSMessageCreator::addMessageHeartbeat(&m_periodic_hb_msg,mp_SFW->getGuid().guidPrefix,
						mp_SFW->getHBReaderEntityId(),mp_SFW->getGuid().entityId,
						firstSeq,lastSeq,mp_SFW->getHeartbeatCount(),false,false);
				logInfo(RTPS_WRITER,mp_SFW->getGuid().entityId << " Sending Heartbeat ("<<firstSeq<< " - " << lastSeq<<")" );
				for (std::vector<Locator_t>::iterator lit = locList.begin(); lit != locList.end(); ++lit)
					mp_SFW->getRTPSParticipant()->sendSync(&m_periodic_hb_msg, (*lit));
			}
			//Reset TIMER
			this->restart_timer();
		}

	}
	else if(code == EVENT_ABORT)
	{
		logInfo(RTPS_WRITER,"Aborted");
		this->stopSemaphorePost();
	}
	else
	{
		logInfo(RTPS_WRITER,"Boost message: " <<msg);
	}
}
Example #2
0
bool PDPSimple::removeRemoteParticipant(GUID_t& partGUID)
{
	const char* const METHOD_NAME = "removeRemoteParticipant";
	logInfo(RTPS_PDP,partGUID,C_CYAN );
	boost::unique_lock<boost::recursive_mutex> guardW(*this->mp_SPDPWriter->getMutex());
	boost::unique_lock<boost::recursive_mutex> guardR(*this->mp_SPDPReader->getMutex());
	ParticipantProxyData* pdata = nullptr;
	//Remove it from our vector or RTPSParticipantProxies:
	boost::unique_lock<boost::recursive_mutex> guardPDP(*this->mp_mutex);
	for(std::vector<ParticipantProxyData*>::iterator pit = m_participantProxies.begin();
			pit!=m_participantProxies.end();++pit)
	{
		boost::lock_guard<boost::recursive_mutex> guard(*(*pit)->mp_mutex);
		if((*pit)->m_guid == partGUID)
		{
			pdata = *pit;
			m_participantProxies.erase(pit);
			break;
		}
	}

	if(pdata !=nullptr)
	{
		pdata->mp_mutex->lock();
		if(mp_EDP!=nullptr)
		{
			for(std::vector<ReaderProxyData*>::iterator rit = pdata->m_readers.begin();
					rit!= pdata->m_readers.end();++rit)
			{
				mp_EDP->unpairReaderProxy(pdata, *rit);
			}
			for(std::vector<WriterProxyData*>::iterator wit = pdata->m_writers.begin();
					wit!=pdata->m_writers.end();++wit)
			{
				mp_EDP->unpairWriterProxy(pdata, *wit);
			}
		}
		if(mp_builtin->mp_WLP != nullptr)
			this->mp_builtin->mp_WLP->removeRemoteEndpoints(pdata);
		this->mp_EDP->removeRemoteEndpoints(pdata);
		this->removeRemoteEndpoints(pdata);
		for(std::vector<CacheChange_t*>::iterator it=this->mp_SPDPReaderHistory->changesBegin();
				it!=this->mp_SPDPReaderHistory->changesEnd();++it)
		{
			if((*it)->instanceHandle == pdata->m_key)
			{
				this->mp_SPDPReaderHistory->remove_change(*it);
				break;
			}
		}
		pdata->mp_mutex->unlock();

        guardPDP.unlock();
        guardW.unlock();
        guardR.unlock();

		delete(pdata);
		return true;
	}

	return false;
}
Example #3
0
void PeriodicHeartbeat::event(EventCode code, const char* msg)
{

    // Unused in release mode.
    (void)msg;

	if(code == EVENT_SUCCESS)
	{
		SequenceNumber_t firstSeq, lastSeq;
		Count_t heartbeatCount = 0;
		LocatorList_t locList;
		bool unacked_changes = false;
		{//BEGIN PROTECTION
			boost::lock_guard<boost::recursive_mutex> guardW(*mp_SFW->getMutex());
			for(std::vector<ReaderProxy*>::iterator it = mp_SFW->matchedReadersBegin();
					it != mp_SFW->matchedReadersEnd(); ++it)
			{
				if(!unacked_changes)
				{
                    if((*it)->thereIsUnacknowledged())
					{
						unacked_changes= true;
					}
				}
				locList.push_back((*it)->m_att.endpoint.unicastLocatorList);
				locList.push_back((*it)->m_att.endpoint.multicastLocatorList);
			}

			if (unacked_changes)
			{
				firstSeq = mp_SFW->get_seq_num_min();
				lastSeq = mp_SFW->get_seq_num_max();

				if (firstSeq == c_SequenceNumber_Unknown || lastSeq == c_SequenceNumber_Unknown)
				{
					firstSeq = mp_SFW->next_sequence_number();
					lastSeq = SequenceNumber_t(0, 0);
				}
				else
				{
					(void)firstSeq;
					assert(firstSeq <= lastSeq);
				}

				mp_SFW->incrementHBCount();
				heartbeatCount = mp_SFW->getHeartbeatCount();
			}
		}

		if (unacked_changes)
		{
			CDRMessage::initCDRMsg(&m_periodic_hb_msg);
			// FinalFlag is always false because this class is used only by StatefulWriter in Reliable.
			RTPSMessageCreator::addMessageHeartbeat(&m_periodic_hb_msg, mp_SFW->getGuid().guidPrefix,
				mp_SFW->getHBReaderEntityId(), mp_SFW->getGuid().entityId,
				firstSeq, lastSeq, heartbeatCount, false, false);
			logInfo(RTPS_WRITER,mp_SFW->getGuid().entityId << " Sending Heartbeat ("<<firstSeq<< " - " << lastSeq<<")" );
			for (std::vector<Locator_t>::iterator lit = locList.begin(); lit != locList.end(); ++lit)
				mp_SFW->getRTPSParticipant()->sendSync(&m_periodic_hb_msg,(Endpoint *)mp_SFW , (*lit));
		
			//Reset TIMER
			this->restart_timer();
		}

	}
	else if(code == EVENT_ABORT)
	{
		logInfo(RTPS_WRITER,"Aborted");
	}
	else
	{
		logInfo(RTPS_WRITER,"Boost message: " <<msg);
	}
}
Example #4
0
void PeriodicHeartbeat::event(EventCode code, const char* msg)
{

    // Unused in release mode.
    (void)msg;

    if(code == EVENT_SUCCESS)
    {
        SequenceNumber_t firstSeq, lastSeq;
        Count_t heartbeatCount = 0;
        LocatorList_t locList;
        bool unacked_changes = false;
        std::vector<GUID_t> remote_readers;

        {//BEGIN PROTECTION
            std::lock_guard<std::recursive_mutex> guardW(*mp_SFW->getMutex());
            for(std::vector<ReaderProxy*>::iterator it = mp_SFW->matchedReadersBegin();
                    it != mp_SFW->matchedReadersEnd(); ++it)
            {
                if(!unacked_changes)
                {
                    if((*it)->thereIsUnacknowledged())
                    {
                        unacked_changes= true;
                    }
                }
                locList.push_back((*it)->m_att.endpoint.unicastLocatorList);
                locList.push_back((*it)->m_att.endpoint.multicastLocatorList);
                remote_readers.push_back((*it)->m_att.guid);
            }

            if (unacked_changes)
            {
                firstSeq = mp_SFW->get_seq_num_min();
                lastSeq = mp_SFW->get_seq_num_max();

                if (firstSeq == c_SequenceNumber_Unknown || lastSeq == c_SequenceNumber_Unknown)
                {
                    return;
                }
                else
                {
                    (void)firstSeq;
                    assert(firstSeq <= lastSeq);
                }

                mp_SFW->incrementHBCount();
                heartbeatCount = mp_SFW->getHeartbeatCount();

                // TODO(Ricardo) Use StatefulWriter::send_heartbeat_to_nts.
            }
        }

        if (unacked_changes)
        {
            RTPSMessageGroup group(mp_SFW->getRTPSParticipant(), mp_SFW, RTPSMessageGroup::WRITER, m_cdrmessages);

            // FinalFlag is always false because this class is used only by StatefulWriter in Reliable.
            group.add_heartbeat(remote_readers,
                    firstSeq, lastSeq, heartbeatCount, false, false, locList);
            logInfo(RTPS_WRITER,mp_SFW->getGuid().entityId << " Sending Heartbeat ("<<firstSeq<< " - " << lastSeq<<")" );

            //Reset TIMER
            this->restart_timer();
        }

    }
    else if(code == EVENT_ABORT)
    {
        logInfo(RTPS_WRITER,"Aborted");
    }
    else
    {
        logInfo(RTPS_WRITER,"Event message: " << msg);
    }
}