ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
(Generate patch)

Comparing libev/ev++.h (file contents):
Revision 1.32 by root, Sat Jan 19 00:49:06 2008 UTC vs.
Revision 1.53 by root, Thu Oct 21 14:50:58 2010 UTC

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,2010 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
57namespace ev { 57namespace 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) throw (bad_loop) 139 loop_ref (EV_P) throw ()
137#if EV_MULTIPLICITY 140#if EV_MULTIPLICITY
138 : EV_AX (EV_A) 141 : EV_AX (EV_A)
139#endif 142#endif
140 { 143 {
141#if EV_MULTIPLICITY
142 if (!EV_AX)
143 throw bad_loop ();
144#endif
145 } 144 }
146 145
147 bool operator == (const loop_ref &other) const throw () 146 bool operator == (const loop_ref &other) const throw ()
148 { 147 {
149#if EV_MULTIPLICITY 148#if EV_MULTIPLICITY
161 return false; 160 return false;
162#endif 161#endif
163 } 162 }
164 163
165#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
166 bool operator== (struct ev_loop *other) const throw () 165 bool operator == (const EV_P) const throw ()
167 { 166 {
168 return this->EV_AX == other; 167 return this->EV_AX == EV_A;
169 }
170
171 bool operator!= (struct ev_loop *other) const throw ()
172 { 168 }
173 return ! (*this == other); 169
170 bool operator != (const EV_P) const throw ()
174 } 171 {
175
176 bool operator== (const struct ev_loop *other) const throw ()
177 {
178 return this->EV_AX == other;
179 }
180
181 bool operator!= (const struct ev_loop *other) const throw ()
182 {
183 return (*this == other); 172 return (*this == EV_A);
184 } 173 }
185 174
186 operator struct ev_loop * () const throw () 175 operator struct ev_loop * () const throw ()
187 { 176 {
188 return EV_AX; 177 return EV_AX;
216#else 205#else
217 ev_default_fork (); 206 ev_default_fork ();
218#endif 207#endif
219 } 208 }
220 209
221 unsigned int count () const throw ()
222 {
223 return ev_loop_count (EV_AX);
224 }
225
226 unsigned int backend () const throw () 210 unsigned int backend () const throw ()
227 { 211 {
228 return ev_backend (EV_AX); 212 return ev_backend (EV_AX);
229 } 213 }
230 214
241 void unref () throw () 225 void unref () throw ()
242 { 226 {
243 ev_unref (EV_AX); 227 ev_unref (EV_AX);
244 } 228 }
245 229
230#if EV_FEATURE_API
231 unsigned int iteration () const throw ()
232 {
233 return ev_iteration (EV_AX);
234 }
235
236 unsigned int depth () const throw ()
237 {
238 return ev_depth (EV_AX);
239 }
240
246 void set_io_collect_interval (tstamp interval) throw () 241 void set_io_collect_interval (tstamp interval) throw ()
247 { 242 {
248 ev_set_io_collect_interval (EV_AX_ interval); 243 ev_set_io_collect_interval (EV_AX_ interval);
249 } 244 }
250 245
251 void set_timeout_collect_interval (tstamp interval) throw () 246 void set_timeout_collect_interval (tstamp interval) throw ()
252 { 247 {
253 ev_set_timeout_collect_interval (EV_AX_ interval); 248 ev_set_timeout_collect_interval (EV_AX_ interval);
254 } 249 }
250#endif
255 251
256 // function callback 252 // function callback
257 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 ()
258 { 254 {
259 ev_once (EV_AX_ fd, events, timeout, cb, arg); 255 ev_once (EV_AX_ fd, events, timeout, cb, arg);
260 } 256 }
261 257
262 // method callback 258 // method callback
264 void once (int fd, int events, tstamp timeout, K *object) throw () 260 void once (int fd, int events, tstamp timeout, K *object) throw ()
265 { 261 {
266 once (fd, events, timeout, method_thunk<K, method>, object); 262 once (fd, events, timeout, method_thunk<K, method>, object);
267 } 263 }
268 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
269 template<class K, void (K::*method)(int)> 272 template<class K, void (K::*method)(int)>
270 static void method_thunk (int revents, void* arg) 273 static void method_thunk (int revents, void *arg)
271 {
272 K *obj = static_cast<K *>(arg);
273 (obj->*method) (revents);
274 } 274 {
275 static_cast<K *>(arg)->*method
276 (revents);
277 }
275 278
276 // const method callback 279 // no-argument method callback
277 template<class K, void (K::*method)(int) const>
278 void once (int fd, int events, tstamp timeout, const K *object) throw ()
279 {
280 once (fd, events, timeout, const_method_thunk<K, method>, object);
281 }
282
283 template<class K, void (K::*method)(int) const>
284 static void const_method_thunk (int revents, void* arg)
285 {
286 K *obj = static_cast<K *>(arg);
287 (obj->*method) (revents);
288 }
289
290 // simple method callback
291 template<class K, void (K::*method)()> 280 template<class K, void (K::*method)()>
292 void once (int fd, int events, tstamp timeout, K *object) throw () 281 void once (int fd, int events, tstamp timeout, K *object) throw ()
293 { 282 {
294 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 283 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
295 } 284 }
296 285
297 template<class K, void (K::*method)()> 286 template<class K, void (K::*method)()>
298 static void method_noargs_thunk (int revents, void* arg) 287 static void method_noargs_thunk (int revents, void *arg)
299 { 288 {
300 K *obj = static_cast<K *>(arg); 289 static_cast<K *>(arg)->*method
301 (obj->*method) (); 290 ();
302 } 291 }
303 292
304 // simpler function callback 293 // simpler function callback
305 template<void (*cb)(int)> 294 template<void (*cb)(int)>
306 void once (int fd, int events, tstamp timeout) throw () 295 void once (int fd, int events, tstamp timeout) throw ()
307 { 296 {
308 once (fd, events, timeout, simpler_func_thunk<cb>); 297 once (fd, events, timeout, simpler_func_thunk<cb>);
309 } 298 }
310 299
311 template<void (*cb)(int)> 300 template<void (*cb)(int)>
312 static void simpler_func_thunk (int revents, void* arg) 301 static void simpler_func_thunk (int revents, void *arg)
313 { 302 {
303 (*cb)
314 (*cb) (revents); 304 (revents);
315 } 305 }
316 306
317 // simplest function callback 307 // simplest function callback
318 template<void (*cb)()> 308 template<void (*cb)()>
319 void once (int fd, int events, tstamp timeout) throw () 309 void once (int fd, int events, tstamp timeout) throw ()
320 { 310 {
321 once (fd, events, timeout, simplest_func_thunk<cb>); 311 once (fd, events, timeout, simplest_func_thunk<cb>);
322 } 312 }
323 313
324 template<void (*cb)()> 314 template<void (*cb)()>
325 static void simplest_func_thunk (int revents, void* arg) 315 static void simplest_func_thunk (int revents, void *arg)
326 { 316 {
327 (*cb) (); 317 (*cb)
318 ();
328 } 319 }
329 320
330 void feed_fd_event (int fd, int revents) throw () 321 void feed_fd_event (int fd, int revents) throw ()
331 { 322 {
332 ev_feed_fd_event (EV_AX_ fd, revents); 323 ev_feed_fd_event (EV_AX_ fd, revents);
342#endif 333#endif
343 334
344 }; 335 };
345 336
346#if EV_MULTIPLICITY 337#if EV_MULTIPLICITY
347 struct dynamic_loop: loop_ref 338 struct dynamic_loop : loop_ref
348 { 339 {
349 340
350 dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 341 dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
351 : loop_ref (ev_loop_new (flags)) 342 : loop_ref (ev_loop_new (flags))
352 { 343 {
344 if (!EV_AX)
345 throw bad_loop ();
353 } 346 }
354 347
355 ~dynamic_loop () throw () 348 ~dynamic_loop () throw ()
356 { 349 {
357 ev_loop_destroy (EV_AX); 350 ev_loop_destroy (EV_AX);
365 dynamic_loop & operator= (const dynamic_loop &); 358 dynamic_loop & operator= (const dynamic_loop &);
366 359
367 }; 360 };
368#endif 361#endif
369 362
370 struct default_loop: loop_ref 363 struct default_loop : loop_ref
371 { 364 {
372
373 default_loop (unsigned int flags = AUTO) throw (bad_loop) 365 default_loop (unsigned int flags = AUTO) throw (bad_loop)
374#if EV_MULTIPLICITY 366#if EV_MULTIPLICITY
375 : loop_ref (ev_default_loop (flags)) 367 : loop_ref (ev_default_loop (flags))
376#endif 368#endif
377 { 369 {
370 if (
378#ifndef EV_MULTIPLICITY 371#if EV_MULTIPLICITY
372 !EV_AX
373#else
379 if (!ev_default_loop (flags)) 374 !ev_default_loop (flags)
375#endif
376 )
380 throw bad_loop (); 377 throw bad_loop ();
381#endif
382 } 378 }
383 379
384 ~default_loop () throw () 380 ~default_loop () throw ()
385 { 381 {
386 ev_default_destroy (); 382 ev_default_destroy ();
417 struct base : ev_watcher 413 struct base : ev_watcher
418 { 414 {
419 #if EV_MULTIPLICITY 415 #if EV_MULTIPLICITY
420 EV_PX; 416 EV_PX;
421 417
418 // loop set
422 void set (EV_PX) throw () 419 void set (EV_P) throw ()
423 { 420 {
424 this->EV_A = EV_A; 421 this->EV_A = EV_A;
425 } 422 }
426 #endif 423 #endif
427 424
431 #endif 428 #endif
432 { 429 {
433 ev_init (this, 0); 430 ev_init (this, 0);
434 } 431 }
435 432
436 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () 433 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
437 { 434 {
438 this->data = data; 435 this->data = (void *)data;
439 ev_set_cb (static_cast<ev_watcher *>(this), cb); 436 ev_set_cb (static_cast<ev_watcher *>(this), cb);
437 }
438
439 // function callback
440 template<void (*function)(watcher &w, int)>
441 void set (void *data = 0) throw ()
442 {
443 set_ (data, function_thunk<function>);
444 }
445
446 template<void (*function)(watcher &w, int)>
447 static void function_thunk (EV_P_ ev_watcher *w, int revents)
448 {
449 function
450 (*static_cast<watcher *>(w), revents);
440 } 451 }
441 452
442 // method callback 453 // method callback
443 template<class K, void (K::*method)(watcher &w, int)> 454 template<class K, void (K::*method)(watcher &w, int)>
444 void set (K *object) throw () 455 void set (K *object) throw ()
445 { 456 {
446 set_ (object, method_thunk<K, method>); 457 set_ (object, method_thunk<K, method>);
447 } 458 }
448 459
460 // default method == operator ()
461 template<class K>
462 void set (K *object) throw ()
463 {
464 set_ (object, method_thunk<K, &K::operator ()>);
465 }
466
449 template<class K, void (K::*method)(watcher &w, int)> 467 template<class K, void (K::*method)(watcher &w, int)>
450 static void method_thunk (EV_P_ ev_watcher *w, int revents) 468 static void method_thunk (EV_P_ ev_watcher *w, int revents)
451 { 469 {
452 K *obj = static_cast<K *>(w->data); 470 (static_cast<K *>(w->data)->*method)
453 (obj->*method) (*static_cast<watcher *>(w), revents);
454 }
455
456 // const method callback
457 template<class K, void (K::*method)(watcher &w, int) const>
458 void set (const K *object) throw ()
459 {
460 set_ (object, const_method_thunk<K, method>);
461 }
462
463 template<class K, void (K::*method)(watcher &w, int) const>
464 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
465 {
466 K *obj = static_cast<K *>(w->data);
467 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
468 }
469
470 // function callback
471 template<void (*function)(watcher &w, int)>
472 void set (void *data = 0) throw ()
473 {
474 set_ (data, function_thunk<function>);
475 }
476
477 template<void (*function)(watcher &w, int)>
478 static void function_thunk (EV_P_ ev_watcher *w, int revents)
479 {
480 function (*static_cast<watcher *>(w), revents); 471 (*static_cast<watcher *>(w), revents);
481 } 472 }
482 473
483 // simple callback 474 // no-argument callback
484 template<class K, void (K::*method)()> 475 template<class K, void (K::*method)()>
485 void set (K *object) throw () 476 void set (K *object) throw ()
486 { 477 {
487 set_ (object, method_noargs_thunk<K, method>); 478 set_ (object, method_noargs_thunk<K, method>);
488 } 479 }
489 480
490 template<class K, void (K::*method)()> 481 template<class K, void (K::*method)()>
491 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 482 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
492 { 483 {
493 K *obj = static_cast<K *>(w->data); 484 (static_cast<K *>(w->data)->*method)
494 (obj->*method) (); 485 ();
495 } 486 }
496 487
497 void operator ()(int events = EV_UNDEF) 488 void operator ()(int events = EV_UNDEF)
498 { 489 {
490 return
499 return ev_cb (static_cast<ev_watcher *>(this)) 491 ev_cb (static_cast<ev_watcher *>(this))
500 (static_cast<ev_watcher *>(this), events); 492 (static_cast<ev_watcher *>(this), events);
501 } 493 }
502 494
503 bool is_active () const throw () 495 bool is_active () const throw ()
504 { 496 {
505 return ev_is_active (static_cast<const ev_watcher *>(this)); 497 return ev_is_active (static_cast<const ev_watcher *>(this));
561 ev_set_syserr_cb (cb); 553 ev_set_syserr_cb (cb);
562 } 554 }
563 555
564 #if EV_MULTIPLICITY 556 #if EV_MULTIPLICITY
565 #define EV_CONSTRUCT(cppstem,cstem) \ 557 #define EV_CONSTRUCT(cppstem,cstem) \
566 (EV_PX = get_default_loop ()) throw () \ 558 (EV_PX = get_default_loop ()) throw () \
567 : base<ev_ ## cstem, cppstem> (EV_A) \ 559 : base<ev_ ## cstem, cppstem> (EV_A) \
568 { \ 560 { \
569 } 561 }
570 #else 562 #else
571 #define EV_CONSTRUCT(cppstem,cstem) \ 563 #define EV_CONSTRUCT(cppstem,cstem) \
572 () throw () \ 564 () throw () \
573 { \ 565 { \
574 } 566 }
575 #endif 567 #endif
576 568
577 /* using a template here would require quite a bit more lines, 569 /* using a template here would require quite a bit more lines,
578 * so a macro solution was chosen */ 570 * so a macro solution was chosen */
579 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 571 #define EV_BEGIN_WATCHER(cppstem,cstem) \
580 \ 572 \
581 struct cppstem : base<ev_ ## cstem, cppstem> \ 573 struct cppstem : base<ev_ ## cstem, cppstem> \
582 { \ 574 { \
583 void start () throw () \ 575 void start () throw () \
584 { \ 576 { \
585 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 577 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
586 } \ 578 } \
587 \ 579 \
588 void stop () throw () \ 580 void stop () throw () \
589 { \ 581 { \
590 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 582 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
591 } \ 583 } \
592 \ 584 \
593 cppstem EV_CONSTRUCT(cppstem,cstem) \ 585 cppstem EV_CONSTRUCT(cppstem,cstem) \
594 \ 586 \
595 ~cppstem () throw () \ 587 ~cppstem () throw () \
596 { \ 588 { \
597 stop (); \ 589 stop (); \
598 } \ 590 } \
599 \ 591 \
600 using base<ev_ ## cstem, cppstem>::set; \ 592 using base<ev_ ## cstem, cppstem>::set; \
601 \ 593 \
602 private: \ 594 private: \
603 \ 595 \
604 cppstem (const cppstem &o); \ 596 cppstem (const cppstem &o); \
605 \ 597 \
606 cppstem & operator =(const cppstem &o); \ 598 cppstem &operator =(const cppstem &o); \
607 \ 599 \
608 public: 600 public:
609 601
610 #define EV_END_WATCHER(cppstem,cstem) \ 602 #define EV_END_WATCHER(cppstem,cstem) \
611 }; 603 };
651 643
652 void again () throw () 644 void again () throw ()
653 { 645 {
654 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 646 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
655 } 647 }
648
649 ev_tstamp remaining ()
650 {
651 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
652 }
656 EV_END_WATCHER (timer, timer) 653 EV_END_WATCHER (timer, timer)
657 654
658 #if EV_PERIODIC_ENABLE 655 #if EV_PERIODIC_ENABLE
659 EV_BEGIN_WATCHER (periodic, periodic) 656 EV_BEGIN_WATCHER (periodic, periodic)
660 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 657 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
676 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 673 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
677 } 674 }
678 EV_END_WATCHER (periodic, periodic) 675 EV_END_WATCHER (periodic, periodic)
679 #endif 676 #endif
680 677
678 #if EV_SIGNAL_ENABLE
681 EV_BEGIN_WATCHER (sig, signal) 679 EV_BEGIN_WATCHER (sig, signal)
682 void set (int signum) throw () 680 void set (int signum) throw ()
683 { 681 {
684 int active = is_active (); 682 int active = is_active ();
685 if (active) stop (); 683 if (active) stop ();
691 { 689 {
692 set (signum); 690 set (signum);
693 start (); 691 start ();
694 } 692 }
695 EV_END_WATCHER (sig, signal) 693 EV_END_WATCHER (sig, signal)
694 #endif
696 695
696 #if EV_CHILD_ENABLE
697 EV_BEGIN_WATCHER (child, child) 697 EV_BEGIN_WATCHER (child, child)
698 void set (int pid) throw () 698 void set (int pid, int trace = 0) throw ()
699 { 699 {
700 int active = is_active (); 700 int active = is_active ();
701 if (active) stop (); 701 if (active) stop ();
702 ev_child_set (static_cast<ev_child *>(this), pid); 702 ev_child_set (static_cast<ev_child *>(this), pid, trace);
703 if (active) start (); 703 if (active) start ();
704 } 704 }
705 705
706 void start (int pid) throw () 706 void start (int pid, int trace = 0) throw ()
707 { 707 {
708 set (pid); 708 set (pid, trace);
709 start (); 709 start ();
710 } 710 }
711 EV_END_WATCHER (child, child) 711 EV_END_WATCHER (child, child)
712 #endif
712 713
713 #if EV_STAT_ENABLE 714 #if EV_STAT_ENABLE
714 EV_BEGIN_WATCHER (stat, stat) 715 EV_BEGIN_WATCHER (stat, stat)
715 void set (const char *path, ev_tstamp interval = 0.) throw () 716 void set (const char *path, ev_tstamp interval = 0.) throw ()
716 { 717 {
732 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 733 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
733 } 734 }
734 EV_END_WATCHER (stat, stat) 735 EV_END_WATCHER (stat, stat)
735 #endif 736 #endif
736 737
738 #if EV_IDLE_ENABLE
737 EV_BEGIN_WATCHER (idle, idle) 739 EV_BEGIN_WATCHER (idle, idle)
738 void set () throw () { } 740 void set () throw () { }
739 EV_END_WATCHER (idle, idle) 741 EV_END_WATCHER (idle, idle)
742 #endif
740 743
744 #if EV_PREPARE_ENABLE
741 EV_BEGIN_WATCHER (prepare, prepare) 745 EV_BEGIN_WATCHER (prepare, prepare)
742 void set () throw () { } 746 void set () throw () { }
743 EV_END_WATCHER (prepare, prepare) 747 EV_END_WATCHER (prepare, prepare)
748 #endif
744 749
750 #if EV_CHECK_ENABLE
745 EV_BEGIN_WATCHER (check, check) 751 EV_BEGIN_WATCHER (check, check)
746 void set () throw () { } 752 void set () throw () { }
747 EV_END_WATCHER (check, check) 753 EV_END_WATCHER (check, check)
754 #endif
748 755
749 #if EV_EMBED_ENABLE 756 #if EV_EMBED_ENABLE
750 EV_BEGIN_WATCHER (embed, embed) 757 EV_BEGIN_WATCHER (embed, embed)
758 void set (struct ev_loop *embedded_loop) throw ()
759 {
760 int active = is_active ();
761 if (active) stop ();
762 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
763 if (active) start ();
764 }
765
751 void start (struct ev_loop *embedded_loop) throw () 766 void start (struct ev_loop *embedded_loop) throw ()
752 { 767 {
753 stop (); 768 set (embedded_loop);
754 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
755 start (); 769 start ();
756 } 770 }
757 771
758 void sweep () 772 void sweep ()
759 { 773 {
764 778
765 #if EV_FORK_ENABLE 779 #if EV_FORK_ENABLE
766 EV_BEGIN_WATCHER (fork, fork) 780 EV_BEGIN_WATCHER (fork, fork)
767 void set () throw () { } 781 void set () throw () { }
768 EV_END_WATCHER (fork, fork) 782 EV_END_WATCHER (fork, fork)
783 #endif
784
785 #if EV_ASYNC_ENABLE
786 EV_BEGIN_WATCHER (async, async)
787 void send () throw ()
788 {
789 ev_async_send (EV_A_ static_cast<ev_async *>(this));
790 }
791
792 bool async_pending () throw ()
793 {
794 return ev_async_pending (static_cast<ev_async *>(this));
795 }
796 EV_END_WATCHER (async, async)
769 #endif 797 #endif
770 798
771 #undef EV_PX 799 #undef EV_PX
772 #undef EV_PX_ 800 #undef EV_PX_
773 #undef EV_CONSTRUCT 801 #undef EV_CONSTRUCT
774 #undef EV_BEGIN_WATCHER 802 #undef EV_BEGIN_WATCHER
775 #undef EV_END_WATCHER 803 #undef EV_END_WATCHER
776
777} 804}
778 805
779#undef EV_THROW
780
781#endif 806#endif
782 807

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines