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.53 by root, Thu Oct 21 14:50:58 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 *
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
222 unsigned int count () const throw ()
223 {
224 return ev_loop_count (EV_AX);
225 }
226
227 unsigned int backend () const throw () 210 unsigned int backend () const throw ()
228 { 211 {
229 return ev_backend (EV_AX); 212 return ev_backend (EV_AX);
230 } 213 }
231 214
242 void unref () throw () 225 void unref () throw ()
243 { 226 {
244 ev_unref (EV_AX); 227 ev_unref (EV_AX);
245 } 228 }
246 229
230#if EV_FEATURE_API
231 unsigned int iteration () const throw ()
232 {
233 return ev_iteration (EV_AX);
234 }
235
236 unsigned int depth () const throw ()
237 {
238 return ev_depth (EV_AX);
239 }
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);
250 } 244 }
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
418 // loop set
436 void set (EV_PX) throw () 419 void set (EV_P) throw ()
437 { 420 {
438 this->EV_A = EV_A; 421 this->EV_A = EV_A;
439 } 422 }
440 #endif 423 #endif
441 424
445 #endif 428 #endif
446 { 429 {
447 ev_init (this, 0); 430 ev_init (this, 0);
448 } 431 }
449 432
450 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () 433 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
451 { 434 {
452 this->data = data; 435 this->data = (void *)data;
453 ev_set_cb (static_cast<ev_watcher *>(this), cb); 436 ev_set_cb (static_cast<ev_watcher *>(this), cb);
437 }
438
439 // function callback
440 template<void (*function)(watcher &w, int)>
441 void set (void *data = 0) throw ()
442 {
443 set_ (data, function_thunk<function>);
444 }
445
446 template<void (*function)(watcher &w, int)>
447 static void function_thunk (EV_P_ ev_watcher *w, int revents)
448 {
449 function
450 (*static_cast<watcher *>(w), revents);
454 } 451 }
455 452
456 // method callback 453 // method callback
457 template<class K, void (K::*method)(watcher &w, int)> 454 template<class K, void (K::*method)(watcher &w, int)>
458 void set (K *object) throw () 455 void set (K *object) throw ()
459 { 456 {
460 set_ (object, method_thunk<K, method>); 457 set_ (object, method_thunk<K, method>);
461 } 458 }
462 459
460 // default method == operator ()
461 template<class K>
462 void set (K *object) throw ()
463 {
464 set_ (object, method_thunk<K, &K::operator ()>);
465 }
466
463 template<class K, void (K::*method)(watcher &w, int)> 467 template<class K, void (K::*method)(watcher &w, int)>
464 static void method_thunk (EV_P_ ev_watcher *w, int revents) 468 static void method_thunk (EV_P_ ev_watcher *w, int revents)
465 { 469 {
466 K *obj = static_cast<K *>(w->data); 470 (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); 471 (*static_cast<watcher *>(w), revents);
495 } 472 }
496 473
497 // simple callback 474 // no-argument callback
498 template<class K, void (K::*method)()> 475 template<class K, void (K::*method)()>
499 void set (K *object) throw () 476 void set (K *object) throw ()
500 { 477 {
501 set_ (object, method_noargs_thunk<K, method>); 478 set_ (object, method_noargs_thunk<K, method>);
502 } 479 }
503 480
504 template<class K, void (K::*method)()> 481 template<class K, void (K::*method)()>
505 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 482 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
506 { 483 {
507 K *obj = static_cast<K *>(w->data); 484 (static_cast<K *>(w->data)->*method)
508 (obj->*method) (); 485 ();
509 } 486 }
510 487
511 void operator ()(int events = EV_UNDEF) 488 void operator ()(int events = EV_UNDEF)
512 { 489 {
490 return
513 return ev_cb (static_cast<ev_watcher *>(this)) 491 ev_cb (static_cast<ev_watcher *>(this))
514 (static_cast<ev_watcher *>(this), events); 492 (static_cast<ev_watcher *>(this), events);
515 } 493 }
516 494
517 bool is_active () const throw () 495 bool is_active () const throw ()
518 { 496 {
519 return ev_is_active (static_cast<const ev_watcher *>(this)); 497 return ev_is_active (static_cast<const ev_watcher *>(this));
575 ev_set_syserr_cb (cb); 553 ev_set_syserr_cb (cb);
576 } 554 }
577 555
578 #if EV_MULTIPLICITY 556 #if EV_MULTIPLICITY
579 #define EV_CONSTRUCT(cppstem,cstem) \ 557 #define EV_CONSTRUCT(cppstem,cstem) \
580 (EV_PX = get_default_loop ()) throw () \ 558 (EV_PX = get_default_loop ()) throw () \
581 : base<ev_ ## cstem, cppstem> (EV_A) \ 559 : base<ev_ ## cstem, cppstem> (EV_A) \
582 { \ 560 { \
583 } 561 }
584 #else 562 #else
585 #define EV_CONSTRUCT(cppstem,cstem) \ 563 #define EV_CONSTRUCT(cppstem,cstem) \
586 () throw () \ 564 () throw () \
587 { \ 565 { \
588 } 566 }
589 #endif 567 #endif
590 568
591 /* using a template here would require quite a bit more lines, 569 /* using a template here would require quite a bit more lines,
592 * so a macro solution was chosen */ 570 * so a macro solution was chosen */
593 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 571 #define EV_BEGIN_WATCHER(cppstem,cstem) \
594 \ 572 \
595 struct cppstem : base<ev_ ## cstem, cppstem> \ 573 struct cppstem : base<ev_ ## cstem, cppstem> \
596 { \ 574 { \
597 void start () throw () \ 575 void start () throw () \
598 { \ 576 { \
599 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 577 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
600 } \ 578 } \
601 \ 579 \
602 void stop () throw () \ 580 void stop () throw () \
603 { \ 581 { \
604 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 582 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
605 } \ 583 } \
606 \ 584 \
607 cppstem EV_CONSTRUCT(cppstem,cstem) \ 585 cppstem EV_CONSTRUCT(cppstem,cstem) \
608 \ 586 \
609 ~cppstem () throw () \ 587 ~cppstem () throw () \
610 { \ 588 { \
611 stop (); \ 589 stop (); \
612 } \ 590 } \
613 \ 591 \
614 using base<ev_ ## cstem, cppstem>::set; \ 592 using base<ev_ ## cstem, cppstem>::set; \
615 \ 593 \
616 private: \ 594 private: \
617 \ 595 \
618 cppstem (const cppstem &o); \ 596 cppstem (const cppstem &o); \
619 \ 597 \
620 cppstem & operator =(const cppstem &o); \ 598 cppstem &operator =(const cppstem &o); \
621 \ 599 \
622 public: 600 public:
623 601
624 #define EV_END_WATCHER(cppstem,cstem) \ 602 #define EV_END_WATCHER(cppstem,cstem) \
625 }; 603 };
665 643
666 void again () throw () 644 void again () throw ()
667 { 645 {
668 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 646 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
669 } 647 }
648
649 ev_tstamp remaining ()
650 {
651 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
652 }
670 EV_END_WATCHER (timer, timer) 653 EV_END_WATCHER (timer, timer)
671 654
672 #if EV_PERIODIC_ENABLE 655 #if EV_PERIODIC_ENABLE
673 EV_BEGIN_WATCHER (periodic, periodic) 656 EV_BEGIN_WATCHER (periodic, periodic)
674 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 657 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
690 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 673 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
691 } 674 }
692 EV_END_WATCHER (periodic, periodic) 675 EV_END_WATCHER (periodic, periodic)
693 #endif 676 #endif
694 677
678 #if EV_SIGNAL_ENABLE
695 EV_BEGIN_WATCHER (sig, signal) 679 EV_BEGIN_WATCHER (sig, signal)
696 void set (int signum) throw () 680 void set (int signum) throw ()
697 { 681 {
698 int active = is_active (); 682 int active = is_active ();
699 if (active) stop (); 683 if (active) stop ();
705 { 689 {
706 set (signum); 690 set (signum);
707 start (); 691 start ();
708 } 692 }
709 EV_END_WATCHER (sig, signal) 693 EV_END_WATCHER (sig, signal)
694 #endif
710 695
696 #if EV_CHILD_ENABLE
711 EV_BEGIN_WATCHER (child, child) 697 EV_BEGIN_WATCHER (child, child)
712 void set (int pid) throw () 698 void set (int pid, int trace = 0) throw ()
713 { 699 {
714 int active = is_active (); 700 int active = is_active ();
715 if (active) stop (); 701 if (active) stop ();
716 ev_child_set (static_cast<ev_child *>(this), pid); 702 ev_child_set (static_cast<ev_child *>(this), pid, trace);
717 if (active) start (); 703 if (active) start ();
718 } 704 }
719 705
720 void start (int pid) throw () 706 void start (int pid, int trace = 0) throw ()
721 { 707 {
722 set (pid); 708 set (pid, trace);
723 start (); 709 start ();
724 } 710 }
725 EV_END_WATCHER (child, child) 711 EV_END_WATCHER (child, child)
712 #endif
726 713
727 #if EV_STAT_ENABLE 714 #if EV_STAT_ENABLE
728 EV_BEGIN_WATCHER (stat, stat) 715 EV_BEGIN_WATCHER (stat, stat)
729 void set (const char *path, ev_tstamp interval = 0.) throw () 716 void set (const char *path, ev_tstamp interval = 0.) throw ()
730 { 717 {
746 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 733 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
747 } 734 }
748 EV_END_WATCHER (stat, stat) 735 EV_END_WATCHER (stat, stat)
749 #endif 736 #endif
750 737
738 #if EV_IDLE_ENABLE
751 EV_BEGIN_WATCHER (idle, idle) 739 EV_BEGIN_WATCHER (idle, idle)
752 void set () throw () { } 740 void set () throw () { }
753 EV_END_WATCHER (idle, idle) 741 EV_END_WATCHER (idle, idle)
742 #endif
754 743
744 #if EV_PREPARE_ENABLE
755 EV_BEGIN_WATCHER (prepare, prepare) 745 EV_BEGIN_WATCHER (prepare, prepare)
756 void set () throw () { } 746 void set () throw () { }
757 EV_END_WATCHER (prepare, prepare) 747 EV_END_WATCHER (prepare, prepare)
748 #endif
758 749
750 #if EV_CHECK_ENABLE
759 EV_BEGIN_WATCHER (check, check) 751 EV_BEGIN_WATCHER (check, check)
760 void set () throw () { } 752 void set () throw () { }
761 EV_END_WATCHER (check, check) 753 EV_END_WATCHER (check, check)
754 #endif
762 755
763 #if EV_EMBED_ENABLE 756 #if EV_EMBED_ENABLE
764 EV_BEGIN_WATCHER (embed, embed) 757 EV_BEGIN_WATCHER (embed, embed)
758 void set (struct ev_loop *embedded_loop) throw ()
759 {
760 int active = is_active ();
761 if (active) stop ();
762 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
763 if (active) start ();
764 }
765
765 void start (struct ev_loop *embedded_loop) throw () 766 void start (struct ev_loop *embedded_loop) throw ()
766 { 767 {
767 stop (); 768 set (embedded_loop);
768 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
769 start (); 769 start ();
770 } 770 }
771 771
772 void sweep () 772 void sweep ()
773 { 773 {
778 778
779 #if EV_FORK_ENABLE 779 #if EV_FORK_ENABLE
780 EV_BEGIN_WATCHER (fork, fork) 780 EV_BEGIN_WATCHER (fork, fork)
781 void set () throw () { } 781 void set () throw () { }
782 EV_END_WATCHER (fork, fork) 782 EV_END_WATCHER (fork, fork)
783 #endif
784
785 #if EV_ASYNC_ENABLE
786 EV_BEGIN_WATCHER (async, async)
787 void send () throw ()
788 {
789 ev_async_send (EV_A_ static_cast<ev_async *>(this));
790 }
791
792 bool async_pending () throw ()
793 {
794 return ev_async_pending (static_cast<ev_async *>(this));
795 }
796 EV_END_WATCHER (async, async)
783 #endif 797 #endif
784 798
785 #undef EV_PX 799 #undef EV_PX
786 #undef EV_PX_ 800 #undef EV_PX_
787 #undef EV_CONSTRUCT 801 #undef EV_CONSTRUCT
788 #undef EV_BEGIN_WATCHER 802 #undef EV_BEGIN_WATCHER
789 #undef EV_END_WATCHER 803 #undef EV_END_WATCHER
790
791} 804}
792 805
793#undef EV_THROW
794
795#endif 806#endif
796 807

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines