InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
timer.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
5  * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6  * Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
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 #ifndef INSPIRCD_TIMER_H
23 #define INSPIRCD_TIMER_H
24 
35 class CoreExport Timer
36 {
37  private:
40  time_t trigger;
43  long secs;
46  bool repeat;
47  public:
53  Timer(long secs_from_now, time_t now, bool repeating = false)
54  {
55  trigger = now + secs_from_now;
56  secs = secs_from_now;
57  repeat = repeating;
58  }
59 
62  virtual ~Timer() { }
63 
66  virtual time_t GetTimer()
67  {
68  return trigger;
69  }
70 
73  virtual void SetTimer(time_t t)
74  {
75  trigger = t;
76  }
77 
82  virtual void Tick(time_t TIME) = 0;
83 
86  bool GetRepeat()
87  {
88  return repeat;
89  }
90 
94  long GetSecs()
95  {
96  return secs;
97  }
98 
110  {
111  repeat = false;
112  }
113 };
114 
115 
120 class CoreExport TimerManager
121 {
122  protected:
125  std::vector<Timer *> Timers;
126 
127  public:
130  TimerManager();
131  ~TimerManager();
132 
136  void TickTimers(time_t TIME);
137 
141  void AddTimer(Timer *T);
142 
146  void DelTimer(Timer* T);
147 
150  static bool TimerComparison( Timer *one, Timer*two);
151 };
152 
153 #endif
154 
Definition: timer.h:35
void CancelRepeat()
Definition: timer.h:109
virtual time_t GetTimer()
Definition: timer.h:66
long GetSecs()
Definition: timer.h:94
virtual ~Timer()
Definition: timer.h:62
Timer(long secs_from_now, time_t now, bool repeating=false)
Definition: timer.h:53
std::vector< Timer * > Timers
Definition: timer.h:125
bool GetRepeat()
Definition: timer.h:86
virtual void SetTimer(time_t t)
Definition: timer.h:73
Definition: timer.h:120