… | |
… | |
38 | vector<const io_watcher *> iow; |
38 | vector<const io_watcher *> iow; |
39 | vector<time_watcher *> tw; // actually a heap |
39 | vector<time_watcher *> tw; // actually a heap |
40 | |
40 | |
41 | void idle_cb (tstamp &ts); time_watcher *idle; |
41 | void idle_cb (tstamp &ts); time_watcher *idle; |
42 | public: |
42 | public: |
|
|
43 | |
|
|
44 | void reschedule_time_watchers (); |
43 | |
45 | |
44 | // register a watcher |
46 | // register a watcher |
45 | void reg (int fd, short events, io_watcher *w); |
47 | void reg (int fd, short events, io_watcher *w); |
46 | void unreg (const io_watcher *w); |
48 | void unreg (const io_watcher *w); |
47 | void reg (time_watcher *w); |
49 | void reg (time_watcher *w); |
… | |
… | |
102 | template<class O1, class O2> |
104 | template<class O1, class O2> |
103 | io_watcher (O1 *object, void (O2::*method)(short revents)) |
105 | io_watcher (O1 *object, void (O2::*method)(short revents)) |
104 | : callback<void, short>(object,method) |
106 | : callback<void, short>(object,method) |
105 | { } |
107 | { } |
106 | |
108 | |
|
|
109 | ~io_watcher () |
|
|
110 | { |
|
|
111 | iom.unreg (this); |
|
|
112 | } |
|
|
113 | |
107 | void start (int fd, short events) |
114 | void start (int fd, short events) |
108 | { |
115 | { |
109 | iom.reg (fd, events, this); |
116 | iom.reg (fd, events, this); |
110 | } |
117 | } |
111 | |
118 | |
… | |
… | |
116 | }; |
123 | }; |
117 | |
124 | |
118 | #define TSTAMP_CANCEL -1. |
125 | #define TSTAMP_CANCEL -1. |
119 | |
126 | |
120 | struct time_watcher : callback<void, tstamp &> { |
127 | struct time_watcher : callback<void, tstamp &> { |
|
|
128 | bool registered; // already registered? |
121 | tstamp at; |
129 | tstamp at; |
122 | |
130 | |
123 | template<class O1, class O2> |
131 | template<class O1, class O2> |
124 | time_watcher (O1 *object, void (O2::*method)(tstamp &)) |
132 | time_watcher (O1 *object, void (O2::*method)(tstamp &)) |
125 | : callback<void, tstamp &>(object,method) |
133 | : callback<void, tstamp &>(object,method) |
|
|
134 | , registered(false) |
126 | { } |
135 | { } |
|
|
136 | |
|
|
137 | ~time_watcher () |
|
|
138 | { |
|
|
139 | iom.unreg (this); |
|
|
140 | } |
127 | |
141 | |
128 | void set (tstamp when); |
142 | void set (tstamp when); |
129 | void trigger (); |
143 | void trigger (); |
130 | |
144 | |
131 | void operator ()() |
145 | void operator ()() |