1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/object.hpp"
8 #include <boost/signals2.hpp>
15 * A timer that periodically triggers an event.
19 class Timer final : public Object
22 DECLARE_PTR_TYPEDEFS(Timer);
26 static void Initialize();
27 static void Uninitialize();
28 static void InitializeThread();
29 static void UninitializeThread();
31 void SetInterval(double interval);
32 double GetInterval() const;
34 static void AdjustTimers(double adjustment);
37 void Stop(bool wait = false);
39 void Reschedule(double next = -1);
40 double GetNext() const;
42 boost::signals2::signal<void(const Timer * const&)> OnTimerExpired;
45 double m_Interval{0}; /**< The interval of the timer. */
46 double m_Next{0}; /**< When the next event should happen. */
47 bool m_Started{false}; /**< Whether the timer is enabled. */
48 bool m_Running{false}; /**< Whether the timer proc is currently running. */
51 void InternalReschedule(bool completed, double next = -1);
53 static void TimerThreadProc();
55 friend class TimerHolder;