00001 #ifndef _TIMER_HANDLER_H
00002 #define _TIMER_HANDLER_H
00003
00004 #include <pthread.h>
00005 #include <unistd.h>
00006 #include <stdint.h>
00007 #include <sys/types.h>
00008 #include <string>
00009
00011 class TimerHandler {
00012 public:
00014 TimerHandler(std::string desc = "");
00015
00016 virtual ~TimerHandler() { }
00017
00019 void fire() {
00020 scheduled = false;
00021 expire();
00022 }
00023
00033 uint64_t schedule(uint64_t time, bool abs = false, bool align = false);
00034
00036 void cancel();
00037 const std::string& getDescription() const { return description; }
00038 unsigned getId() const { return id; }
00039 bool isScheduled() const { return scheduled; }
00040 bool isRunning() const { return running; }
00041 bool operator==(const TimerHandler& other) const { return getId() == other.getId(); }
00042
00043 protected:
00044 virtual void expire() = 0;
00045
00046 void clearRunning() {
00047 running = false;
00048 }
00049
00050 private:
00051 std::string description;
00052 bool scheduled;
00053 bool running;
00054
00055
00059 unsigned id;
00060 };
00061
00062 #endif // _TIMER_HANDLER_H