X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Ftimer.hh;h=774d0e49c385743e0ae476ddfccd5cf1da4bbb53;hb=373de009f7e98b0c6f3a78f31c1e5c120cd722ed;hp=f13ad4dcbe64a90e0ca3ad9e0f56c7f640fbf519;hpb=db451d95bf97b8a8e995f031ac98da50606fd3a0;p=chaz%2Fopenbox diff --git a/src/timer.hh b/src/timer.hh index f13ad4dc..774d0e49 100644 --- a/src/timer.hh +++ b/src/timer.hh @@ -1,26 +1,4 @@ // -*- mode: C++; indent-tabs-mode: nil; -*- -// Timer.hh for Blackbox - An X11 Window Manager -// Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry -// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - #ifndef _BLACKBOX_Timer_hh #define _BLACKBOX_Timer_hh @@ -37,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); @@ -81,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: @@ -114,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