all repos — openbox @ 231f4dadabd532183317188c1a0e8ffe87dc579b

openbox fork - make it a bit more like ryudo

no long used with our Timer-ng!
Dana Jansens danakj@orodu.net
commit

231f4dadabd532183317188c1a0e8ffe87dc579b

parent

a388c41df485e6ac7cfb26231b7ac6be76e3522e

3 files changed, 0 insertions(+), 165 deletions(-)

jump to
D otk/timerqueue.hh

@@ -1,51 +0,0 @@

-// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __timerqueue_hh -#define __timerqueue_hh - -#ifndef DOXYGEN_IGNORE - -#include "timer.hh" - -#include <queue> -#include <vector> -#include <algorithm> - -namespace otk { - -template <class _Tp, class _Sequence, class _Compare> -class _timer_queue: protected std::priority_queue<_Tp, _Sequence, _Compare> { -public: - typedef std::priority_queue<_Tp, _Sequence, _Compare> _Base; - - _timer_queue(): _Base() {} - ~_timer_queue() {} - - void release(const _Tp& value) { - c.erase(std::remove(c.begin(), c.end(), value), c.end()); - // after removing the item we need to make the heap again - std::make_heap(c.begin(), c.end(), comp); - } - bool empty() const { return _Base::empty(); } - size_t size() const { return _Base::size(); } - void push(const _Tp& value) { _Base::push(value); } - void pop() { _Base::pop(); } - const _Tp& top() const { return _Base::top(); } -private: - // no copying! - _timer_queue(const _timer_queue&) {} - _timer_queue& operator=(const _timer_queue&) {} -}; - -struct TimerLessThan { - bool operator()(const Timer* const l, const Timer* const r) const { - return *r < *l; - } -}; - -typedef _timer_queue<Timer*, std::vector<Timer*>, TimerLessThan> TimerQueue; - -} - -#endif // DOXYGEN_IGNORE - -#endif // __timerqueue_hh
D otk/timerqueuemanager.cc

@@ -1,68 +0,0 @@

-// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H - -#include "timerqueuemanager.hh" -#include "display.hh" - -namespace otk { - -void TimerQueueManager::fire(bool wait) -{ - fd_set rfds; - timeval now, tm, *timeout = (timeval *) 0; - - const int xfd = ConnectionNumber(**display); - - FD_ZERO(&rfds); - FD_SET(xfd, &rfds); // break on any x events - - if (wait) { - if (! timerList.empty()) { - const Timer* const timer = timerList.top(); - - gettimeofday(&now, 0); - tm = timer->remainingTime(now); - - timeout = &tm; - } - - select(xfd + 1, &rfds, 0, 0, timeout); - } - - // check for timer timeout - gettimeofday(&now, 0); - - // there is a small chance for deadlock here: - // *IF* the timer list keeps getting refreshed *AND* the time between - // timer->start() and timer->shouldFire() is within the timer's period - // then the timer will keep firing. This should be VERY near impossible. - while (! timerList.empty()) { - Timer *timer = timerList.top(); - if (! timer->shouldFire(now)) - break; - - timerList.pop(); - - timer->fire(); - if (timer->recurring()) - timer->start(); - } -} - - -void TimerQueueManager::addTimer(Timer *timer) -{ - assert(timer); - timerList.push(timer); -} - -void TimerQueueManager::removeTimer(Timer* timer) -{ - assert(timer); - timerList.release(timer); -} - -}
D otk/timerqueuemanager.hh

@@ -1,46 +0,0 @@

-// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __timerqueuemanager_hh -#define __timerqueuemanager_hh - -#include "timerqueue.hh" - -namespace otk { - -//! Manages a queue of Timer objects -/*! - All Timer objects add themself to a TimerQueueManager. The manager is - what fires the timers when their time has elapsed. This is done by having the - application call the TimerQueueManager::fire class in its main event loop. -*/ -class TimerQueueManager { -private: - //! A priority queue of all timers being managed by this class. - TimerQueue timerList; -public: - //! Constructs a new TimerQueueManager - TimerQueueManager() {} - //! Destroys the TimerQueueManager - virtual ~TimerQueueManager() {} - - //! Fire the next timer in the queue. - /*! - @param wait If true, this function will wait for the next timer, breaking - on any events from the X server. - */ - virtual void fire(bool wait = true); - - //! Adds a new timer to the queue - /*! - @param timer An Timer to add to the queue - */ - virtual void addTimer(Timer* timer); - //! Removes a timer from the queue - /*! - @param timer An Timer already in the queue to remove - */ - virtual void removeTimer(Timer* timer); -}; - -} - -#endif // __timerqueuemanager_hh