]> Dogcows Code - chaz/openbox/blobdiff - src/timer.hh
new timers, timer manager
[chaz/openbox] / src / timer.hh
index f13ad4dcbe64a90e0ca3ad9e0f56c7f640fbf519..774d0e49c385743e0ae476ddfccd5cf1da4bbb53 100644 (file)
@@ -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 <shaleh@debian.org>
-// 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 <queue>
+#include <algorithm>
+#include <vector>
+
+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 <queue>
-#include <algorithm>
-
 template <class _Tp, class _Sequence, class _Compare>
 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 <vector>
-typedef _timer_queue<BTimer*, std::vector<BTimer*>, TimerLessThan> TimerQueue;
+typedef _timer_queue<OBTimer*,
+                     std::vector<OBTimer*>, 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
This page took 0.022409 seconds and 4 git commands to generate.