1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 * InspTimer 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 InspTimer, inherit a class from
22 * InspTimer, 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 InspTimer : public Extensible
30 /** The triggering time
36 /** Default constructor, initializes the triggering time
37 * @param secs_from_now The number of seconds from now to trigger the timer
38 * @param now The time now
39 * @param repeating Repeat this timer every secs_from_now seconds if set to true
41 InspTimer(long secs_from_now,time_t now, bool repeating = false)
43 trigger = now + secs_from_now;
47 /** Default destructor, does nothing.
49 virtual ~InspTimer() { }
50 /** Retrieve the current triggering time
52 virtual time_t GetTimer()
56 /** Called when the timer ticks.
58 virtual void Tick(time_t TIME) = 0;
72 /** This class manages sets of InspTimers, and triggers them at their defined times.
73 * This will ensure timers are not missed, as well as removing timers that have
74 * expired and allowing the addition of new ones.
76 class TimerManager : public Extensible
79 /** A group of timers all set to trigger at the same time
81 typedef std::vector<InspTimer*> timergroup;
82 /** A map of timergroups, each group has a specific trigger time
84 typedef std::map<time_t, timergroup*> timerlist;
88 /** The current timer set, a map of timergroups
93 /** Tick all pending InspTimers
94 * @param TIME the current system time
96 void TickTimers(time_t TIME);
98 * @param T an InspTimer derived class to add
99 * @param secs_from_now You may set this to the number of seconds
100 * from the current time when the timer will tick, or you may just
101 * leave this unset and the values set by the InspTimers constructor
102 * will be used. This is used internally for re-triggering repeating
105 void AddTimer(InspTimer* T, long secs_from_now = 0);
106 /** Delete an InspTimer
107 * @param T an InspTimer derived class to delete
109 void DelTimer(InspTimer* T);
110 /** Tick any timers that have been missed due to lag
111 * @param TIME the current system time
113 void TickMissedTimers(time_t TIME);