Includes cleanups
[invirt/third/libt4.git] / rpc / pollmgr.h
1 #ifndef pollmgr_h
2 #define pollmgr_h 
3
4 #include "types.h"
5
6 #define MAX_POLL_FDS 128
7
8 typedef enum {
9     CB_NONE = 0x0,
10     CB_RDONLY = 0x1,
11     CB_WRONLY = 0x10,
12     CB_RDWR = 0x11,
13     CB_MASK = ~0x11,
14 } poll_flag;
15
16 class aio_callback {
17     public:
18         virtual void read_cb(int fd) = 0;
19         virtual void write_cb(int fd) = 0;
20         virtual ~aio_callback() {}
21 };
22
23 class PollMgr {
24     public:
25         PollMgr();
26         ~PollMgr();
27
28         static PollMgr & Instance();
29
30         void add_callback(int fd, poll_flag flag, aio_callback *ch);
31         void del_callback(int fd, poll_flag flag);
32         void block_remove_fd(int fd);
33         void wait_loop();
34
35     private:
36         mutex m_;
37         cond changedone_c_;
38
39         map<int, aio_callback *> callbacks_;
40         class wait_manager *aio_;
41         bool pending_change_=false, shutdown_=false;
42
43         thread th_;
44 };
45
46 #endif