diff options
author | Chris Wilson <chris+github@qwirx.com> | 2006-11-06 20:43:12 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2006-11-06 20:43:12 +0000 |
commit | 3a590d43ce5e108e42483993b3ce7bfaaa20d74d (patch) | |
tree | 56aeb826bce234eb3f2fe5e747fe8194a84d9c42 /lib/common/Timer.h | |
parent | ee4dc408e4ce8364322ea19a4fabbb5e8edf4d46 (diff) |
Added generic timer support class
Diffstat (limited to 'lib/common/Timer.h')
-rw-r--r-- | lib/common/Timer.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/common/Timer.h b/lib/common/Timer.h new file mode 100644 index 00000000..6e4a5952 --- /dev/null +++ b/lib/common/Timer.h @@ -0,0 +1,65 @@ +// -------------------------------------------------------------------------- +// +// File +// Name: Timer.h +// Purpose: Generic timers which execute arbitrary code when +// they expire. +// Created: 5/11/2006 +// +// -------------------------------------------------------------------------- + +#ifndef TIMER__H +#define TIMER__H + +#include <sys/time.h> + +#include <vector> + +#include "MemLeakFindOn.h" +#include "BoxTime.h" + +class Timer +{ +public: + Timer(size_t timeoutSecs); + virtual ~Timer(); + Timer(const Timer &); + Timer &operator=(const Timer &); + +public: + box_time_t GetExpiryTime() { return mExpires; } + bool HasExpired () { return mExpired; } + virtual void OnExpire (); + +private: + box_time_t mExpires; + bool mExpired; +}; + +// -------------------------------------------------------------------------- +// +// Class +// Name: Timers +// Purpose: Static class to manage all timers and arrange +// efficient delivery of wakeup signals +// Created: 19/3/04 +// +// -------------------------------------------------------------------------- +class Timers +{ + private: + static std::vector<Timer*> sTimers; + static bool sInitialised; + static void Reschedule(); + + public: + static void Init(); + static void Cleanup(); + static void Add (Timer& rTimer); + static void Remove(Timer& rTimer); + static void Signal(); +}; + +#include "MemLeakFindOff.h" + +#endif // TIMER__H |