MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Essentials/pAntler/Antler.h
Go to the documentation of this file.
00001 /*
00002  *  Antler.h
00003  *  MOOS
00004  *
00005  *  Created by pnewman on 18/04/2008.
00006  *  Copyright 2008 __MyCompanyName__. All rights reserved.
00007  *
00008  */
00009 
00010 
00011 #ifdef _WIN32
00012 #pragma warning(disable : 4786)
00013 #endif
00014 
00015 #ifndef ANTLERH
00016 #define ANTLERH
00017 
00018 #include <MOOSLIB/MOOSLib.h>
00019 #include <MOOSGenLib/MOOSGenLib.h>
00020 #include <string>
00021 #include <iostream>
00022 
00023 #ifdef _WIN32
00024         #include "XPCProcess.h"
00025         #include "XPCProcessAttrib.h"
00026         #include "XPCException.h"
00027 #else
00028         #include <unistd.h>
00029         #include <sys/types.h>
00030         #include <sys/wait.h>
00031         #include <signal.h>
00032 #endif 
00033 
00034 #define DEFAULT_NIX_TERMINAL "xterm"
00035 #define DEFAULTTIMEBETWEENSPAWN 1000
00036 
00037 
00038 class CAntler 
00039     {
00040     public:
00041         
00042         //something to hold alient process information for the Antler class
00043         struct MOOSProc
00044         {
00045 #ifdef _WIN32
00046             XPCProcess * pWin32Proc;
00047             XPCProcessAttrib * pWin32Attrib;
00048 #else
00049             pid_t m_ChildPID;
00050 #endif        
00051             std::string m_sApp;
00052             std::string m_sMOOSName;
00053             std::string m_sMissionFile;
00054             bool m_bInhibitMOOSParams;
00055             bool m_bNewConsole;
00056             STRING_LIST m_ExtraCommandLineParameters;
00057             STRING_LIST m_ConsoleLaunchParameters;
00058             
00059         };
00060         
00061     public:
00062         
00063         //constructor
00064         CAntler();
00065         //this is the only public function. Call it to have Antler do its thing.
00066         bool Run(const std::string & sMissionFile,std::set<std::string> Filter = std::set<std::string>() );
00067         
00068         //run in a headless fashion - instructions will be recieved via MOOSComms
00069         bool Run(const std::string & sHost,  int lPort, const std::string & sAntlerName);
00070                 
00071                 enum VERBOSITY_LEVEL
00072                 {
00073                         QUIET,
00074                         TERSE,
00075                         CHATTY,
00076                 };
00077                 bool SetVerbosity(VERBOSITY_LEVEL eLevel);
00078                 
00079                 //call this to cause a clean shut down 
00080                 bool ShutDown();
00081                                                   
00082     protected:
00083         
00084         //top level spawn - all comes from here
00085         bool Spawn(const std::string & sMissionFile, bool bHeadless = false);
00086         
00087         
00088         //create, configure and launch a process
00089         MOOSProc* CreateMOOSProcess(std:: string sProcName);
00090         
00091         // called to figure out what xterm parameters should be used with launch (ie where should the xterm be and how should it look)
00092         bool MakeConsoleLaunchParams(std::string sParam,STRING_LIST & LaunchList,std::string sProcName,std::string sMOOSName);
00093         
00094         //caled to figure out what if any additional  parameters should be passed to the process being launched 
00095         bool MakeExtraExecutableParameters(std::string sParam,STRING_LIST & ExtraCommandLineParameters,std::string sProcName,std::string sMOOSName);
00096         
00097         //Functions responsible for actually start new processes according to OS
00098 #ifndef _WIN32
00099         bool DoNixOSLaunch(MOOSProc * pNewProc);
00100 #else
00101         bool DoWin32Launch(MOOSProc *pNewProc);
00102 #endif
00103         bool ConfigureMOOSComms();
00104         bool SendMissionFile();
00105         
00106         //tell a Monarch what is goinon remotely
00107         bool PublishProcessQuit(const std::string & sProc);
00108         bool PublishProcessLaunch(const std::string & sProc);
00109         
00110         typedef std::list<MOOSProc*> MOOSPROC_LIST;
00111         MOOSPROC_LIST    m_ProcList;
00112         std::string m_sDefaultExecutablePath;
00113         CProcessConfigReader m_MissionReader;
00114         
00115         //if this set is non empty then only procs listed here will be run..
00116         std::set<std::string> m_Filter;
00117         
00118         int m_nCurrentLaunch;
00119         
00120         //this is used to communicate with the BD and ultimately other instantiations of
00121         //pAntler on different machines...
00122         CMOOSThread m_RemoteControlThread;
00123         CMOOSCommClient * m_pMOOSComms;
00125         static bool _RemoteControlCB(void* pParam)
00126         {
00127             CAntler* pMe = (CAntler*) pParam;
00128             return pMe->DoRemoteControl();
00129         }
00131         static bool _MOOSConnectCB(void *pParam)
00132         {
00133             CAntler* pMe = (CAntler*) pParam;
00134             return pMe->OnMOOSConnect();
00135         }
00136         static bool _MOOSDisconnectCB(void *pParam)
00137         {
00138             CAntler* pMe = (CAntler*) pParam;
00139             return pMe->OnMOOSDisconnect();
00140         }
00142         bool DoRemoteControl();
00144         bool OnMOOSConnect();
00146         bool OnMOOSDisconnect();
00147                 
00149                 bool KillNicely(MOOSProc* pProc);
00150         
00151         CMOOSLock m_JobLock;
00152         std::string m_sMissionFile;
00153         bool m_bHeadless;
00154         bool m_bQuitCurrentJob;
00155                 bool m_bSupportGentleKill;
00156         bool m_bRunning;
00157         bool m_bNewJob;
00158         std::string m_sMonarchAntler;
00159         bool m_bKillOnDBDisconnect;
00160         std::string m_sReceivedMissionFile;
00161         std::string m_sAntlerName;
00162         std::string m_sDBHost;
00163         int m_nDBPort;
00164         
00165                 VERBOSITY_LEVEL m_eVerbosity;
00166 
00167 
00168         
00169     };
00170 #endif
00171 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines