CARMA C++
MonitorPointSet.h
Go to the documentation of this file.
1 
13 #ifndef CARMA_MONITOR_MONITOR_POINT_SET_h
14 #define CARMA_MONITOR_MONITOR_POINT_SET_h
15 
16 #include "carma/corba/corba.h"
17 #include "carma/monitor/monitorframe.h"
18 #include "carma/monitor/types.h"
19 #include "carma/util/PthreadMutex.h"
20 
21 #include <boost/thread/thread.hpp>
22 #include <map>
23 
24 namespace carma {
25  namespace monitor {
26 
27 class SubsystemFrame;
28 class SubsystemFrameBuffer;
29 class Runnable;
30 
31 
38  public:
44  virtual unsigned int read() ;
45 
52  virtual bool readNewest() ;
53 
60  virtual bool readNewestConditionalCopy();
61 
67  virtual ushort getSubsystemID() const;
68 
76  void markMpAtIndexModified (int index);
77 
84  void markMpWithTagIdModified (const tagIDType tagID);
85 
96  virtual void setNumSamplesPerCycle (int index, const ushort samples);
97 
104 
109  void consolidateStorage();
110 
111 
125  static MonitorPointSet& getMonitorPointSet(long subsystemID,
126  long maxMonitorPoints,
127  long maxSamples);
128 
129 
142  void startAutoWriter ();
143 
159  void startAutoWriter (double delay);
160 
169  void stopAutoWriter ();
170 
177  bool autoWriterIsAlive ();
178 
189  double getStartWriteTime () const { return this->startWriteTime_; }
190 
199  double getStartScriberWriteTime () const
200  { return this->inScriberTime_; }
201 
208  double getEndWriteTime () const { return this->endWriteTime_; }
209 
224  void installPrewriteMethod( const Runnable & prewriteMethod );
225 
229  void removePrewriteMethod( const Runnable & prewriteMethod );
230 
234  virtual ~MonitorPointSet();
235 
236  SubsystemFrameBuffer & getBuffer( ) const;
237 
248  virtual void write( bool autoWrite, double autoWriteDelay = 0.0 );
249 
258  unsigned int getHighWaterMark( MonitorValueType mvt );
259 
260  private:
261  friend class SystemFrameBuffer;
262 
263  MonitorPointSet( const MonitorPointSet & rhs );
264  MonitorPointSet & operator=( const MonitorPointSet & rhs );
265 
266  explicit MonitorPointSet( ::std::auto_ptr< SubsystemFrame > & frame );
267 
268  MonitorPointSet( long subsystemID,
269  long maxMonitorPoints,
270  long maxSamples );
271 
272 
273  static MonitorPointUpdate_var getScriberHandle (const std::string& name);
274 
275  static double
276  writeToScriber( const SubsystemFrame & ssFrame,
277  MonitorPointUpdate_var & monUpdater,
278  double delay,
279  bool & writeSucceeded,
280  const MonitorSampleValues & samples );
281 
282  void
283  fillMonSampleValuesHoldingMpModifiedLock(
284  MonitorSampleValues & samples,
285  const SubsystemFrame & ssFrame,
286  const char * const mpModifiedClone );
287 
288  void remergeFailedWriteInfoHoldingWritingLock( );
289 
290  const Runnable * prewriteMethod_;
291 
292  SubsystemFrameBuffer * frameBuffer_;
293  ::std::auto_ptr< SubsystemFrame > frame_;
294 
295  const int mpModifiedAllocCount_;
296 
297  // various memebers which indicates which monitor points have been modified
298  // since the last update
299  util::PthreadMutex mpModifiedGuard_;
300  bool mpModifiedAny_;
301  char * mpModifiedState_;
302  int mpModifiedSamplesCount_;
303 
304  util::PthreadMutex writingGuard_;
305  char * writingMpModifiedState_;
306 
307  const ::std::string name_;
308 
312  const ::std::string scriberName_;
313 
317  MonitorPointUpdate_var monUpdater_;
318 
319  static void autoWriterThread( MonitorPointSet & owner,
320  const double delayInS );
321 
322  boost::thread autoWriterThread_;
323 
324  // time at which last write began
325  double startWriteTime_;
326  // time at which CORBA remote method was invoked in ScriberPublisher
327  double inScriberTime_;
328  // time at which last write finished
329  double endWriteTime_;
330 
331  // Map to carry high water marks for adding monitor points
332  ::std::map< MonitorValueType, unsigned int > typeHighWaterMarks_;
333 };
334 
335 
336 
337 } } // namespace monitor, carma
338 
339 #endif // CARMA_MONITOR_MONITOR_POINT_SET_h
Abstract class that defines the interface for executing a method.
Definition: Runnable.h:30
short MonitorValueType
Enumeration of possible types for monitor point values.
Frame containing monitor points for a monitor subsystem, and mapped to an IPQ - essentially a Subsyst...
bool autoWriterIsAlive()
method to test whether the auto-writer thread is alive.
void startAutoWriter()
method to start the auto-write thread.
virtual void write(bool autoWrite, double autoWriteDelay=0.0)
Sends local monitor point values to FrameScriberPublisher Only sample values of modified monitor poin...
double getStartWriteTime() const
method to return the time at which the last write started.
double getStartScriberWriteTime() const
method to return the time at which the last write invoked the remote procedure on the ScriberPublishe...
A class that manages the sets of monitor points for a monitor subsystem.
void removePrewriteMethod(const Runnable &prewriteMethod)
virtual ushort getSubsystemID() const
Returns subsystemID of subsystem managed by this MonitorPointSet.
virtual void setNumSamplesPerCycle(int index, const ushort samples)
Method to modify number of samples associated with the monitor point whose header is at position &#39;ind...
void markMpWithTagIdModified(const tagIDType tagID)
Marks the monitor point specified by tagID as modified.
void consolidateStorage()
Calls SubsystemFrame::consolidateSamples() on the SubsystemFrame managed by this MonitorPointSet.
void installPrewriteMethod(const Runnable &prewriteMethod)
virtual ~MonitorPointSet()
Destructor.
void stopAutoWriter()
method to stop the auto-write thread.
virtual unsigned int read()
Causes a read from the IPQ associated with the internally stored subsystem frame. ...
virtual bool readNewestConditionalCopy()
If new data is available it is copied from the queue into the monitor system.
void markMpAtIndexModified(int index)
Marks the monitor point specified by index in monitorHeader array as modified.
type definitions for monitor system
Frame containing monitor points for a monitor subsystem frame.
double getEndWriteTime() const
method to return the time at which the last write ended.
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
static MonitorPointSet & getMonitorPointSet(long subsystemID, long maxMonitorPoints, long maxSamples)
method to return a MonitorPointSet.
virtual bool readNewest()
Causes a read of the latest frame from the IPQ associated wit the internally stored subsystem frame...
SubsystemFrame & getSubsystemFrame() const
Returns reference to SubsystemFrame managed by this MonitorPointSet.
unsigned int getHighWaterMark(MonitorValueType mvt)
Get highwater marks for a particular MonitorValueType.