]>
Dogcows Code - chaz/openbox/blob - src/timer.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
12 BTimer::BTimer(TimerQueueManager
*m
, TimeoutHandler
*h
) {
16 recur
= timing
= False
;
20 BTimer::~BTimer(void) {
25 void BTimer::setTimeout(long t
) {
26 _timeout
.tv_sec
= t
/ 1000;
27 _timeout
.tv_usec
= t
% 1000;
28 _timeout
.tv_usec
*= 1000;
32 void BTimer::setTimeout(const timeval
&t
) {
33 _timeout
.tv_sec
= t
.tv_sec
;
34 _timeout
.tv_usec
= t
.tv_usec
;
38 void BTimer::start(void) {
39 gettimeofday(&_start
, 0);
43 manager
->addTimer(this);
48 void BTimer::stop(void) {
51 manager
->removeTimer(this);
55 void BTimer::halt(void) {
60 void BTimer::fireTimeout(void) {
66 timeval
BTimer::timeRemaining(const timeval
&tm
) const {
67 timeval ret
= endpoint();
69 ret
.tv_sec
-= tm
.tv_sec
;
70 ret
.tv_usec
-= tm
.tv_usec
;
72 return normalizeTimeval(ret
);
76 timeval
BTimer::endpoint(void) const {
79 ret
.tv_sec
= _start
.tv_sec
+ _timeout
.tv_sec
;
80 ret
.tv_usec
= _start
.tv_usec
+ _timeout
.tv_usec
;
82 return normalizeTimeval(ret
);
86 bool BTimer::shouldFire(const timeval
&tm
) const {
87 timeval end
= endpoint();
89 return ! ((tm
.tv_sec
< end
.tv_sec
) ||
90 (tm
.tv_sec
== end
.tv_sec
&& tm
.tv_usec
< end
.tv_usec
));
This page took 0.041284 seconds and 5 git commands to generate.