Exemplo n.º 1
0
bool CMOOSRemoteLite::MailLoop()
{
    m_bRunMailLoop = true;
    while(!m_bQuit)
    {
        MOOSPause(300);

        MOOSMSG_LIST MailIn;
        if(m_bRunMailLoop && m_Comms.Fetch(MailIn))
        {
            //process mail
            //simply write out
            MOOSMSG_LIST::iterator p;

            //make it in time order
            MailIn.sort();
            MailIn.reverse();

            for(p = MailIn.begin();p!=MailIn.end();p++)
            {

                if(p->IsSkewed(MOOSTime()))
                    continue;
                if(MOOSStrCmp(p->m_sKey,"NAV_SUMMARY"))
                {
                    DoNavSummary(*p);
                }
                else

                if(p->GetKey().find("DEBUG")!=string::npos)
                {
                    //we print MOOS_DEBUG messages to the screen
                    string sMsg = p->m_sVal;
                    MOOSRemoveChars(sMsg,"\r\n");

                    MOOSTrace(">%-10s @ %7.2f \"%s\"\n",
                        p->m_sSrc.c_str(),
                        p->m_dfTime-GetAppStartTime(),
                        sMsg.c_str());
                }

                else
                {
                    CUSTOMJOURNAL_MAP::iterator w = m_CustomJournals.find(p->GetKey());
                    if(w!=m_CustomJournals.end())
                    {
                        w->second.Add(p->GetAsString());
                    }

                }
            }


            UpdateMOOSVariables(MailIn);

        }

    }
    return true;
}
Exemplo n.º 2
0
bool CMOOSLogger::OnNewMail(MOOSMSG_LIST &NewMail)
{
    //these three calls look through the incoming mail
    //and handle all appropriate logging
    DoAsyncLog(NewMail);

    UpdateMOOSVariables(NewMail);

    LogSystemMessages(NewMail);


    //here we look for more unusual things
    MOOSMSG_LIST::iterator q;

    for(q=NewMail.begin();q!=NewMail.end();q++)
    {

        if(q->IsSkewed(MOOSTime()))
            continue;

        //are we being asked to restart?
        if(MOOSStrCmp(q->GetKey(),"LOGGER_RESTART"))
        {
            OnLoggerRestart();
        }

    }

    return true;
}
Exemplo n.º 3
0
	bool OnNewMail(MOOSMSG_LIST & Mail){
		//process it
		MOOSMSG_LIST::iterator q;
		for(q=Mail.begin();q!=Mail.end();q++)
		{
			//are we a ponger
			if(q->GetKey()=="ex1010-ping")
				Notify("ex1010-pong",q->GetDouble());

			if(q->GetKey()=="ex1010-pong"){
				double latency =(MOOSLocalTime()-q->GetDouble())/2;
				mean_latency_+= latency;
				if(count_>2)//this simply removes case of stale data in DB
					max_latency_ = std::max(latency,max_latency_);
				if(count_<burstsize_-1)
					Notify("ex1010-ping",MOOSLocalTime());
			}
			count_++;
		}
		return true;
	}
