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.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
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
215 ev_loop_fork (EV_AX); 222 ev_loop_fork (EV_AX);
216#else
217 ev_default_fork ();
218#endif
219 }
220
221 unsigned int count () const throw ()
222 {
223 return ev_loop_count (EV_AX);
224 } 223 }
225 224
226 unsigned int backend () const throw () 225 unsigned int backend () const throw ()
227 { 226 {
228 return ev_backend (EV_AX); 227 return ev_backend (EV_AX);
241 void unref () throw () 240 void unref () throw ()
242 { 241 {
243 ev_unref (EV_AX); 242 ev_unref (EV_AX);
244 } 243 }
245 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
246 void set_io_collect_interval (tstamp interval) throw () 256 void set_io_collect_interval (tstamp interval) throw ()
247 { 257 {
248 ev_set_io_collect_interval (EV_AX_ interval); 258 ev_set_io_collect_interval (EV_AX_ interval);
249 } 259 }
250 260
251 void set_timeout_collect_interval (tstamp interval) throw () 261 void set_timeout_collect_interval (tstamp interval) throw ()
252 { 262 {
253 ev_set_timeout_collect_interval (EV_AX_ interval); 263 ev_set_timeout_collect_interval (EV_AX_ interval);
254 } 264 }
265#endif
255 266
256 // function callback 267 // function callback
257 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 ()
258 { 269 {
259 ev_once (EV_AX_ fd, events, timeout, cb, arg); 270 ev_once (EV_AX_ fd, events, timeout, cb, arg);
260 } 271 }
261 272
262 // method callback 273 // method callback
264 void once (int fd, int events, tstamp timeout, K *object) throw () 275 void once (int fd, int events, tstamp timeout, K *object) throw ()
265 { 276 {
266 once (fd, events, timeout, method_thunk<K, method>, object); 277 once (fd, events, timeout, method_thunk<K, method>, object);
267 } 278 }
268 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
269 template<class K, void (K::*method)(int)> 287 template<class K, void (K::*method)(int)>
270 static void method_thunk (int revents, void* arg) 288 static void method_thunk (int revents, void *arg)
271 {
272 K *obj = static_cast<K *>(arg);
273 (obj->*method) (revents);
274 } 289 {
290 static_cast<K *>(arg)->*method
291 (revents);
292 }
275 293
276 // const method callback 294 // 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)()> 295 template<class K, void (K::*method)()>
292 void once (int fd, int events, tstamp timeout, K *object) throw () 296 void once (int fd, int events, tstamp timeout, K *object) throw ()
293 { 297 {
294 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 298 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
295 } 299 }
296 300
297 template<class K, void (K::*method)()> 301 template<class K, void (K::*method)()>
298 static void method_noargs_thunk (int revents, void* arg) 302 static void method_noargs_thunk (int revents, void *arg)
299 { 303 {
300 K *obj = static_cast<K *>(arg); 304 static_cast<K *>(arg)->*method
301 (obj->*method) (); 305 ();
302 } 306 }
303 307
304 // simpler function callback 308 // simpler function callback
305 template<void (*cb)(int)> 309 template<void (*cb)(int)>
306 void once (int fd, int events, tstamp timeout) throw () 310 void once (int fd, int events, tstamp timeout) throw ()
307 { 311 {
308 once (fd, events, timeout, simpler_func_thunk<cb>); 312 once (fd, events, timeout, simpler_func_thunk<cb>);
309 } 313 }
310 314
311 template<void (*cb)(int)> 315 template<void (*cb)(int)>
312 static void simpler_func_thunk (int revents, void* arg) 316 static void simpler_func_thunk (int revents, void *arg)
313 { 317 {
318 (*cb)
314 (*cb) (revents); 319 (revents);
315 } 320 }
316 321
317 // simplest function callback 322 // simplest function callback
318 template<void (*cb)()> 323 template<void (*cb)()>
319 void once (int fd, int events, tstamp timeout) throw () 324 void once (int fd, int events, tstamp timeout) throw ()
320 { 325 {
321 once (fd, events, timeout, simplest_func_thunk<cb>); 326 once (fd, events, timeout, simplest_func_thunk<cb>);
322 } 327 }
323 328
324 template<void (*cb)()> 329 template<void (*cb)()>
325 static void simplest_func_thunk (int revents, void* arg) 330 static void simplest_func_thunk (int revents, void *arg)
326 { 331 {
327 (*cb) (); 332 (*cb)
333 ();
328 } 334 }
329 335
330 void feed_fd_event (int fd, int revents) throw () 336 void feed_fd_event (int fd, int revents) throw ()
331 { 337 {
332 ev_feed_fd_event (EV_AX_ fd, revents); 338 ev_feed_fd_event (EV_AX_ fd, revents);
342#endif 348#endif
343 349
344 }; 350 };
345 351
346#if EV_MULTIPLICITY 352#if EV_MULTIPLICITY
347 struct dynamic_loop: loop_ref 353 struct dynamic_loop : loop_ref
348 { 354 {
349 355
350 dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 356 dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
351 : loop_ref (ev_loop_new (flags)) 357 : loop_ref (ev_loop_new (flags))
352 { 358 {
359 if (!EV_AX)
360 throw bad_loop ();
353 } 361 }
354 362
355 ~dynamic_loop () throw () 363 ~dynamic_loop () throw ()
356 { 364 {
357 ev_loop_destroy (EV_AX); 365 ev_loop_destroy (EV_AX);
365 dynamic_loop & operator= (const dynamic_loop &); 373 dynamic_loop & operator= (const dynamic_loop &);
366 374
367 }; 375 };
368#endif 376#endif
369 377
370 struct default_loop: loop_ref 378 struct default_loop : loop_ref
371 { 379 {
372
373 default_loop (unsigned int flags = AUTO) throw (bad_loop) 380 default_loop (unsigned int flags = AUTO) throw (bad_loop)
374#if EV_MULTIPLICITY 381#if EV_MULTIPLICITY
375 : loop_ref (ev_default_loop (flags)) 382 : loop_ref (ev_default_loop (flags))
376#endif 383#endif
377 { 384 {
385 if (
378#ifndef EV_MULTIPLICITY 386#if EV_MULTIPLICITY
387 !EV_AX
388#else
379 if (!ev_default_loop (flags)) 389 !ev_default_loop (flags)
390#endif
391 )
380 throw bad_loop (); 392 throw bad_loop ();
381#endif
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) 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 ();
702 ev_child_set (static_cast<ev_child *>(this), pid); 712 ev_child_set (static_cast<ev_child *>(this), pid, trace);
703 if (active) start (); 713 if (active) start ();
704 } 714 }
705 715
706 void start (int pid) throw () 716 void start (int pid, int trace = 0) throw ()
707 { 717 {
708 set (pid); 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
774 #undef EV_BEGIN_WATCHER 812 #undef EV_BEGIN_WATCHER
775 #undef EV_END_WATCHER 813 #undef EV_END_WATCHER
776
777} 814}
778 815
779#undef EV_THROW
780
781#endif 816#endif
782 817

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines