summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-02-23 18:56:21 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-02-23 18:56:21 +0000
commit932f00f8bfa8a78626fe52b8f20f159c18f24c8e (patch)
tree733352a6fa6749f8e044a8c921ec18935641e1cd
parent4d057b65c47b72358c058a8c54e7cd0b80bb62ec (diff)
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
-rw-r--r--include/timer.h15
-rw-r--r--src/timer.cpp94
2 files changed, 109 insertions, 0 deletions
diff --git a/include/timer.h b/include/timer.h
new file mode 100644
index 000000000..b6fd62281
--- /dev/null
+++ b/include/timer.h
@@ -0,0 +1,15 @@
+class InspTimer
+{
+ private:
+ time_t trigger;
+ public:
+ virtual InspTimer(long secs_from_now) : trigger(time(NULL) + secs_from_now) { }
+ virtual ~InspTimer() { }
+ virtual time_t GetTimer()
+ {
+ return trigger;
+ }
+ virtual void Tick(time_t TIME) {}
+};
+
+
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:
+ * <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.
+ *
+ * ---------------------------------------------------
+ */
+
+using namespace std;
+
+#include "inspircd_config.h"
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <string>
+#include <unistd.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include <stdexcept>
+#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<InspTimer*> timergroup;
+typedef std::map<time_t, timergroup*> 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);
+}