X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Ftimer.hh;h=774d0e49c385743e0ae476ddfccd5cf1da4bbb53;hb=373de009f7e98b0c6f3a78f31c1e5c120cd722ed;hp=b022b0c43ebeb2c5c0980bdd7865d50dd279425d;hpb=86bef745b9e974f664752c6cc56f7e6ec5642efc;p=chaz%2Fopenbox diff --git a/src/timer.hh b/src/timer.hh index b022b0c4..774d0e49 100644 --- a/src/timer.hh +++ b/src/timer.hh @@ -15,28 +15,33 @@ extern "C" { #endif // TIME_WITH_SYS_TIME } +#include +#include +#include + +namespace ob { + // forward declaration -class TimerQueueManager; +class OBTimerQueueManager; class TimeoutHandler { public: virtual void timeout(void) = 0; }; -class BTimer { +class OBTimer { private: - TimerQueueManager *manager; TimeoutHandler *handler; bool timing, recur; timeval _start, _timeout; - BTimer(const BTimer&); - BTimer& operator=(const BTimer&); + OBTimer(const OBTimer&); + OBTimer& operator=(const OBTimer&); public: - BTimer(TimerQueueManager *m, TimeoutHandler *h); - virtual ~BTimer(void); + OBTimer(TimeoutHandler *h); + virtual ~OBTimer(void); void fireTimeout(void); @@ -59,14 +64,11 @@ public: void stop(void); // manager releases timer void halt(void); // halts the timer - bool operator<(const BTimer& other) const + bool operator<(const OBTimer& other) const { return shouldFire(other.endpoint()); } }; -#include -#include - template class _timer_queue: protected std::priority_queue<_Tp, _Sequence, _Compare> { public: @@ -92,18 +94,31 @@ private: }; struct TimerLessThan { - bool operator()(const BTimer* const l, const BTimer* const r) const { + bool operator()(const OBTimer* const l, const OBTimer* const r) const { return *r < *l; } }; -#include -typedef _timer_queue, TimerLessThan> TimerQueue; +typedef _timer_queue, TimerLessThan> TimerQueue; -class TimerQueueManager { +class OBTimerQueueManager { +private: + TimerQueue timerList; public: - virtual void addTimer(BTimer* timer) = 0; - virtual void removeTimer(BTimer* timer) = 0; + OBTimerQueueManager() {} + virtual ~OBTimerQueueManager() {} + + //! Will wait for and fire the next timer in the queue. + /*! + The function will stop waiting if an event is received from the X server. + */ + virtual void fire(); + + virtual void addTimer(OBTimer* timer); + virtual void removeTimer(OBTimer* timer); }; +} + #endif // _BLACKBOX_Timer_hh