forked from voidccc/mini-muduo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.h
46 lines (40 loc) · 810 Bytes
/
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
#ifndef TIMER_H
#define TIMER_H
#include "Declear.h"
#include "IRun.h"
class Timer
{
public:
Timer(Timestamp stamp, IRun0* pRun, double interval)
:_stamp(stamp)
,_id(stamp)
,_pRun0(pRun)
,_interval(interval)
{}
Timestamp getStamp()
{
return _stamp;
}
Timestamp getId()
{
return _id;
}
void timeout()
{
_pRun0->run0();
}
bool isRepeat()
{
return _interval > 0.0;
}
void moveToNext()
{
_stamp = Timestamp::nowAfter(_interval);
}
private:
Timestamp _stamp;
Timestamp _id;
IRun0* _pRun0;
double _interval;//seconds
};
#endif