-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventhandler.hpp
49 lines (38 loc) · 871 Bytes
/
eventhandler.hpp
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
#ifndef EVENTHANDLER_HPP__
#define EVENTHANDLER_HPP__
#include <functional>
#include <map>
#include <memory>
#include <list>
#include <sys/epoll.h>
class Remote;
class EventHandler;
class EventHandled;
class EventHandled : public std::enable_shared_from_this<EventHandled>
{
public:
struct FD
{
int fd;
unsigned events;
};
typedef std::list<FD> PollList;
virtual PollList pollfds() const = 0;
virtual void handle(EventHandler &handler) = 0;
virtual void set_remote(Remote &) {};
};
class EventHandler
{
public:
EventHandler();
~EventHandler();
void add(std::weak_ptr<EventHandled> fd);
void remove(const EventHandled &fd);
void kill();
bool wait();
private:
int epfd;
bool killed;
std::map<int, std::function<void ()>> cb_map;
};
#endif