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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines