- //! Returns if the Timer is started and timing
- inline bool timing() const { return _timing; }
- //! Returns if the Timer is going to repeat
- inline bool recurring() const { return _recur; }
-
- //! Gets the amount of time the Timer should last before firing
- inline const timeval &timeout() const { return _timeout; }
- //! Gets the time at which the Timer started
- inline const timeval &startTime() const { return _start; }
-
- //! Gets the amount of time left before the Timer fires
- timeval remainingTime(const timeval &tm) const;
- //! Returns if the Timer is past its timeout time, and should fire
- bool shouldFire(const timeval &tm) const;
-
- //! Gets the time at which the Timer will fire
- timeval endTime() const;
-
- //! Sets the Timer to repeat or not
+private:
+ //! Compares two timeval structs
+ struct TimerCompare {
+ //! Compares two timeval structs
+ inline bool operator()(const Timer *a, const Timer *b) const {
+ return timercmp(&a->_timeout, &b->_timeout, >);
+ }
+ };
+ friend struct TimerCompare; // give access to _timeout for shitty compilers
+
+ typedef
+ std::priority_queue<Timer*, std::vector<Timer*>, TimerCompare> TimerQ;
+
+ //! Milliseconds between timer firings
+ long _delay;
+ //! Callback for timer expiry
+ TimeoutHandler _action;
+ //! Data sent to callback
+ void *_data;
+ //! We overload the delete operator to just set this to true
+ bool _del_me;
+ //! The time the last fire should've been at
+ struct timeval _last;
+ //! When this timer will next trigger
+ struct timeval _timeout;
+
+ //! Queue of pending timers
+ static TimerQ _q;
+ //! Time next timer will expire
+ static timeval _nearest_timeout;
+ //! Time at start of current processing loop
+ static timeval _now;
+
+ //! Really delete something (not just flag for later)