LRAUV  revA
Supervisor.h
Go to the documentation of this file.
1 
18 #ifndef SUPERVISOR_H_
19 #define SUPERVISOR_H_
20 
23 #include "logger/Logger.h"
24 #include "logger/Reporter.h"
25 #include "module/ModuleLoader.h"
26 #include "supervisor/CommandLine.h"
27 #include "supervisor/Maintainer.h"
28 
29 #include <dirent.h>
30 
31 class BinaryLogWriter;
32 class CycleStarter;
33 class DataEntry;
35 class FileLogWriter;
36 class Handler;
38 class LogEngine;
39 class MissionItem;
40 class MissionManager;
41 class SplitFileLogWriter;
42 
43 #ifndef __APPLE_CC__
44 #define DIRENT_CONST const
45 #else
46 #define DIRENT_CONST
47 #endif
48 
50 typedef int ( *FileFilterType )( DIRENT_CONST struct dirent * );
51 
66 {
67 public:
68 
69  friend class CommandLine;
70  friend class CBIT;
71 
75  Supervisor( int argc, char **argv, Str& dataDir );
76 
78  virtual ~Supervisor();
79 
82  virtual void initialize();
83 
88  virtual void run();
89 
92  virtual void uninitialize();
93 
95  static Str GenerateDataDir( const Str& logSymlinkSubdir = "" );
96 
98  static Str RestartLogs();
99 
101  static void IncrementShoreFile();
102 
105  static Str GetToShoreFilename( LogWriter::ServiceType serviceType );
106 
109  static Str GetLatestLogFilename( FileFilterType fileFilter );
110 
111  static bool IsRestart()
112  {
113  return Restart_;
114  }
115 
116  static int GetArgc()
117  {
118  return Argc_;
119  }
120 
121  static char** GetArgv()
122  {
123  return Argv_;
124  }
125 
126  static void ClearArgs();
127 
129  static void SendData( DataEntry* dataEntry, LogWriter::ServiceType serviceType );
130 
132  static bool IsMissionManagerFailed();
133 
135  static bool IsMissionRunning();
136 
139  static void TouchRunningFile();
140 
142  static void ClearRunningFile();
143 
144  static bool WasRunning()
145  {
146  return WasRunning_;
147  }
148 
150  {
151  return RunSimsInRealTime_;
152  }
153 
155  static void QueueSBD( const char* path );
156 
159  static char* GetQueuedSBD();
160 
163  static void ConfigureDecimation( LogWriter::ServiceType serviceType,
165  const Str& name, DataValue* parameter, Logger& logger );
166 
167 private:
168 
169  static void SetArgs( const char* args );
170 
171  static void SetRestart( bool restart )
172  {
173  Restart_ = restart;
174  }
175 
178  {
179  return Instance_;
180  }
181 
182  // Note that the copy constructor below is private and not given a body.
183  // Any attempt to call it will return a compiler error.
184  Supervisor( const Supervisor& old ); // disallow copy constructor
185 
187  void configure();
188 
190  bool loadMission( const char* missionName );
191 
193  bool resumeMission( const char* missionName );
194 
197  bool runMission( const char* missionName, bool quitAtEnd );
198 
200  void showStack( );
201 
203  void stopMission();
204 
206  void terminate();
207 
210  void addMaintain( unsigned short int uriCode, DataValue* dataValue,
211  SyncComponent::CycleOrder cycleOrder, bool unavailable = false, bool invalid = false );
212 
215  void removeMaintain( unsigned short int uriCode );
216 
219  void removeAllMaintains();
220 
223  void listMaintains();
224 
227  void addReport( unsigned short int uriCode, Reporter::ReportType type = Reporter::REPORT_CHANGE, const Timespan *timespan = NULL );
228 
231  void removeReport( unsigned short int uriCode );
232 
235  void removeAllReports();
236 
239  void listReports();
240 
241  // Kick off the command line
242  void startCommandLine();
243 
245  static bool Restart_;
246 
248  static int Argc_;
249  static char **Argv_;
250  static char *Args_;
251  static bool WasRunning_;
252 
254  static bool RunSimsInRealTime_;
255 
258 
261 
263  int argc_;
264  char **argv_;
265 
266  // alternate configuration location
268 
272 
275 
278 
281 
284 
286  bool running_;
287 
290 
293 
296 
304 
306  static int FilterLogDir( DIRENT_CONST struct dirent* dirEntry );
307 
309 
311  static FileFilterType GetServiceFilter( LogWriter::ServiceType serviceType, bool lzma );
312 
314  static int FilterCourier( DIRENT_CONST struct dirent* dirEntry );
315 
317  static int FilterCourierLzma( DIRENT_CONST struct dirent* dirEntry );
318 
320  static int FilterExpress( DIRENT_CONST struct dirent* dirEntry );
321 
323  static int FilterExpressLzma( DIRENT_CONST struct dirent* dirEntry );
324 
326  static int FilterPriority( DIRENT_CONST struct dirent* dirEntry );
327 
329  static int FilterPriorityLzma( DIRENT_CONST struct dirent* dirEntry );
330 
332  static int FilterNormal( DIRENT_CONST struct dirent* dirEntry );
333 
335  static int FilterNormalLzma( DIRENT_CONST struct dirent* dirEntry );
336 };
337 
338 #endif /*Supervisor_H_*/
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
void listReports()
List the uriCodes being reported by the Reporter – available only to CommandLine function prototype ...
Definition: Supervisor.cpp:796
Contains the DecimationLogWriter class definition.
char ** argv_
Definition: Supervisor.h:264
static char ** Argv_
Definition: Supervisor.h:249
Logger logger_
Logger for Supervisor.
Definition: Supervisor.h:260
Contains the SyncComponent class definition.
MissionManager is the computation cycle component that contains the main mission stack and manages it...
Definition: MissionManager.h:25
static bool IsMissionRunning()
Indicates if a loaded mission is running.
Definition: Supervisor.cpp:119
int(* FileFilterType)(DIRENT_CONST struct dirent *)
Helper typedef for GetToShoreFilename() and GetLatestLogFilename()
Definition: Supervisor.h:50
Wraps around another LogWriter to write LogEntries to a file.
Definition: FileLogWriter.h:28
void configure()
Load up configuration settings.
Definition: Supervisor.cpp:632
static int FilterExpressLzma(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:868
ReportType
Definition: Reporter.h:42
FileLogWriter * syslogFileWriter_
Write logs.
Definition: Supervisor.h:298
static bool RunSimsInRealTime_
To make simulated missions run in real-time.
Definition: Supervisor.h:254
The CycleStarter's only purpose is to send its CycleStartEntry_ to its logger_ at the start of every ...
Definition: CycleStarter.h:22
static char * Args_
Definition: Supervisor.h:250
Loads modules (either compiled c++ or scripted).
Definition: ModuleLoader.h:31
static char * GetQueuedSBD()
Get the path to next SBD to be resent, if any Delete the pointer after use!
Definition: Supervisor.cpp:171
Wraps a Behavior or Aggregate with mission-specific settings pertaining to that item.
Definition: MissionItem.h:31
static bool WasRunning_
Definition: Supervisor.h:251
static bool IsRestart()
Definition: Supervisor.h:111
int argc_
Arguments passed from main.
Definition: Supervisor.h:263
BinaryLogWriter * slateWriter_
Definition: Supervisor.h:299
Definition: DecimationLogManager.h:23
SplitFileLogWriter * slateFileWriter_
Definition: Supervisor.h:300
static int FilterCourierLzma(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:847
Defines a LogWriter that can perform lossy decimation on a stream of DataEntries, by outputting value...
Definition: LinearApproximationLogWriter.h:42
void removeReport(unsigned short int uriCode)
Remove the reporting of an uriCode from the Reporter – available only to CommandLine function protot...
Definition: Supervisor.cpp:772
static void SetRestart(bool restart)
Definition: Supervisor.h:171
bool resumeMission(const char *missionName)
Resumes a previously stopped mission.
Definition: Supervisor.cpp:652
void startCommandLine()
Definition: Supervisor.cpp:343
bool loadMission(const char *missionName)
Loads the specified mission file.
Definition: Supervisor.cpp:646
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
static bool IsMissionManagerFailed()
Indicates if mission manager is failed.
Definition: Supervisor.cpp:112
void listMaintains()
List the uriCodes being maintained by the Maintainer – available only to CommandLine function protot...
Definition: Supervisor.cpp:748
MissionManager * missionManager_
Mission handling.
Definition: Supervisor.h:277
static int FilterNormal(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:901
Component responsible for handling periodic logging of variable values to the syslog and the console...
Definition: Reporter.h:37
A DataValue is an abstract base class for a data value and associated engineering units of the value...
Definition: DataValue.h:35
DecimationLogManager * decimationLogManager_
Manages the "toShore" files.
Definition: Supervisor.h:295
static Supervisor * GetInstance()
Returns singleton instance.
Definition: Supervisor.h:177
static Str GetToShoreFilename(LogWriter::ServiceType serviceType)
Gets the name of the latest "toShore" file May be from a previous run of the software.
Definition: Supervisor.cpp:541
Contains the Module class definition.
Supervisor(int argc, char **argv, Str &dataDir)
Constructor: To meet requirement The vehicle control loop (start time) must be accurate to within 10 ...
Definition: Supervisor.cpp:188
Provides a simple command line interface to the LRAUV.
Definition: CommandLine.h:38
static int FilterPriorityLzma(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:889
static Str RestartLogs()
Create a new directory in Logs and begin writing to it.
Definition: Supervisor.cpp:444
static Str GetLatestLogFilename(FileFilterType fileFilter)
Gets the name of the latest Log file that matches the filter May be from a previous run of the softwa...
Definition: Supervisor.cpp:594
ServiceType
Definition: LogWriter.h:29
ModuleLoader moduleLoader_
Definition: Supervisor.h:271
LinearApproximationLogWriter * kmlApproximationWriter_
Definition: Supervisor.h:303
Str altConfig_
Definition: Supervisor.h:267
Contains the CommandLine class declaration.
void stopMission()
Kills the currently running mission file.
Definition: Supervisor.cpp:692
Code unit that represents an atomic unit of data destined for writing in the log file.
Definition: DataEntry.h:43
These are enumerated to simplify sorting and ordering.
Definition: SyncComponent.h:42
void removeAllReports()
Remove the reporting of all uriCodes from the Reporter – available only to CommandLine function prot...
Definition: Supervisor.cpp:784
Contains the Reporter class definition.
DecimationType
Definition: DecimationLogWriter.h:26
static int FilterPriority(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:879
void addReport(unsigned short int uriCode, Reporter::ReportType type=Reporter::REPORT_CHANGE, const Timespan *timespan=NULL)
Add the reporting of an uriCode to the Reporter – available only to CommandLine function prototype m...
Definition: Supervisor.cpp:760
static bool IsRunningSimsInRealTime()
Definition: Supervisor.h:149
static bool WasRunning()
Definition: Supervisor.h:144
static int FilterNormalLzma(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:911
#define DIRENT_CONST
Definition: Supervisor.h:44
void addMaintain(unsigned short int uriCode, DataValue *dataValue, SyncComponent::CycleOrder cycleOrder, bool unavailable=false, bool invalid=false)
Add a uriCode and value to be maintained – available only to CommandLine function prototype mirrored...
Definition: Supervisor.cpp:711
virtual void uninitialize()
Uninitialization.
Definition: Supervisor.cpp:387
Defines a LogWriter specific to writing binary values to a stream See FileLogWriter for output to the...
Definition: BinaryLogWriter.h:23
FileLogWriter * kmlFileWriter_
Definition: Supervisor.h:302
static int FilterCourier(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:837
Component responsible for handling periodic logging of variable values to the syslog and the console...
Definition: Maintainer.h:34
void removeMaintain(unsigned short int uriCode)
Remove the maintaining of an uriCode from the Maintainer – available only to CommandLine function pr...
Definition: Supervisor.cpp:724
Replacement for standard template class string.
Definition: Str.h:12
Str & dataDir_
Where to write data!
Definition: Supervisor.h:289
Component responsible for handling the contents of the LogQueue.
Definition: LogEngine.h:63
static int GetArgc()
Definition: Supervisor.h:116
Base class for "handlers" of Components.
Definition: Handler.h:49
ListOfLoadedModulePtrs loadedModules_
Module handling.
Definition: Supervisor.h:270
virtual void initialize()
Initialization.
Definition: Supervisor.cpp:221
void removeAllMaintains()
Remove the maintaining of all uriCodes from the Maintainer – available only to CommandLine function ...
Definition: Supervisor.cpp:736
static void SendData(DataEntry *dataEntry, LogWriter::ServiceType serviceType)
Forces an entry into the shore log.
Definition: Supervisor.cpp:106
static void IncrementShoreFile()
Closes the current "toShore" file and begins a new one.
Definition: Supervisor.cpp:430
static void SetArgs(const char *args)
Definition: Supervisor.cpp:61
void showStack()
Causes the currently running mission stack to be displayed.
Definition: Supervisor.cpp:686
Contains the Logger class definition.
static char ** GetArgv()
Definition: Supervisor.h:121
static void ClearArgs()
Definition: Supervisor.cpp:90
FileLogWriter * slateDirFileWriter_
Definition: Supervisor.h:301
void terminate()
Terminates Supervisor run – available only to CommandLine.
Definition: Supervisor.cpp:702
static bool Restart_
Flag set when it's time to restart.
Definition: Supervisor.h:245
Writes LogEntries to files that are split over time or capacity.
Definition: SplitFileLogWriter.h:20
Contains the Maintainer class definition.
static void QueueSBD(const char *path)
Queue up the sbd at the indicated address to be resent.
Definition: Supervisor.cpp:159
virtual void run()
The run() function.
Definition: Supervisor.cpp:350
Reporter * reporter_
Reporting to console.
Definition: Supervisor.h:283
virtual ~Supervisor()
Destructor.
Definition: Supervisor.cpp:215
The supervisor is the "main" component in the vehicle software.
Definition: Supervisor.h:65
static Str GenerateDataDir(const Str &logSymlinkSubdir="")
Generates a new data directory and returns its name.
Definition: Supervisor.cpp:478
bool running_
For shutdown purposes.
Definition: Supervisor.h:286
static void TouchRunningFile()
If there is a file at Data/running, set WasRunning_ to true; Otherwise, just create file...
Definition: Supervisor.cpp:127
static Supervisor * Instance_
Definition: Supervisor.h:308
static int Argc_
Arguments passed to main when restarting.
Definition: Supervisor.h:248
Maintainer * maintainer_
Maintains values specified at console.
Definition: Supervisor.h:280
FlexArray< char * > sbdQueue_
Queue of SBDs to re-send to shore.
Definition: Supervisor.h:292
Definition: Reporter.h:44
static FileFilterType GetServiceFilter(LogWriter::ServiceType serviceType, bool lzma)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:819
static int FilterLogDir(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:807
static int FilterExpress(DIRENT_CONST struct dirent *dirEntry)
Helper function for GetToShoreFilename()
Definition: Supervisor.cpp:858
static void ConfigureDecimation(LogWriter::ServiceType serviceType, DecimationLogWriter::DecimationType decimationType, const Str &name, DataValue *parameter, Logger &logger)
Call upon DecimationLogManager to configure automatic Logging of data.
Definition: Supervisor.cpp:178
bool runMission(const char *missionName, bool quitAtEnd)
Loads the specified mission file if non-null Runs that mission or previously loaded one...
Definition: Supervisor.cpp:669
static void ClearRunningFile()
As part of orderly shutdown, delete the file at Data/running.
Definition: Supervisor.cpp:152
Handler * commandLineHandler_
Command handler.
Definition: Supervisor.h:274
LogEngine * logEngine_
Main LogEngine for the system.
Definition: Supervisor.h:257
The CBIT built-in-test (CBIT) component provides monitoring of vehicle health during a mission...
Definition: CBIT.h:38