]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/timer.cpp
Relocate timer stuff into TimerManager class
[user/henk/code/inspircd.git] / src / timer.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <vector>
18 #include <map>
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "typedefs.h"
22 #include "helperfuncs.h"
23 #include "timer.h"
24
25 void TimerManager::TickTimers(time_t TIME)
26 {
27         timerlist::iterator found = Timers.find(TIME);
28
29         if (found != Timers.end())
30         {
31                 timergroup* x = found->second;
32                 /*
33                  * There are pending timers to trigger
34                  */
35                 for (timergroup::iterator y = x->begin(); y != x->end(); y++)
36                 {
37                         InspTimer* n = *y;
38                         n->Tick(TIME);
39                         DELETE(n);
40                 }
41
42                 Timers.erase(found);
43                 DELETE(x);
44         }
45 }
46
47 /*
48  * Because some muppets may do odd things, and their ircd may lock up due
49  * to crappy 3rd party modules, or they may change their system time a bit,
50  * this accounts for shifts of up to 120 secs by looking behind for missed
51  * timers and executing them. This is only executed once every 5 secs.
52  * If you move your clock BACK, and your timers move further ahead as a result,
53  * then tough titty you'll just have to wait.
54  */
55 void TimerManager::TickMissedTimers(time_t TIME)
56 {
57         for (time_t n = TIME-1; n > TIME-120; n--)
58         {
59                 timerlist::iterator found = Timers.find(n);
60                 if (found != Timers.end())
61                 {
62                         timergroup* x = found->second;
63                         for (timergroup::iterator y = x->begin(); y != x->end(); y++)
64                         {
65                                 InspTimer* z = *y;
66                                 z->Tick(TIME);
67                                 DELETE(z);
68                         }
69
70                         Timers.erase(found);
71                         DELETE(x);
72                 }
73         }
74 }
75
76 void TimerManager::AddTimer(InspTimer* T)
77 {
78         timergroup* x = NULL;
79
80         timerlist::iterator found = Timers.find(T->GetTimer());
81         
82         if (found != Timers.end())
83         {
84                 x = found->second;
85         }
86         else
87         {
88                 x = new timergroup;
89                 Timers[T->GetTimer()] = x;
90         }
91
92         x->push_back(T);
93 }
94