CARMA C++
carma::util::FrameAlignedTimer Class Reference

Timer object that fires at a fixed offset after every Nth CARMA frame time. More...

#include <carma/util/FrameAlignedTimer.h>

Inheritance diagram for carma::util::FrameAlignedTimer:
carma::util::ScheduledTimer

Public Member Functions

 FrameAlignedTimer (long offsetNanos=0, long periodFrames=1, bool preflight=true)
 Construct an instance with the given offset and period. More...
 
struct::timespec getNextFireTime ()
 
struct::timespec ResetNextFireTime (long delayFrames=0)
 Reset the next fire time (and by association the entire queue of fire times) to the soonest absolute time that is the correct offset from a CARMA frame time and also is at least delayFrames CARMA frames after the time of the call and then return that new next fire absolute time. More...
 
struct::timespec ResetNextFireTimeAndWait (long delayFrames=0)
 Same as ResetNextFireTime( ) except that this method also waits for the new next fire time to arrive before returning the new next fire time that it has just waited for. More...
 
- Public Member Functions inherited from carma::util::ScheduledTimer
void InterruptPresentOrNextWait ()
 Interrupt the wait that is presently occurring on this timer object or if no such wait is presently occurring then preemptively interrupt the next wait that occurs. More...
 
void WaitForNextFireTime ()
 Block (the thread of the caller) until the next fire time for the timer arrives. More...
 

Protected Member Functions

virtual Timespec CalculateNextFireAbsoluteTime (const Timespec &fireAbsTime)
 
Timespec InternalResetNextFireTime (long delayFrames, bool wait)
 
- Protected Member Functions inherited from carma::util::ScheduledTimer
void refreshNextFireAbsTimeIfNeeded (Timespec *nextFireAbsTime)
 
 ScheduledTimer (bool preflight)
 
void SetNextFireTime (const Timespec &nextFireAbsTime)
 
void SetNextFireTimeAndWait (const Timespec &nextFireAbsTime)
 

Additional Inherited Members

- Protected Types inherited from carma::util::ScheduledTimer
typedef struct::timespec Timespec
 
- Static Protected Member Functions inherited from carma::util::ScheduledTimer
static void sanityCheckTimespec (const Timespec &ts)
 

Detailed Description

Timer object that fires at a fixed offset after every Nth CARMA frame time.

Warning
An instance is NOT ready to wait on simply by being constructed. You MUST reset an instance's next fire time before (or at the same time as) the first wait on an instance.

Definition at line 20 of file FrameAlignedTimer.h.

Constructor & Destructor Documentation

carma::util::FrameAlignedTimer::FrameAlignedTimer ( long  offsetNanos = 0,
long  periodFrames = 1,
bool  preflight = true 
)
explicit

Construct an instance with the given offset and period.

If any parameters are invalid or an internal error occurs then an exception will be thrown.

Parameters
offsetNanosOffset in nanoseconds from the CARMA frame time to the fire time for the instance. The value must be greater than 0 and less than the CARMA frame period in nanoseconds.
periodFramesHow often (in integral CARMA frame periods) the instance will fire. The value must be greater than 0.
preflightIf true then the instance will be preflighted as part of construction. Preflighting involves actually performing a very quick wait and/or test on the internal primitives used to implement the instance. This MAY reduce any increased one-time latency and/or drift in the first wait on the instance (on some operating systems).
Precondition
offsetNanos is greater than 0 and less than the CARMA frame period in nanoseconds.
periodFrames is greater than 0.

Member Function Documentation

struct ::timespec carma::util::FrameAlignedTimer::ResetNextFireTime ( long  delayFrames = 0)

Reset the next fire time (and by association the entire queue of fire times) to the soonest absolute time that is the correct offset from a CARMA frame time and also is at least delayFrames CARMA frames after the time of the call and then return that new next fire absolute time.

All old fire times are removed from the queue as though they never existed.

Parameters
delayFramesminimum number of CARMA frames to delay the next fire time after the time of the call.
Precondition
delayFrames is greater than or equal to 0.
Returns
new next absolute fire time.
struct ::timespec carma::util::FrameAlignedTimer::ResetNextFireTimeAndWait ( long  delayFrames = 0)

Same as ResetNextFireTime( ) except that this method also waits for the new next fire time to arrive before returning the new next fire time that it has just waited for.

Postcondition
Either absolute time is greater than or equal to the fire time returned or an exception has been thrown.

The documentation for this class was generated from the following file: