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

Comparing libev/ev++.h (file contents):
Revision 1.38 by root, Mon Jan 28 11:43:37 2008 UTC vs.
Revision 1.55 by root, Sun Oct 24 17:58:41 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,
67#if EV_COMPAT3
66 TIMEOUT = EV_TIMEOUT, 68 TIMEOUT = EV_TIMEOUT,
69#endif
70 TIMER = EV_TIMER,
67 PERIODIC = EV_PERIODIC, 71 PERIODIC = EV_PERIODIC,
68 SIGNAL = EV_SIGNAL, 72 SIGNAL = EV_SIGNAL,
69 CHILD = EV_CHILD, 73 CHILD = EV_CHILD,
70 STAT = EV_STAT, 74 STAT = EV_STAT,
71 IDLE = EV_IDLE, 75 IDLE = EV_IDLE,
72 CHECK = EV_CHECK, 76 CHECK = EV_CHECK,
73 PREPARE = EV_PREPARE, 77 PREPARE = EV_PREPARE,
74 FORK = EV_FORK, 78 FORK = EV_FORK,
79 ASYNC = EV_ASYNC,
75 EMBED = EV_EMBED, 80 EMBED = EV_EMBED,
81# undef ERROR // some systems stupidly #define ERROR
76 ERROR = EV_ERROR, 82 ERROR = EV_ERROR
77 }; 83 };
78 84
79 enum 85 enum
80 { 86 {
81 AUTO = EVFLAG_AUTO, 87 AUTO = EVFLAG_AUTO,
82 NOENV = EVFLAG_NOENV, 88 NOENV = EVFLAG_NOENV,
83 FORKCHECK = EVFLAG_FORKCHECK, 89 FORKCHECK = EVFLAG_FORKCHECK,
90
84 SELECT = EVBACKEND_SELECT, 91 SELECT = EVBACKEND_SELECT,
85 POLL = EVBACKEND_POLL, 92 POLL = EVBACKEND_POLL,
86 EPOLL = EVBACKEND_EPOLL, 93 EPOLL = EVBACKEND_EPOLL,
87 KQUEUE = EVBACKEND_KQUEUE, 94 KQUEUE = EVBACKEND_KQUEUE,
88 DEVPOLL = EVBACKEND_DEVPOLL, 95 DEVPOLL = EVBACKEND_DEVPOLL,
89 PORT = EVBACKEND_PORT 96 PORT = EVBACKEND_PORT
90 }; 97 };
91 98
92 enum 99 enum
93 { 100 {
101#if EV_COMPAT3
94 NONBLOCK = EVLOOP_NONBLOCK, 102 NONBLOCK = EVLOOP_NONBLOCK,
95 ONESHOT = EVLOOP_ONESHOT 103 ONESHOT = EVLOOP_ONESHOT,
104#endif
105 NOWAIT = EVRUN_NOWAIT,
106 ONCE = EVRUN_ONCE
96 }; 107 };
97 108
98 enum how_t 109 enum how_t
99 { 110 {
100 ONE = EVUNLOOP_ONE, 111 ONE = EVBREAK_ONE,
101 ALL = EVUNLOOP_ALL 112 ALL = EVBREAK_ALL
102 }; 113 };
103 114
104 struct bad_loop 115 struct bad_loop
105#if EV_USE_STDEXCEPT 116#if EV_USE_STDEXCEPT
106 : std::runtime_error 117 : std::runtime_error
156 return false; 167 return false;
157#endif 168#endif
158 } 169 }
159 170
160#if EV_MULTIPLICITY 171#if EV_MULTIPLICITY
161 bool operator == (struct ev_loop *other) const throw () 172 bool operator == (const EV_P) const throw ()
162 { 173 {
163 return this->EV_AX == other; 174 return this->EV_AX == EV_A;
164 }
165
166 bool operator != (struct ev_loop *other) const throw ()
167 { 175 }
168 return ! (*this == other); 176
177 bool operator != (const EV_P) const throw ()
169 } 178 {
170
171 bool operator == (const struct ev_loop *other) const throw ()
172 {
173 return this->EV_AX == other;
174 }
175
176 bool operator != (const struct ev_loop *other) const throw ()
177 {
178 return (*this == other); 179 return (*this == EV_A);
179 } 180 }
180 181
181 operator struct ev_loop * () const throw () 182 operator struct ev_loop * () const throw ()
182 { 183 {
183 return EV_AX; 184 return EV_AX;
192 { 193 {
193 return EV_AX == ev_default_loop (0); 194 return EV_AX == ev_default_loop (0);
194 } 195 }
195#endif 196#endif
196 197
198#if EV_COMPAT3
197 void loop (int flags = 0) 199 void loop (int flags = 0)
198 { 200 {
199 ev_loop (EV_AX_ flags); 201 ev_run (EV_AX_ flags);
200 } 202 }
201 203
202 void unloop (how_t how = ONE) throw () 204 void unloop (how_t how = ONE) throw ()
203 { 205 {
204 ev_unloop (EV_AX_ how); 206 ev_break (EV_AX_ how);
207 }
208#endif
209
210 void run (int flags = 0)
211 {
212 ev_run (EV_AX_ flags);
213 }
214
215 void break_loop (how_t how = ONE) throw ()
216 {
217 ev_break (EV_AX_ how);
205 } 218 }
206 219
207 void post_fork () throw () 220 void post_fork () throw ()
208 { 221 {
209#if EV_MULTIPLICITY
210 ev_loop_fork (EV_AX); 222 ev_loop_fork (EV_AX);
211#else
212 ev_default_fork ();
213#endif
214 }
215
216 unsigned int count () const throw ()
217 {
218 return ev_loop_count (EV_AX);
219 } 223 }
220 224
221 unsigned int backend () const throw () 225 unsigned int backend () const throw ()
222 { 226 {
223 return ev_backend (EV_AX); 227 return ev_backend (EV_AX);
236 void unref () throw () 240 void unref () throw ()
237 { 241 {
238 ev_unref (EV_AX); 242 ev_unref (EV_AX);
239 } 243 }
240 244
245#if EV_FEATURE_API
246 unsigned int iteration () const throw ()
247 {
248 return ev_iteration (EV_AX);
249 }
250
251 unsigned int depth () const throw ()
252 {
253 return ev_depth (EV_AX);
254 }
255
241 void set_io_collect_interval (tstamp interval) throw () 256 void set_io_collect_interval (tstamp interval) throw ()
242 { 257 {
243 ev_set_io_collect_interval (EV_AX_ interval); 258 ev_set_io_collect_interval (EV_AX_ interval);
244 } 259 }
245 260
246 void set_timeout_collect_interval (tstamp interval) throw () 261 void set_timeout_collect_interval (tstamp interval) throw ()
247 { 262 {
248 ev_set_timeout_collect_interval (EV_AX_ interval); 263 ev_set_timeout_collect_interval (EV_AX_ interval);
249 } 264 }
265#endif
250 266
251 // function callback 267 // function callback
252 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () 268 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw ()
253 { 269 {
254 ev_once (EV_AX_ fd, events, timeout, cb, arg); 270 ev_once (EV_AX_ fd, events, timeout, cb, arg);
255 } 271 }
256 272
257 // method callback 273 // method callback
259 void once (int fd, int events, tstamp timeout, K *object) throw () 275 void once (int fd, int events, tstamp timeout, K *object) throw ()
260 { 276 {
261 once (fd, events, timeout, method_thunk<K, method>, object); 277 once (fd, events, timeout, method_thunk<K, method>, object);
262 } 278 }
263 279
280 // default method == operator ()
281 template<class K>
282 void once (int fd, int events, tstamp timeout, K *object) throw ()
283 {
284 once (fd, events, timeout, method_thunk<K, &K::operator ()>, object);
285 }
286
264 template<class K, void (K::*method)(int)> 287 template<class K, void (K::*method)(int)>
265 static void method_thunk (int revents, void* arg) 288 static void method_thunk (int revents, void *arg)
266 {
267 K *obj = static_cast<K *>(arg);
268 (obj->*method) (revents);
269 } 289 {
290 static_cast<K *>(arg)->*method
291 (revents);
292 }
270 293
271 // const method callback 294 // no-argument method callback
272 template<class K, void (K::*method)(int) const>
273 void once (int fd, int events, tstamp timeout, const K *object) throw ()
274 {
275 once (fd, events, timeout, const_method_thunk<K, method>, object);
276 }
277
278 template<class K, void (K::*method)(int) const>
279 static void const_method_thunk (int revents, void* arg)
280 {
281 K *obj = static_cast<K *>(arg);
282 (obj->*method) (revents);
283 }
284
285 // simple method callback
286 template<class K, void (K::*method)()> 295 template<class K, void (K::*method)()>
287 void once (int fd, int events, tstamp timeout, K *object) throw () 296 void once (int fd, int events, tstamp timeout, K *object) throw ()
288 { 297 {
289 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 298 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
290 } 299 }
291 300
292 template<class K, void (K::*method)()> 301 template<class K, void (K::*method)()>
293 static void method_noargs_thunk (int revents, void* arg) 302 static void method_noargs_thunk (int revents, void *arg)
294 { 303 {
295 K *obj = static_cast<K *>(arg); 304 static_cast<K *>(arg)->*method
296 (obj->*method) (); 305 ();
297 } 306 }
298 307
299 // simpler function callback 308 // simpler function callback
300 template<void (*cb)(int)> 309 template<void (*cb)(int)>
301 void once (int fd, int events, tstamp timeout) throw () 310 void once (int fd, int events, tstamp timeout) throw ()
302 { 311 {
303 once (fd, events, timeout, simpler_func_thunk<cb>); 312 once (fd, events, timeout, simpler_func_thunk<cb>);
304 } 313 }
305 314
306 template<void (*cb)(int)> 315 template<void (*cb)(int)>
307 static void simpler_func_thunk (int revents, void* arg) 316 static void simpler_func_thunk (int revents, void *arg)
308 { 317 {
318 (*cb)
309 (*cb) (revents); 319 (revents);
310 } 320 }
311 321
312 // simplest function callback 322 // simplest function callback
313 template<void (*cb)()> 323 template<void (*cb)()>
314 void once (int fd, int events, tstamp timeout) throw () 324 void once (int fd, int events, tstamp timeout) throw ()
315 { 325 {
316 once (fd, events, timeout, simplest_func_thunk<cb>); 326 once (fd, events, timeout, simplest_func_thunk<cb>);
317 } 327 }
318 328
319 template<void (*cb)()> 329 template<void (*cb)()>
320 static void simplest_func_thunk (int revents, void* arg) 330 static void simplest_func_thunk (int revents, void *arg)
321 { 331 {
322 (*cb) (); 332 (*cb)
333 ();
323 } 334 }
324 335
325 void feed_fd_event (int fd, int revents) throw () 336 void feed_fd_event (int fd, int revents) throw ()
326 { 337 {
327 ev_feed_fd_event (EV_AX_ fd, revents); 338 ev_feed_fd_event (EV_AX_ fd, revents);
377#else 388#else
378 !ev_default_loop (flags) 389 !ev_default_loop (flags)
379#endif 390#endif
380 ) 391 )
381 throw bad_loop (); 392 throw bad_loop ();
382 }
383
384 ~default_loop () throw ()
385 {
386 ev_default_destroy ();
387 } 393 }
388 394
389 private: 395 private:
390 default_loop (const default_loop &); 396 default_loop (const default_loop &);
391 default_loop &operator = (const default_loop &); 397 default_loop &operator = (const default_loop &);
417 struct base : ev_watcher 423 struct base : ev_watcher
418 { 424 {
419 #if EV_MULTIPLICITY 425 #if EV_MULTIPLICITY
420 EV_PX; 426 EV_PX;
421 427
428 // loop set
422 void set (EV_PX) throw () 429 void set (EV_P) throw ()
423 { 430 {
424 this->EV_A = EV_A; 431 this->EV_A = EV_A;
425 } 432 }
426 #endif 433 #endif
427 434
431 #endif 438 #endif
432 { 439 {
433 ev_init (this, 0); 440 ev_init (this, 0);
434 } 441 }
435 442
436 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () 443 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
437 { 444 {
438 this->data = data; 445 this->data = (void *)data;
439 ev_set_cb (static_cast<ev_watcher *>(this), cb); 446 ev_set_cb (static_cast<ev_watcher *>(this), cb);
447 }
448
449 // function callback
450 template<void (*function)(watcher &w, int)>
451 void set (void *data = 0) throw ()
452 {
453 set_ (data, function_thunk<function>);
454 }
455
456 template<void (*function)(watcher &w, int)>
457 static void function_thunk (EV_P_ ev_watcher *w, int revents)
458 {
459 function
460 (*static_cast<watcher *>(w), revents);
440 } 461 }
441 462
442 // method callback 463 // method callback
443 template<class K, void (K::*method)(watcher &w, int)> 464 template<class K, void (K::*method)(watcher &w, int)>
444 void set (K *object) throw () 465 void set (K *object) throw ()
445 { 466 {
446 set_ (object, method_thunk<K, method>); 467 set_ (object, method_thunk<K, method>);
447 } 468 }
448 469
470 // default method == operator ()
471 template<class K>
472 void set (K *object) throw ()
473 {
474 set_ (object, method_thunk<K, &K::operator ()>);
475 }
476
449 template<class K, void (K::*method)(watcher &w, int)> 477 template<class K, void (K::*method)(watcher &w, int)>
450 static void method_thunk (EV_P_ ev_watcher *w, int revents) 478 static void method_thunk (EV_P_ ev_watcher *w, int revents)
451 { 479 {
452 K *obj = static_cast<K *>(w->data); 480 (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); 481 (*static_cast<watcher *>(w), revents);
481 } 482 }
482 483
483 // simple callback 484 // no-argument callback
484 template<class K, void (K::*method)()> 485 template<class K, void (K::*method)()>
485 void set (K *object) throw () 486 void set (K *object) throw ()
486 { 487 {
487 set_ (object, method_noargs_thunk<K, method>); 488 set_ (object, method_noargs_thunk<K, method>);
488 } 489 }
489 490
490 template<class K, void (K::*method)()> 491 template<class K, void (K::*method)()>
491 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 492 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
492 { 493 {
493 K *obj = static_cast<K *>(w->data); 494 (static_cast<K *>(w->data)->*method)
494 (obj->*method) (); 495 ();
495 } 496 }
496 497
497 void operator ()(int events = EV_UNDEF) 498 void operator ()(int events = EV_UNDEF)
498 { 499 {
500 return
499 return ev_cb (static_cast<ev_watcher *>(this)) 501 ev_cb (static_cast<ev_watcher *>(this))
500 (static_cast<ev_watcher *>(this), events); 502 (static_cast<ev_watcher *>(this), events);
501 } 503 }
502 504
503 bool is_active () const throw () 505 bool is_active () const throw ()
504 { 506 {
505 return ev_is_active (static_cast<const ev_watcher *>(this)); 507 return ev_is_active (static_cast<const ev_watcher *>(this));
561 ev_set_syserr_cb (cb); 563 ev_set_syserr_cb (cb);
562 } 564 }
563 565
564 #if EV_MULTIPLICITY 566 #if EV_MULTIPLICITY
565 #define EV_CONSTRUCT(cppstem,cstem) \ 567 #define EV_CONSTRUCT(cppstem,cstem) \
566 (EV_PX = get_default_loop ()) throw () \ 568 (EV_PX = get_default_loop ()) throw () \
567 : base<ev_ ## cstem, cppstem> (EV_A) \ 569 : base<ev_ ## cstem, cppstem> (EV_A) \
568 { \ 570 { \
569 } 571 }
570 #else 572 #else
571 #define EV_CONSTRUCT(cppstem,cstem) \ 573 #define EV_CONSTRUCT(cppstem,cstem) \
572 () throw () \ 574 () throw () \
573 { \ 575 { \
574 } 576 }
575 #endif 577 #endif
576 578
577 /* using a template here would require quite a bit more lines, 579 /* using a template here would require quite a bit more lines,
578 * so a macro solution was chosen */ 580 * so a macro solution was chosen */
579 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 581 #define EV_BEGIN_WATCHER(cppstem,cstem) \
580 \ 582 \
581 struct cppstem : base<ev_ ## cstem, cppstem> \ 583 struct cppstem : base<ev_ ## cstem, cppstem> \
582 { \ 584 { \
583 void start () throw () \ 585 void start () throw () \
584 { \ 586 { \
585 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 587 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
586 } \ 588 } \
587 \ 589 \
588 void stop () throw () \ 590 void stop () throw () \
589 { \ 591 { \
590 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 592 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
591 } \ 593 } \
592 \ 594 \
593 cppstem EV_CONSTRUCT(cppstem,cstem) \ 595 cppstem EV_CONSTRUCT(cppstem,cstem) \
594 \ 596 \
595 ~cppstem () throw () \ 597 ~cppstem () throw () \
596 { \ 598 { \
597 stop (); \ 599 stop (); \
598 } \ 600 } \
599 \ 601 \
600 using base<ev_ ## cstem, cppstem>::set; \ 602 using base<ev_ ## cstem, cppstem>::set; \
601 \ 603 \
602 private: \ 604 private: \
603 \ 605 \
604 cppstem (const cppstem &o); \ 606 cppstem (const cppstem &o); \
605 \ 607 \
606 cppstem & operator =(const cppstem &o); \ 608 cppstem &operator =(const cppstem &o); \
607 \ 609 \
608 public: 610 public:
609 611
610 #define EV_END_WATCHER(cppstem,cstem) \ 612 #define EV_END_WATCHER(cppstem,cstem) \
611 }; 613 };
651 653
652 void again () throw () 654 void again () throw ()
653 { 655 {
654 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 656 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
655 } 657 }
658
659 ev_tstamp remaining ()
660 {
661 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
662 }
656 EV_END_WATCHER (timer, timer) 663 EV_END_WATCHER (timer, timer)
657 664
658 #if EV_PERIODIC_ENABLE 665 #if EV_PERIODIC_ENABLE
659 EV_BEGIN_WATCHER (periodic, periodic) 666 EV_BEGIN_WATCHER (periodic, periodic)
660 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 667 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
676 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 683 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
677 } 684 }
678 EV_END_WATCHER (periodic, periodic) 685 EV_END_WATCHER (periodic, periodic)
679 #endif 686 #endif
680 687
688 #if EV_SIGNAL_ENABLE
681 EV_BEGIN_WATCHER (sig, signal) 689 EV_BEGIN_WATCHER (sig, signal)
682 void set (int signum) throw () 690 void set (int signum) throw ()
683 { 691 {
684 int active = is_active (); 692 int active = is_active ();
685 if (active) stop (); 693 if (active) stop ();
691 { 699 {
692 set (signum); 700 set (signum);
693 start (); 701 start ();
694 } 702 }
695 EV_END_WATCHER (sig, signal) 703 EV_END_WATCHER (sig, signal)
704 #endif
696 705
706 #if EV_CHILD_ENABLE
697 EV_BEGIN_WATCHER (child, child) 707 EV_BEGIN_WATCHER (child, child)
698 void set (int pid, int trace = 0) throw () 708 void set (int pid, int trace = 0) throw ()
699 { 709 {
700 int active = is_active (); 710 int active = is_active ();
701 if (active) stop (); 711 if (active) stop ();
707 { 717 {
708 set (pid, trace); 718 set (pid, trace);
709 start (); 719 start ();
710 } 720 }
711 EV_END_WATCHER (child, child) 721 EV_END_WATCHER (child, child)
722 #endif
712 723
713 #if EV_STAT_ENABLE 724 #if EV_STAT_ENABLE
714 EV_BEGIN_WATCHER (stat, stat) 725 EV_BEGIN_WATCHER (stat, stat)
715 void set (const char *path, ev_tstamp interval = 0.) throw () 726 void set (const char *path, ev_tstamp interval = 0.) throw ()
716 { 727 {
732 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 743 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
733 } 744 }
734 EV_END_WATCHER (stat, stat) 745 EV_END_WATCHER (stat, stat)
735 #endif 746 #endif
736 747
748 #if EV_IDLE_ENABLE
737 EV_BEGIN_WATCHER (idle, idle) 749 EV_BEGIN_WATCHER (idle, idle)
738 void set () throw () { } 750 void set () throw () { }
739 EV_END_WATCHER (idle, idle) 751 EV_END_WATCHER (idle, idle)
752 #endif
740 753
754 #if EV_PREPARE_ENABLE
741 EV_BEGIN_WATCHER (prepare, prepare) 755 EV_BEGIN_WATCHER (prepare, prepare)
742 void set () throw () { } 756 void set () throw () { }
743 EV_END_WATCHER (prepare, prepare) 757 EV_END_WATCHER (prepare, prepare)
758 #endif
744 759
760 #if EV_CHECK_ENABLE
745 EV_BEGIN_WATCHER (check, check) 761 EV_BEGIN_WATCHER (check, check)
746 void set () throw () { } 762 void set () throw () { }
747 EV_END_WATCHER (check, check) 763 EV_END_WATCHER (check, check)
764 #endif
748 765
749 #if EV_EMBED_ENABLE 766 #if EV_EMBED_ENABLE
750 EV_BEGIN_WATCHER (embed, embed) 767 EV_BEGIN_WATCHER (embed, embed)
768 void set (struct ev_loop *embedded_loop) throw ()
769 {
770 int active = is_active ();
771 if (active) stop ();
772 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
773 if (active) start ();
774 }
775
751 void start (struct ev_loop *embedded_loop) throw () 776 void start (struct ev_loop *embedded_loop) throw ()
752 { 777 {
753 stop (); 778 set (embedded_loop);
754 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
755 start (); 779 start ();
756 } 780 }
757 781
758 void sweep () 782 void sweep ()
759 { 783 {
764 788
765 #if EV_FORK_ENABLE 789 #if EV_FORK_ENABLE
766 EV_BEGIN_WATCHER (fork, fork) 790 EV_BEGIN_WATCHER (fork, fork)
767 void set () throw () { } 791 void set () throw () { }
768 EV_END_WATCHER (fork, fork) 792 EV_END_WATCHER (fork, fork)
793 #endif
794
795 #if EV_ASYNC_ENABLE
796 EV_BEGIN_WATCHER (async, async)
797 void send () throw ()
798 {
799 ev_async_send (EV_A_ static_cast<ev_async *>(this));
800 }
801
802 bool async_pending () throw ()
803 {
804 return ev_async_pending (static_cast<ev_async *>(this));
805 }
806 EV_END_WATCHER (async, async)
769 #endif 807 #endif
770 808
771 #undef EV_PX 809 #undef EV_PX
772 #undef EV_PX_ 810 #undef EV_PX_
773 #undef EV_CONSTRUCT 811 #undef EV_CONSTRUCT

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines