1 /******************************************************************************
3 * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
23 #include "base/i2-base.hpp"
24 #include "base/object.hpp"
25 #include <boost/signals2.hpp>
30 * A timer that periodically triggers an event.
34 class I2_BASE_API Timer : public Object
37 DECLARE_PTR_TYPEDEFS(Timer);
42 void SetInterval(double interval);
43 double GetInterval(void) const;
45 static void AdjustTimers(double adjustment);
48 void Stop(bool wait = false);
50 void Reschedule(double next = -1);
51 double GetNext(void) const;
53 boost::signals2::signal<void(const Timer::Ptr&)> OnTimerExpired;
61 inline Timer *GetObject(void) const
66 inline double GetNextUnlocked(void) const
68 return m_Timer->m_Next;
71 operator Timer *(void) const
81 double m_Interval; /**< The interval of the timer. */
82 double m_Next; /**< When the next event should happen. */
83 bool m_Started; /**< Whether the timer is enabled. */
84 bool m_Running; /**< Whether the timer proc is currently running. */
87 void InternalReschedule(bool completed, double next = -1);
89 static void TimerThreadProc(void);
91 static void Initialize(void);
92 static void Uninitialize(void);
94 friend class Application;