hlswmaster-ng/timerservice.h

55 lines
834 B
C
Raw Permalink Normal View History

2006-02-02 16:55:44 +01:00
#ifndef _TIMERSERVICE_H_
#define _TIMERSERVICE_H_
#include "mutex.h"
2006-02-20 21:58:59 +01:00
class Event {
2006-02-02 16:55:44 +01:00
public:
2006-02-20 21:58:59 +01:00
virtual ~Event() {};
2006-02-02 16:55:44 +01:00
virtual void execute() =0;
protected:
2006-02-20 21:58:59 +01:00
Event() {};
2006-02-02 16:55:44 +01:00
};
class Timer {
friend class TimerService;
public:
2006-02-20 21:58:59 +01:00
Timer(Event* event, unsigned int timeval);
2006-02-02 16:55:44 +01:00
~Timer();
protected:
Timer(const Timer& te);
Timer& operator=(const Timer& te);
private:
Timer* next;
2006-02-20 21:58:59 +01:00
Event* event;
2006-02-02 16:55:44 +01:00
int timeval;
long timeout;
};
class TimerService {
public:
static void registerTimer(Timer* te);
static void checkTimers();
protected:
TimerService(const TimerService& ts);
TimerService& operator=(const TimerService& ts);
private:
TimerService() {}
~TimerService();
static TimerService* getInstance();
void addTimer(Timer* te, bool trigger);
void checkTimeouts();
Timer* firstTimer;
Mutex mutex;
};
#endif // _TIMERSERVICE_H_