bool CMOOSCommClient::Peek(MOOSMSG_LIST & MsgList, int nIDRequired,bool bClear)
{
	MsgList.clear();

	m_InLock.Lock();

	MOOSMSG_LIST::iterator p,q;

	p=m_InBox.begin();
	while(p!=m_InBox.end())
	{
		if(!p->IsType(MOOS_NULL_MSG))
		{
			//only give client non NULL Msgs
			if(p->m_nID==nIDRequired)
			{
				//this is the correct ID!
				MsgList.push_front(*p);
				q=p++;
				m_InBox.erase(q);
				continue;
			}
		}
		p++;
	}

	//conditionally (ex MIT suggestion 2006) remove all elements
	if(bClear) 
		m_InBox.clear();


	m_InLock.UnLock();

	return !MsgList.empty();
}
/** this is called by a user of a CommClient object
to retrieve mail */
bool CMOOSCommClient::Fetch(MOOSMSG_LIST &MsgList)
{

	if(!m_bMailPresent)
		return false;

	MsgList.clear();

	m_InLock.Lock();

	MOOSMSG_LIST::iterator p;

	m_InBox.remove_if(IsNullMsg);


	MsgList.splice(MsgList.begin(),m_InBox,m_InBox.begin(),m_InBox.end());

	//remove all elements
	m_InBox.clear();

	m_bMailPresent = false;

	m_InLock.UnLock();

	return !MsgList.empty();
}
示例#3
0
/**this will be called each time a new packet is recieved*/
bool CMOOSDB::OnRxPkt(const std::string & sClient,MOOSMSG_LIST & MsgListRx,MOOSMSG_LIST & MsgListTx)
{
    

    MOOSMSG_LIST::iterator p;
    
    for(p = MsgListRx.begin();p!=MsgListRx.end();p++)
    {
        ProcessMsg(*p,MsgListTx);
    }
    
    //good spot to update our internal time    
    UpdateDBTimeVars();

    //and send clients an occasional membersip list
    UpdateDBClientsVar();

    if(!MsgListRx.empty())
    {
        
        //now we fill in the packet with our replies to THIS CLIENT
        //MOOSMSG_LIST_STRING_MAP::iterator q = m_HeldMailMap.find(MsgListRx.front().m_sSrc);
        
        MOOSMSG_LIST_STRING_MAP::iterator q = m_HeldMailMap.find(sClient);
        
        if(q==m_HeldMailMap.end())
        {
            
            //CMOOSMsg & rMsg = MsgListRx.front();
            //there is no mail waiting to be sent to this client
            //should only happen at start up...
            //string sClient = MsgListRx.front().m_sSrc;
            
            MOOSMSG_LIST NewList;
            
            m_HeldMailMap[sClient] = NewList;
            
            q = m_HeldMailMap.find(sClient);
            
            assert(q!=m_HeldMailMap.end());
        }
        
        
        if(q!=m_HeldMailMap.end())
        {
            if(!q->second.empty())
            {
                //copy all the held mail to MsgListTx
                MsgListTx.splice(MsgListTx.begin(),q->second);
            }
        }
    }
    
    return true;
}
示例#4
0
bool CMOOSCommObject::ReadMsg(XPCTcpSocket *pSocket,CMOOSMsg &Msg, int nSecondsTimeout)
{
    MOOSMSG_LIST MsgList;
    
    CMOOSCommPkt Pkt;

    if(ReadPkt(pSocket,Pkt,nSecondsTimeout))
    {

        Pkt.Serialize(MsgList,false);

        if(!MsgList.empty())
        {
            Msg = MsgList.front();
        }
        
    }


    return !MsgList.empty();
}
示例#5
0
/**this will be called each time a new packet is recieved*/
bool CMOOSDB::OnRxPkt(const std::string & sClient,MOOSMSG_LIST & MsgListRx,MOOSMSG_LIST & MsgListTx)
{

    MOOSMSG_LIST::iterator p;
    
    for(p = MsgListRx.begin();p!=MsgListRx.end();p++)
    {
        ProcessMsg(*p,MsgListTx);
    }
    

    double dfNow = MOOS::Time();
    if(dfNow-m_dfSummaryTime>2.0)
    {
        m_dfSummaryTime = dfNow;

        //good spot to update our internal time
        UpdateDBTimeVars();

        //and send clients an occasional membersip list
        UpdateDBClientsVar();

        //update a db summary var once in a while
        UpdateSummaryVar();

        //update quality of service summary
        UpdateQoSVar();

        //update variable which publishes who is reading and writing what
        UpdateReadWriteSummaryVar();
    }

    if(!MsgListRx.empty())
    {
        
        //now we fill in the packet with our replies to THIS CLIENT
        MOOSMSG_LIST_STRING_MAP::iterator q = m_HeldMailMap.find(sClient);
        
        if(q==m_HeldMailMap.end())
        {
            
            //CMOOSMsg & rMsg = MsgListRx.front();
            //there is no mail waiting to be sent to this client
            //should only happen at start up...
            //string sClient = MsgListRx.front().m_sSrc;
            
            MOOSMSG_LIST NewList;
            
            m_HeldMailMap[sClient] = NewList;
            
            q = m_HeldMailMap.find(sClient);
            
            assert(q!=m_HeldMailMap.end());
        }
        
        
        if(q!=m_HeldMailMap.end())
        {
            //MOOSTrace("%f OnRxPkt %d messages held for client %s\n",MOOSTime(),q->second.size(),sClient.c_str());

            if(!q->second.empty())
            {
                //copy all the held mail to MsgListTx
                MsgListTx.splice(MsgListTx.begin(),
                		q->second,
                		q->second.begin(),
                		q->second.end());
            }
        }
    }
    
    return true;
}
示例#6
0
bool CMOOSPlayBackV2::Iterate(MOOSMSG_LIST &Output)
{
    if(IsEOF())
        return false;

    double dfStopTime = m_dfLastMessageTime+m_dfTickTime;
    
    bool bDone = false;
    
    while(!bDone && !IsEOF() )    
    {
        CMOOSMsg NewMsg;
        double dfTNext = m_ALog.GetEntryTime(m_nCurrentLine);


        //are we in a mode in which we are slaved to a client
        //via its publishing of MOOS_CHOKE?
        m_dfClientLagTime = MOOSTime() - m_dfLastClientProcessedTime;
        if (m_dfLastClientProcessedTime != -1 &&
             m_dfClientLagTime > MAX_CHOKE_TIME)
        {
            m_bWaitingForClientCatchup = true;    
            bDone = true;
            dfStopTime = dfTNext;
            continue;
        } 
        else
        {
            //normal sequential processing under our own steam
            m_bWaitingForClientCatchup = false;

            if(dfTNext<=dfStopTime)
            {
                
                if(MessageFromLine(m_ALog.GetLine(m_nCurrentLine),NewMsg))
                {
                    if(!IsFiltered(NewMsg.GetSource()))
                    {
                        Output.push_front(NewMsg);
                    }
                }                             

				
				// arh moved this out of the loop above, because a failed
				// call to MessageFromLine would make uPlayback hang in
				// an infinite loop
				m_nCurrentLine++;
            }
            else
            {
                bDone = true;
            }

        }                         
    }

    //post a playback time
    if(!Output.empty())
    {
        CMOOSMsg timeMsg( MOOS_NOTIFY, "PLAYBACK_DB_TIME", dfStopTime );
        timeMsg.m_sSrc = "uPlayback";
        Output.push_front( timeMsg );
    }


    m_dfLastMessageTime = dfStopTime;



    return true;
}