fix compiling in display.
make the timer manager work in and of itself
This commit is contained in:
parent
8ad2610917
commit
c5f62494f1
4 changed files with 77 additions and 12 deletions
|
@ -158,6 +158,11 @@ void OBDisplay::destroy()
|
|||
}
|
||||
|
||||
|
||||
const ScreenInfo* OBDisplay::screenInfo(int snum) {
|
||||
assert(snum >= 0);
|
||||
assert(snum < static_cast<int>(_screenInfoList.size()));
|
||||
return &_screenInfoList[snum];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -50,11 +50,7 @@ public:
|
|||
\param snum The screen number of the screen to retrieve info on
|
||||
\return Info on the requested screen, in a ScreenInfo class
|
||||
*/
|
||||
inline static const ScreenInfo* screenInfo(int snum) {
|
||||
assert(snum >= 0);
|
||||
assert(snum < static_cast<int>(_screenInfoList.size()));
|
||||
return &_screenInfoList[snum];
|
||||
}
|
||||
static const ScreenInfo* screenInfo(int snum);
|
||||
|
||||
//! Returns if the display has the shape extention available
|
||||
inline static bool shape() { return _shape; }
|
||||
|
|
59
src/timer.cc
59
src/timer.cc
|
@ -4,12 +4,13 @@
|
|||
# include "../config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include "otk/display.hh"
|
||||
#include "timer.hh"
|
||||
#include "util.hh"
|
||||
|
||||
namespace ob {
|
||||
|
||||
BTimer::BTimer(TimerQueueManager *m, TimeoutHandler *h) {
|
||||
BTimer::BTimer(OBTimerQueueManager *m, TimeoutHandler *h) {
|
||||
manager = m;
|
||||
handler = h;
|
||||
|
||||
|
@ -90,4 +91,60 @@ bool BTimer::shouldFire(const timeval &tm) const {
|
|||
(tm.tv_sec == end.tv_sec && tm.tv_usec < end.tv_usec));
|
||||
}
|
||||
|
||||
|
||||
void OBTimerQueueManager::go()
|
||||
{
|
||||
fd_set rfds;
|
||||
timeval now, tm, *timeout = (timeval *) 0;
|
||||
|
||||
const int xfd = ConnectionNumber(otk::OBDisplay::display);
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(xfd, &rfds); // break on any x events
|
||||
|
||||
if (! timerList.empty()) {
|
||||
const BTimer* const timer = timerList.top();
|
||||
|
||||
gettimeofday(&now, 0);
|
||||
tm = timer->timeRemaining(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()) {
|
||||
BTimer *timer = timerList.top();
|
||||
if (! timer->shouldFire(now))
|
||||
break;
|
||||
|
||||
timerList.pop();
|
||||
|
||||
timer->fireTimeout();
|
||||
timer->halt();
|
||||
if (timer->isRecurring())
|
||||
timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OBTimerQueueManager::addTimer(BTimer *timer)
|
||||
{
|
||||
assert(timer);
|
||||
timerList.push(timer);
|
||||
}
|
||||
|
||||
void OBTimerQueueManager::removeTimer(BTimer* timer)
|
||||
{
|
||||
assert(timer);
|
||||
timerList.release(timer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
19
src/timer.hh
19
src/timer.hh
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
namespace ob {
|
||||
|
||||
// forward declaration
|
||||
class TimerQueueManager;
|
||||
class OBTimerQueueManager;
|
||||
|
||||
class TimeoutHandler {
|
||||
public:
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
|
||||
class BTimer {
|
||||
private:
|
||||
TimerQueueManager *manager;
|
||||
OBTimerQueueManager *manager;
|
||||
TimeoutHandler *handler;
|
||||
bool timing, recur;
|
||||
|
||||
|
@ -41,7 +41,7 @@ private:
|
|||
BTimer& operator=(const BTimer&);
|
||||
|
||||
public:
|
||||
BTimer(TimerQueueManager *m, TimeoutHandler *h);
|
||||
BTimer(OBTimerQueueManager *m, TimeoutHandler *h);
|
||||
virtual ~BTimer(void);
|
||||
|
||||
void fireTimeout(void);
|
||||
|
@ -102,10 +102,17 @@ struct TimerLessThan {
|
|||
|
||||
typedef _timer_queue<BTimer*, std::vector<BTimer*>, 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() {}
|
||||
|
||||
virtual void go();
|
||||
|
||||
virtual void addTimer(BTimer* timer);
|
||||
virtual void removeTimer(BTimer* timer);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue