예제 #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);
	}
}
예제 #2
0
LocatorList_t MockTransport::ShrinkLocatorLists(const std::vector<LocatorList_t>& locatorLists)
{
    LocatorList_t result;

    for(auto locatorList : locatorLists)
        result.push_back(locatorList);

    return result;
}
예제 #3
0
bool RTPSParticipantImpl::assignEndpoint2LocatorList(Endpoint* endp,LocatorList_t& list,bool isMulti,bool isFixed)
{
	bool valid = true;
	LocatorList_t finalList;
	bool added = false;
	for(auto lit = list.begin();lit != list.end();++lit)
	{
		added = false;
		boost::lock_guard<boost::recursive_mutex> guard(*mp_mutex);
		for(std::vector<ListenResource*>::iterator it = m_listenResourceList.begin();it!=m_listenResourceList.end();++it)
		{
			if((*it)->isListeningTo(*lit))
			{
				(*it)->addAssociatedEndpoint(endp);
				LocatorList_t locList = (*it)->getListenLocators();
				finalList.push_back(locList);
				added = true;
			}
		}
		if(added)
			continue;
		ListenResource* LR = new ListenResource(this,++m_threadID,false);
		if(LR->init_thread(this,*lit,m_att.listenSocketBufferSize,isMulti,isFixed))
		{
			LR->addAssociatedEndpoint(endp);
			LocatorList_t locList = LR->getListenLocators();
			finalList.push_back(locList);
			m_listenResourceList.push_back(LR);
			added = true;
		}
		else
		{
			delete(LR);
			valid &= false;
		}
	}
	if(valid && added)
		list = finalList;
	return valid;
}
예제 #4
0
bool RTPSParticipantImpl::assignLocatorForBuiltin_unsafe(LocatorList_t& list, bool isMulti, bool isFixed)
{
	bool valid = true;
	LocatorList_t finalList;
	bool added = false;
	for(auto lit = list.begin();lit != list.end();++lit)
	{
		added = false;
		for(std::vector<ListenResource*>::iterator it = m_listenResourceList.begin();it!=m_listenResourceList.end();++it)
		{
			if((*it)->isListeningTo(*lit))
			{
				LocatorList_t locList = (*it)->getListenLocators();
				finalList.push_back(locList);
				added = true;
			}
		}
		if(added)
			continue;
		ListenResource* LR = new ListenResource(this,++m_threadID,false);
		if(LR->init_thread(this,*lit,m_att.listenSocketBufferSize,isMulti,isFixed))
		{
			LocatorList_t locList = LR->getListenLocators();
			finalList.push_back(locList);
			m_listenResourceList.push_back(LR);
			added = true;
		}
		else
		{
			delete(LR);
			valid &= false;
		}
	}
	if(valid && added)
		list = finalList;
	return valid;
}
예제 #5
0
LocatorList_t MockTransport::NormalizeLocator(const Locator_t& locator)
{
    LocatorList_t list;
    list.push_back(locator);
    return list;
}
예제 #6
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);
	}
}
예제 #7
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);
    }
}