Exemplo n.º 4
0
bool CMOOSApp::LookForAndHandleAppCommand(MOOSMSG_LIST & NewMail)
{
    MOOSMSG_LIST::iterator q;
    bool bResult = true;
    for(q=NewMail.begin();q!=NewMail.end();q++)
    {
        if(MOOSStrCmp(q->GetKey(),GetCommandKey()))
        {
            //give a derived class a chance to respond
            bResult&= OnCommandMsg(*q);
        }
    }
    return bResult;
}
Exemplo n.º 5
0
void moossafir::SimDriver::do_work()
{
    MOOSMSG_LIST msgs;
    if(moos_client_.Fetch(msgs))
    {
        for(MOOSMSG_LIST::iterator it = msgs.begin(),
                end = msgs.end(); it != end; ++it)
        {
            const std::string& in_moos_var = driver_cfg_.GetExtension(moossafir::Config::incoming_moos_var);
            if(it->GetKey() == in_moos_var)
            {
                const std::string& value = it->GetString();
                
                glog.is(DEBUG1) &&
                    glog << group(glog_in_group())  << in_moos_var << ": " << value  << std::endl;
                goby::acomms::protobuf::ModemRaw in_raw;
                in_raw.set_raw(value);
                ModemDriverBase::signal_raw_incoming(in_raw);

                try
                {
                    goby::acomms::protobuf::ModemTransmission m;
                    std::string data;
                    int id;
                    if(goby::moos::val_from_string(data, value, "data"))
                        m.add_frame(dccl::hex_decode(data));

                    if(!goby::moos::val_from_string(id, value, "modem_id"))
                        throw(std::runtime_error("No `modem_id` field"));

                    m.set_src(id);
                    receive_message(m);
                }
                catch(std::exception& e)
                {
                    glog.is(DEBUG1) &&
                        glog << group(glog_in_group())  << warn << "Failed to parse incoming  message: " << e.what() << std::endl;
                }                
            }            
        }
    }
} 
Exemplo n.º 6
0
bool CMOOSCommClient::DispatchInBoxToActiveThreads()
{


	//here we dispatch to special callbacks managed by threads

	MOOS::ScopedLock L(ActiveQueuesLock_);


	//before we start we can see if we have a default queue installed...
	std::map<std::string, std::set<std::string> >::iterator q;

	MOOSMSG_LIST::iterator t = m_InBox.begin();

	//iterate over all pending messages.
	while(t!=m_InBox.end())
	{

//	    std::cerr<<"Inbox size:"<<m_InBox.size()<<"\n";
//	    t->Trace();

		//does this message have a active queue mapping?
		q= Msg2ActiveQueueName_.find(t->GetKey());

		//have we ever checked this message against the wildcard queues?
		std::set<std::string>::iterator u  =  WildcardCheckSet_.find(t->GetKey());

		if(q==Msg2ActiveQueueName_.end() || u==WildcardCheckSet_.end() )
		{
			//maybe the wildcard queues are interested?
			//or maybe this is a new message whihc has not been seen by wildcard queues

			//each element is a <nickname,pattern> string pair;
			std::map<std::string, std::string  >::iterator w;

			bool bFoundWCMatch = false;
			for(w = WildcardQueuePatterns_.begin();w!=WildcardQueuePatterns_.end();w++)
			{
				std::string sPattern = w->second;
				//build a list of all wc queues that match this message
				//add these queues to the list of queues pointed to by this message
				if(MOOSWildCmp(sPattern,t->GetKey()))
				{
//				    std::cerr<<"found wildcard match adding queue  "<<w->first
//				            <<" to routing for "<<t->GetKey()<<"\n";

					Msg2ActiveQueueName_[t->GetKey()].insert(w->first);
					bFoundWCMatch = true;
				}
			}

			//remember all messages that have been received...
			//we do it here because at this point wild card queue have been given
			//the option to register their interest....
			//but what to do if a wc queue in installed at run time...?
			WildcardCheckSet_.insert(t->GetKey());

			//std::cerr<<"added key"<<t->GetKey()<<" to wildcard chacek set\n";

			//if we found a least one mapping simply go again without
			//incrementing t...smart
			if(bFoundWCMatch)
			{
			    continue;
			}
			else
			{
			    if(q==Msg2ActiveQueueName_.end())
			    {
			        //wildcard queues are not interested
			        //no standard queue is interested
			        //nothing to do....
			        return true;
			    }
			}
		}

		//now we know which queue(s) are relevant for us.
		//there namaes are in a string list.
		std::set<std::string>::iterator r;

		bool bPickedUpByActiveQueue = false;
		for(r = q->second.begin();r!=q->second.end();r++)
		{

//		    std::cerr<<"found queue that is relevent "<<*r<<"\n";

		    //for each named queue find a pointer to
			//the actual active queue
			std::map<std::string,MOOS::ActiveMailQueue*>::iterator v;
			v = ActiveQueueMap_.find(*r);
			if(v!=ActiveQueueMap_.end())
			{
				//and now we have checked it exists push this message to that
				//queue
                MOOS::ActiveMailQueue* pQ = v->second;
//                std::cerr<<"pushing to queue: "<<(void*)pQ<<"\n";
                bPickedUpByActiveQueue = true;
				pQ->Push(*t);
			}
			else
			{
				//this is bad news - we have be told to use a queue
				//which does not exist.
			    //std::cerr<<"WTF\n";
				throw std::runtime_error("active queue "+*r+" not found");
			}
		}


		if(bPickedUpByActiveQueue)
		{
	        //we have now handled this message remove it from the Inbox.
		    MOOSMSG_LIST::iterator to_erase = t;
		    ++t;
		    m_InBox.erase(to_erase);
		}
		else
		{
		    ++t;
		}
	}

	return true;
}