MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman at MIT 2001-2002 and Oxford 00010 // University 2003-2005. email: pnewman@robots.ox.ac.uk. 00011 // 00012 // This file is part of a MOOS Core Component. 00013 // 00014 // This program is free software; you can redistribute it and/or 00015 // modify it under the terms of the GNU General Public License as 00016 // published by the Free Software Foundation; either version 2 of the 00017 // License, or (at your option) any later version. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 // General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00030 00031 // MOOSApp.cpp: implementation of the CMOOSApp class. 00032 // 00034 #ifdef _WIN32 00035 #pragma warning(disable : 4786) 00036 #pragma warning(disable : 4503) 00037 #endif 00038 00039 #include "MOOSGlobalHelper.h" 00040 #include "MOOSApp.h" 00041 #include <cmath> 00042 #include <iostream> 00043 #include <sstream> 00044 #include <iterator> 00045 00046 using namespace std; 00047 00048 // predicate for sorting on time 00049 bool MOOSMsgTimeSorter(const CMOOSMsg &M1, const CMOOSMsg &M2) 00050 { 00051 return (M1.GetTime() < M2.GetTime()); 00052 } 00053 00055 // these are file-scope methods which allow 00056 // redirection of a call back into the CMOOSApp Class 00057 // they don't concern the average user... 00059 bool MOOSAPP_OnConnect(void * pParam) 00060 { 00061 if(pParam!=NULL) 00062 { 00063 CMOOSApp* pApp = (CMOOSApp*)pParam; 00064 00065 //we may have private work to do 00066 pApp->OnConnectToServerPrivate(); 00067 00068 //client work 00069 return pApp->OnConnectToServer(); 00070 00071 } 00072 return false; 00073 } 00074 00075 bool MOOSAPP_OnDisconnect(void * pParam) 00076 { 00077 if(pParam!=NULL) 00078 { 00079 CMOOSApp* pApp = (CMOOSApp*)pParam; 00080 00081 //private work 00082 pApp->OnDisconnectToServerPrivate(); 00083 00084 //client work 00085 return pApp->OnDisconnectFromServer(); 00086 00087 } 00088 return false; 00089 } 00090 00091 00092 bool MOOSAPP_OnMail(void *pParam) 00093 { 00094 if(pParam!=NULL) 00095 { 00096 CMOOSApp* pApp = (CMOOSApp*)pParam; 00097 00098 //client mail work 00099 return pApp->OnMailCallBack(); 00100 00101 } 00102 return false; 00103 00104 } 00105 00107 // Construction/Destruction 00109 CMOOSApp::CMOOSApp() 00110 { 00111 m_dfFreq=DEFAULT_MOOS_APP_FREQ; 00112 m_nCommsFreq=DEFAULT_MOOS_APP_COMMS_FREQ; 00113 m_nIterateCount = 0; 00114 m_nMailCount = 0; 00115 m_bServerSet = false; 00116 m_dfAppStartTime = -1; 00117 m_bDebug = false; 00118 m_bSimMode = false; 00119 m_bUseMOOSComms = true; 00120 m_dfLastRunTime = -1; 00121 m_bCommandMessageFiltering = false; 00122 m_dfLastStatusTime = -1; 00123 m_bSortMailByTime = true; 00124 m_bAppError = false; 00125 m_bQuitOnIterateFail = false; 00126 m_bQuitRequested = false; 00127 00128 SetMOOSTimeWarp(1.0); 00129 00130 EnableIterateWithoutComms(false); 00131 } 00132 00133 CMOOSApp::~CMOOSApp() 00134 { 00135 00136 } 00137 00138 //this is an overloaded 3 parameter version which allows explicit setting of the registration name 00139 bool CMOOSApp::Run(const char * sName,const char * sMissionFile,const char * sMOOSName) 00140 { 00141 //fill in specialised MOOSName 00142 m_sMOOSName = sMOOSName; 00143 return Run(sName,sMissionFile); 00144 } 00145 00146 //the main MOOSApp Run function 00147 bool CMOOSApp::Run( const char * sName, 00148 const char * sMissionFile) 00149 { 00150 00151 //save absolutely crucial info... 00152 m_sAppName = sName; 00153 m_sMissionFile = sMissionFile; 00154 m_MissionReader.SetAppName(m_sAppName); 00155 00156 //by default we will 00157 if(m_sMOOSName.empty()) 00158 m_sMOOSName=m_sAppName; 00159 00160 00161 //can we see the mission file 00162 if(sMissionFile!=NULL) 00163 { 00164 if(!m_MissionReader.SetFile(m_sMissionFile.c_str())) 00165 { 00166 MOOSTrace("Warning Mission File \"%s\" not found...\n",m_sMissionFile.c_str()); 00167 } 00168 00169 if(1) 00170 { 00171 //what is the global time warp 00172 double dfTimeWarp = 1.0; 00173 if(m_MissionReader.GetValue("MOOSTimeWarp", dfTimeWarp)) 00174 { 00175 SetMOOSTimeWarp(dfTimeWarp); 00176 } 00177 00178 00179 //are we expected to use MOOS comms? 00180 m_MissionReader.GetConfigurationParam("UseMOOSComms",m_bUseMOOSComms); 00181 00182 //are we being asked to sort mail by time.. 00183 m_MissionReader.GetConfigurationParam("SortMailByTime",m_bSortMailByTime); 00184 00185 //are we in debug mode 00186 m_MissionReader.GetConfigurationParam("DEBUG",m_bDebug); 00187 00188 //are we in simulator mode? 00189 string sSim; 00190 if(m_MissionReader.GetValue("SIMULATOR",sSim)) 00191 { 00192 m_bSimMode = MOOSStrCmp(sSim,"TRUE"); 00193 } 00194 00195 //are we in playback mode 00196 string sPlayBack; 00197 if(m_MissionReader.GetValue("PLAYBACK",sPlayBack)) 00198 { 00199 SetMOOSPlayBack(MOOSStrCmp(sPlayBack,"TRUE")); 00200 } 00201 00202 //OK now figure out our tick speeds above what is set by default 00203 //in derived class constructors this can be set in the process config block 00204 //by the mission architect 00205 m_MissionReader.GetConfigurationParam("APPTICK",m_dfFreq); 00206 00207 00208 //do we want to enable command filtering (default is set in constructor) 00209 m_MissionReader.GetConfigurationParam("CatchCommandMessages",m_bCommandMessageFiltering); 00210 } 00211 } 00212 00213 //what time did we start? 00214 m_dfAppStartTime = MOOSTime(); 00215 00216 //can we start the communications ? 00217 if(m_bUseMOOSComms) 00218 { 00219 if(!ConfigureComms()) 00220 { 00221 return false; 00222 } 00223 00225 //OK we are going to wait for a conenction to be established 00226 // this is a little harsh but it saves derived classes having to 00227 // hold off connecting to the server until ready 00228 // but we will only hang around for 1 second... 00229 // so it is possible that notifies will fail...but very unlikely 00230 // note this is not a hack! just being helpful. Ths success of an 00231 // application is NOT dependent on this 00232 int t = 0; 00233 int dT = 50; 00234 while(!m_Comms.IsConnected()) 00235 { 00236 MOOSPause(dT); 00237 t+=dT; 00238 if(t>5000) 00239 break; 00240 } 00241 //give iostream time to write comms start details up to screen..this is not really necessary 00242 //as the code is thread safe...it is aesthetic only 00243 MOOSPause(500); 00244 } 00245 00246 00247 00249 if(!OnStartUp()) 00250 { 00251 MOOSTrace("Derived OnStartUp() returned false... Quitting\n"); 00252 return false; 00253 } 00254 00255 00256 MOOSTrace("%s is Running:\n",GetAppName().c_str()); 00257 MOOSTrace("\t AppTick @ %.1f Hz\n",m_dfFreq); 00258 MOOSTrace("\t CommsTick @ %d Hz\n",m_nCommsFreq); 00259 if(GetMOOSTimeWarp()!=1.0) 00260 MOOSTrace("\t Time Warp @ %.1f \n",GetMOOSTimeWarp()); 00261 00262 00263 /**************************** THE MAIN MOOS APP LOOP **********************************/ 00264 00265 while(!m_bQuitRequested) 00266 { 00267 if(!m_Comms.HasMailCallBack()) 00268 { 00269 00270 bool bOK = DoRunWork(); 00271 00272 if(m_bQuitOnIterateFail && !bOK) 00273 return MOOSFail("MOOSApp Exiting as requested"); 00274 } 00275 else 00276 MOOSPause(1000); 00277 00278 } 00279 00280 /*************************** END OF MOOS APP LOOP ***************************************/ 00281 00282 return true; 00283 } 00284 00285 00286 /*called by a third party to request a MOOS App to quit - only useful for 00287 example if a MOOSApp is run in a secondary thread */ 00288 bool CMOOSApp::RequestQuit() 00289 { 00290 m_bQuitRequested = true; 00291 return true; 00292 } 00293 00294 bool CMOOSApp::DoRunWork() 00295 { 00296 //look for mail 00297 double dfT1 = MOOSLocalTime(); 00298 //local vars 00299 MOOSMSG_LIST MailIn; 00300 if(m_bUseMOOSComms) 00301 { 00302 if( m_Comms.Fetch(MailIn)) 00303 { 00305 // process mail 00306 if(m_bSortMailByTime) 00307 MailIn.sort(MOOSMsgTimeSorter); 00308 00309 00310 //call our own private version 00311 OnNewMailPrivate(MailIn); 00312 00313 //classes will have their own personal versions of this 00314 OnNewMail(MailIn); 00315 00316 m_nMailCount++; 00317 } 00318 00319 if(m_Comms.IsConnected() || CanIterateWithoutComms() ) 00320 { 00321 //do private work 00322 IteratePrivate(); 00323 00325 // do application specific processing 00326 bool bOK = Iterate(); 00327 00328 if(m_bQuitOnIterateFail && !bOK) 00329 return false; 00330 00331 m_nIterateCount++; 00332 } 00333 } 00334 else 00335 { 00336 //do private work 00337 IteratePrivate(); 00338 00340 // do application specific processing 00341 bool bOK = Iterate(); 00342 00343 if(m_bQuitOnIterateFail && !bOK) 00344 return false; 00345 00346 00347 m_nIterateCount++; 00348 } 00349 00350 //store for derived class use the last time iterate was called; 00351 m_dfLastRunTime = MOOSLocalTime(); 00352 00353 //sleep 00354 if(m_dfFreq>0) 00355 { 00356 int nElapsedTime_ms = static_cast<int> (1000.0*(m_dfLastRunTime-dfT1)); 00357 int nRequiredWait_ms = static_cast<int> (1000.0/m_dfFreq); 00358 00359 if (nElapsedTime_ms < 0) nElapsedTime_ms = 0; 00360 00361 int nSleep = (nRequiredWait_ms - nElapsedTime_ms); 00362 00363 //a 10 ms sleep is a good as you are likely to get, if we are being told to sleep less than this we may as well 00364 //tick once more and let the OS schedule us appropriately 00365 if(nSleep>10 && !m_Comms.HasMailCallBack()) 00366 { 00367 MOOSPause(nSleep); 00368 } 00369 } 00370 00371 return true; 00372 00373 } 00374 00375 00376 00377 void CMOOSApp::SetServer(const char *sServerHost, long lPort) 00378 { 00379 m_sServerHost = sServerHost; 00380 m_lServerPort = lPort; 00381 m_bServerSet = true; 00382 } 00383 00384 bool CMOOSApp::CheckSetUp() 00385 { 00386 if(m_sServerHost.empty()) 00387 { 00388 MOOSTrace("MOOS Server host not specified\n"); 00389 return false; 00390 } 00391 00392 if(m_lServerPort==0) 00393 { 00394 MOOSTrace("MOOS Server port not specified\n"); 00395 return false; 00396 } 00397 00398 return true; 00399 } 00400 00401 00402 void CMOOSApp::SetAppError(bool bErr, const std::string & sErr) 00403 { 00404 m_bAppError = bErr; 00405 m_sAppError = m_bAppError ? sErr : ""; 00406 } 00407 00408 00410 bool CMOOSApp::UseMailCallBack() 00411 { 00412 /* by calling this function Iterate and OnNewMail will be 00413 called from the thread that is servicing the MOOS Comms client. It 00414 is provided to let really very specialised MOOSApps have very speedy 00415 response times. It is not recommended for general use*/ 00416 m_Comms.SetOnMailCallBack(MOOSAPP_OnMail,this); 00417 return true; 00418 } 00419 00421 bool CMOOSApp::OnNewMail(MOOSMSG_LIST &NewMail) 00422 { 00423 return true; 00424 } 00425 00426 bool CMOOSApp::Iterate() 00427 { 00428 if(m_nIterateCount==0) 00429 { 00430 MOOSTrace("Warning default Iterate handler invoked...doing nothing\n"); 00431 } 00432 return true; 00433 } 00434 00435 bool CMOOSApp::OnConnectToServer() 00436 { 00437 MOOSTrace("- default OnConnectToServer called\n"); 00438 return true; 00439 } 00440 00441 00442 bool CMOOSApp::OnDisconnectFromServer() 00443 { 00444 MOOSTrace("- default OnDisconnectFromServer called\n"); 00445 return true; 00446 } 00447 00449 bool CMOOSApp::OnMailCallBack() 00450 { 00451 return DoRunWork(); 00452 } 00453 00454 bool CMOOSApp::OnCommandMsg(CMOOSMsg CmdMsg) 00455 { 00456 MOOSTrace("- default OnCommandMsg called\n"); 00457 return true; 00458 } 00459 00460 00461 bool CMOOSApp::ConfigureComms() 00462 { 00463 00464 00465 00466 if(!m_MissionReader.GetValue("SERVERHOST",m_sServerHost)) 00467 { 00468 MOOSTrace("Warning Server host not read from mission file: assuming LOCALHOST\n"); 00469 m_sServerHost = "LOCALHOST"; 00470 } 00471 00472 00473 if(!m_MissionReader.GetValue("SERVERPORT",m_sServerPort)) 00474 { 00475 MOOSTrace("Warning Server port not read from mission file: assuming 9000\n"); 00476 m_sServerPort = "9000"; 00477 } 00478 00479 m_lServerPort = atoi(m_sServerPort.c_str()); 00480 00481 if(m_lServerPort==0) 00482 { 00483 m_lServerPort = 9000; 00484 MOOSTrace("Warning Server port not read from mission file: assuming 9000\n"); 00485 } 00486 00487 if(!CheckSetUp()) 00488 return false; 00489 00490 00491 //OK now figure out our speeds etc above what is set by default 00492 //in derived class constructors 00493 m_MissionReader.GetConfigurationParam("COMMSTICK",m_nCommsFreq); 00494 m_nCommsFreq = m_nCommsFreq <0 ? 1 : m_nCommsFreq; 00495 00496 //register a callback for On Connect 00497 m_Comms.SetOnConnectCallBack(MOOSAPP_OnConnect,this); 00498 00499 //and one for the disconnect callback 00500 m_Comms.SetOnDisconnectCallBack(MOOSAPP_OnDisconnect,this); 00501 00502 //start the comms client.... 00503 if(m_sMOOSName.empty()) 00504 m_sMOOSName = m_sAppName; 00505 00506 m_Comms.Run(m_sServerHost.c_str(),m_lServerPort,m_sMOOSName.c_str(),m_nCommsFreq); 00507 00508 return true; 00509 } 00510 00512 bool CMOOSApp::OnStartUp() 00513 { 00514 return true; 00515 } 00516 00517 int CMOOSApp::GetIterateCount() 00518 { 00519 return m_nIterateCount; 00520 } 00521 00522 double CMOOSApp::GetAppStartTime() 00523 { 00524 return m_dfAppStartTime; 00525 } 00526 00527 void CMOOSApp::SetAppFreq(double dfFreq) 00528 { 00529 if(m_dfFreq<=MOOS_MAX_APP_FREQ) 00530 { 00531 m_dfFreq = dfFreq; 00532 } 00533 } 00534 00535 bool CMOOSApp::SetCommsFreq(unsigned int nFreq) 00536 { 00537 if(nFreq<=MOOS_MAX_COMMS_FREQ) 00538 { 00539 m_nCommsFreq = nFreq; 00540 return m_Comms.SetCommsTick(m_nCommsFreq); 00541 } 00542 return false; 00543 } 00544 00545 bool CMOOSApp::IsSimulateMode() 00546 { 00547 return m_bSimMode; 00548 } 00549 00550 bool CMOOSApp::AddMOOSVariable(string sName, string sSubscribeName, string sPublishName,double dfCommsTime) 00551 { 00552 CMOOSVariable NewVar(sName,sSubscribeName,sPublishName,dfCommsTime); 00553 00554 //does it already exist? 00555 if(m_MOOSVars.find(sName)!=m_MOOSVars.end()) 00556 return false; 00557 00558 m_MOOSVars[sName] = NewVar; 00559 00560 return true; 00561 } 00562 00563 //this function publishes all the fresh variables belong to the 00564 //apllication. Useful in many sensor applications! 00565 bool CMOOSApp::PublishFreshMOOSVariables() 00566 { 00567 MOOSVARMAP::iterator p; 00568 00569 for(p = m_MOOSVars.begin();p!=m_MOOSVars.end();p++) 00570 { 00571 CMOOSVariable & Var = p->second; 00572 if(Var.IsFresh()) 00573 { 00574 if(Var.IsDouble()) 00575 { 00576 m_Comms.Notify(Var.GetPublishName(),Var.GetDoubleVal(),Var.GetTime()); 00577 } 00578 else 00579 { 00580 m_Comms.Notify(Var.GetPublishName(),Var.GetStringVal(),Var.GetTime()); 00581 } 00582 00583 Var.SetFresh(false); 00584 } 00585 } 00586 00587 return true; 00588 } 00589 00590 bool CMOOSApp::SetMOOSVar(const string &sVarName, double dfVal, double dfTime) 00591 { 00592 MOOSVARMAP::iterator p = m_MOOSVars.find(sVarName); 00593 00594 if(p==m_MOOSVars.end()) 00595 return false; 00596 00597 CMOOSVariable & rVar = p->second; 00598 00599 return rVar.Set(dfVal,dfTime); 00600 } 00601 00602 bool CMOOSApp::SetMOOSVar(const string &sVarName,const string &sVal, double dfTime) 00603 { 00604 MOOSVARMAP::iterator p = m_MOOSVars.find(sVarName); 00605 00606 if(p==m_MOOSVars.end()) 00607 return false; 00608 00609 CMOOSVariable & rVar = p->second; 00610 00611 return rVar.Set(sVal,dfTime); 00612 00613 00614 } 00615 00616 bool CMOOSApp::SetMOOSVar(const CMOOSVariable& Var) 00617 { 00618 MOOSVARMAP::iterator p = m_MOOSVars.find(Var.GetName ()); 00619 00620 if(p==m_MOOSVars.end()) 00621 return false; 00622 00623 p->second = Var; 00624 p->second.SetFresh (true); 00625 return true; 00626 } 00627 00628 bool CMOOSApp::UpdateMOOSVariables(MOOSMSG_LIST &NewMail) 00629 { 00630 //we only subscribe to things if we are in simulator mode 00631 MOOSVARMAP::iterator p; 00632 double dfTimeNow = MOOSTime(); 00633 for(p = m_MOOSVars.begin();p!=m_MOOSVars.end();p++) 00634 { 00635 CMOOSVariable & rVar = p->second; 00636 CMOOSMsg Msg; 00637 if(m_Comms.PeekMail(NewMail,rVar.GetSubscribeName(),Msg)) 00638 { 00639 if(!Msg.IsSkewed(dfTimeNow)) 00640 { 00641 rVar.Set(Msg); 00642 rVar.SetFresh(true); 00643 } 00644 } 00645 } 00646 00647 return true; 00648 } 00649 00650 bool CMOOSApp::RegisterMOOSVariables() 00651 { 00652 bool bSuccess = true; 00653 00654 MOOSVARMAP::iterator p; 00655 00656 for(p = m_MOOSVars.begin();p!=m_MOOSVars.end();p++) 00657 { 00658 CMOOSVariable & rVar = p->second; 00659 if(!rVar.GetSubscribeName().empty()) 00660 { 00661 double dfCommsTime = rVar.GetCommsTime(); 00662 if(dfCommsTime<0) 00663 { 00664 dfCommsTime = 0; 00665 } 00666 00667 bSuccess &= m_Comms.Register(rVar.GetSubscribeName(),dfCommsTime); 00668 } 00669 } 00670 00671 return bSuccess; 00672 } 00673 00674 bool CMOOSApp::MOOSDebugWrite(const string &sTxt) 00675 { 00676 if(m_Comms.IsConnected()) 00677 { 00678 MOOSTrace(" %s says: %s\n",GetAppName().c_str(),sTxt.c_str()); 00679 return m_Comms.Notify("MOOS_DEBUG",sTxt); 00680 } 00681 else 00682 { 00683 return false; 00684 } 00685 } 00686 00687 bool CMOOSApp::CanIterateWithoutComms() 00688 { 00689 return m_bIterateWithoutComms; 00690 } 00691 00692 void CMOOSApp::EnableIterateWithoutComms(bool bEnable) 00693 { 00694 m_bIterateWithoutComms = bEnable; 00695 } 00696 00697 00698 00699 double CMOOSApp::GetTimeSinceIterate() 00700 { 00701 return MOOSLocalTime()-m_dfLastRunTime; 00702 } 00703 00704 double CMOOSApp::GetLastIterateTime() 00705 { 00706 return m_dfLastRunTime; 00707 } 00708 00709 00710 std::string CMOOSApp::GetMissionFileName() 00711 { 00712 return m_sMissionFile; 00713 } 00714 00715 string CMOOSApp::GetAppName() 00716 { 00717 return m_sAppName; 00718 } 00719 00720 bool CMOOSApp::UseMOOSComms(bool bUse) 00721 { 00722 m_bUseMOOSComms = bUse; 00723 00724 return true; 00725 } 00726 00727 CMOOSVariable * CMOOSApp::GetMOOSVar(string sName) 00728 { 00729 MOOSVARMAP::iterator p = m_MOOSVars.find(sName); 00730 if(p==m_MOOSVars.end()) 00731 { 00732 return NULL; 00733 } 00734 else 00735 { 00736 return &(p->second); 00737 } 00738 } 00739 00740 00741 std::string CMOOSApp::GetCommandKey() 00742 { 00743 std::string sCommandKey = GetAppName()+"_CMD"; 00744 MOOSToUpper(sCommandKey); 00745 return sCommandKey; 00746 } 00747 00748 bool CMOOSApp::LookForAndHandleAppCommand(MOOSMSG_LIST & NewMail) 00749 { 00750 MOOSMSG_LIST::iterator q; 00751 bool bResult = true; 00752 for(q=NewMail.begin();q!=NewMail.end();q++) 00753 { 00754 if(MOOSStrCmp(q->GetKey(),GetCommandKey())) 00755 { 00756 //give a derived class a chance to respond 00757 bResult&= OnCommandMsg(*q); 00758 } 00759 } 00760 return bResult; 00761 } 00762 00763 00764 void CMOOSApp::EnableCommandMessageFiltering(bool bEnable) 00765 { 00766 m_bCommandMessageFiltering = bEnable; 00767 if(bEnable) 00768 { 00769 //we had better register for the message 00770 m_Comms.Register(GetCommandKey(),0); 00771 } 00772 else 00773 { 00774 //we are no longer interested 00775 m_Comms.UnRegister(GetCommandKey()); 00776 } 00777 } 00778 00779 00780 std::string CMOOSApp::MakeStatusString() 00781 { 00782 std::set<std::string> Published = m_Comms.GetPublished(); 00783 std::set<std::string> Registered = m_Comms.GetRegistered(); 00784 00785 std::stringstream ssStatus; 00786 ssStatus<<"AppErrorFlag="<<(m_bAppError?"true":"false")<<","; 00787 if(m_bAppError) 00788 ssStatus<<"AppErrorReason="<<m_sAppError<<","; 00789 00790 ssStatus<<"Uptime="<<MOOSTime()-GetAppStartTime()<<","; 00791 00792 ssStatus<<"MOOSName="<<GetAppName()<<","; 00793 00794 ssStatus<<"Publishing=\""; 00795 std::copy(Published.begin(),Published.end(),std::ostream_iterator<string>(ssStatus,",")); 00796 ssStatus<<"\","; 00797 00798 ssStatus<<"Subscribing=\""; 00799 std::copy(Registered.begin(),Registered.end(),std::ostream_iterator<string>(ssStatus,",")); 00800 ssStatus<<"\""; 00801 00802 return ssStatus.str(); 00803 } 00804 00805 void CMOOSApp::OnDisconnectToServerPrivate() 00806 { 00807 return; 00808 } 00809 00810 //called just before calling a derived classes OnConnectToServer() 00811 void CMOOSApp::OnConnectToServerPrivate() 00812 { 00813 if(m_bCommandMessageFiltering) 00814 { 00815 m_Comms.Register(GetCommandKey(),0); 00816 } 00817 } 00818 00820 void CMOOSApp::OnNewMailPrivate(MOOSMSG_LIST & Mail) 00821 { 00822 //look to handle a command string 00823 if(m_bCommandMessageFiltering) 00824 LookForAndHandleAppCommand(Mail); 00825 } 00826 00827 void CMOOSApp::IteratePrivate() 00828 { 00829 if(fabs(m_dfLastStatusTime-MOOSTime())>STATUS_PERIOD) 00830 { 00831 std::string sStatus = GetAppName()+"_STATUS"; 00832 MOOSToUpper(sStatus); 00833 m_Comms.Notify(sStatus,MakeStatusString()); 00834 m_dfLastStatusTime = MOOSTime(); 00835 } 00836 }