MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Essentials/pLogger/MOOSLogger.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 // MOOSLogger.h: interface for the CMOOSLogger class.
00031 //
00033 
00034 #if !defined(MOOSLOGGERH)
00035 #define MOOSLOGGERH
00036 
00037 #include <fstream>
00038 #include <set>
00039 #include <string>
00040 #include "Zipper.h"
00041 
00042 typedef std::vector<std::string> STRING_VECTOR; 
00043 
00044 class CMOOSLogger : public CMOOSApp  
00045 {
00046 public:
00047     /* vanilla construction and destruction*/
00048     CMOOSLogger();
00049     virtual ~CMOOSLogger();
00050 
00051 
00053     bool Iterate();
00054 
00057     bool OnConnectToServer();
00058 
00060     bool OnNewMail(MOOSMSG_LIST &NewMail);
00061 
00063     bool OnStartUp();
00064 
00066     bool OnCommandMsg(CMOOSMsg Msg);
00067 
00069         bool DoZipLogging();
00070         
00072         bool ShutDown();
00073 
00074 
00075 protected:
00076 
00078     bool HandleLogRequest(std::string sParam,std::string &sNewVariable, bool bDynamic= false);
00079     bool HandleDynamicLogRequest(std::string sRequest);
00080     bool HandleCopyFileRequest(std::string sFileToCopy);
00081     bool HandleWildCardLogging();
00082     bool IsWildCardAccepted(const std::string & sVariableName) const;
00083     bool IsWildCardRejected(const std::string & sVariableName) const;
00084 
00085     bool CopyMissionFile();
00086     bool ConfigureLogging();
00087     bool DoAsyncLog(MOOSMSG_LIST & NewMail);
00088     bool OnLoggerRestart();
00089     bool AddSyncLineOfTimes(double dfTimeNow=-1);
00090     bool LabelSyncColumns();
00091     bool DoBanner(std::ostream & os,std::string & sFileName);
00092     bool IsSystemMessage(std::string & sKey);
00093     bool LogSystemMessages(MOOSMSG_LIST & NewMail);
00094     bool OpenAsyncFiles();
00095     bool OpenSystemFile();
00096     bool CloseFiles();
00097     bool OpenSyncFile();
00098     bool DoSyncLog(double dfTimeNow);
00099     std::string MakeLogName(std::string sStem);
00100     bool OpenFile(std::ofstream & of,const std::string & sName, bool bBinary = false);
00101     bool OnNewSession();
00102     bool CreateDirectory(const std::string & sDirectory);
00103     std::string MakeStatusString();
00104 
00105     std::ofstream m_AsyncLogFile;
00106     std::ofstream m_ExcludeLogFile;
00107     std::ofstream m_SyncLogFile;
00108     std::ofstream m_SystemLogFile;
00109     std::ofstream m_BinaryLogFile;
00110 
00111         
00112         std::string m_sLogRootName;
00113     std::string m_sAsyncFileName;
00114         std::string m_sExcludeFileName;
00115     std::string m_sSyncFileName;
00116     std::string m_sSystemFileName;
00117     std::string m_sBinaryFileName;
00118 
00119     std::string m_sMissionCopyName;
00120     std::string m_sHoofCopyName;
00121 
00122     std::string m_sPath;
00123     std::string m_sStemFileName;
00124     std::string m_sLogDirectoryName;
00125     
00126     STRING_VECTOR m_SynchronousLogVars;
00127     STRING_LIST m_UnusedDynamicVariables;
00128     bool    m_bSynchronousLog;
00129     bool    m_bAsynchronousLog;
00130     bool    m_bWildCardLogging;
00131         bool    m_bUseExcludedLog;
00132 
00133         //variables to do with compressed logging...
00134         bool    m_bCompressAlog;
00135         CZipper m_AlogZipper;
00136         CZipper m_XlogZipper;
00137         
00138         
00139     //how many synline have been written?
00140     int     m_nSyncLines;
00141 
00143     bool    m_bAppendFileTimeStamp;
00144         
00146         bool m_bUseUTCLogNames;
00147 
00148         //.true if we want to log AuxSrc varaibles
00149         bool m_bLogAuxSrc;
00150 
00151     //housekeeping  variables for performing tasks
00152     double m_dfLastSyncLogTime;
00153     double m_dfSyncLogPeriod;
00154     double m_dfLastMonitorTime;
00155         
00156         //what precision do we log doubles with?
00157         int m_nDoublePrecision;
00158     
00159     //name of a file where logger summary is written
00160     std::string     m_sSummaryFile;
00161         
00162         //current position of bianry file pointer
00163         std::streampos m_BinaryCursor;
00164 
00165 
00166     //housekeeping variables for checking that monotired messages
00167     //rally are being written to...
00168     typedef std::map< std::string, double > VARIABLE_TIMER_MAP;
00169     VARIABLE_TIMER_MAP m_MonitorMap;
00170         
00171         //house keeping functions and storage to keeptrack of which variable
00172         //goes to which log (especially when xlogging is on)
00173         enum LogType
00174         {
00175                 XLOG,
00176                 YLOG,
00177                 SLOG,
00178                 ALOG,
00179                 UNKNOWN
00180         };
00181         
00182         CMOOSLogger::LogType GetDestinationLog(const std::string & sStr);
00183         std::map<std::string, LogType> m_LogDestinations;
00184 
00185 private:
00186     //this is a collection of file position pointers which we will use
00187     //to fill in column names for dynamically registered variables
00188     //as and when they come in (housekeeping for the header block on
00189     //slog files)
00190     std::map< std::string, std::streampos > m_DynamicNameIndex;
00191     
00192     // collection of strings which specify names (can use wild card * and ? ) which
00193     // should be ommited from dynamic logging
00194     std::vector< std::string >  m_sWildCardOmitted;
00195 
00196     
00197     // collection of strings which specify names (can use wild card * and ? ) which
00198     // should be allowed in dynamic logging. If empty all strings are assumed to be wanted
00199     // unless they are in m_sDynamicMasked
00200     std::list< std::string >  m_sWildCardAccepted;
00201     
00202 };
00203 
00204 #endif 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines