#include <cascade/app/CascadeTimer.h>
Inheritance diagram for CascadeTimer:
Public Member Functions | |
CascadeTimer () | |
virtual | ~CascadeTimer () |
u32 | SetTimer (u32 nMilliseconds) |
void | KillTimer (u32 nTimerID) |
virtual void | OnTimer (u32 nTimerID)=0 |
CascadeTimer is a mix-in class that allows any class that is running in the context of a CascadeApp to receive timer notifications.
Example Usage:
class MyWindow : public CascadeWindow, CascadeTimer { public: virtual void OnTimer(u32 nTimerID) { if (m_nTimerID == nTimerID) { KillTimer(nTimerID); m_nTimerID = 0; } }; public: u32 m_nTimerID; };
MyWindow myWindow; myWindow.m_nTimerID = myWindow.SetTimer(1000); // set a timer to fire every 1000 ms
In this example, the CascadeTimer is mixed into the MyWindow class. A timer is set to fire every 1000 milliseconds and its timer id is remembered in the member variable m_nTimerID. The first time the timer is fired, the timer is killed in OnTimer(). Note that we make sure that the timer id passed into OnTimer is the timer id of the timer we created. In this example that is overkill since we've only set one timer on the MyWindow CascadeTimer derived object.
Timer notifications are always delivered to the app's main thread. To avoid thread contention for the CascadeApp object, all CascadeTimer functions must only be called within the context of the main app thread.
|
default constructor The CascadeTimer constructor is lightweight. |
|
destructor The CascadeTimer destructor is lightweight. |
|
kills a previously created timer KillTimer() kills a timer that was previously set with SetTimer().
|
|
called whenever a timer expires OnTimer() is called within the context of a CascadeApp's main thread whenever the timer identified by nTimerID fires.
|
|
sets a new timer SetTimer() sets a timer to repeatedly expire every nMilliseconds until KillTimer() is called. Whenever the timer expires, OnTimer() is called.
|