forked from marklion/zinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZinxTimer.h
More file actions
69 lines (55 loc) · 1.55 KB
/
ZinxTimer.h
File metadata and controls
69 lines (55 loc) · 1.55 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include<zinx.h>
#include<vector>
#include<list>
using namespace std;
class ZinxTimerChannel :
public Ichannel
{
public:
int m_TimerFd;
// 通过 Ichannel 继承
bool Init() override;
bool ReadFd(string& _input) override;
bool WriteFd(string& _output) override;
void Fini() override;
int GetFd() override;
string GetChannelInfo() override;
AZinxHandler* GetInputNextStage(BytesMsg& _oInput) override;
};
//class output_hello :public AZinxHandler
//{
// // 通过 AZinxHandler 继承
// IZinxMsg* InternelHandle(IZinxMsg& _oInput) override;
// AZinxHandler* GetNextHandler(IZinxMsg& _oNextMsg) override;
//};
//定义事件处理类
class TimeOutProc
{
public:
virtual void proc() = 0;
virtual int GetTimeSec() = 0;
//所剩圈数
int iCount = -1;
};
//定义时间事件管理类
class TimeOutMng :public AZinxHandler
{
public:
//定义时间轮
vector<list<TimeOutProc*>> m_timer_wheel;
int cur_index = 0;
static TimeOutMng single;
//构造函数
TimeOutMng();
static TimeOutMng& GetInstance()
{
return single;
}
list<TimeOutProc*> m_task_list;
// 通过 AZinxHandler 继承
IZinxMsg* InternelHandle(IZinxMsg& _oInput) override;
AZinxHandler* GetNextHandler(IZinxMsg& _oNextMsg) override;
void AddTask(TimeOutProc* _ptask);
void DelTask(TimeOutProc* _ptask);
};