CARMA C++
FrameSubscriber.h
Go to the documentation of this file.
1 
11 #ifndef CARMA_MONITOR_FRAME_SUBSCRIBER_H
12 #define CARMA_MONITOR_FRAME_SUBSCRIBER_H
13 
16 #include "carma/util/PthreadMutex.h"
17 #include "carma/util/types.h"
18 
19 #include <map>
20 #include <vector>
21 
22 namespace carma {
23 namespace monitor {
24 
25 
26 class MonitorSystemQueueEntry;
27 
28 
36  public:
37  NullEventException (const ::std::string & message,
38  const char* fileName,
39  int lineNo)
40  : ::carma::util::ErrorException (message, fileName, lineNo)
41  { }
42 
43  NullEventException (const ::std::ostringstream & message,
44  const char* fileName,
45  int lineNo)
46  : ::carma::util::ErrorException (message, fileName, lineNo)
47  { }
48 
49  NullEventException (const ::carma::util::ErrorException& errorException)
50  : ::carma::util::ErrorException (errorException)
51  { }
52 
53  virtual ~NullEventException () throw() { }
54 
70 };
71 
72 
73 
82  {
83  public:
84 
97  FrameSubscriber(double delayInS, bool rawMode);
98 
103 
104  /*
105  * Set scheduled first fire time for call to writeMonitorSystemToIPQ.
106  * Should be called once and only once to synchronize internal timing.
107  * @param firstFireTimeMJD First fire time as MJD.
108  * @pre No collation takes place prior to call.
109  * @throw IllegalStateException if already called.
110  * @see writeMonitorSystemToIPQ
111  */
112  void setFirstFireTime( double firstFireTimeMJD );
113 
114 
119  void writeMonitorSystemToIPQ(double currentFireTimeMJD,
120  double delayInSeconds,
121  int clearDelayInFrames);
122 
127 
128  protected:
129 
141  void printTimes (double timestamps[], int numTimes) const;
142 
143  private:
144 
145  void writeMonitorStatsHoldingMsMapLock( MonitorSystem & ms );
146  /*
147  * Clears class variables containing subsystem and totals for various
148  * error counts, including late, early, and missing frames.
149  */
150  void clearErrorCounts();
151 
152  bool rawMode_;
153 
154  typedef ::std::map< carma::util::frameType,
155  MonitorSystemQueueEntry * > MonitorSystemMap;
156 
157  carma::util::PthreadMutex msMapMutex_;
158  MonitorSystemMap msMap_;
159  bool initialized_;
160  carma::util::frameType lastWriteFrame_;
161 
162  typedef ::std::map< subsystemIDType, int > SubsystemCountMap;
163  typedef ::std::map< subsystemIDType,
164  carma::util::frameType > SubsystemFrameMap;
165 
166 
167  carma::util::PthreadMutex subsystemDataMutex_;
168  SubsystemCountMap receivedSubsystemFrameCount_;
169  SubsystemCountMap receivedSubsystemDataCount_;
170  SubsystemCountMap lateSubsystemFrameCount_;
171  SubsystemCountMap earlySubsystemFrameCount_;
172  SubsystemCountMap missedSubsystemFrameCount_;
173  SubsystemCountMap missedDataFrameCount_;
174  SubsystemFrameMap lastReceivedSubsystemFrames_;
175 
176  int totalFrames_;
177  int totalMissedDataFrames_;
178  int totalEarlyFrames_;
179  int totalLateFrames_;
180  int totalMissedFrames_;
181 
182  int outOfOrderSubsystemFrames_;
183  int duplicateSubsystemFrames_;
184  int erroneousNotifications_;
185 
186  // Fill msMap_ with ((int)(2*delay)+1) monitor systems.
187  // The delay is the writeDelay param to the frameCollator,
188  // currently 600 (0.600sec) in carmaCore.xml
189  void allocateMonitorSystems(double delayInS);
190  void deallocateMonitorSystems();
191  void rebuildMapHoldingLock( carma::util::frameType newHeadFrame );
192  void checkForWriteDiscontinuityHoldingLock( const double currentFireTimeMJD );
193 
194  // There are some subsystems that are not counted
195  bool isMissedDataCountingEnabled(unsigned int subsystemID);
196 
197  // Subsystem has a timestamp MP that can be used to check transport
198  bool subsystemHasTimestamp(unsigned int subsystemID);
199 
200  }; // End class FrameSubscriber
201 
202  } // End namespace monitor
203 } // End namespace carma
204 
205 #endif // CARMA_MONITOR_FRAME_SUBSCRIBER_H
A class that accepts named events from a Push supplier.
void operator()(const carma::monitor::TransportSubsystemFrame &tsf)
Process a TransportSubsystemFrame.
Exception class for errors.
The monitor system base class.
unsigned int frameType
Half second frames since Jan 1, 2000.
Definition: types.h:29
Contains sample values from all monitor points in a monitor subsystem.
void printTimes(double timestamps[], int numTimes) const
Called by push_structured_event.
FrameSubscriber(double delayInS, bool rawMode)
Constructor This constructor is used if this FrameSubscriber is to use the default ORB and clean up a...
Indicates that a null event was returned by FrameSubscriber::retrieveNotification() ...
Exception class for errors The exception comes with a text string that can be printed or logged...
Monitor system base class.
Definition: MonitorSystem.h:81
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
void writeMonitorSystemToIPQ(double currentFireTimeMJD, double delayInSeconds, int clearDelayInFrames)
Write monitor system to IPQ.
Various type definitions for util classes.