- OBTimerQueueManager *manager;
- OBTimeoutHandler handler;
- OBTimeoutData data;
- bool timing, recur;
-
- timeval _start, _timeout;
-
- OBTimer(const OBTimer&);
- OBTimer& operator=(const OBTimer&);
+ //! 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, >);
+ }
+ };
+
+ 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)
+ /*!
+ @param self Timer to be deleted.
+ */
+ static void realDelete(Timer *self);
+
+ //! Adds a millisecond delay to a timeval structure
+ /*!
+ @param a Amount of time to increment.
+ @param msec Number of milliseconds to increment by.
+ */
+ static void timevalAdd(timeval &a, long msec);