InspIRCd  3.0
timer.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2007-2008 Robin Burchell <[email protected]>
5  * Copyright (C) 2007 Dennis Friis <[email protected]>
6  * Copyright (C) 2006-2007 Craig Edwards <[email protected]>
7  *
8  * This file is part of InspIRCd. InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #pragma once
23 
24 class Module;
25 
36 class CoreExport Timer
37 {
40  time_t trigger;
41 
44  unsigned int secs;
45 
48  bool repeat;
49 
50  public:
55  Timer(unsigned int secs_from_now, bool repeating = false);
56 
59  virtual ~Timer();
60 
63  time_t GetTrigger() const
64  {
65  return trigger;
66  }
67 
72  void SetTrigger(time_t nexttrigger)
73  {
74  trigger = nexttrigger;
75  }
76 
79  void SetInterval(time_t interval);
80 
87  virtual bool Tick(time_t TIME) = 0;
88 
91  bool GetRepeat() const
92  {
93  return repeat;
94  }
95 
99  unsigned int GetInterval() const
100  {
101  return secs;
102  }
103 
109  {
110  repeat = false;
111  }
112 };
113 
118 class CoreExport TimerManager
119 {
120  typedef std::multimap<time_t, Timer*> TimerMap;
121 
124  TimerMap Timers;
125 
126  public:
130  void TickTimers(time_t TIME);
131 
135  void AddTimer(Timer *T);
136 
140  void DelTimer(Timer* T);
141 };
Definition: timer.h:36
void CancelRepeat()
Definition: timer.h:108
Definition: modules.h:245
unsigned int GetInterval() const
Definition: timer.h:99
time_t GetTrigger() const
Definition: timer.h:63
Definition: timer.h:118
bool GetRepeat() const
Definition: timer.h:91
void SetTrigger(time_t nexttrigger)
Definition: timer.h:72