1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #ifndef INSPIRCD_TIMER_H
15 #define INSPIRCD_TIMER_H
17 /** Timer class for one-second resolution timers
18 * Timer provides a facility which allows module
19 * developers to create one-shot timers. The timer
20 * can be made to trigger at any time up to a one-second
21 * resolution. To use Timer, inherit a class from
22 * Timer, then insert your inherited class into the
23 * queue using Server::AddTimer(). The Tick() method of
24 * your object (which you should override) will be called
27 class CoreExport Timer
30 /** The triggering time
33 /** Number of seconds between triggers
36 /** True if this is a repeating timer
40 /** Default constructor, initializes the triggering time
41 * @param secs_from_now The number of seconds from now to trigger the timer
42 * @param now The time now
43 * @param repeating Repeat this timer every secs_from_now seconds if set to true
45 Timer(long secs_from_now, time_t now, bool repeating = false)
47 trigger = now + secs_from_now;
52 /** Default destructor, does nothing.
56 /** Retrieve the current triggering time
58 virtual time_t GetTimer()
63 /** Sets the trigger timeout to a new value
65 virtual void SetTimer(time_t t)
70 /** Called when the timer ticks.
71 * You should override this method with some useful code to
72 * handle the tick event.
74 virtual void Tick(time_t TIME) = 0;
76 /** Returns true if this timer is set to repeat
83 /** Returns the interval (number of seconds between ticks)
84 * of this timer object.
91 /** Cancels the repeat state of a repeating timer.
92 * If you call this method, then the next time your
93 * timer ticks, it will be removed immediately after.
94 * You should use this method call to remove a recurring
95 * timer if you wish to do so within the timer's Tick
96 * event, as calling TimerManager::DelTimer() from within
97 * the Timer::Tick() method is dangerous and may
98 * cause a segmentation fault. Calling CancelRepeat()
99 * is safe in this case.
108 /** This class manages sets of Timers, and triggers them at their defined times.
109 * This will ensure timers are not missed, as well as removing timers that have
110 * expired and allowing the addition of new ones.
112 class CoreExport TimerManager
115 /** A list of all pending timers
117 std::vector<Timer *> Timers;
125 /** Tick all pending Timers
126 * @param TIME the current system time
128 void TickTimers(time_t TIME);
131 * @param T an Timer derived class to add
132 * @param secs_from_now You may set this to the number of seconds
133 * from the current time when the timer will tick, or you may just
134 * leave this unset and the values set by the Timers constructor
135 * will be used. This is used internally for re-triggering repeating
138 void AddTimer(Timer *T);
141 * @param T an Timer derived class to delete
143 void DelTimer(Timer* T);
145 /** Compares two timers
147 static bool TimerComparison( Timer *one, Timer*two);