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

Comparing libev/ev++.h (file contents):
Revision 1.31 by root, Sat Jan 19 00:39:38 2008 UTC vs.
Revision 1.45 by root, Fri Jul 10 00:36:21 2009 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 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 *
44# include EV_H 44# include EV_H
45#else 45#else
46# include "ev.h" 46# include "ev.h"
47#endif 47#endif
48 48
49#ifndef EV_CXX_EXCEPTIONS 49#ifndef EV_USE_STDEXCEPT
50#define EV_CXX_EXCEPTIONS 1 50# define EV_USE_STDEXCEPT 1
51#endif 51#endif
52 52
53#undef EV_THROW 53#if EV_USE_STDEXCEPT
54#if EV_CXX_EXCEPTIONS
55# include <stdexcept> 54# include <stdexcept>
56# define EV_THROW(exception) throw (exception)
57#else
58# define EV_THROW(exception)
59#endif 55#endif
60 56
61namespace ev { 57namespace ev {
62 58
63 typedef ev_tstamp tstamp; 59 typedef ev_tstamp tstamp;
64 60
65 enum { 61 enum
62 {
66 UNDEF = EV_UNDEF, 63 UNDEF = EV_UNDEF,
67 NONE = EV_NONE, 64 NONE = EV_NONE,
68 READ = EV_READ, 65 READ = EV_READ,
69 WRITE = EV_WRITE, 66 WRITE = EV_WRITE,
70 TIMEOUT = EV_TIMEOUT, 67 TIMEOUT = EV_TIMEOUT,
74 STAT = EV_STAT, 71 STAT = EV_STAT,
75 IDLE = EV_IDLE, 72 IDLE = EV_IDLE,
76 CHECK = EV_CHECK, 73 CHECK = EV_CHECK,
77 PREPARE = EV_PREPARE, 74 PREPARE = EV_PREPARE,
78 FORK = EV_FORK, 75 FORK = EV_FORK,
76 ASYNC = EV_ASYNC,
79 EMBED = EV_EMBED, 77 EMBED = EV_EMBED,
78# undef ERROR // some systems stupidly #define ERROR
80 ERROR = EV_ERROR, 79 ERROR = EV_ERROR,
81 }; 80 };
82 81
83 enum 82 enum
84 { 83 {
85 AUTO = EVFLAG_AUTO, 84 AUTO = EVFLAG_AUTO,
86 NOENV = EVFLAG_NOENV, 85 NOENV = EVFLAG_NOENV,
87 FORKCHECK = EVFLAG_FORKCHECK, 86 FORKCHECK = EVFLAG_FORKCHECK,
87
88 SELECT = EVBACKEND_SELECT, 88 SELECT = EVBACKEND_SELECT,
89 POLL = EVBACKEND_POLL, 89 POLL = EVBACKEND_POLL,
90 EPOLL = EVBACKEND_EPOLL, 90 EPOLL = EVBACKEND_EPOLL,
91 KQUEUE = EVBACKEND_KQUEUE, 91 KQUEUE = EVBACKEND_KQUEUE,
92 DEVPOLL = EVBACKEND_DEVPOLL, 92 DEVPOLL = EVBACKEND_DEVPOLL,
93 PORT = EVBACKEND_PORT 93 PORT = EVBACKEND_PORT
94 }; 94 };
95 95
96 enum 96 enum
97 { 97 {
98 NONBLOCK = EVLOOP_NONBLOCK, 98 NONBLOCK = EVLOOP_NONBLOCK,
99 ONESHOT = EVLOOP_ONESHOT 99 ONESHOT = EVLOOP_ONESHOT
100 }; 100 };
101 101
102 enum how_t 102 enum how_t
103 { 103 {
104 ONE = EVUNLOOP_ONE, 104 ONE = EVUNLOOP_ONE,
105 ALL = EVUNLOOP_ALL 105 ALL = EVUNLOOP_ALL
106 }; 106 };
107 107
108#if EV_CXX_EXCEPTIONS 108 struct bad_loop
109 struct bad_loop : std::runtime_error 109#if EV_USE_STDEXCEPT
110 : std::runtime_error
111#endif
110 { 112 {
113#if EV_USE_STDEXCEPT
111 bad_loop () 114 bad_loop ()
112 : std::runtime_error ("loop can't be initialized") 115 : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?")
113 {
114 } 116 {
115 }; 117 }
116#endif 118#endif
119 };
117 120
118#ifdef EV_AX 121#ifdef EV_AX
119# undef EV_AX 122# undef EV_AX
120#endif 123#endif
121 124
131# define EV_AX_ 134# define EV_AX_
132#endif 135#endif
133 136
134 struct loop_ref 137 struct loop_ref
135 { 138 {
136
137 loop_ref (EV_P) 139 loop_ref (EV_P) throw ()
138#if EV_MULTIPLICITY 140#if EV_MULTIPLICITY
139 EV_THROW (bad_loop) : EV_AX (EV_A) 141 : EV_AX (EV_A)
140#endif 142#endif
141 {
142#if EV_MULTIPLICIY && EV_CXX_EXCEPTIONS
143 if (!EV_A)
144 throw bad_loop ();
145#endif
146 } 143 {
144 }
147 145
148 bool operator== (const loop_ref &other) const throw () 146 bool operator == (const loop_ref &other) const throw ()
149 { 147 {
150#if EV_MULTIPLICITY 148#if EV_MULTIPLICITY
151 return this->EV_AX == other.EV_AX; 149 return EV_AX == other.EV_AX;
152#else 150#else
153 return true; 151 return true;
154#endif 152#endif
155 } 153 }
156 154
157 bool operator!= (const loop_ref &other) const throw () 155 bool operator != (const loop_ref &other) const throw ()
158 { 156 {
159#if EV_MULTIPLICITY 157#if EV_MULTIPLICITY
160 return ! (*this == other); 158 return ! (*this == other);
161#else 159#else
162 return false; 160 return false;
163#endif 161#endif
164 } 162 }
165 163
166#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
167 bool operator== (struct ev_loop *other) const throw () 165 bool operator == (const EV_P) const throw ()
168 { 166 {
169 return this->EV_AX == other; 167 return this->EV_AX == EV_A;
170 }
171
172 bool operator!= (struct ev_loop *other) const throw ()
173 { 168 }
174 return ! (*this == other); 169
170 bool operator != (const EV_P) const throw ()
175 } 171 {
176
177 bool operator== (const struct ev_loop *other) const throw ()
178 {
179 return this->EV_AX == other;
180 }
181
182 bool operator!= (const struct ev_loop *other) const throw ()
183 {
184 return (*this == other); 172 return (*this == EV_A);
185 } 173 }
186 174
187 operator struct ev_loop * () const throw () 175 operator struct ev_loop * () const throw ()
188 { 176 {
189 return EV_AX; 177 return EV_AX;
217#else 205#else
218 ev_default_fork (); 206 ev_default_fork ();
219#endif 207#endif
220 } 208 }
221 209
210 unsigned int backend () const throw ()
211 {
212 return ev_backend (EV_AX);
213 }
214
215 tstamp now () const throw ()
216 {
217 return ev_now (EV_AX);
218 }
219
220 void ref () throw ()
221 {
222 ev_ref (EV_AX);
223 }
224
225 void unref () throw ()
226 {
227 ev_unref (EV_AX);
228 }
229
230#if EV_MINIMAL < 2
222 unsigned int count () const throw () 231 unsigned int count () const throw ()
223 { 232 {
224 return ev_loop_count (EV_AX); 233 return ev_loop_count (EV_AX);
225 } 234 }
226 235
227 unsigned int backend () const throw () 236 unsigned int depth () const throw ()
228 {
229 return ev_backend (EV_AX);
230 } 237 {
231
232 tstamp now () const throw ()
233 {
234 return ev_now (EV_AX); 238 return ev_loop_depth (EV_AX);
235 }
236
237 void ref () throw ()
238 {
239 ev_ref (EV_AX);
240 }
241
242 void unref () throw ()
243 {
244 ev_unref (EV_AX);
245 } 239 }
246 240
247 void set_io_collect_interval (tstamp interval) throw () 241 void set_io_collect_interval (tstamp interval) throw ()
248 { 242 {
249 ev_set_io_collect_interval (EV_AX_ interval); 243 ev_set_io_collect_interval (EV_AX_ interval);
251 245
252 void set_timeout_collect_interval (tstamp interval) throw () 246 void set_timeout_collect_interval (tstamp interval) throw ()
253 { 247 {
254 ev_set_timeout_collect_interval (EV_AX_ interval); 248 ev_set_timeout_collect_interval (EV_AX_ interval);
255 } 249 }
250#endif
256 251
257 // function callback 252 // function callback
258 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 ()
259 { 254 {
260 ev_once (EV_AX_ fd, events, timeout, cb, arg); 255 ev_once (EV_AX_ fd, events, timeout, cb, arg);
261 } 256 }
262 257
263 // method callback 258 // method callback
265 void once (int fd, int events, tstamp timeout, K *object) throw () 260 void once (int fd, int events, tstamp timeout, K *object) throw ()
266 { 261 {
267 once (fd, events, timeout, method_thunk<K, method>, object); 262 once (fd, events, timeout, method_thunk<K, method>, object);
268 } 263 }
269 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
270 template<class K, void (K::*method)(int)> 272 template<class K, void (K::*method)(int)>
271 static void method_thunk (int revents, void* arg) 273 static void method_thunk (int revents, void *arg)
272 {
273 K *obj = static_cast<K *>(arg);
274 (obj->*method) (revents);
275 } 274 {
275 static_cast<K *>(arg)->*method
276 (revents);
277 }
276 278
277 // const method callback 279 // no-argument method callback
278 template<class K, void (K::*method)(int) const>
279 void once (int fd, int events, tstamp timeout, const K *object) throw ()
280 {
281 once (fd, events, timeout, const_method_thunk<K, method>, object);
282 }
283
284 template<class K, void (K::*method)(int) const>
285 static void const_method_thunk (int revents, void* arg)
286 {
287 K *obj = static_cast<K *>(arg);
288 (obj->*method) (revents);
289 }
290
291 // simple method callback
292 template<class K, void (K::*method)()> 280 template<class K, void (K::*method)()>
293 void once (int fd, int events, tstamp timeout, K *object) throw () 281 void once (int fd, int events, tstamp timeout, K *object) throw ()
294 { 282 {
295 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 283 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
296 } 284 }
297 285
298 template<class K, void (K::*method)()> 286 template<class K, void (K::*method)()>
299 static void method_noargs_thunk (int revents, void* arg) 287 static void method_noargs_thunk (int revents, void *arg)
300 { 288 {
301 K *obj = static_cast<K *>(arg); 289 static_cast<K *>(arg)->*method
302 (obj->*method) (); 290 ();
303 } 291 }
304 292
305 // simpler function callback 293 // simpler function callback
306 template<void (*cb)(int)> 294 template<void (*cb)(int)>
307 void once (int fd, int events, tstamp timeout) throw () 295 void once (int fd, int events, tstamp timeout) throw ()
308 { 296 {
309 once (fd, events, timeout, simpler_func_thunk<cb>); 297 once (fd, events, timeout, simpler_func_thunk<cb>);
310 } 298 }
311 299
312 template<void (*cb)(int)> 300 template<void (*cb)(int)>
313 static void simpler_func_thunk (int revents, void* arg) 301 static void simpler_func_thunk (int revents, void *arg)
314 { 302 {
303 (*cb)
315 (*cb) (revents); 304 (revents);
316 } 305 }
317 306
318 // simplest function callback 307 // simplest function callback
319 template<void (*cb)()> 308 template<void (*cb)()>
320 void once (int fd, int events, tstamp timeout) throw () 309 void once (int fd, int events, tstamp timeout) throw ()
321 { 310 {
322 once (fd, events, timeout, simplest_func_thunk<cb>); 311 once (fd, events, timeout, simplest_func_thunk<cb>);
323 } 312 }
324 313
325 template<void (*cb)()> 314 template<void (*cb)()>
326 static void simplest_func_thunk (int revents, void* arg) 315 static void simplest_func_thunk (int revents, void *arg)
327 { 316 {
328 (*cb) (); 317 (*cb)
318 ();
329 } 319 }
330 320
331 void feed_fd_event (int fd, int revents) throw () 321 void feed_fd_event (int fd, int revents) throw ()
332 { 322 {
333 ev_feed_fd_event (EV_AX_ fd, revents); 323 ev_feed_fd_event (EV_AX_ fd, revents);
343#endif 333#endif
344 334
345 }; 335 };
346 336
347#if EV_MULTIPLICITY 337#if EV_MULTIPLICITY
348 struct dynamic_loop: loop_ref 338 struct dynamic_loop : loop_ref
349 { 339 {
350 340
351 dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 341 dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
352 : loop_ref (ev_loop_new (flags)) 342 : loop_ref (ev_loop_new (flags))
353 { 343 {
344 if (!EV_AX)
345 throw bad_loop ();
354 } 346 }
355 347
356 ~dynamic_loop () throw () 348 ~dynamic_loop () throw ()
357 { 349 {
358 ev_loop_destroy (EV_AX); 350 ev_loop_destroy (EV_AX);
366 dynamic_loop & operator= (const dynamic_loop &); 358 dynamic_loop & operator= (const dynamic_loop &);
367 359
368 }; 360 };
369#endif 361#endif
370 362
371 struct default_loop: loop_ref 363 struct default_loop : loop_ref
372 { 364 {
373
374 default_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 365 default_loop (unsigned int flags = AUTO) throw (bad_loop)
375#if EV_MULTIPLICITY 366#if EV_MULTIPLICITY
376 : loop_ref (ev_default_loop (flags)) 367 : loop_ref (ev_default_loop (flags))
377 { 368#endif
378 } 369 {
370 if (
371#if EV_MULTIPLICITY
372 !EV_AX
379#else 373#else
380 {
381 #if EV_CXX_EXCEPTIONS
382 int r =
383 #endif
384 ev_default_loop (flags); 374 !ev_default_loop (flags)
385 #if EV_CXX_EXCEPTIONS 375#endif
386 if (!r) 376 )
387 throw bad_loop (); 377 throw bad_loop ();
388 #endif
389 } 378 }
390#endif
391 379
392 ~default_loop () throw () 380 ~default_loop () throw ()
393 { 381 {
394 ev_default_destroy (); 382 ev_default_destroy ();
395#if EV_MULTIPLICITY
396 EV_AX = 0;
397#endif
398 } 383 }
399 384
400 private: 385 private:
401
402 default_loop (const default_loop &); 386 default_loop (const default_loop &);
403
404 default_loop & operator= (const default_loop &); 387 default_loop &operator = (const default_loop &);
405
406 }; 388 };
407 389
408 inline loop_ref get_default_loop () throw () 390 inline loop_ref get_default_loop () throw ()
409 { 391 {
410#if EV_MULTIPLICITY 392#if EV_MULTIPLICITY
431 struct base : ev_watcher 413 struct base : ev_watcher
432 { 414 {
433 #if EV_MULTIPLICITY 415 #if EV_MULTIPLICITY
434 EV_PX; 416 EV_PX;
435 417
436 void set (EV_PX) throw () 418 void set (EV_P) throw ()
437 { 419 {
438 this->EV_A = EV_A; 420 this->EV_A = EV_A;
439 } 421 }
440 #endif 422 #endif
441 423
445 #endif 427 #endif
446 { 428 {
447 ev_init (this, 0); 429 ev_init (this, 0);
448 } 430 }
449 431
450 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () 432 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
451 { 433 {
452 this->data = data; 434 this->data = (void *)data;
453 ev_set_cb (static_cast<ev_watcher *>(this), cb); 435 ev_set_cb (static_cast<ev_watcher *>(this), cb);
436 }
437
438 // function callback
439 template<void (*function)(watcher &w, int)>
440 void set (void *data = 0) throw ()
441 {
442 set_ (data, function_thunk<function>);
443 }
444
445 template<void (*function)(watcher &w, int)>
446 static void function_thunk (EV_P_ ev_watcher *w, int revents)
447 {
448 function
449 (*static_cast<watcher *>(w), revents);
454 } 450 }
455 451
456 // method callback 452 // method callback
457 template<class K, void (K::*method)(watcher &w, int)> 453 template<class K, void (K::*method)(watcher &w, int)>
458 void set (K *object) throw () 454 void set (K *object) throw ()
459 { 455 {
460 set_ (object, method_thunk<K, method>); 456 set_ (object, method_thunk<K, method>);
461 } 457 }
462 458
459 // default method == operator ()
460 template<class K>
461 void set (K *object) throw ()
462 {
463 set_ (object, method_thunk<K, &K::operator ()>);
464 }
465
463 template<class K, void (K::*method)(watcher &w, int)> 466 template<class K, void (K::*method)(watcher &w, int)>
464 static void method_thunk (EV_P_ ev_watcher *w, int revents) 467 static void method_thunk (EV_P_ ev_watcher *w, int revents)
465 { 468 {
466 K *obj = static_cast<K *>(w->data); 469 (static_cast<K *>(w->data)->*method)
467 (obj->*method) (*static_cast<watcher *>(w), revents);
468 }
469
470 // const method callback
471 template<class K, void (K::*method)(watcher &w, int) const>
472 void set (const K *object) throw ()
473 {
474 set_ (object, const_method_thunk<K, method>);
475 }
476
477 template<class K, void (K::*method)(watcher &w, int) const>
478 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
479 {
480 K *obj = static_cast<K *>(w->data);
481 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
482 }
483
484 // function callback
485 template<void (*function)(watcher &w, int)>
486 void set (void *data = 0) throw ()
487 {
488 set_ (data, function_thunk<function>);
489 }
490
491 template<void (*function)(watcher &w, int)>
492 static void function_thunk (EV_P_ ev_watcher *w, int revents)
493 {
494 function (*static_cast<watcher *>(w), revents); 470 (*static_cast<watcher *>(w), revents);
495 } 471 }
496 472
497 // simple callback 473 // no-argument callback
498 template<class K, void (K::*method)()> 474 template<class K, void (K::*method)()>
499 void set (K *object) throw () 475 void set (K *object) throw ()
500 { 476 {
501 set_ (object, method_noargs_thunk<K, method>); 477 set_ (object, method_noargs_thunk<K, method>);
502 } 478 }
503 479
504 template<class K, void (K::*method)()> 480 template<class K, void (K::*method)()>
505 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 481 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
506 { 482 {
507 K *obj = static_cast<K *>(w->data); 483 static_cast<K *>(w->data)->*method
508 (obj->*method) (); 484 ();
509 } 485 }
510 486
511 void operator ()(int events = EV_UNDEF) 487 void operator ()(int events = EV_UNDEF)
512 { 488 {
489 return
513 return ev_cb (static_cast<ev_watcher *>(this)) 490 ev_cb (static_cast<ev_watcher *>(this))
514 (static_cast<ev_watcher *>(this), events); 491 (static_cast<ev_watcher *>(this), events);
515 } 492 }
516 493
517 bool is_active () const throw () 494 bool is_active () const throw ()
518 { 495 {
519 return ev_is_active (static_cast<const ev_watcher *>(this)); 496 return ev_is_active (static_cast<const ev_watcher *>(this));
575 ev_set_syserr_cb (cb); 552 ev_set_syserr_cb (cb);
576 } 553 }
577 554
578 #if EV_MULTIPLICITY 555 #if EV_MULTIPLICITY
579 #define EV_CONSTRUCT(cppstem,cstem) \ 556 #define EV_CONSTRUCT(cppstem,cstem) \
580 (EV_PX = get_default_loop ()) throw () \ 557 (EV_PX = get_default_loop ()) throw () \
581 : base<ev_ ## cstem, cppstem> (EV_A) \ 558 : base<ev_ ## cstem, cppstem> (EV_A) \
582 { \ 559 { \
583 } 560 }
584 #else 561 #else
585 #define EV_CONSTRUCT(cppstem,cstem) \ 562 #define EV_CONSTRUCT(cppstem,cstem) \
586 () throw () \ 563 () throw () \
587 { \ 564 { \
588 } 565 }
589 #endif 566 #endif
590 567
591 /* using a template here would require quite a bit more lines, 568 /* using a template here would require quite a bit more lines,
592 * so a macro solution was chosen */ 569 * so a macro solution was chosen */
593 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 570 #define EV_BEGIN_WATCHER(cppstem,cstem) \
594 \ 571 \
595 struct cppstem : base<ev_ ## cstem, cppstem> \ 572 struct cppstem : base<ev_ ## cstem, cppstem> \
596 { \ 573 { \
597 void start () throw () \ 574 void start () throw () \
598 { \ 575 { \
599 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 576 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
600 } \ 577 } \
601 \ 578 \
602 void stop () throw () \ 579 void stop () throw () \
603 { \ 580 { \
604 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 581 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
605 } \ 582 } \
606 \ 583 \
607 cppstem EV_CONSTRUCT(cppstem,cstem) \ 584 cppstem EV_CONSTRUCT(cppstem,cstem) \
608 \ 585 \
609 ~cppstem () throw () \ 586 ~cppstem () throw () \
610 { \ 587 { \
611 stop (); \ 588 stop (); \
612 } \ 589 } \
613 \ 590 \
614 using base<ev_ ## cstem, cppstem>::set; \ 591 using base<ev_ ## cstem, cppstem>::set; \
615 \ 592 \
616 private: \ 593 private: \
617 \ 594 \
618 cppstem (const cppstem &o); \ 595 cppstem (const cppstem &o); \
619 \ 596 \
620 cppstem & operator =(const cppstem &o); \ 597 cppstem &operator =(const cppstem &o); \
621 \ 598 \
622 public: 599 public:
623 600
624 #define EV_END_WATCHER(cppstem,cstem) \ 601 #define EV_END_WATCHER(cppstem,cstem) \
625 }; 602 };
707 start (); 684 start ();
708 } 685 }
709 EV_END_WATCHER (sig, signal) 686 EV_END_WATCHER (sig, signal)
710 687
711 EV_BEGIN_WATCHER (child, child) 688 EV_BEGIN_WATCHER (child, child)
712 void set (int pid) throw () 689 void set (int pid, int trace = 0) throw ()
713 { 690 {
714 int active = is_active (); 691 int active = is_active ();
715 if (active) stop (); 692 if (active) stop ();
716 ev_child_set (static_cast<ev_child *>(this), pid); 693 ev_child_set (static_cast<ev_child *>(this), pid, trace);
717 if (active) start (); 694 if (active) start ();
718 } 695 }
719 696
720 void start (int pid) throw () 697 void start (int pid, int trace = 0) throw ()
721 { 698 {
722 set (pid); 699 set (pid, trace);
723 start (); 700 start ();
724 } 701 }
725 EV_END_WATCHER (child, child) 702 EV_END_WATCHER (child, child)
726 703
727 #if EV_STAT_ENABLE 704 #if EV_STAT_ENABLE
760 void set () throw () { } 737 void set () throw () { }
761 EV_END_WATCHER (check, check) 738 EV_END_WATCHER (check, check)
762 739
763 #if EV_EMBED_ENABLE 740 #if EV_EMBED_ENABLE
764 EV_BEGIN_WATCHER (embed, embed) 741 EV_BEGIN_WATCHER (embed, embed)
742 void set (struct ev_loop *embedded_loop) throw ()
743 {
744 int active = is_active ();
745 if (active) stop ();
746 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
747 if (active) start ();
748 }
749
765 void start (struct ev_loop *embedded_loop) throw () 750 void start (struct ev_loop *embedded_loop) throw ()
766 { 751 {
767 stop (); 752 set (embedded_loop);
768 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
769 start (); 753 start ();
770 } 754 }
771 755
772 void sweep () 756 void sweep ()
773 { 757 {
780 EV_BEGIN_WATCHER (fork, fork) 764 EV_BEGIN_WATCHER (fork, fork)
781 void set () throw () { } 765 void set () throw () { }
782 EV_END_WATCHER (fork, fork) 766 EV_END_WATCHER (fork, fork)
783 #endif 767 #endif
784 768
769 #if EV_ASYNC_ENABLE
770 EV_BEGIN_WATCHER (async, async)
771 void set () throw () { }
772
773 void send () throw ()
774 {
775 ev_async_send (EV_A_ static_cast<ev_async *>(this));
776 }
777
778 bool async_pending () throw ()
779 {
780 return ev_async_pending (static_cast<ev_async *>(this));
781 }
782 EV_END_WATCHER (async, async)
783 #endif
784
785 #undef EV_PX 785 #undef EV_PX
786 #undef EV_PX_ 786 #undef EV_PX_
787 #undef EV_CONSTRUCT 787 #undef EV_CONSTRUCT
788 #undef EV_BEGIN_WATCHER 788 #undef EV_BEGIN_WATCHER
789 #undef EV_END_WATCHER 789 #undef EV_END_WATCHER
790
791} 790}
792 791
793#undef EV_THROW
794
795#endif 792#endif
796 793

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines