1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "basedisplay.hh"
11 BTimer::BTimer(TimerQueueManager *m, TimeoutHandler *h) {
15 recur = timing = False;
19 BTimer::~BTimer(void) {
24 void BTimer::setTimeout(long t) {
25 _timeout.tv_sec = t / 1000;
26 _timeout.tv_usec = t % 1000;
27 _timeout.tv_usec *= 1000;
31 void BTimer::setTimeout(const timeval &t) {
32 _timeout.tv_sec = t.tv_sec;
33 _timeout.tv_usec = t.tv_usec;
37 void BTimer::start(void) {
38 gettimeofday(&_start, 0);
42 manager->addTimer(this);
47 void BTimer::stop(void) {
50 manager->removeTimer(this);
54 void BTimer::halt(void) {
59 void BTimer::fireTimeout(void) {
65 timeval BTimer::timeRemaining(const timeval &tm) const {
66 timeval ret = endpoint();
68 ret.tv_sec -= tm.tv_sec;
69 ret.tv_usec -= tm.tv_usec;
71 return normalizeTimeval(ret);
75 timeval BTimer::endpoint(void) const {
78 ret.tv_sec = _start.tv_sec + _timeout.tv_sec;
79 ret.tv_usec = _start.tv_usec + _timeout.tv_usec;
81 return normalizeTimeval(ret);
85 bool BTimer::shouldFire(const timeval &tm) const {
86 timeval end = endpoint();
88 return ! ((tm.tv_sec < end.tv_sec) ||
89 (tm.tv_sec == end.tv_sec && tm.tv_usec < end.tv_usec));