2006-02-23 20:00:02 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | Inspire Internet Relay Chat Daemon |
|
|
|
|
* +------------------------------------+
|
|
|
|
*
|
|
|
|
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
|
|
|
|
* E-mail:
|
|
|
|
* <brain@chatspike.net>
|
|
|
|
* <Craig@chatspike.net>
|
|
|
|
*
|
|
|
|
* Written by Craig Edwards, Craig McLure, and others.
|
|
|
|
* This program is free but copyrighted software; see
|
|
|
|
* the file COPYING for details.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2006-04-10 22:50:41 +00:00
|
|
|
#ifndef INSPIRCD_TIMER_H
|
|
|
|
#define INSPIRCD_TIMER_H
|
|
|
|
|
2006-03-12 18:03:02 +00:00
|
|
|
/** Timer class for one-second resolution timers
|
|
|
|
* InspTimer provides a facility which allows module
|
|
|
|
* developers to create one-shot timers. The timer
|
|
|
|
* can be made to trigger at any time up to a one-second
|
|
|
|
* resolution. To use InspTimer, inherit a class from
|
|
|
|
* InspTimer, then insert your inherited class into the
|
|
|
|
* queue using Server::AddTimer(). The Tick() method of
|
|
|
|
* your object (which you should override) will be called
|
|
|
|
* at the given time.
|
|
|
|
*/
|
2006-07-10 18:22:16 +00:00
|
|
|
class InspTimer : public Extensible
|
2006-02-23 18:56:21 +00:00
|
|
|
{
|
|
|
|
private:
|
2006-03-12 18:03:02 +00:00
|
|
|
/** The triggering time
|
|
|
|
*/
|
2006-02-23 18:56:21 +00:00
|
|
|
time_t trigger;
|
|
|
|
public:
|
2006-03-12 18:03:02 +00:00
|
|
|
/** Default constructor, initializes the triggering time
|
|
|
|
*/
|
2006-02-23 20:00:02 +00:00
|
|
|
InspTimer(long secs_from_now,time_t now)
|
|
|
|
{
|
|
|
|
trigger = now + secs_from_now;
|
|
|
|
}
|
2006-03-12 18:03:02 +00:00
|
|
|
/** Default destructor, does nothing.
|
|
|
|
*/
|
2006-02-23 18:56:21 +00:00
|
|
|
virtual ~InspTimer() { }
|
2006-03-12 18:03:02 +00:00
|
|
|
/** Retrieve the current triggering time
|
|
|
|
*/
|
2006-02-23 18:56:21 +00:00
|
|
|
virtual time_t GetTimer()
|
|
|
|
{
|
|
|
|
return trigger;
|
|
|
|
}
|
2006-03-12 18:03:02 +00:00
|
|
|
/** Called when the timer ticks.
|
|
|
|
*/
|
|
|
|
virtual void Tick(time_t TIME) = 0;
|
2006-02-23 18:56:21 +00:00
|
|
|
};
|
|
|
|
|
2006-08-11 22:57:42 +00:00
|
|
|
|
|
|
|
/** This class manages sets of InspTimers, and triggers them at their defined times.
|
|
|
|
* This will ensure timers are not missed, as well as removing timers that have
|
|
|
|
* expired and allowing the addition of new ones.
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
class TimerManager : public Extensible
|
|
|
|
{
|
|
|
|
protected:
|
2006-08-11 22:57:42 +00:00
|
|
|
/** A group of timers all set to trigger at the same time
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
typedef std::vector<InspTimer*> timergroup;
|
2006-08-11 22:57:42 +00:00
|
|
|
/** A map of timergroups, each group has a specific trigger time
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
typedef std::map<time_t, timergroup*> timerlist;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2006-08-11 22:57:42 +00:00
|
|
|
/** The current timer set, a map of timergroups
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
timerlist Timers;
|
|
|
|
|
|
|
|
public:
|
2006-08-11 22:57:42 +00:00
|
|
|
/** Tick all pending InspTimers
|
|
|
|
* @param TIME the current system time
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
void TickTimers(time_t TIME);
|
2006-08-11 22:57:42 +00:00
|
|
|
/** Add an InspTimer
|
|
|
|
* @param T an InspTimer derived class to add
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
void AddTimer(InspTimer* T);
|
2006-08-11 22:57:42 +00:00
|
|
|
/** Tick any timers that have been missed due to lag
|
|
|
|
* @param TIME the current system time
|
|
|
|
*/
|
2006-08-10 00:02:31 +00:00
|
|
|
void TickMissedTimers(time_t TIME);
|
|
|
|
};
|
2006-02-23 18:56:21 +00:00
|
|
|
|
2006-04-10 22:50:41 +00:00
|
|
|
#endif
|