MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Essentials/pScheduler/MOOSScheduler.h
Go to the documentation of this file.
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 // MOOSScheduler.h: interface for the CMOOSScheduler class.
00031 //
00033 
00034 #if !defined(AFX_MOOSSCHEDULER_H__0417EFA7_3661_4FF3_AAA3_3F1B6B14A2B6__INCLUDED_)
00035 #define AFX_MOOSSCHEDULER_H__0417EFA7_3661_4FF3_AAA3_3F1B6B14A2B6__INCLUDED_
00036 
00037 #if _MSC_VER > 1000
00038 #pragma once
00039 #endif // _MSC_VER > 1000
00040 
00041 #include <map>
00042 
00043 class CMOOSScheduler : public CMOOSApp  
00044 {
00045 public:
00046     class CEvent
00047     {
00048     public:
00049         bool SetNameVal(std::string sValName);
00050         bool SetStartingTime(double dfTime);
00051         bool OnNewMail(MOOSMSG_LIST &NewMail);
00052         bool SetEnableFlags(std::string sStart, std::string sStop);
00053         bool SetOffset(double dfOffset);
00054         bool SetPeriod(double dfPeriod);
00055         bool Initialise(std::string sName,std::string sVal,double dfPeriod = 1.0,double dfOffset = 0);
00056 
00057         bool Enable(bool bEnable,double dfTimeNow);
00058         double m_dfFireTime;
00059         CEvent();
00060         bool GetOutput(double dfTimeNow,MOOSMSG_LIST & Out);
00061         
00062     protected:
00063         bool m_bEnabled;
00064         double m_dfTimer;
00065         double m_dfPeriod;
00066         double m_dfOffset;
00067         std::string m_sVal;
00068         std::string m_sName;
00069 
00070         std::string m_sVarName;        
00071         std::string m_sStartFlag;
00072         std::string m_sStopFlag;
00073 
00074     };
00075     typedef std::list<CEvent> EVENT_LIST;
00076 
00077 
00078     class CResponseMsg
00079     {
00080     public:
00081         std::string m_sName;
00082         std::string m_sVal;
00083     };    
00084     typedef std::list<CResponseMsg> RESPONSE_LIST;
00085     typedef std::map<std::string,RESPONSE_LIST> RESPONSE_LIST_MAP;
00086 
00087 
00088 
00089     CMOOSScheduler();
00090     virtual ~CMOOSScheduler();
00091 
00093     bool Iterate();
00094 
00097     bool OnConnectToServer();
00098 
00100     bool OnStartUp();
00101 
00103     bool OnNewMail(MOOSMSG_LIST &NewMail);
00104 
00106     bool Schedule();
00107     
00108 
00109 
00110 protected:
00111     bool RegisterResponses();
00112     bool HandleResponses(MOOSMSG_LIST & NewMail);
00113     bool OnControl(std::string sControl);
00114     bool Initialise();
00115     bool Clean();
00116     bool OnRestart();
00117     bool m_bQuit;
00118     bool m_bActive;
00119 
00121     #ifdef _WIN32
00122         HANDLE m_hScheduleThread;
00123     #endif
00124 
00126     unsigned long        m_nScheduleThreadID;
00127 
00128     bool StartThreads();
00129     bool StopThreads();
00130 
00131     bool AddResponses();
00132     bool AddTimers();
00133     bool AddSequences();
00134     EVENT_LIST m_Events;
00135     RESPONSE_LIST_MAP m_Responses;
00136     int m_nTicks;
00137 
00138 };
00139 
00140 #endif // !defined(AFX_MOOSSCHEDULER_H__0417EFA7_3661_4FF3_AAA3_3F1B6B14A2B6__INCLUDED_)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines