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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines