Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::Timer Class Reference
[Threading API]

#include <Timer.h>

Inheritance diagram for GNE::Timer:

GNE::Thread List of all members.

Public Types

typedef SmartPtr< Timer > sptr
typedef WeakPtr< Timer > wptr

Public Member Functions

virtual ~Timer ()
 Destructor.

SmartPtr< TimerCallbackgetCallback () const
 Returns the TimerCallback set in the constructor.

void startTimer ()
 Starts the timer running and calling the callback.

virtual void shutDown ()
 Equivalent to calling stopTimer with false.

void stopTimer (bool waitForEnd)
 Stops the timer and stops calling the callback.


Static Public Member Functions

void stopAll ()
 Stops all Timers.

sptr create (const SmartPtr< TimerCallback > &callback, int rate)
 Create a timer callback.

Time getCurrentTime ()
 Returns the current time from some arbitray point in the past.

Time getAbsoluteTime ()
 Returns the current time from the system clock.


Protected Member Functions

 Timer (const SmartPtr< TimerCallback > &callback, int rate)
void run ()
 This is the thread that will perform the callbacks.


Detailed Description

The timer class is used to get the current time and to provide callbacks. A timer object calls its listeners back every so often based on the time given.

All of the methods in this class are safe to call from multiple threads at the same time, and can also be called from the TimerCallback as well, with a few (some obvious) exceptions.

A Timer thread runs with a higher priority than the main thread, therefore its callbacks are suitable for short, quick tasks.


Member Function Documentation

Timer::sptr GNE::Timer::create const SmartPtr< TimerCallback > &  callback,
int  rate
[static]
 

Create a timer callback.

The first call to the callback will occur after "rate" milliseconds, so this class is suitable for setting timeouts for your operations. Use the startTimer method to start this timer.

The callback is released when the Timer is stopped. This allows the callback to contain a reference to the Timer.

Parameters:
callback A newly allocated object to perform callbacks on.
rate the callback rate in milliseconds.

Time GNE::Timer::getAbsoluteTime  )  [static]
 

Returns the current time from the system clock.

The time returned is an absolute time, relative to midnight, Jan 1, 1970.

TimerCallback::sptr GNE::Timer::getCallback  )  const
 

Returns the TimerCallback set in the constructor.

After the timer has stopped, an empty SmartPtr is returned since the listener is released when the timer stops.

Time GNE::Timer::getCurrentTime  )  [static]
 

Returns the current time from some arbitray point in the past.

This is usually a very high precision timer that likely provides microsecond or better resolution.

void GNE::Timer::startTimer  ) 
 

Starts the timer running and calling the callback.

If the timer has already started, this call will have no effect. You cannot restart a Timer once you have stopped it, you need to create a new Timer.

void GNE::Timer::stopTimer bool  waitForEnd  ) 
 

Stops the timer and stops calling the callback.

The timer will likely be called one more time because the timer will actually stop at the end of its most recent cycle. If you want to wait until the callback is called for the last time, pass true into this function. Then this function will block for at most the time of the callback rate plus the time it takes for the callback to finish.

This timer's callback can call this function, but obviously it must not pass true to this function.

If a Timer is already stopped, this function will have no effect.


The documentation for this class was generated from the following files:
Generated on Fri Aug 22 13:40:07 2003 for GNE by doxygen1.3