/** 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();
}
Example #2
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;
}
Example #3
0
bool CMOOSDB::OnFetchAllMail(const std::string & sWho,MOOSMSG_LIST & MsgListTx)
{
	MOOSMSG_LIST_STRING_MAP::iterator q = m_HeldMailMap.find(sWho);
	if(q!=m_HeldMailMap.end())
	{
		if(!q->second.empty())
		{
            MsgListTx.splice(MsgListTx.begin(),
            		q->second,
            		q->second.begin(),
            		q->second.end());
		}
	}
	return true;
}
Example #4
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;
}