mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-10 21:55:11 +01:00
49 lines
625 B
C++
49 lines
625 B
C++
#ifndef __TIMER_HH__
|
|
#define __TIMER_HH__
|
|
|
|
class TimeoutHandler;
|
|
|
|
class TimerController
|
|
{
|
|
public:
|
|
TimerController();
|
|
|
|
int arm(TimeoutHandler *which, int ms);
|
|
|
|
void disarm(TimeoutHandler *which);
|
|
|
|
void tick();
|
|
|
|
private:
|
|
int n_handlers;
|
|
TimeoutHandler **handlers;
|
|
};
|
|
|
|
class TimeoutHandler
|
|
{
|
|
friend class TimerController;
|
|
public:
|
|
TimeoutHandler()
|
|
{
|
|
this->timeout = 0;
|
|
this->timer_id = -1;
|
|
}
|
|
|
|
~TimeoutHandler();
|
|
|
|
void tick()
|
|
{
|
|
this->timeout--;
|
|
if (this->timeout == 0)
|
|
this->timeoutCallback();
|
|
}
|
|
|
|
virtual void timeoutCallback() = 0;
|
|
|
|
protected:
|
|
int timeout;
|
|
int timer_id;
|
|
};
|
|
|
|
#endif /* __TIMER_HH__ */
|