]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/timer.cpp
Change the SQLutils and SQL providers to also use interfaces for proper unload order...
[user/henk/code/inspircd.git] / src / timer.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "timer.h"
16
17 void TimerManager::TickTimers(time_t TIME)
18 {
19         timerlist::iterator found = Timers.find(TIME);
20
21         if (found != Timers.end())
22         {
23                 timergroup* x = found->second;
24                 /*
25                  * There are pending timers to trigger
26                  */
27                 for (timergroup::iterator y = x->begin(); y != x->end(); y++)
28                 {
29                         InspTimer* n = *y;
30                         n->Tick(TIME);
31                         DELETE(n);
32                 }
33
34                 Timers.erase(found);
35                 DELETE(x);
36         }
37 }
38
39 void TimerManager::DelTimer(InspTimer* T)
40 {
41         timerlist::iterator found = Timers.find(T->GetTimer());
42
43         if (found != Timers.end())
44         {
45                 timergroup* x = found->second;
46                 for (timergroup::iterator y = x->begin(); y != x->end(); y++)
47                 {
48                         InspTimer* n = *y;
49                         if (n == T)
50                         {
51                                 DELETE(n);
52                                 x->erase(y);
53                                 if (!x->size())
54                                         Timers.erase(found);
55                                 return;
56                         }
57                 }
58         }
59 }
60
61 /*
62  * Because some muppets may do odd things, and their ircd may lock up due
63  * to crappy 3rd party modules, or they may change their system time a bit,
64  * this accounts for shifts of up to 120 secs by looking behind for missed
65  * timers and executing them. This is only executed once every 5 secs.
66  * If you move your clock BACK, and your timers move further ahead as a result,
67  * then tough titty you'll just have to wait.
68  */
69 void TimerManager::TickMissedTimers(time_t TIME)
70 {
71         for (time_t n = TIME-1; n > TIME-120; n--)
72         {
73                 timerlist::iterator found = Timers.find(n);
74                 if (found != Timers.end())
75                 {
76                         timergroup* x = found->second;
77                         for (timergroup::iterator y = x->begin(); y != x->end(); y++)
78                         {
79                                 InspTimer* z = *y;
80                                 z->Tick(TIME);
81                                 DELETE(z);
82                         }
83
84                         Timers.erase(found);
85                         DELETE(x);
86                 }
87         }
88 }
89
90 void TimerManager::AddTimer(InspTimer* T)
91 {
92         timergroup* x = NULL;
93
94         timerlist::iterator found = Timers.find(T->GetTimer());
95         
96         if (found != Timers.end())
97         {
98                 x = found->second;
99         }
100         else
101         {
102                 x = new timergroup;
103                 Timers[T->GetTimer()] = x;
104         }
105
106         x->push_back(T);
107 }
108