#include "BaseDisplay.h"
#include "Timer.h"
-BTimer::BTimer(BaseDisplay *d, TimeoutHandler *h) {
- display = d;
- handler = h;
-
+BTimer::BTimer(BaseDisplay &d, TimeoutHandler &h) : display(d), handler(h) {
once = timing = False;
}
_timeout.tv_usec = t;
_timeout.tv_usec -= (_timeout.tv_sec * 1000);
_timeout.tv_usec *= 1000;
+ if (timing) {
+ display.removeTimer(this);
+ display.addTimer(this); // reorder the display
+ }
}
void BTimer::setTimeout(timeval t) {
if (! timing) {
timing = True;
- display->addTimer(this);
+ display.addTimer(this);
}
}
void BTimer::stop(void) {
- timing = False;
+ if (timing) {
+ timing = False;
- display->removeTimer(this);
+ display.removeTimer(this);
+ }
}
void BTimer::fireTimeout(void) {
- if (handler) handler->timeout();
+ handler.timeout();
}