CARMA C++
FrameAlignedTimer.h
1 #ifndef CARMA_UTIL_FRAME_ALIGNED_TIMER_H
2 #define CARMA_UTIL_FRAME_ALIGNED_TIMER_H
3 
4 #include <ctime>
5 
6 #include <sys/time.h>
7 
8 #include "carma/util/ScheduledTimer.h"
9 
10 namespace carma {
11 namespace util {
12 
19 
21  public:
22 
48 
49  explicit FrameAlignedTimer( long offsetNanos = 0,
50  long periodFrames = 1,
51  bool preflight = true );
52 
53 
69 
70  struct ::timespec ResetNextFireTime( long delayFrames = 0 );
71 
72 
79 
80  struct ::timespec ResetNextFireTimeAndWait( long delayFrames = 0 );
81 
82  struct ::timespec getNextFireTime( );
83 
84  protected:
85  virtual Timespec
86  CalculateNextFireAbsoluteTime( const Timespec & fireAbsTime );
87 
88  Timespec InternalResetNextFireTime( long delayFrames,
89  bool wait );
90 
91  private:
92  const Timespec period_;
93  const long offsetNanos_;
94 };
95 
96 } // namespace util
97 } // namespace carma
98 
99 #endif
FrameAlignedTimer(long offsetNanos=0, long periodFrames=1, bool preflight=true)
Construct an instance with the given offset and period.
struct::timespec ResetNextFireTimeAndWait(long delayFrames=0)
Same as ResetNextFireTime( ) except that this method also waits for the new next fire time to arrive ...
Abstract base class for PthreadCond::TimedWait based timers.
struct::timespec ResetNextFireTime(long delayFrames=0)
Reset the next fire time (and by association the entire queue of fire times) to the soonest absolute ...
Timer object that fires at a fixed offset after every Nth CARMA frame time.