From 932f00f8bfa8a78626fe52b8f20f159c18f24c8e Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 23 Feb 2006 18:56:21 +0000 Subject: First revision of new timer code, not in the makefile yet (so it wont build till im done) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3297 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/timer.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/timer.cpp (limited to 'src/timer.cpp') diff --git a/src/timer.cpp b/src/timer.cpp new file mode 100644 index 000000000..e6545bf40 --- /dev/null +++ b/src/timer.cpp @@ -0,0 +1,94 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * + * + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +using namespace std; + +#include "inspircd_config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "timer.h" +#include "inspircd.h" +#include "inspircd_io.h" +#include "inspstring.h" +#include "helperfuncs.h" + +extern InspIRCd* ServerInstance; +extern ServerConfig* Config; +extern time_t TIME; + +typedef std::vector timergroup; +typedef std::map timerlist; +timerlist Timers; + +void TickTimers(time_t TIME) +{ + timerlist::iterator found = Timers.find(TIME); + + if (found != Timers.end()) + { + log("timer.cpp: There are timers to trigger"); + timerlist* x = found->second; + /* + * There are pending timers to trigger + */ + for (timerlist::iterator y = x.begin(); y != x.end(); y++) + { + log("timer.cpp: Triggering a timer"); + InspTimer* n = (InspTimer*)*y; + n->Tick(TIME); + log("timer.cpp: TICK!"); + delete n; + } + + log("timer.cpp: Done triggering timers, tidying up"); + Timers.erase(found); + delete x; + } +} + +void AddTimer(InspTimer* T) +{ + log("timer.cpp: Adding timer"); + + timergroup* x = NULL; + + timerlist::iterator found = Timers.find(T->GetTimer()); + + if (found != Timers.end()) + { + log("timer.cpp: Add timer to existing group"); + x = found->second; + } + else + { + log("timer.cpp: Add timer to new group"); + x = new timergroup; + Timers[T->GetTimer()] = x; + } + + x->push_back(T); +} -- cgit v1.3.1-10-gc9f91