- //! The manager which to add ourself to and remove ourself after we are done
- OBTimerQueueManager *_manager;
- //! The function to call when the time elapses
- OBTimeoutHandler _handler;
- //! The data which gets passed along to the OBTimeoutHandler
- OBTimeoutData _data;
- //! Determines if the timer is currently started
- bool _timing;
- //! When this is true, the timer will reset itself to fire again every time
- bool _recur;
-
- //! The time at which the timer started
- timeval _start;
- //! The time at which the timer is going to fire
- timeval _timeout;
-
- //! Disallows copying of OBTimer objects
- OBTimer(const OBTimer&);
- //! Disallows copying of OBTimer objects
- OBTimer& operator=(const OBTimer&);
-
-public:
- //! Constructs a new OBTimer object
+ //! 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)