#include <Timer.h>
Inheritance diagram for GNE::Timer:
Public Types | |
typedef SmartPtr< Timer > | sptr |
typedef WeakPtr< Timer > | wptr |
Public Member Functions | |
virtual | ~Timer () |
Destructor. | |
SmartPtr< TimerCallback > | getCallback () 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. |
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.
|
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.
|
|
Returns the current time from the system clock. The time returned is an absolute time, relative to midnight, Jan 1, 1970. |
|
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. |
|
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. |
|
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. |
|
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. |