-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.h
51 lines (39 loc) · 1.01 KB
/
Timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* File: Timer.h
* Author: dell
*
* Created on 2012年4月7日, 下午5:18
*/
#ifndef OUTTIMER_H
#define OUTTIMER_H
#include "resources.h"
#include "libev.h"
#include "event/EventDispatcher.h"
#include "events.h"
/**
* 定时器, 其实只是对ev::timer的再次包装,使用更方便些
*/
class Timer : public EventDispatcher{
public:
Timer();
virtual ~Timer();
/**
* @param after 多少时间之后开始, 单位:秒
* @param repeat 重复间隔,如果为0,不重复, 单位:秒
*/
void set(double after, double repeat = 0.);
void start(double after, double repeat = 0.);
void start();
void stop();
protected:
virtual bool onTimerEvent(const TimerEvent* e){
return false;
}
private:
// double after;
// double repeat;
TimerEvent timerEvent;
ev::timer timer;
void timerCallback(ev::timer& timer, int revents);
};
#endif /* OUTTIMER_H */