2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** Timer class for one-second resolution timers
25 * Timer provides a facility which allows module
26 * developers to create one-shot timers. The timer
27 * can be made to trigger at any time up to a one-second
28 * resolution. To use Timer, inherit a class from
29 * Timer, then insert your inherited class into the
30 * queue using Server::AddTimer(). The Tick() method of
31 * your object (which you should override) will be called
34 class CoreExport Timer
37 /** The triggering time
40 /** Number of seconds between triggers
43 /** True if this is a repeating timer
47 /** Default constructor, initializes the triggering time
48 * @param secs_from_now The number of seconds from now to trigger the timer
49 * @param now The time now
50 * @param repeating Repeat this timer every secs_from_now seconds if set to true
52 Timer(long secs_from_now, time_t now, bool repeating = false)
54 trigger = now + secs_from_now;
59 /** Default destructor, does nothing.
63 /** Retrieve the current triggering time
65 virtual time_t GetTimer()
70 /** Sets the trigger timeout to a new value
72 virtual void SetTimer(time_t t)
77 /** Called when the timer ticks.
78 * You should override this method with some useful code to
79 * handle the tick event.
81 virtual void Tick(time_t TIME) = 0;
83 /** Returns true if this timer is set to repeat
90 /** Returns the interval (number of seconds between ticks)
91 * of this timer object.
98 /** Cancels the repeat state of a repeating timer.
99 * If you call this method, then the next time your
100 * timer ticks, it will be removed immediately after.
101 * You should use this method call to remove a recurring
102 * timer if you wish to do so within the timer's Tick
103 * event, as calling TimerManager::DelTimer() from within
104 * the Timer::Tick() method is dangerous and may
105 * cause a segmentation fault. Calling CancelRepeat()
106 * is safe in this case.
115 /** This class manages sets of Timers, and triggers them at their defined times.
116 * This will ensure timers are not missed, as well as removing timers that have
117 * expired and allowing the addition of new ones.
119 class CoreExport TimerManager
122 /** A list of all pending timers
124 std::vector<Timer *> Timers;
132 /** Tick all pending Timers
133 * @param TIME the current system time
135 void TickTimers(time_t TIME);
138 * @param T an Timer derived class to add
140 void AddTimer(Timer *T);
143 * @param T an Timer derived class to delete
145 void DelTimer(Timer* T);
147 /** Compares two timers
149 static bool TimerComparison( Timer *one, Timer*two);