1 | /* |
1 | /* |
2 | * libev simple C++ wrapper classes |
2 | * libev simple C++ wrapper classes |
3 | * |
3 | * |
4 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
56 | |
56 | |
57 | namespace ev { |
57 | namespace ev { |
58 | |
58 | |
59 | typedef ev_tstamp tstamp; |
59 | typedef ev_tstamp tstamp; |
60 | |
60 | |
61 | enum { |
61 | enum |
|
|
62 | { |
62 | UNDEF = EV_UNDEF, |
63 | UNDEF = EV_UNDEF, |
63 | NONE = EV_NONE, |
64 | NONE = EV_NONE, |
64 | READ = EV_READ, |
65 | READ = EV_READ, |
65 | WRITE = EV_WRITE, |
66 | WRITE = EV_WRITE, |
66 | TIMEOUT = EV_TIMEOUT, |
67 | TIMEOUT = EV_TIMEOUT, |
… | |
… | |
70 | STAT = EV_STAT, |
71 | STAT = EV_STAT, |
71 | IDLE = EV_IDLE, |
72 | IDLE = EV_IDLE, |
72 | CHECK = EV_CHECK, |
73 | CHECK = EV_CHECK, |
73 | PREPARE = EV_PREPARE, |
74 | PREPARE = EV_PREPARE, |
74 | FORK = EV_FORK, |
75 | FORK = EV_FORK, |
|
|
76 | ASYNC = EV_ASYNC, |
75 | EMBED = EV_EMBED, |
77 | EMBED = EV_EMBED, |
|
|
78 | # undef ERROR // some systems stupidly #define ERROR |
76 | ERROR = EV_ERROR, |
79 | ERROR = EV_ERROR, |
77 | }; |
80 | }; |
78 | |
81 | |
79 | enum |
82 | enum |
80 | { |
83 | { |
81 | AUTO = EVFLAG_AUTO, |
84 | AUTO = EVFLAG_AUTO, |
82 | NOENV = EVFLAG_NOENV, |
85 | NOENV = EVFLAG_NOENV, |
83 | FORKCHECK = EVFLAG_FORKCHECK, |
86 | FORKCHECK = EVFLAG_FORKCHECK, |
|
|
87 | |
84 | SELECT = EVBACKEND_SELECT, |
88 | SELECT = EVBACKEND_SELECT, |
85 | POLL = EVBACKEND_POLL, |
89 | POLL = EVBACKEND_POLL, |
86 | EPOLL = EVBACKEND_EPOLL, |
90 | EPOLL = EVBACKEND_EPOLL, |
87 | KQUEUE = EVBACKEND_KQUEUE, |
91 | KQUEUE = EVBACKEND_KQUEUE, |
88 | DEVPOLL = EVBACKEND_DEVPOLL, |
92 | DEVPOLL = EVBACKEND_DEVPOLL, |
89 | PORT = EVBACKEND_PORT |
93 | PORT = EVBACKEND_PORT |
90 | }; |
94 | }; |
91 | |
95 | |
92 | enum |
96 | enum |
93 | { |
97 | { |
94 | NONBLOCK = EVLOOP_NONBLOCK, |
98 | NONBLOCK = EVLOOP_NONBLOCK, |
95 | ONESHOT = EVLOOP_ONESHOT |
99 | ONESHOT = EVLOOP_ONESHOT |
96 | }; |
100 | }; |
97 | |
101 | |
98 | enum how_t |
102 | enum how_t |
99 | { |
103 | { |
100 | ONE = EVUNLOOP_ONE, |
104 | ONE = EVUNLOOP_ONE, |
… | |
… | |
130 | # define EV_AX_ |
134 | # define EV_AX_ |
131 | #endif |
135 | #endif |
132 | |
136 | |
133 | struct loop_ref |
137 | struct loop_ref |
134 | { |
138 | { |
135 | |
|
|
136 | loop_ref (EV_P) |
139 | loop_ref (EV_P) throw () |
137 | #if EV_MULTIPLICITY |
140 | #if EV_MULTIPLICITY |
138 | throw (bad_loop) : EV_AX (EV_A) |
141 | : EV_AX (EV_A) |
139 | { |
142 | #endif |
140 | if (!EV_AX) |
|
|
141 | throw bad_loop (); |
|
|
142 | } |
143 | { |
143 | #else |
|
|
144 | throw () |
|
|
145 | { |
144 | } |
146 | } |
|
|
147 | #endif |
|
|
148 | |
145 | |
149 | bool operator == (const loop_ref &other) const throw () |
146 | bool operator == (const loop_ref &other) const throw () |
150 | { |
147 | { |
151 | #if EV_MULTIPLICITY |
148 | #if EV_MULTIPLICITY |
152 | return EV_AX == other.EV_AX; |
149 | return EV_AX == other.EV_AX; |
… | |
… | |
163 | return false; |
160 | return false; |
164 | #endif |
161 | #endif |
165 | } |
162 | } |
166 | |
163 | |
167 | #if EV_MULTIPLICITY |
164 | #if EV_MULTIPLICITY |
168 | bool operator== (struct ev_loop *other) const throw () |
165 | bool operator == (const EV_P) const throw () |
169 | { |
166 | { |
170 | return this->EV_AX == other; |
167 | return this->EV_AX == EV_A; |
171 | } |
|
|
172 | |
|
|
173 | bool operator!= (struct ev_loop *other) const throw () |
|
|
174 | { |
168 | } |
175 | return ! (*this == other); |
169 | |
|
|
170 | bool operator != (const EV_P) const throw () |
176 | } |
171 | { |
177 | |
|
|
178 | bool operator== (const struct ev_loop *other) const throw () |
|
|
179 | { |
|
|
180 | return this->EV_AX == other; |
|
|
181 | } |
|
|
182 | |
|
|
183 | bool operator!= (const struct ev_loop *other) const throw () |
|
|
184 | { |
|
|
185 | return (*this == other); |
172 | return (*this == EV_A); |
186 | } |
173 | } |
187 | |
174 | |
188 | operator struct ev_loop * () const throw () |
175 | operator struct ev_loop * () const throw () |
189 | { |
176 | { |
190 | return EV_AX; |
177 | return EV_AX; |
… | |
… | |
218 | #else |
205 | #else |
219 | ev_default_fork (); |
206 | ev_default_fork (); |
220 | #endif |
207 | #endif |
221 | } |
208 | } |
222 | |
209 | |
|
|
210 | unsigned int backend () const throw () |
|
|
211 | { |
|
|
212 | return ev_backend (EV_AX); |
|
|
213 | } |
|
|
214 | |
|
|
215 | tstamp now () const throw () |
|
|
216 | { |
|
|
217 | return ev_now (EV_AX); |
|
|
218 | } |
|
|
219 | |
|
|
220 | void ref () throw () |
|
|
221 | { |
|
|
222 | ev_ref (EV_AX); |
|
|
223 | } |
|
|
224 | |
|
|
225 | void unref () throw () |
|
|
226 | { |
|
|
227 | ev_unref (EV_AX); |
|
|
228 | } |
|
|
229 | |
|
|
230 | #if EV_MINIMAL < 2 |
223 | unsigned int count () const throw () |
231 | unsigned int count () const throw () |
224 | { |
232 | { |
225 | return ev_loop_count (EV_AX); |
233 | return ev_loop_count (EV_AX); |
226 | } |
234 | } |
227 | |
235 | |
228 | unsigned int backend () const throw () |
236 | unsigned int depth () const throw () |
229 | { |
|
|
230 | return ev_backend (EV_AX); |
|
|
231 | } |
237 | { |
232 | |
|
|
233 | tstamp now () const throw () |
|
|
234 | { |
|
|
235 | return ev_now (EV_AX); |
238 | return ev_loop_depth (EV_AX); |
236 | } |
|
|
237 | |
|
|
238 | void ref () throw () |
|
|
239 | { |
|
|
240 | ev_ref (EV_AX); |
|
|
241 | } |
|
|
242 | |
|
|
243 | void unref () throw () |
|
|
244 | { |
|
|
245 | ev_unref (EV_AX); |
|
|
246 | } |
239 | } |
247 | |
240 | |
248 | void set_io_collect_interval (tstamp interval) throw () |
241 | void set_io_collect_interval (tstamp interval) throw () |
249 | { |
242 | { |
250 | ev_set_io_collect_interval (EV_AX_ interval); |
243 | ev_set_io_collect_interval (EV_AX_ interval); |
… | |
… | |
252 | |
245 | |
253 | void set_timeout_collect_interval (tstamp interval) throw () |
246 | void set_timeout_collect_interval (tstamp interval) throw () |
254 | { |
247 | { |
255 | ev_set_timeout_collect_interval (EV_AX_ interval); |
248 | ev_set_timeout_collect_interval (EV_AX_ interval); |
256 | } |
249 | } |
|
|
250 | #endif |
257 | |
251 | |
258 | // function callback |
252 | // function callback |
259 | void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () |
253 | void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw () |
260 | { |
254 | { |
261 | ev_once (EV_AX_ fd, events, timeout, cb, arg); |
255 | ev_once (EV_AX_ fd, events, timeout, cb, arg); |
262 | } |
256 | } |
263 | |
257 | |
264 | // method callback |
258 | // method callback |
… | |
… | |
266 | void once (int fd, int events, tstamp timeout, K *object) throw () |
260 | void once (int fd, int events, tstamp timeout, K *object) throw () |
267 | { |
261 | { |
268 | once (fd, events, timeout, method_thunk<K, method>, object); |
262 | once (fd, events, timeout, method_thunk<K, method>, object); |
269 | } |
263 | } |
270 | |
264 | |
|
|
265 | // default method == operator () |
|
|
266 | template<class K> |
|
|
267 | void once (int fd, int events, tstamp timeout, K *object) throw () |
|
|
268 | { |
|
|
269 | once (fd, events, timeout, method_thunk<K, &K::operator ()>, object); |
|
|
270 | } |
|
|
271 | |
271 | template<class K, void (K::*method)(int)> |
272 | template<class K, void (K::*method)(int)> |
272 | static void method_thunk (int revents, void* arg) |
273 | static void method_thunk (int revents, void *arg) |
273 | { |
|
|
274 | K *obj = static_cast<K *>(arg); |
|
|
275 | (obj->*method) (revents); |
|
|
276 | } |
274 | { |
|
|
275 | static_cast<K *>(arg)->*method |
|
|
276 | (revents); |
|
|
277 | } |
277 | |
278 | |
278 | // const method callback |
279 | // no-argument method callback |
279 | template<class K, void (K::*method)(int) const> |
|
|
280 | void once (int fd, int events, tstamp timeout, const K *object) throw () |
|
|
281 | { |
|
|
282 | once (fd, events, timeout, const_method_thunk<K, method>, object); |
|
|
283 | } |
|
|
284 | |
|
|
285 | template<class K, void (K::*method)(int) const> |
|
|
286 | static void const_method_thunk (int revents, void* arg) |
|
|
287 | { |
|
|
288 | K *obj = static_cast<K *>(arg); |
|
|
289 | (obj->*method) (revents); |
|
|
290 | } |
|
|
291 | |
|
|
292 | // simple method callback |
|
|
293 | template<class K, void (K::*method)()> |
280 | template<class K, void (K::*method)()> |
294 | void once (int fd, int events, tstamp timeout, K *object) throw () |
281 | void once (int fd, int events, tstamp timeout, K *object) throw () |
295 | { |
282 | { |
296 | once (fd, events, timeout, method_noargs_thunk<K, method>, object); |
283 | once (fd, events, timeout, method_noargs_thunk<K, method>, object); |
297 | } |
284 | } |
298 | |
285 | |
299 | template<class K, void (K::*method)()> |
286 | template<class K, void (K::*method)()> |
300 | static void method_noargs_thunk (int revents, void* arg) |
287 | static void method_noargs_thunk (int revents, void *arg) |
301 | { |
288 | { |
302 | K *obj = static_cast<K *>(arg); |
289 | static_cast<K *>(arg)->*method |
303 | (obj->*method) (); |
290 | (); |
304 | } |
291 | } |
305 | |
292 | |
306 | // simpler function callback |
293 | // simpler function callback |
307 | template<void (*cb)(int)> |
294 | template<void (*cb)(int)> |
308 | void once (int fd, int events, tstamp timeout) throw () |
295 | void once (int fd, int events, tstamp timeout) throw () |
309 | { |
296 | { |
310 | once (fd, events, timeout, simpler_func_thunk<cb>); |
297 | once (fd, events, timeout, simpler_func_thunk<cb>); |
311 | } |
298 | } |
312 | |
299 | |
313 | template<void (*cb)(int)> |
300 | template<void (*cb)(int)> |
314 | static void simpler_func_thunk (int revents, void* arg) |
301 | static void simpler_func_thunk (int revents, void *arg) |
315 | { |
302 | { |
|
|
303 | (*cb) |
316 | (*cb) (revents); |
304 | (revents); |
317 | } |
305 | } |
318 | |
306 | |
319 | // simplest function callback |
307 | // simplest function callback |
320 | template<void (*cb)()> |
308 | template<void (*cb)()> |
321 | void once (int fd, int events, tstamp timeout) throw () |
309 | void once (int fd, int events, tstamp timeout) throw () |
322 | { |
310 | { |
323 | once (fd, events, timeout, simplest_func_thunk<cb>); |
311 | once (fd, events, timeout, simplest_func_thunk<cb>); |
324 | } |
312 | } |
325 | |
313 | |
326 | template<void (*cb)()> |
314 | template<void (*cb)()> |
327 | static void simplest_func_thunk (int revents, void* arg) |
315 | static void simplest_func_thunk (int revents, void *arg) |
328 | { |
316 | { |
329 | (*cb) (); |
317 | (*cb) |
|
|
318 | (); |
330 | } |
319 | } |
331 | |
320 | |
332 | void feed_fd_event (int fd, int revents) throw () |
321 | void feed_fd_event (int fd, int revents) throw () |
333 | { |
322 | { |
334 | ev_feed_fd_event (EV_AX_ fd, revents); |
323 | ev_feed_fd_event (EV_AX_ fd, revents); |
… | |
… | |
344 | #endif |
333 | #endif |
345 | |
334 | |
346 | }; |
335 | }; |
347 | |
336 | |
348 | #if EV_MULTIPLICITY |
337 | #if EV_MULTIPLICITY |
349 | struct dynamic_loop: loop_ref |
338 | struct dynamic_loop : loop_ref |
350 | { |
339 | { |
351 | |
340 | |
352 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
341 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
353 | : loop_ref (ev_loop_new (flags)) |
342 | : loop_ref (ev_loop_new (flags)) |
354 | { |
343 | { |
|
|
344 | if (!EV_AX) |
|
|
345 | throw bad_loop (); |
355 | } |
346 | } |
356 | |
347 | |
357 | ~dynamic_loop () throw () |
348 | ~dynamic_loop () throw () |
358 | { |
349 | { |
359 | ev_loop_destroy (EV_AX); |
350 | ev_loop_destroy (EV_AX); |
… | |
… | |
367 | dynamic_loop & operator= (const dynamic_loop &); |
358 | dynamic_loop & operator= (const dynamic_loop &); |
368 | |
359 | |
369 | }; |
360 | }; |
370 | #endif |
361 | #endif |
371 | |
362 | |
372 | struct default_loop: loop_ref |
363 | struct default_loop : loop_ref |
373 | { |
364 | { |
374 | |
|
|
375 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
365 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
376 | #if EV_MULTIPLICITY |
366 | #if EV_MULTIPLICITY |
377 | : loop_ref (ev_default_loop (flags)) |
367 | : loop_ref (ev_default_loop (flags)) |
378 | #endif |
368 | #endif |
379 | { |
369 | { |
|
|
370 | if ( |
380 | #if !EV_MULTIPLICITY |
371 | #if EV_MULTIPLICITY |
|
|
372 | !EV_AX |
|
|
373 | #else |
381 | if (!ev_default_loop (flags)) |
374 | !ev_default_loop (flags) |
|
|
375 | #endif |
|
|
376 | ) |
382 | throw bad_loop (); |
377 | throw bad_loop (); |
383 | #endif |
|
|
384 | } |
378 | } |
385 | |
379 | |
386 | ~default_loop () throw () |
380 | ~default_loop () throw () |
387 | { |
381 | { |
388 | ev_default_destroy (); |
382 | ev_default_destroy (); |
… | |
… | |
419 | struct base : ev_watcher |
413 | struct base : ev_watcher |
420 | { |
414 | { |
421 | #if EV_MULTIPLICITY |
415 | #if EV_MULTIPLICITY |
422 | EV_PX; |
416 | EV_PX; |
423 | |
417 | |
424 | void set (EV_PX) throw () |
418 | void set (EV_P) throw () |
425 | { |
419 | { |
426 | this->EV_A = EV_A; |
420 | this->EV_A = EV_A; |
427 | } |
421 | } |
428 | #endif |
422 | #endif |
429 | |
423 | |
… | |
… | |
433 | #endif |
427 | #endif |
434 | { |
428 | { |
435 | ev_init (this, 0); |
429 | ev_init (this, 0); |
436 | } |
430 | } |
437 | |
431 | |
438 | void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () |
432 | void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () |
439 | { |
433 | { |
440 | this->data = data; |
434 | this->data = (void *)data; |
441 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
435 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
|
|
436 | } |
|
|
437 | |
|
|
438 | // function callback |
|
|
439 | template<void (*function)(watcher &w, int)> |
|
|
440 | void set (void *data = 0) throw () |
|
|
441 | { |
|
|
442 | set_ (data, function_thunk<function>); |
|
|
443 | } |
|
|
444 | |
|
|
445 | template<void (*function)(watcher &w, int)> |
|
|
446 | static void function_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
447 | { |
|
|
448 | function |
|
|
449 | (*static_cast<watcher *>(w), revents); |
442 | } |
450 | } |
443 | |
451 | |
444 | // method callback |
452 | // method callback |
445 | template<class K, void (K::*method)(watcher &w, int)> |
453 | template<class K, void (K::*method)(watcher &w, int)> |
446 | void set (K *object) throw () |
454 | void set (K *object) throw () |
447 | { |
455 | { |
448 | set_ (object, method_thunk<K, method>); |
456 | set_ (object, method_thunk<K, method>); |
449 | } |
457 | } |
450 | |
458 | |
|
|
459 | // default method == operator () |
|
|
460 | template<class K> |
|
|
461 | void set (K *object) throw () |
|
|
462 | { |
|
|
463 | set_ (object, method_thunk<K, &K::operator ()>); |
|
|
464 | } |
|
|
465 | |
451 | template<class K, void (K::*method)(watcher &w, int)> |
466 | template<class K, void (K::*method)(watcher &w, int)> |
452 | static void method_thunk (EV_P_ ev_watcher *w, int revents) |
467 | static void method_thunk (EV_P_ ev_watcher *w, int revents) |
453 | { |
468 | { |
454 | K *obj = static_cast<K *>(w->data); |
469 | (static_cast<K *>(w->data)->*method) |
455 | (obj->*method) (*static_cast<watcher *>(w), revents); |
|
|
456 | } |
|
|
457 | |
|
|
458 | // const method callback |
|
|
459 | template<class K, void (K::*method)(watcher &w, int) const> |
|
|
460 | void set (const K *object) throw () |
|
|
461 | { |
|
|
462 | set_ (object, const_method_thunk<K, method>); |
|
|
463 | } |
|
|
464 | |
|
|
465 | template<class K, void (K::*method)(watcher &w, int) const> |
|
|
466 | static void const_method_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
467 | { |
|
|
468 | K *obj = static_cast<K *>(w->data); |
|
|
469 | (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents); |
|
|
470 | } |
|
|
471 | |
|
|
472 | // function callback |
|
|
473 | template<void (*function)(watcher &w, int)> |
|
|
474 | void set (void *data = 0) throw () |
|
|
475 | { |
|
|
476 | set_ (data, function_thunk<function>); |
|
|
477 | } |
|
|
478 | |
|
|
479 | template<void (*function)(watcher &w, int)> |
|
|
480 | static void function_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
481 | { |
|
|
482 | function (*static_cast<watcher *>(w), revents); |
470 | (*static_cast<watcher *>(w), revents); |
483 | } |
471 | } |
484 | |
472 | |
485 | // simple callback |
473 | // no-argument callback |
486 | template<class K, void (K::*method)()> |
474 | template<class K, void (K::*method)()> |
487 | void set (K *object) throw () |
475 | void set (K *object) throw () |
488 | { |
476 | { |
489 | set_ (object, method_noargs_thunk<K, method>); |
477 | set_ (object, method_noargs_thunk<K, method>); |
490 | } |
478 | } |
491 | |
479 | |
492 | template<class K, void (K::*method)()> |
480 | template<class K, void (K::*method)()> |
493 | static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) |
481 | static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) |
494 | { |
482 | { |
495 | K *obj = static_cast<K *>(w->data); |
483 | static_cast<K *>(w->data)->*method |
496 | (obj->*method) (); |
484 | (); |
497 | } |
485 | } |
498 | |
486 | |
499 | void operator ()(int events = EV_UNDEF) |
487 | void operator ()(int events = EV_UNDEF) |
500 | { |
488 | { |
|
|
489 | return |
501 | return ev_cb (static_cast<ev_watcher *>(this)) |
490 | ev_cb (static_cast<ev_watcher *>(this)) |
502 | (static_cast<ev_watcher *>(this), events); |
491 | (static_cast<ev_watcher *>(this), events); |
503 | } |
492 | } |
504 | |
493 | |
505 | bool is_active () const throw () |
494 | bool is_active () const throw () |
506 | { |
495 | { |
507 | return ev_is_active (static_cast<const ev_watcher *>(this)); |
496 | return ev_is_active (static_cast<const ev_watcher *>(this)); |
… | |
… | |
563 | ev_set_syserr_cb (cb); |
552 | ev_set_syserr_cb (cb); |
564 | } |
553 | } |
565 | |
554 | |
566 | #if EV_MULTIPLICITY |
555 | #if EV_MULTIPLICITY |
567 | #define EV_CONSTRUCT(cppstem,cstem) \ |
556 | #define EV_CONSTRUCT(cppstem,cstem) \ |
568 | (EV_PX = get_default_loop ()) throw () \ |
557 | (EV_PX = get_default_loop ()) throw () \ |
569 | : base<ev_ ## cstem, cppstem> (EV_A) \ |
558 | : base<ev_ ## cstem, cppstem> (EV_A) \ |
570 | { \ |
559 | { \ |
571 | } |
560 | } |
572 | #else |
561 | #else |
573 | #define EV_CONSTRUCT(cppstem,cstem) \ |
562 | #define EV_CONSTRUCT(cppstem,cstem) \ |
574 | () throw () \ |
563 | () throw () \ |
575 | { \ |
564 | { \ |
576 | } |
565 | } |
577 | #endif |
566 | #endif |
578 | |
567 | |
579 | /* using a template here would require quite a bit more lines, |
568 | /* using a template here would require quite a bit more lines, |
580 | * so a macro solution was chosen */ |
569 | * so a macro solution was chosen */ |
581 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
570 | #define EV_BEGIN_WATCHER(cppstem,cstem) \ |
582 | \ |
571 | \ |
583 | struct cppstem : base<ev_ ## cstem, cppstem> \ |
572 | struct cppstem : base<ev_ ## cstem, cppstem> \ |
584 | { \ |
573 | { \ |
585 | void start () throw () \ |
574 | void start () throw () \ |
586 | { \ |
575 | { \ |
587 | ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
576 | ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
588 | } \ |
577 | } \ |
589 | \ |
578 | \ |
590 | void stop () throw () \ |
579 | void stop () throw () \ |
591 | { \ |
580 | { \ |
592 | ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
581 | ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ |
593 | } \ |
582 | } \ |
594 | \ |
583 | \ |
595 | cppstem EV_CONSTRUCT(cppstem,cstem) \ |
584 | cppstem EV_CONSTRUCT(cppstem,cstem) \ |
596 | \ |
585 | \ |
597 | ~cppstem () throw () \ |
586 | ~cppstem () throw () \ |
598 | { \ |
587 | { \ |
599 | stop (); \ |
588 | stop (); \ |
600 | } \ |
589 | } \ |
601 | \ |
590 | \ |
602 | using base<ev_ ## cstem, cppstem>::set; \ |
591 | using base<ev_ ## cstem, cppstem>::set; \ |
603 | \ |
592 | \ |
604 | private: \ |
593 | private: \ |
605 | \ |
594 | \ |
606 | cppstem (const cppstem &o); \ |
595 | cppstem (const cppstem &o); \ |
607 | \ |
596 | \ |
608 | cppstem & operator =(const cppstem &o); \ |
597 | cppstem &operator =(const cppstem &o); \ |
609 | \ |
598 | \ |
610 | public: |
599 | public: |
611 | |
600 | |
612 | #define EV_END_WATCHER(cppstem,cstem) \ |
601 | #define EV_END_WATCHER(cppstem,cstem) \ |
613 | }; |
602 | }; |
… | |
… | |
695 | start (); |
684 | start (); |
696 | } |
685 | } |
697 | EV_END_WATCHER (sig, signal) |
686 | EV_END_WATCHER (sig, signal) |
698 | |
687 | |
699 | EV_BEGIN_WATCHER (child, child) |
688 | EV_BEGIN_WATCHER (child, child) |
700 | void set (int pid) throw () |
689 | void set (int pid, int trace = 0) throw () |
701 | { |
690 | { |
702 | int active = is_active (); |
691 | int active = is_active (); |
703 | if (active) stop (); |
692 | if (active) stop (); |
704 | ev_child_set (static_cast<ev_child *>(this), pid); |
693 | ev_child_set (static_cast<ev_child *>(this), pid, trace); |
705 | if (active) start (); |
694 | if (active) start (); |
706 | } |
695 | } |
707 | |
696 | |
708 | void start (int pid) throw () |
697 | void start (int pid, int trace = 0) throw () |
709 | { |
698 | { |
710 | set (pid); |
699 | set (pid, trace); |
711 | start (); |
700 | start (); |
712 | } |
701 | } |
713 | EV_END_WATCHER (child, child) |
702 | EV_END_WATCHER (child, child) |
714 | |
703 | |
715 | #if EV_STAT_ENABLE |
704 | #if EV_STAT_ENABLE |
… | |
… | |
734 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
723 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
735 | } |
724 | } |
736 | EV_END_WATCHER (stat, stat) |
725 | EV_END_WATCHER (stat, stat) |
737 | #endif |
726 | #endif |
738 | |
727 | |
|
|
728 | #if EV_IDLE_ENABLE |
739 | EV_BEGIN_WATCHER (idle, idle) |
729 | EV_BEGIN_WATCHER (idle, idle) |
740 | void set () throw () { } |
730 | void set () throw () { } |
741 | EV_END_WATCHER (idle, idle) |
731 | EV_END_WATCHER (idle, idle) |
|
|
732 | #endif |
742 | |
733 | |
743 | EV_BEGIN_WATCHER (prepare, prepare) |
734 | EV_BEGIN_WATCHER (prepare, prepare) |
744 | void set () throw () { } |
735 | void set () throw () { } |
745 | EV_END_WATCHER (prepare, prepare) |
736 | EV_END_WATCHER (prepare, prepare) |
746 | |
737 | |
… | |
… | |
748 | void set () throw () { } |
739 | void set () throw () { } |
749 | EV_END_WATCHER (check, check) |
740 | EV_END_WATCHER (check, check) |
750 | |
741 | |
751 | #if EV_EMBED_ENABLE |
742 | #if EV_EMBED_ENABLE |
752 | EV_BEGIN_WATCHER (embed, embed) |
743 | EV_BEGIN_WATCHER (embed, embed) |
|
|
744 | void set (struct ev_loop *embedded_loop) throw () |
|
|
745 | { |
|
|
746 | int active = is_active (); |
|
|
747 | if (active) stop (); |
|
|
748 | ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); |
|
|
749 | if (active) start (); |
|
|
750 | } |
|
|
751 | |
753 | void start (struct ev_loop *embedded_loop) throw () |
752 | void start (struct ev_loop *embedded_loop) throw () |
754 | { |
753 | { |
755 | stop (); |
754 | set (embedded_loop); |
756 | ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); |
|
|
757 | start (); |
755 | start (); |
758 | } |
756 | } |
759 | |
757 | |
760 | void sweep () |
758 | void sweep () |
761 | { |
759 | { |
… | |
… | |
768 | EV_BEGIN_WATCHER (fork, fork) |
766 | EV_BEGIN_WATCHER (fork, fork) |
769 | void set () throw () { } |
767 | void set () throw () { } |
770 | EV_END_WATCHER (fork, fork) |
768 | EV_END_WATCHER (fork, fork) |
771 | #endif |
769 | #endif |
772 | |
770 | |
|
|
771 | #if EV_ASYNC_ENABLE |
|
|
772 | EV_BEGIN_WATCHER (async, async) |
|
|
773 | void set () throw () { } |
|
|
774 | |
|
|
775 | void send () throw () |
|
|
776 | { |
|
|
777 | ev_async_send (EV_A_ static_cast<ev_async *>(this)); |
|
|
778 | } |
|
|
779 | |
|
|
780 | bool async_pending () throw () |
|
|
781 | { |
|
|
782 | return ev_async_pending (static_cast<ev_async *>(this)); |
|
|
783 | } |
|
|
784 | EV_END_WATCHER (async, async) |
|
|
785 | #endif |
|
|
786 | |
773 | #undef EV_PX |
787 | #undef EV_PX |
774 | #undef EV_PX_ |
788 | #undef EV_PX_ |
775 | #undef EV_CONSTRUCT |
789 | #undef EV_CONSTRUCT |
776 | #undef EV_BEGIN_WATCHER |
790 | #undef EV_BEGIN_WATCHER |
777 | #undef EV_END_WATCHER |
791 | #undef EV_END_WATCHER |
778 | |
|
|
779 | } |
792 | } |
780 | |
793 | |
781 | #endif |
794 | #endif |
782 | |
795 | |