-
Notifications
You must be signed in to change notification settings - Fork 3
/
timer_channel.h
54 lines (46 loc) · 1.19 KB
/
timer_channel.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
52
53
#pragma once
#include <zinx.h>
#include <vector>
#include <list>
class timer_channel :
public Ichannel
{
int m_fd = -1;
public:
timer_channel();
virtual ~timer_channel();
// 通过 Ichannel 继承
virtual bool Init() override;
virtual bool ReadFd(std::string & _input) override;
virtual bool WriteFd(std::string & _output) override;
virtual void Fini() override;
virtual int GetFd() override;
virtual std::string GetChannelInfo() override;
virtual AZinxHandler * GetInputNextStage(BytesMsg & _oInput) override;
};
class timeout_task {
public:
virtual void proc_timeout() = 0;
int m_count = 0;
int time_out = 0;
};
class timeout_deliver :
public AZinxHandler
{
timeout_deliver();
virtual ~timeout_deliver();
/*单例对象指针*/
static timeout_deliver *m_single;
/*时间轮*/
std::vector<std::list<timeout_task *>> m_wheel;
/*当前指向的刻度*/
int cur_pos = 0;
public:
static timeout_deliver *GetInstance();
// 通过 AZinxHandler 继承
virtual IZinxMsg * InternelHandle(IZinxMsg & _oInput) override;
virtual AZinxHandler * GetNextHandler(IZinxMsg & _oNextMsg) override;
/*提供任务队列的添加删除函数*/
void register_task(int _sec, timeout_task *_task);
void unregister_task(timeout_task *_task);
};