ubit::UTimer Class Reference
a UTimer object fires callbacks after a given delay.
More...
#include <utimer.hpp>
Inheritance diagram for ubit::UTimer:
List of all members.
|
Public Member Functions |
virtual void | onAction (UCall &callback) |
virtual void | onTimeout (UCall &callback) |
| adds a callback that is fired when the time is up.
|
virtual void | start (UTime delay, int ntimes=0, bool auto_delete=true) |
| starts the timer.
|
virtual void | stop () |
| stops the timer.
|
int | getDelay () const |
void | setDelay (UTime) |
bool | isRunning () const |
| returns true if the timer is running.
|
virtual void | fireTimer () |
Friends |
class | UAppli |
class | UNatAppli |
Detailed Description
a UTimer object fires callbacks after a given delay.
Callbacks can be fired repeatedly (each time after the delay) or only one time. Timers can also be used to postpone operations that take a long amount of time to execute by using a delay of 0 msec.
Exemple:
uptr<UTimer> t = new UTimer();
t->onAction( ucall(x, y, printArgs) );
t->onAction( ucall(obj, val, &Demo::doIt) );
t->start(1000);
- starts the timer with a delay of 1000 msec in repeat mode. The 'onAction' callbacks are fired when the delay has passed. In this example, they call printArgs(x, y) and obj->doIt(val)
- by default these callbacks are fired until stop() is called. start() can have an optional arg that specifies how many times they must be called.
Member Function Documentation
virtual void ubit::UTimer::onTimeout |
( |
UCall & |
callback |
) |
[virtual] |
adds a callback that is fired when the time is up.
'callback' is a ucall<> expression (see UCall). It is destroyed when the timer is destroyed except if it is "referenced elsewhere" (see UBrick).
void ubit::UTimer::start |
( |
UTime |
delay, |
|
|
int |
ntimes = 0 , |
|
|
bool |
auto_delete = true | |
|
) |
| | [virtual] |
starts the timer.
- the 'delay' is in milliseconds. if 'delay' = 0, the timer is immediately fired when the main loop becomes idle.
- 'ntimes' specifies how many times the callbacks are fired (each time after the specified 'delay'). If ntimes <= 0 the callbacks are fired repeatedly until stop() is called.
- if 'auto_delete' is true, the UTimer is automatically destroyed on completion if it is not "referenced elsewhere" (see UBrick). To avoid memory leaks, this arg should be true except if the timer will be reused by calling start() again.
void ubit::UTimer::stop |
( |
|
) |
[virtual] |
stops the timer.
the UTimer is destroyed if it was started in auto_delete mode (see start()) and if it is not referenced elsewhere (see UBrick).
The documentation for this class was generated from the following files:
Generated on Mon Jan 29 00:20:57 2007 for Ubit by
1.4.7