2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2013, 2017 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006-2007, 2010 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 /** Timer class for one-second resolution timers
32 * Timer provides a facility which allows module
33 * developers to create one-shot timers. The timer
34 * can be made to trigger at any time up to a one-second
35 * resolution. To use Timer, inherit a class from
36 * Timer, then insert your inherited class into the
37 * queue using Server::AddTimer(). The Tick() method of
38 * your object (which you have to override) will be called
41 class CoreExport Timer
43 /** The triggering time
47 /** Number of seconds between triggers
51 /** True if this is a repeating timer
56 /** Default constructor, initializes the triggering time
57 * @param secs_from_now The number of seconds from now to trigger the timer
58 * @param repeating Repeat this timer every secs_from_now seconds if set to true
60 Timer(unsigned int secs_from_now, bool repeating = false);
62 /** Default destructor, removes the timer from the timer manager
66 /** Retrieve the current triggering time
68 time_t GetTrigger() const
73 /** Sets the trigger timeout to a new value
74 * This does not update the bookkeeping in TimerManager, use SetInterval()
75 * to change the interval between ticks while keeping TimerManager updated
77 void SetTrigger(time_t nexttrigger)
79 trigger = nexttrigger;
82 /** Sets the interval between two ticks.
84 void SetInterval(unsigned int interval);
86 /** Called when the timer ticks.
87 * You should override this method with some useful code to
88 * handle the tick event.
89 * @param TIME The current time.
90 * @return True if the Timer object is still valid, false if it was destructed.
92 virtual bool Tick(time_t TIME) = 0;
94 /** Returns true if this timer is set to repeat
96 bool GetRepeat() const
101 /** Returns the interval (number of seconds between ticks)
102 * of this timer object.
104 unsigned int GetInterval() const
109 /** Cancels the repeat state of a repeating timer.
110 * If you call this method, then the next time your
111 * timer ticks, it will be removed immediately after.
119 /** This class manages sets of Timers, and triggers them at their defined times.
120 * This will ensure timers are not missed, as well as removing timers that have
121 * expired and allowing the addition of new ones.
123 class CoreExport TimerManager
125 typedef std::multimap<time_t, Timer*> TimerMap;
127 /** A list of all pending 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 remove
145 void DelTimer(Timer* T);