CARMA C++
SystemFrame.h
Go to the documentation of this file.
1 #ifndef CARMA_MONITOR_SYSTEMFRAME_H
2 #define CARMA_MONITOR_SYSTEMFRAME_H
3 
17 #include <memory>
18 #include "carma/util/PthreadRWLock.h"
19 
20 namespace carma {
21 namespace monitor {
22 
23 
24 struct TransportSubsystemFrame;
25 struct SubsystemHeader;
26 struct SubsystemDataPointers;
27 class SubsystemFrame;
28 
29 
59 class SystemFrame {
60  public:
64  virtual ~SystemFrame( );
65 
66  void synchronize( const SystemFrame & src );
67 
74  bool isCurrentFrame( ) const;
75 
76  // callers responsibility to delete memory
88  ::std::auto_ptr< SubsystemFrame >
89  makeSubsystemFrame( unsigned short subsystemID ) const;
90 
100  ::std::auto_ptr< SubsystemFrame >
101  makeSubsystemFrameForIndex( int index ) const;
102 
111  bool isCurrent (unsigned short subsystemID) const ;
112 
118  long getFrameCount () const ;
119 
125  long setFrameCount (const long frameCount) ;
126 
134  bool isComplete () const ;
135 
144  void writeSubsystemFrame (
145  const TransportSubsystemFrame & subsystemFrame );
146 
154  long getMaxNumSubsystemFrames () const ;
155 
164  long getMaxTotalMonitorPoints () const ;
165 
173  long getMaxTotalSamples () const ;
174 
182  long getNumSubsystemFrames () const ;
183 
191  void setNumSubsystemFrames (unsigned short numSubsystems) ;
192 
201  void setCollatorWriteDelay (double writeDelay);
202 
211  double getCollatorWriteDelay () const;
212 
219  void setCollatorWriteTime( double mjdTimestamp );
220  //void setCollatorWriteTime( );
221 
228  double getCollatorWriteTime () const;
229 
237  void setRawReadTime ( double mjdTimestamp );
238  //void setRawReadTime( );
239 
247  double getRawReadTime () const;
248 
256  void setFinalWriteTime( double mjdTimestamp );
257  //void setFinalWriteTime( );
258 
266  double getFinalWriteTime () const;
267 
272  void clearAllTimes();
273 
281  unsigned char getStatusFlags () const ;
282 
290  void setStatusFlags (unsigned char flags) ;
291 
301  bool subsystemFrameIsWritten( unsigned short subsystemID ) const;
302 
320  int allocateSubsystemFrame( unsigned short subsystemID,
321  long ssMaxMonitorPoints,
322  long ssMaxSamples );
323 
327  void resetNumCleanFrames() ;
328 
329  static size_t getSystemHeaderSizeInBytes( );
330 
331  size_t getSystemTotalSizeInBytes( ) const;
332 
333  protected:
334  static const int SUBSYSTEM_FRAME_ABSENT;
335 
336  struct SystemHeader;
337 
341  SystemFrame( long maxSubsystems,
342  long maxMonitorPoints,
343  long maxSamples );
344 
345  SystemHeader & getSystemFrameDataHoldingWriteLock( );
346  const SystemHeader & getSystemFrameDataHoldingLock( ) const;
347 
348  ::std::auto_ptr< SubsystemFrame >
349  makeSubsystemFrameForIndexHoldingLock( int index ) const;
350 
351  int
352  allocateSubsystemHoldingWriteLock( unsigned short subsystemID,
353  long ssMaxMonitorPoints,
354  long ssMaxSamples );
355 
356  bool checkIsCurrentFrameHoldingLock( double * mjdDelta ) const;
357 
368  int getSubsystemIndexHoldingLock( unsigned short subsystemID ) const;
369 
379 
380  private:
381  // No copying
382  SystemFrame( const SystemFrame & rhs );
383  SystemFrame & operator=( const SystemFrame & rhs );
384 
385  class SsDataPointersManager;
386 
398  getSubsystemFrameStructHoldingLock( int index ) const;
399 
411  void indexInsertKeyHoldingWriteLock( unsigned short subsystemID,
412  int newIndex );
413 
423  size_t getNextFreeSubsystemFrameHoldingLock( );
424 
425  static size_t getSystemFrameStorageSizeInBytes( long maxSubsystems,
426  long maxMonitorPoints,
427  long maxSamples );
428 
429  protected:
430  const long maxSubsystems_;
431  const long maxMonitorPoints_;
432  const long maxSamples_;
433  const size_t frameStorageSizeInBytes_;
434 
435  mutable util::PthreadRWLock guard_;
436 
437  const int * frameDataSsIndexArray_;
438  const size_t * frameDataSsDataOffsetArray_;
439 
440  private:
441  void * frameStorage_;
442 
443  int * writableFrameDataSsIndexArray_;
444  size_t * writableFrameDataSsDataOffsetArray_;
445 
446  SsDataPointersManager * ssDataPointersManager_;
447 
448  int numCleanSubsystemFrames_;
449  size_t nextFreeSubsystemFrame_;
450 };
451 
452 
453 } // namespace carma::monitor
454 } // namespace carma
455 
456 
457 #endif
int getSubsystemIndexHoldingLock(unsigned short subsystemID) const
Given the subsystemID, returns the index of the subsystem in the subsystemFrameOffset array...
void resetNumCleanFrames()
Sets numCleanSubsystemnFrames_ to getNumSubsystemFrames().
long setFrameCount(const long frameCount)
Sets timestamp for SystemHeader as frameCount.
long getFrameCount() const
Returns timestamp for SystemHeader as frameCount.
A simple wrapper class that makes use of ::pthread_rwlock_t easier in a C++ world.
Definition: PthreadRWLock.h:46
void setRawReadTime(double mjdTimestamp)
Sets the time of the last read from the associated RawCarmaMonitorSystem.
double getCollatorWriteTime() const
Gets the time of the last collator write to the associated system IPQ.
::std::auto_ptr< SubsystemFrame > makeSubsystemFrame(unsigned short subsystemID) const
Returns a SubsystemFrame object wrapped around an internally stored SubsystemHeader structure contain...
SystemFrame(long maxSubsystems, long maxMonitorPoints, long maxSamples)
Constructs a SystemFrame instance.
void setFinalWriteTime(double mjdTimestamp)
Sets the time of the last write to the associated CarmaMonitorSystem.
::std::auto_ptr< SubsystemFrame > makeSubsystemFrameForIndex(int index) const
Returns newly created SubsystemFrame object given the index to the subsystem in the subsystemFrameOff...
long getMaxNumSubsystemFrames() const
Size information - returns maximum number of subsystems this SystemFrame can accommodate.
Contains sample values from all monitor points in a monitor subsystem.
void syncSystemAndSubsystemsToNewFrameDataHoldingWriteLock()
Sets the pointers to the subsystem index array (subsystemIndex) and the subsystem offset array (subsy...
unsigned char getStatusFlags() const
Returns status flags for system frame.
bool isCurrent(unsigned short subsystemID) const
True if subsystem with subsystemID has frameCount == this-&gt;getFrameCount().
long getMaxTotalMonitorPoints() const
Size information - returns maximum cumulative number of monitor points across all subsystems that thi...
double getCollatorWriteDelay() const
Returns the delay used by the writer part of the frameCollator to write to the associated IPQ in the ...
double getFinalWriteTime() const
Gets the time of the last write to the associated CarmaMonitorSystem.
double getRawReadTime() const
Gets the time of the last read from the associated RawCarmaMonitorSystem.
virtual ~SystemFrame()
Destructor.
void writeSubsystemFrame(const TransportSubsystemFrame &subsystemFrame)
Writes transported sample values into subsystem frame given all sample values assciated with the subs...
void setNumSubsystemFrames(unsigned short numSubsystems)
Size information - Sets number of allocated subsystems in this SystemFrame.
void setCollatorWriteTime(double mjdTimestamp)
Sets the time of the last collator write to the associated system IPQ.
Frame containing monitor points for all monitor subsystems.
Definition: SystemFrame.h:59
void clearAllTimes()
Clears all times - collator time, raw read time and final write time.
long getMaxTotalSamples() const
Size information - returns cumulative maximum number of monitor samples, across all subsystems...
long getNumSubsystemFrames() const
Size information - returns number of allocated subsystems in this SystemFrame.
Structure used to manage memory for a subsystem frame.
bool subsystemFrameIsWritten(unsigned short subsystemID) const
Returns true if subsystem frame corresponding to &#39;subsystemID&#39; was written to its IPQ even once...
void setStatusFlags(unsigned char flags)
Sets status flags for system frame.
int allocateSubsystemFrame(unsigned short subsystemID, long ssMaxMonitorPoints, long ssMaxSamples)
method to allocate space within the system frame for a subsystem frame, its monitor points and its sa...
bool isCurrentFrame() const
Method returns true if frame&#39;s timestamp is current; false otherwise.
bool isComplete() const
True if getNumCleanFrames() == 0.
void setCollatorWriteDelay(double writeDelay)
Writes the value of the delay used by the writer part of the frameCollator * to write to the associat...