… | |
… | |
160 | return false; |
160 | return false; |
161 | #endif |
161 | #endif |
162 | } |
162 | } |
163 | |
163 | |
164 | #if EV_MULTIPLICITY |
164 | #if EV_MULTIPLICITY |
165 | bool operator == (struct ev_loop *other) const throw () |
165 | bool operator == (const EV_P) const throw () |
166 | { |
166 | { |
167 | return this->EV_AX == other; |
167 | return this->EV_AX == EV_A; |
168 | } |
|
|
169 | |
|
|
170 | bool operator != (struct ev_loop *other) const throw () |
|
|
171 | { |
168 | } |
172 | return ! (*this == other); |
169 | |
|
|
170 | bool operator != (const EV_P) const throw () |
173 | } |
171 | { |
174 | |
|
|
175 | bool operator == (const struct ev_loop *other) const throw () |
|
|
176 | { |
|
|
177 | return this->EV_AX == other; |
|
|
178 | } |
|
|
179 | |
|
|
180 | bool operator != (const struct ev_loop *other) const throw () |
|
|
181 | { |
|
|
182 | return (*this == other); |
172 | return (*this == EV_A); |
183 | } |
173 | } |
184 | |
174 | |
185 | operator struct ev_loop * () const throw () |
175 | operator struct ev_loop * () const throw () |
186 | { |
176 | { |
187 | return EV_AX; |
177 | return EV_AX; |
… | |
… | |
251 | { |
241 | { |
252 | ev_set_timeout_collect_interval (EV_AX_ interval); |
242 | ev_set_timeout_collect_interval (EV_AX_ interval); |
253 | } |
243 | } |
254 | |
244 | |
255 | // function callback |
245 | // function callback |
256 | void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () |
246 | void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw () |
257 | { |
247 | { |
258 | ev_once (EV_AX_ fd, events, timeout, cb, arg); |
248 | ev_once (EV_AX_ fd, events, timeout, cb, arg); |
259 | } |
249 | } |
260 | |
250 | |
261 | // method callback |
251 | // method callback |
… | |
… | |
263 | void once (int fd, int events, tstamp timeout, K *object) throw () |
253 | void once (int fd, int events, tstamp timeout, K *object) throw () |
264 | { |
254 | { |
265 | once (fd, events, timeout, method_thunk<K, method>, object); |
255 | once (fd, events, timeout, method_thunk<K, method>, object); |
266 | } |
256 | } |
267 | |
257 | |
|
|
258 | // default method == operator () |
|
|
259 | template<class K> |
|
|
260 | void once (int fd, int events, tstamp timeout, K *object) throw () |
|
|
261 | { |
|
|
262 | once (fd, events, timeout, method_thunk<K, &K::operator ()>, object); |
|
|
263 | } |
|
|
264 | |
268 | template<class K, void (K::*method)(int)> |
265 | template<class K, void (K::*method)(int)> |
269 | static void method_thunk (int revents, void* arg) |
266 | static void method_thunk (int revents, void *arg) |
270 | { |
|
|
271 | K *obj = static_cast<K *>(arg); |
|
|
272 | (obj->*method) (revents); |
|
|
273 | } |
267 | { |
|
|
268 | static_cast<K *>(arg)->*method |
|
|
269 | (revents); |
|
|
270 | } |
274 | |
271 | |
275 | // const method callback |
272 | // no-argument method callback |
276 | template<class K, void (K::*method)(int) const> |
|
|
277 | void once (int fd, int events, tstamp timeout, const K *object) throw () |
|
|
278 | { |
|
|
279 | once (fd, events, timeout, const_method_thunk<K, method>, object); |
|
|
280 | } |
|
|
281 | |
|
|
282 | template<class K, void (K::*method)(int) const> |
|
|
283 | static void const_method_thunk (int revents, void* arg) |
|
|
284 | { |
|
|
285 | K *obj = static_cast<K *>(arg); |
|
|
286 | (obj->*method) (revents); |
|
|
287 | } |
|
|
288 | |
|
|
289 | // simple method callback |
|
|
290 | template<class K, void (K::*method)()> |
273 | template<class K, void (K::*method)()> |
291 | void once (int fd, int events, tstamp timeout, K *object) throw () |
274 | void once (int fd, int events, tstamp timeout, K *object) throw () |
292 | { |
275 | { |
293 | once (fd, events, timeout, method_noargs_thunk<K, method>, object); |
276 | once (fd, events, timeout, method_noargs_thunk<K, method>, object); |
294 | } |
277 | } |
295 | |
278 | |
296 | template<class K, void (K::*method)()> |
279 | template<class K, void (K::*method)()> |
297 | static void method_noargs_thunk (int revents, void* arg) |
280 | static void method_noargs_thunk (int revents, void *arg) |
298 | { |
281 | { |
299 | K *obj = static_cast<K *>(arg); |
282 | static_cast<K *>(arg)->*method |
300 | (obj->*method) (); |
283 | (); |
301 | } |
284 | } |
302 | |
285 | |
303 | // simpler function callback |
286 | // simpler function callback |
304 | template<void (*cb)(int)> |
287 | template<void (*cb)(int)> |
305 | void once (int fd, int events, tstamp timeout) throw () |
288 | void once (int fd, int events, tstamp timeout) throw () |
306 | { |
289 | { |
307 | once (fd, events, timeout, simpler_func_thunk<cb>); |
290 | once (fd, events, timeout, simpler_func_thunk<cb>); |
308 | } |
291 | } |
309 | |
292 | |
310 | template<void (*cb)(int)> |
293 | template<void (*cb)(int)> |
311 | static void simpler_func_thunk (int revents, void* arg) |
294 | static void simpler_func_thunk (int revents, void *arg) |
312 | { |
295 | { |
|
|
296 | (*cb) |
313 | (*cb) (revents); |
297 | (revents); |
314 | } |
298 | } |
315 | |
299 | |
316 | // simplest function callback |
300 | // simplest function callback |
317 | template<void (*cb)()> |
301 | template<void (*cb)()> |
318 | void once (int fd, int events, tstamp timeout) throw () |
302 | void once (int fd, int events, tstamp timeout) throw () |
319 | { |
303 | { |
320 | once (fd, events, timeout, simplest_func_thunk<cb>); |
304 | once (fd, events, timeout, simplest_func_thunk<cb>); |
321 | } |
305 | } |
322 | |
306 | |
323 | template<void (*cb)()> |
307 | template<void (*cb)()> |
324 | static void simplest_func_thunk (int revents, void* arg) |
308 | static void simplest_func_thunk (int revents, void *arg) |
325 | { |
309 | { |
326 | (*cb) (); |
310 | (*cb) |
|
|
311 | (); |
327 | } |
312 | } |
328 | |
313 | |
329 | void feed_fd_event (int fd, int revents) throw () |
314 | void feed_fd_event (int fd, int revents) throw () |
330 | { |
315 | { |
331 | ev_feed_fd_event (EV_AX_ fd, revents); |
316 | ev_feed_fd_event (EV_AX_ fd, revents); |
… | |
… | |
421 | struct base : ev_watcher |
406 | struct base : ev_watcher |
422 | { |
407 | { |
423 | #if EV_MULTIPLICITY |
408 | #if EV_MULTIPLICITY |
424 | EV_PX; |
409 | EV_PX; |
425 | |
410 | |
426 | void set (EV_PX) throw () |
411 | void set (EV_P) throw () |
427 | { |
412 | { |
428 | this->EV_A = EV_A; |
413 | this->EV_A = EV_A; |
429 | } |
414 | } |
430 | #endif |
415 | #endif |
431 | |
416 | |
… | |
… | |
435 | #endif |
420 | #endif |
436 | { |
421 | { |
437 | ev_init (this, 0); |
422 | ev_init (this, 0); |
438 | } |
423 | } |
439 | |
424 | |
440 | void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () |
425 | void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () |
441 | { |
426 | { |
442 | this->data = data; |
427 | this->data = (void *)data; |
443 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
428 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
|
|
429 | } |
|
|
430 | |
|
|
431 | // function callback |
|
|
432 | template<void (*function)(watcher &w, int)> |
|
|
433 | void set (void *data = 0) throw () |
|
|
434 | { |
|
|
435 | set_ (data, function_thunk<function>); |
|
|
436 | } |
|
|
437 | |
|
|
438 | template<void (*function)(watcher &w, int)> |
|
|
439 | static void function_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
440 | { |
|
|
441 | function |
|
|
442 | (*static_cast<watcher *>(w), revents); |
444 | } |
443 | } |
445 | |
444 | |
446 | // method callback |
445 | // method callback |
447 | template<class K, void (K::*method)(watcher &w, int)> |
446 | template<class K, void (K::*method)(watcher &w, int)> |
448 | void set (K *object) throw () |
447 | void set (K *object) throw () |
449 | { |
448 | { |
450 | set_ (object, method_thunk<K, method>); |
449 | set_ (object, method_thunk<K, method>); |
451 | } |
450 | } |
452 | |
451 | |
|
|
452 | // default method == operator () |
|
|
453 | template<class K> |
|
|
454 | void set (K *object) throw () |
|
|
455 | { |
|
|
456 | set_ (object, method_thunk<K, &K::operator ()>); |
|
|
457 | } |
|
|
458 | |
453 | template<class K, void (K::*method)(watcher &w, int)> |
459 | template<class K, void (K::*method)(watcher &w, int)> |
454 | static void method_thunk (EV_P_ ev_watcher *w, int revents) |
460 | static void method_thunk (EV_P_ ev_watcher *w, int revents) |
455 | { |
461 | { |
456 | K *obj = static_cast<K *>(w->data); |
462 | (static_cast<K *>(w->data)->*method) |
457 | (obj->*method) (*static_cast<watcher *>(w), revents); |
|
|
458 | } |
|
|
459 | |
|
|
460 | // const method callback |
|
|
461 | template<class K, void (K::*method)(watcher &w, int) const> |
|
|
462 | void set (const K *object) throw () |
|
|
463 | { |
|
|
464 | set_ (object, const_method_thunk<K, method>); |
|
|
465 | } |
|
|
466 | |
|
|
467 | template<class K, void (K::*method)(watcher &w, int) const> |
|
|
468 | static void const_method_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
469 | { |
|
|
470 | K *obj = static_cast<K *>(w->data); |
|
|
471 | (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents); |
|
|
472 | } |
|
|
473 | |
|
|
474 | // function callback |
|
|
475 | template<void (*function)(watcher &w, int)> |
|
|
476 | void set (void *data = 0) throw () |
|
|
477 | { |
|
|
478 | set_ (data, function_thunk<function>); |
|
|
479 | } |
|
|
480 | |
|
|
481 | template<void (*function)(watcher &w, int)> |
|
|
482 | static void function_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
483 | { |
|
|
484 | function (*static_cast<watcher *>(w), revents); |
463 | (*static_cast<watcher *>(w), revents); |
485 | } |
464 | } |
486 | |
465 | |
487 | // simple callback |
466 | // no-argument callback |
488 | template<class K, void (K::*method)()> |
467 | template<class K, void (K::*method)()> |
489 | void set (K *object) throw () |
468 | void set (K *object) throw () |
490 | { |
469 | { |
491 | set_ (object, method_noargs_thunk<K, method>); |
470 | set_ (object, method_noargs_thunk<K, method>); |
492 | } |
471 | } |
493 | |
472 | |
494 | template<class K, void (K::*method)()> |
473 | template<class K, void (K::*method)()> |
495 | static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) |
474 | static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) |
496 | { |
475 | { |
497 | K *obj = static_cast<K *>(w->data); |
476 | static_cast<K *>(w->data)->*method |
498 | (obj->*method) (); |
477 | (); |
499 | } |
478 | } |
500 | |
479 | |
501 | void operator ()(int events = EV_UNDEF) |
480 | void operator ()(int events = EV_UNDEF) |
502 | { |
481 | { |
|
|
482 | return |
503 | return ev_cb (static_cast<ev_watcher *>(this)) |
483 | ev_cb (static_cast<ev_watcher *>(this)) |
504 | (static_cast<ev_watcher *>(this), events); |
484 | (static_cast<ev_watcher *>(this), events); |
505 | } |
485 | } |
506 | |
486 | |
507 | bool is_active () const throw () |
487 | bool is_active () const throw () |
508 | { |
488 | { |
509 | return ev_is_active (static_cast<const ev_watcher *>(this)); |
489 | return ev_is_active (static_cast<const ev_watcher *>(this)); |