Beispiel #1
0
bool CMOOSLogger::HandleWildCardLogging()
{
    static double  dfLastWildCardTime = -1.0;

    if(MOOSTime()-dfLastWildCardTime>DEFAULT_WILDCARD_TIME)
    {
        MOOSMSG_LIST InMail;
        if(m_Comms.ServerRequest("VAR_SUMMARY", InMail, 2.0, false))
        {
            MOOSAssert(InMail.size()==1);
            std::string ss(InMail.begin()->GetString());
            bool bHit = false;
            while(!ss.empty())
            {
                std::string sVar = MOOSChomp(ss);
                if(GetMOOSVar(sVar)==NULL)
                {
					bool bWouldNormallyReject = IsWildCardRejected(sVar);
					bool bWouldNormallyAccept = IsWildCardAccepted(sVar);
					bool bWanted = false;
					
					if(m_bUseExcludedLog)
					{
						bWanted = true;
						if( bWouldNormallyAccept && !bWouldNormallyReject)
						{
							MOOSTrace("  Added wildcard logging of %-20s\n",sVar.c_str());
							m_LogDestinations[sVar] = ALOG;
						}
						else 
						{
							MOOSTrace("  Added wildcard logging of %-20s  (xlog) \n",sVar.c_str());
							m_LogDestinations[sVar] = XLOG;
							
						}
					}
				
					else
					{
						if( bWouldNormallyAccept &&	!bWouldNormallyReject )
						{
							MOOSTrace("  Added wildcard logging of %-20s\n",sVar.c_str());
							m_LogDestinations[sVar] = ALOG;
							bWanted = true;
						}
						else if(bWouldNormallyAccept && bWouldNormallyReject)
						{
							//MOOSTrace("  denied added wildcard logging of %-20s   (fits Omit pattern as well as Accept pattern)\n",sVar.c_str());	
							bWanted = false;
						}
					}
					
					if(bWanted)
					{
						//yep we want to know....
						if(AddMOOSVariable(sVar,sVar,"",0.0))
						{
							bHit = true;
						}		
					}
						
                }
            }

            if(bHit)
                RegisterMOOSVariables();
        }

        dfLastWildCardTime = MOOSTime();
    }

    return true;
}
Beispiel #2
0
/** This function stuffs messages in/from a packet */
bool CMOOSCommPkt::Serialize(MOOSMSG_LIST &List, bool bToStream, bool bNoNULL, double * pdfPktTime)
{
    if(bToStream)
    {

        m_nMsgLen=0;
        m_pNextData = m_pStream;
        m_nByteCount = 0;

        //we need to leave space at the start of the packet for total
        //length and number of include messages
        m_pNextData+=2*sizeof(int);
        m_nByteCount+= 2* sizeof(int);


        #define PKT_TMP_BUFFER_SIZE 40000
        unsigned char TmpBuffer[PKT_TMP_BUFFER_SIZE];
        unsigned char * pTmpBuffer = TmpBuffer;


        MOOSMSG_LIST::iterator p;
        int nCount = 0;
        for(p = List.begin();p!=List.end();p++,nCount++)
        {
        
            //MOOSTrace("Sending %s \n",p->m_sKey.c_str());
            int nTmpSize = PKT_TMP_BUFFER_SIZE;

            int nCopied = (*p).Serialize(pTmpBuffer,nTmpSize);

            if(nCopied!=-1)
            {
                //now copy to our stream...
                CopyToStream(pTmpBuffer,nCopied);
            }
            else
            {
                return false;
            }

        }

        //finally write how many bytes we have written at the start
        //look for need to swap byte order if required
        m_pNextData = m_pStream;
        int nBC = IsLittleEndian() ? m_nByteCount : SwapByteOrder<int>(m_nByteCount);
        memcpy((void*)m_pNextData,(void*)(&nBC),sizeof(m_nByteCount));
        m_pNextData+=sizeof(m_nByteCount);


        //and then how many messages are included
        //look for need to swap byte order if required
        int nMessages = List.size();
        nMessages = IsLittleEndian() ? nMessages : SwapByteOrder<int>(nMessages);
        memcpy((void*)m_pNextData,(void*)(&nMessages),sizeof(nMessages));
        m_pNextData+=sizeof(nMessages);


    }
    else
    {
        
        m_pNextData = m_pStream;
        m_nMsgLen = 0;
        m_nByteCount = 0;

        //first figure out the length of the message
        //look to swap byte order as required
        memcpy((void*)(&m_nMsgLen),(void*)m_pNextData,sizeof(m_nMsgLen));
        m_nMsgLen = IsLittleEndian() ? m_nMsgLen : SwapByteOrder<int>(m_nMsgLen);
        m_pNextData+=sizeof(m_nMsgLen);
        m_nByteCount+=sizeof(m_nMsgLen);

        int nSpaceFree=m_nMsgLen - sizeof(m_nMsgLen);

        //no figure out how many messages are packed in this packet
        //look to swap byte order as required
        int nMessages = 0;
        memcpy((void*)(&nMessages),(void*)m_pNextData,sizeof(nMessages));
        nMessages = IsLittleEndian() ? nMessages : SwapByteOrder<int>(nMessages);
        m_pNextData+=sizeof(nMessages);
        nSpaceFree-=sizeof(nMessages);
        m_nByteCount+=sizeof(nMessages);

        for(int i = 0; i<nMessages;i++)
        {
                    
            CMOOSMsg Msg;
            int nUsed = Msg.Serialize(m_pNextData,nSpaceFree,false);

            if(nUsed!=-1) 
            {
                //allows us to not store NULL messages
                bool bOmit = bNoNULL && (Msg.m_cMsgType==MOOS_NULL_MSG);

                if(Msg.m_cMsgType==MOOS_NULL_MSG && pdfPktTime!=NULL && i == 0 )
                {
                    *pdfPktTime     = Msg.GetDouble();                    
                }

                if(!bOmit)
                {
                    List.push_front(Msg);
                }


                m_pNextData+=nUsed;
                m_nByteCount+=nUsed;
                nSpaceFree-=nUsed;

            }
            else
            {
                //bad news...
                break;
            }        
        }
    }

    //here at the last moment we can fill in our totalm length for safe keeping
    m_nMsgLen = m_nByteCount;

    return true;
}