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
34 /** Default constructor, initializes the triggering time
36 InspTimer(long secs_from_now,time_t now)
38 trigger = now + secs_from_now;
40 /** Default destructor, does nothing.
42 virtual ~InspTimer() { }
43 /** Retrieve the current triggering time
45 virtual time_t GetTimer()
49 /** Called when the timer ticks.
51 virtual void Tick(time_t TIME) = 0;
55 /** This class manages sets of InspTimers, and triggers them at their defined times.
56 * This will ensure timers are not missed, as well as removing timers that have
57 * expired and allowing the addition of new ones.
59 class TimerManager : public Extensible
62 /** A group of timers all set to trigger at the same time
64 typedef std::vector<InspTimer*> timergroup;
65 /** A map of timergroups, each group has a specific trigger time
67 typedef std::map<time_t, timergroup*> timerlist;
71 /** The current timer set, a map of timergroups
76 /** Tick all pending InspTimers
77 * @param TIME the current system time
79 void TickTimers(time_t TIME);
81 * @param T an InspTimer derived class to add
83 void AddTimer(InspTimer* T);
84 /** Delete an InspTimer
85 * @param T an InspTimer derived class to delete
87 void DelTimer(InspTimer* T);
88 /** Tick any timers that have been missed due to lag
89 * @param TIME the current system time
91 void TickMissedTimers(time_t TIME);