Better bounds checking on DNS
[network-sink.git] / include / timers.hpp
blob5e8f702f158cb70ae877e5600e6587a6de51543e
1 #ifndef TIMERS_H
2 #define TIMERS_H
4 namespace Sinkhole
6 class Timer
8 private:
9 /** The time this was created
11 time_t settime;
13 /** The triggering time
15 time_t trigger;
17 /** Numer of seconds between triggers
19 long secs;
21 /** True if this is a repeating timer
23 bool repeat;
25 public:
26 /** Default constructor, initializes the triggering time
27 * @param time_from_now The number of seconds from now to trigger the timer
28 * @param now The time now
29 * @param repeating Repeat this timer every time_from_now if this is true
31 Timer(long time_from_now, time_t now = Sinkhole::curtime, bool repeating = false);
33 /** Default destructor, removes the timer from the list
35 virtual ~Timer();
37 /** Set the trigger time to a new value
38 * @param t The new time
40 void SetTimer(time_t t);
42 /** Retrieve the triggering time
43 * @return The trigger time
45 time_t GetTimer() const;
47 /** Returns true if the timer is set to repeat
48 * @return Returns true if the timer is set to repeat
50 bool GetRepeat() const;
52 /** Returns the interval between ticks
53 * @return The interval
55 long GetSecs() const;
57 /** Returns the time this timer was created
58 * @return The time this timer was created
60 time_t GetSetTime() const;
62 /** Called when the timer ticks
64 virtual void Tick() = 0;
67 /** This class manages sets of Timers, and triggers them at their defined times.
68 * This will ensure timers are not missed, as well as removing timers that have
69 * expired and allowing the addition of new ones.
71 class TimerManager
73 private:
74 /** A list of timers
76 static std::vector<Timer *> Timers;
77 public:
78 /** Add a timer to the list
79 * @param T A Timer derived class to add
81 static void AddTimer(Timer *T);
83 /** Deletes a timer
84 * @param T A Timer derived class to delete
86 static void DelTimer(Timer *T);
88 /** Tick all pending timers
90 static void Process();
92 /** Compares two timers
94 static bool TimerComparison(Timer *one, Timer *two);
98 #endif // TIMERS_H