… | |
… | |
91 | |
91 | |
92 | #endif |
92 | #endif |
93 | |
93 | |
94 | /* using a template here would require quite a bit more lines, |
94 | /* using a template here would require quite a bit more lines, |
95 | * so a macro solution was chosen */ |
95 | * so a macro solution was chosen */ |
96 | #define EV_DECLARE_WATCHER(cppstem,cstem) \ |
96 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
97 | \ |
|
|
98 | extern "C" void cb_ ## cppstem (struct ev_ ## cstem *w, int revents); \ |
|
|
99 | \ |
97 | \ |
100 | struct cppstem : ev_ ## cstem, callback<cppstem> \ |
98 | struct cppstem : ev_ ## cstem, callback<cppstem> \ |
101 | { \ |
99 | { \ |
102 | EV_CONSTRUCT (cppstem) \ |
100 | EV_CONSTRUCT (cppstem) \ |
103 | { \ |
101 | { \ |
104 | ev_init (static_cast<ev_ ## cstem *>(this), cb_ ## cppstem); \ |
102 | ev_init (static_cast<ev_ ## cstem *>(this), thunk); \ |
105 | } \ |
103 | } \ |
106 | \ |
104 | \ |
107 | bool is_active () const \ |
105 | bool is_active () const \ |
108 | { \ |
106 | { \ |
109 | return ev_is_active (static_cast<const ev_ ## cstem *>(this)); \ |
107 | return ev_is_active (static_cast<const ev_ ## cstem *>(this)); \ |
… | |
… | |
137 | private: \ |
135 | private: \ |
138 | \ |
136 | \ |
139 | cppstem (const cppstem &o) \ |
137 | cppstem (const cppstem &o) \ |
140 | : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \ |
138 | : callback<cppstem> (this, (void (cppstem::*)(cppstem &, int))0) \ |
141 | { /* disabled */ } \ |
139 | { /* disabled */ } \ |
|
|
140 | \ |
142 | void operator =(const cppstem &o) { /* disabled */ } \ |
141 | void operator =(const cppstem &o) { /* disabled */ } \ |
143 | \ |
142 | \ |
|
|
143 | static void thunk (EV_P_ struct ev_ ## cstem *w, int revents) \ |
|
|
144 | { \ |
|
|
145 | (*static_cast<cppstem *>(w))(revents); \ |
|
|
146 | } \ |
|
|
147 | \ |
144 | public: |
148 | public: |
145 | |
149 | |
|
|
150 | #define EV_END_WATCHER(cppstem,cstem) \ |
|
|
151 | }; |
|
|
152 | |
146 | EV_DECLARE_WATCHER (io, io) |
153 | EV_BEGIN_WATCHER (io, io) |
147 | void set (int fd, int events) |
154 | void set (int fd, int events) |
148 | { |
155 | { |
149 | int active = is_active (); |
156 | int active = is_active (); |
150 | if (active) stop (); |
157 | if (active) stop (); |
151 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
158 | ev_io_set (static_cast<ev_io *>(this), fd, events); |
… | |
… | |
163 | void start (int fd, int events) |
170 | void start (int fd, int events) |
164 | { |
171 | { |
165 | set (fd, events); |
172 | set (fd, events); |
166 | start (); |
173 | start (); |
167 | } |
174 | } |
168 | }; |
175 | EV_END_WATCHER (io, io) |
169 | |
176 | |
170 | EV_DECLARE_WATCHER (timer, timer) |
177 | EV_BEGIN_WATCHER (timer, timer) |
171 | void set (ev_tstamp after, ev_tstamp repeat = 0.) |
178 | void set (ev_tstamp after, ev_tstamp repeat = 0.) |
172 | { |
179 | { |
173 | int active = is_active (); |
180 | int active = is_active (); |
174 | if (active) stop (); |
181 | if (active) stop (); |
175 | ev_timer_set (static_cast<ev_timer *>(this), after, repeat); |
182 | ev_timer_set (static_cast<ev_timer *>(this), after, repeat); |
… | |
… | |
184 | |
191 | |
185 | void again () |
192 | void again () |
186 | { |
193 | { |
187 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
194 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
188 | } |
195 | } |
189 | }; |
196 | EV_END_WATCHER (timer, timer) |
190 | |
197 | |
191 | #if EV_PERIODICS |
198 | #if EV_PERIODICS |
192 | EV_DECLARE_WATCHER (periodic, periodic) |
199 | EV_BEGIN_WATCHER (periodic, periodic) |
193 | void set (ev_tstamp at, ev_tstamp interval = 0.) |
200 | void set (ev_tstamp at, ev_tstamp interval = 0.) |
194 | { |
201 | { |
195 | int active = is_active (); |
202 | int active = is_active (); |
196 | if (active) stop (); |
203 | if (active) stop (); |
197 | ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); |
204 | ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); |
… | |
… | |
206 | |
213 | |
207 | void again () |
214 | void again () |
208 | { |
215 | { |
209 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
216 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
210 | } |
217 | } |
211 | }; |
218 | EV_END_WATCHER (periodic, periodic) |
212 | #endif |
219 | #endif |
213 | |
220 | |
|
|
221 | EV_BEGIN_WATCHER (idle, idle) |
214 | EV_DECLARE_WATCHER (idle, idle) |
222 | EV_END_WATCHER (idle, idle) |
215 | }; |
|
|
216 | |
223 | |
|
|
224 | EV_BEGIN_WATCHER (prepare, prepare) |
217 | EV_DECLARE_WATCHER (prepare, prepare) |
225 | EV_END_WATCHER (prepare, prepare) |
218 | }; |
|
|
219 | |
226 | |
|
|
227 | EV_BEGIN_WATCHER (check, check) |
220 | EV_DECLARE_WATCHER (check, check) |
228 | EV_END_WATCHER (check, check) |
221 | }; |
|
|
222 | |
229 | |
223 | EV_DECLARE_WATCHER (sig, signal) |
230 | EV_BEGIN_WATCHER (sig, signal) |
224 | void set (int signum) |
231 | void set (int signum) |
225 | { |
232 | { |
226 | int active = is_active (); |
233 | int active = is_active (); |
227 | if (active) stop (); |
234 | if (active) stop (); |
228 | ev_signal_set (static_cast<ev_signal *>(this), signum); |
235 | ev_signal_set (static_cast<ev_signal *>(this), signum); |
… | |
… | |
232 | void start (int signum) |
239 | void start (int signum) |
233 | { |
240 | { |
234 | set (signum); |
241 | set (signum); |
235 | start (); |
242 | start (); |
236 | } |
243 | } |
237 | }; |
244 | EV_END_WATCHER (sig, signal) |
238 | |
245 | |
239 | EV_DECLARE_WATCHER (child, child) |
246 | EV_BEGIN_WATCHER (child, child) |
240 | void set (int pid) |
247 | void set (int pid) |
241 | { |
248 | { |
242 | int active = is_active (); |
249 | int active = is_active (); |
243 | if (active) stop (); |
250 | if (active) stop (); |
244 | ev_child_set (static_cast<ev_child *>(this), pid); |
251 | ev_child_set (static_cast<ev_child *>(this), pid); |
… | |
… | |
248 | void start (int pid) |
255 | void start (int pid) |
249 | { |
256 | { |
250 | set (pid); |
257 | set (pid); |
251 | start (); |
258 | start (); |
252 | } |
259 | } |
253 | }; |
260 | EV_END_WATCHER (child, child) |
254 | |
261 | |
255 | #undef EV_CONSTRUCT |
262 | #undef EV_CONSTRUCT |
256 | #undef EV_DECLARE_WATCHER |
263 | #undef EV_BEGIN_WATCHER |
257 | } |
264 | } |
258 | |
265 | |
259 | #endif |
266 | #endif |
260 | |
267 | |