icinga2/base/timer.h

58 lines
975 B
C
Raw Normal View History

#ifndef TIMER_H
#define TIMER_H
2012-03-28 13:24:49 +02:00
#include <time.h>
namespace icinga {
struct TimerEventArgs : public EventArgs
{
typedef shared_ptr<TimerEventArgs> Ptr;
typedef weak_ptr<TimerEventArgs> WeakPtr;
2012-03-28 13:24:49 +02:00
EventArgs::Ptr UserArgs;
2012-03-28 13:24:49 +02:00
};
class Timer : public Object
{
private:
EventArgs::Ptr m_UserArgs;
2012-03-28 13:24:49 +02:00
unsigned int m_Interval;
time_t m_Next;
static time_t NextCall;
static void RescheduleTimers(void);
void Call(void);
public:
typedef shared_ptr<Timer> Ptr;
typedef weak_ptr<Timer> WeakPtr;
2012-03-28 13:24:49 +02:00
static list<Timer::WeakPtr> Timers;
2012-03-28 13:24:49 +02:00
Timer(void);
void SetInterval(unsigned int interval);
unsigned int GetInterval(void) const;
void SetUserArgs(const EventArgs::Ptr& userArgs);
EventArgs::Ptr GetUserArgs(void) const;
2012-03-28 13:24:49 +02:00
static time_t GetNextCall(void);
static void CallExpiredTimers(void);
static void StopAllTimers(void);
void Start(void);
void Stop(void);
void Reschedule(time_t next);
event<TimerEventArgs::Ptr> OnTimerExpired;
2012-03-28 13:24:49 +02:00
};
}
#endif /* TIMER_H */