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

Comparing libev/ev++.h (file contents):
Revision 1.37 by root, Fri Jan 25 15:45:08 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 () 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 {
157 return false; 167 return false;
158#endif 168#endif
159 } 169 }
160 170
161#if EV_MULTIPLICITY 171#if EV_MULTIPLICITY
162 bool operator == (struct ev_loop *other) const throw () 172 bool operator == (const EV_P) const throw ()
163 { 173 {
164 return this->EV_AX == other; 174 return this->EV_AX == EV_A;
165 }
166
167 bool operator != (struct ev_loop *other) const throw ()
168 { 175 }
169 return ! (*this == other); 176
177 bool operator != (const EV_P) const throw ()
170 } 178 {
171
172 bool operator == (const struct ev_loop *other) const throw ()
173 {
174 return this->EV_AX == other;
175 }
176
177 bool operator != (const struct ev_loop *other) const throw ()
178 {
179 return (*this == other); 179 return (*this == EV_A);
180 } 180 }
181 181
182 operator struct ev_loop * () const throw () 182 operator struct ev_loop * () const throw ()
183 { 183 {
184 return EV_AX; 184 return EV_AX;
193 { 193 {
194 return EV_AX == ev_default_loop (0); 194 return EV_AX == ev_default_loop (0);
195 } 195 }
196#endif 196#endif
197 197
198#if EV_COMPAT3
198 void loop (int flags = 0) 199 void loop (int flags = 0)
199 { 200 {
200 ev_loop (EV_AX_ flags); 201 ev_run (EV_AX_ flags);
201 } 202 }
202 203
203 void unloop (how_t how = ONE) throw () 204 void unloop (how_t how = ONE) throw ()
204 { 205 {
205 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);
206 } 218 }
207 219
208 void post_fork () throw () 220 void post_fork () throw ()
209 { 221 {
210#if EV_MULTIPLICITY
211 ev_loop_fork (EV_AX); 222 ev_loop_fork (EV_AX);
212#else
213 ev_default_fork ();
214#endif
215 }
216
217 unsigned int count () const throw ()
218 {
219 return ev_loop_count (EV_AX);
220 } 223 }
221 224
222 unsigned int backend () const throw () 225 unsigned int backend () const throw ()
223 { 226 {
224 return ev_backend (EV_AX); 227 return ev_backend (EV_AX);
237 void unref () throw () 240 void unref () throw ()
238 { 241 {
239 ev_unref (EV_AX); 242 ev_unref (EV_AX);
240 } 243 }
241 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
242 void set_io_collect_interval (tstamp interval) throw () 256 void set_io_collect_interval (tstamp interval) throw ()
243 { 257 {
244 ev_set_io_collect_interval (EV_AX_ interval); 258 ev_set_io_collect_interval (EV_AX_ interval);
245 } 259 }
246 260
247 void set_timeout_collect_interval (tstamp interval) throw () 261 void set_timeout_collect_interval (tstamp interval) throw ()
248 { 262 {
249 ev_set_timeout_collect_interval (EV_AX_ interval); 263 ev_set_timeout_collect_interval (EV_AX_ interval);
250 } 264 }
265#endif
251 266
252 // function callback 267 // function callback
253 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 ()
254 { 269 {
255 ev_once (EV_AX_ fd, events, timeout, cb, arg); 270 ev_once (EV_AX_ fd, events, timeout, cb, arg);
256 } 271 }
257 272
258 // method callback 273 // method callback
260 void once (int fd, int events, tstamp timeout, K *object) throw () 275 void once (int fd, int events, tstamp timeout, K *object) throw ()
261 { 276 {
262 once (fd, events, timeout, method_thunk<K, method>, object); 277 once (fd, events, timeout, method_thunk<K, method>, object);
263 } 278 }
264 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
265 template<class K, void (K::*method)(int)> 287 template<class K, void (K::*method)(int)>
266 static void method_thunk (int revents, void* arg) 288 static void method_thunk (int revents, void *arg)
267 {
268 K *obj = static_cast<K *>(arg);
269 (obj->*method) (revents);
270 } 289 {
290 static_cast<K *>(arg)->*method
291 (revents);
292 }
271 293
272 // const method callback 294 // no-argument method callback
273 template<class K, void (K::*method)(int) const>
274 void once (int fd, int events, tstamp timeout, const K *object) throw ()
275 {
276 once (fd, events, timeout, const_method_thunk<K, method>, object);
277 }
278
279 template<class K, void (K::*method)(int) const>
280 static void const_method_thunk (int revents, void* arg)
281 {
282 K *obj = static_cast<K *>(arg);
283 (obj->*method) (revents);
284 }
285
286 // simple method callback
287 template<class K, void (K::*method)()> 295 template<class K, void (K::*method)()>
288 void once (int fd, int events, tstamp timeout, K *object) throw () 296 void once (int fd, int events, tstamp timeout, K *object) throw ()
289 { 297 {
290 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 298 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
291 } 299 }
292 300
293 template<class K, void (K::*method)()> 301 template<class K, void (K::*method)()>
294 static void method_noargs_thunk (int revents, void* arg) 302 static void method_noargs_thunk (int revents, void *arg)
295 { 303 {
296 K *obj = static_cast<K *>(arg); 304 static_cast<K *>(arg)->*method
297 (obj->*method) (); 305 ();
298 } 306 }
299 307
300 // simpler function callback 308 // simpler function callback
301 template<void (*cb)(int)> 309 template<void (*cb)(int)>
302 void once (int fd, int events, tstamp timeout) throw () 310 void once (int fd, int events, tstamp timeout) throw ()
303 { 311 {
304 once (fd, events, timeout, simpler_func_thunk<cb>); 312 once (fd, events, timeout, simpler_func_thunk<cb>);
305 } 313 }
306 314
307 template<void (*cb)(int)> 315 template<void (*cb)(int)>
308 static void simpler_func_thunk (int revents, void* arg) 316 static void simpler_func_thunk (int revents, void *arg)
309 { 317 {
318 (*cb)
310 (*cb) (revents); 319 (revents);
311 } 320 }
312 321
313 // simplest function callback 322 // simplest function callback
314 template<void (*cb)()> 323 template<void (*cb)()>
315 void once (int fd, int events, tstamp timeout) throw () 324 void once (int fd, int events, tstamp timeout) throw ()
316 { 325 {
317 once (fd, events, timeout, simplest_func_thunk<cb>); 326 once (fd, events, timeout, simplest_func_thunk<cb>);
318 } 327 }
319 328
320 template<void (*cb)()> 329 template<void (*cb)()>
321 static void simplest_func_thunk (int revents, void* arg) 330 static void simplest_func_thunk (int revents, void *arg)
322 { 331 {
323 (*cb) (); 332 (*cb)
333 ();
324 } 334 }
325 335
326 void feed_fd_event (int fd, int revents) throw () 336 void feed_fd_event (int fd, int revents) throw ()
327 { 337 {
328 ev_feed_fd_event (EV_AX_ fd, revents); 338 ev_feed_fd_event (EV_AX_ fd, revents);
365 }; 375 };
366#endif 376#endif
367 377
368 struct default_loop : loop_ref 378 struct default_loop : loop_ref
369 { 379 {
370
371 default_loop (unsigned int flags = AUTO) throw (bad_loop) 380 default_loop (unsigned int flags = AUTO) throw (bad_loop)
372#if EV_MULTIPLICITY 381#if EV_MULTIPLICITY
373 : loop_ref (ev_default_loop (flags)) 382 : loop_ref (ev_default_loop (flags))
374#endif 383#endif
375 { 384 {
379#else 388#else
380 !ev_default_loop (flags) 389 !ev_default_loop (flags)
381#endif 390#endif
382 ) 391 )
383 throw bad_loop (); 392 throw bad_loop ();
384 }
385
386 ~default_loop () throw ()
387 {
388 ev_default_destroy ();
389 } 393 }
390 394
391 private: 395 private:
392 default_loop (const default_loop &); 396 default_loop (const default_loop &);
393 default_loop &operator = (const default_loop &); 397 default_loop &operator = (const default_loop &);
419 struct base : ev_watcher 423 struct base : ev_watcher
420 { 424 {
421 #if EV_MULTIPLICITY 425 #if EV_MULTIPLICITY
422 EV_PX; 426 EV_PX;
423 427
428 // loop set
424 void set (EV_PX) throw () 429 void set (EV_P) throw ()
425 { 430 {
426 this->EV_A = EV_A; 431 this->EV_A = EV_A;
427 } 432 }
428 #endif 433 #endif
429 434
433 #endif 438 #endif
434 { 439 {
435 ev_init (this, 0); 440 ev_init (this, 0);
436 } 441 }
437 442
438 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 ()
439 { 444 {
440 this->data = data; 445 this->data = (void *)data;
441 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);
442 } 461 }
443 462
444 // method callback 463 // method callback
445 template<class K, void (K::*method)(watcher &w, int)> 464 template<class K, void (K::*method)(watcher &w, int)>
446 void set (K *object) throw () 465 void set (K *object) throw ()
447 { 466 {
448 set_ (object, method_thunk<K, method>); 467 set_ (object, method_thunk<K, method>);
449 } 468 }
450 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
451 template<class K, void (K::*method)(watcher &w, int)> 477 template<class K, void (K::*method)(watcher &w, int)>
452 static void method_thunk (EV_P_ ev_watcher *w, int revents) 478 static void method_thunk (EV_P_ ev_watcher *w, int revents)
453 { 479 {
454 K *obj = static_cast<K *>(w->data); 480 (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); 481 (*static_cast<watcher *>(w), revents);
483 } 482 }
484 483
485 // simple callback 484 // no-argument callback
486 template<class K, void (K::*method)()> 485 template<class K, void (K::*method)()>
487 void set (K *object) throw () 486 void set (K *object) throw ()
488 { 487 {
489 set_ (object, method_noargs_thunk<K, method>); 488 set_ (object, method_noargs_thunk<K, method>);
490 } 489 }
491 490
492 template<class K, void (K::*method)()> 491 template<class K, void (K::*method)()>
493 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)
494 { 493 {
495 K *obj = static_cast<K *>(w->data); 494 (static_cast<K *>(w->data)->*method)
496 (obj->*method) (); 495 ();
497 } 496 }
498 497
499 void operator ()(int events = EV_UNDEF) 498 void operator ()(int events = EV_UNDEF)
500 { 499 {
500 return
501 return ev_cb (static_cast<ev_watcher *>(this)) 501 ev_cb (static_cast<ev_watcher *>(this))
502 (static_cast<ev_watcher *>(this), events); 502 (static_cast<ev_watcher *>(this), events);
503 } 503 }
504 504
505 bool is_active () const throw () 505 bool is_active () const throw ()
506 { 506 {
507 return ev_is_active (static_cast<const ev_watcher *>(this)); 507 return ev_is_active (static_cast<const ev_watcher *>(this));
563 ev_set_syserr_cb (cb); 563 ev_set_syserr_cb (cb);
564 } 564 }
565 565
566 #if EV_MULTIPLICITY 566 #if EV_MULTIPLICITY
567 #define EV_CONSTRUCT(cppstem,cstem) \ 567 #define EV_CONSTRUCT(cppstem,cstem) \
568 (EV_PX = get_default_loop ()) throw () \ 568 (EV_PX = get_default_loop ()) throw () \
569 : base<ev_ ## cstem, cppstem> (EV_A) \ 569 : base<ev_ ## cstem, cppstem> (EV_A) \
570 { \ 570 { \
571 } 571 }
572 #else 572 #else
573 #define EV_CONSTRUCT(cppstem,cstem) \ 573 #define EV_CONSTRUCT(cppstem,cstem) \
574 () throw () \ 574 () throw () \
575 { \ 575 { \
576 } 576 }
577 #endif 577 #endif
578 578
579 /* using a template here would require quite a bit more lines, 579 /* using a template here would require quite a bit more lines,
580 * so a macro solution was chosen */ 580 * so a macro solution was chosen */
581 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 581 #define EV_BEGIN_WATCHER(cppstem,cstem) \
582 \ 582 \
583 struct cppstem : base<ev_ ## cstem, cppstem> \ 583 struct cppstem : base<ev_ ## cstem, cppstem> \
584 { \ 584 { \
585 void start () throw () \ 585 void start () throw () \
586 { \ 586 { \
587 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 587 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
588 } \ 588 } \
589 \ 589 \
590 void stop () throw () \ 590 void stop () throw () \
591 { \ 591 { \
592 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 592 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
593 } \ 593 } \
594 \ 594 \
595 cppstem EV_CONSTRUCT(cppstem,cstem) \ 595 cppstem EV_CONSTRUCT(cppstem,cstem) \
596 \ 596 \
597 ~cppstem () throw () \ 597 ~cppstem () throw () \
598 { \ 598 { \
599 stop (); \ 599 stop (); \
600 } \ 600 } \
601 \ 601 \
602 using base<ev_ ## cstem, cppstem>::set; \ 602 using base<ev_ ## cstem, cppstem>::set; \
603 \ 603 \
604 private: \ 604 private: \
605 \ 605 \
606 cppstem (const cppstem &o); \ 606 cppstem (const cppstem &o); \
607 \ 607 \
608 cppstem & operator =(const cppstem &o); \ 608 cppstem &operator =(const cppstem &o); \
609 \ 609 \
610 public: 610 public:
611 611
612 #define EV_END_WATCHER(cppstem,cstem) \ 612 #define EV_END_WATCHER(cppstem,cstem) \
613 }; 613 };
653 653
654 void again () throw () 654 void again () throw ()
655 { 655 {
656 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 656 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
657 } 657 }
658
659 ev_tstamp remaining ()
660 {
661 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
662 }
658 EV_END_WATCHER (timer, timer) 663 EV_END_WATCHER (timer, timer)
659 664
660 #if EV_PERIODIC_ENABLE 665 #if EV_PERIODIC_ENABLE
661 EV_BEGIN_WATCHER (periodic, periodic) 666 EV_BEGIN_WATCHER (periodic, periodic)
662 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 667 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
678 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 683 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
679 } 684 }
680 EV_END_WATCHER (periodic, periodic) 685 EV_END_WATCHER (periodic, periodic)
681 #endif 686 #endif
682 687
688 #if EV_SIGNAL_ENABLE
683 EV_BEGIN_WATCHER (sig, signal) 689 EV_BEGIN_WATCHER (sig, signal)
684 void set (int signum) throw () 690 void set (int signum) throw ()
685 { 691 {
686 int active = is_active (); 692 int active = is_active ();
687 if (active) stop (); 693 if (active) stop ();
693 { 699 {
694 set (signum); 700 set (signum);
695 start (); 701 start ();
696 } 702 }
697 EV_END_WATCHER (sig, signal) 703 EV_END_WATCHER (sig, signal)
704 #endif
698 705
706 #if EV_CHILD_ENABLE
699 EV_BEGIN_WATCHER (child, child) 707 EV_BEGIN_WATCHER (child, child)
700 void set (int pid, int trace = 0) throw () 708 void set (int pid, int trace = 0) throw ()
701 { 709 {
702 int active = is_active (); 710 int active = is_active ();
703 if (active) stop (); 711 if (active) stop ();
709 { 717 {
710 set (pid, trace); 718 set (pid, trace);
711 start (); 719 start ();
712 } 720 }
713 EV_END_WATCHER (child, child) 721 EV_END_WATCHER (child, child)
722 #endif
714 723
715 #if EV_STAT_ENABLE 724 #if EV_STAT_ENABLE
716 EV_BEGIN_WATCHER (stat, stat) 725 EV_BEGIN_WATCHER (stat, stat)
717 void set (const char *path, ev_tstamp interval = 0.) throw () 726 void set (const char *path, ev_tstamp interval = 0.) throw ()
718 { 727 {
734 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 743 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
735 } 744 }
736 EV_END_WATCHER (stat, stat) 745 EV_END_WATCHER (stat, stat)
737 #endif 746 #endif
738 747
748 #if EV_IDLE_ENABLE
739 EV_BEGIN_WATCHER (idle, idle) 749 EV_BEGIN_WATCHER (idle, idle)
740 void set () throw () { } 750 void set () throw () { }
741 EV_END_WATCHER (idle, idle) 751 EV_END_WATCHER (idle, idle)
752 #endif
742 753
754 #if EV_PREPARE_ENABLE
743 EV_BEGIN_WATCHER (prepare, prepare) 755 EV_BEGIN_WATCHER (prepare, prepare)
744 void set () throw () { } 756 void set () throw () { }
745 EV_END_WATCHER (prepare, prepare) 757 EV_END_WATCHER (prepare, prepare)
758 #endif
746 759
760 #if EV_CHECK_ENABLE
747 EV_BEGIN_WATCHER (check, check) 761 EV_BEGIN_WATCHER (check, check)
748 void set () throw () { } 762 void set () throw () { }
749 EV_END_WATCHER (check, check) 763 EV_END_WATCHER (check, check)
764 #endif
750 765
751 #if EV_EMBED_ENABLE 766 #if EV_EMBED_ENABLE
752 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
753 void start (struct ev_loop *embedded_loop) throw () 776 void start (struct ev_loop *embedded_loop) throw ()
754 { 777 {
755 stop (); 778 set (embedded_loop);
756 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
757 start (); 779 start ();
758 } 780 }
759 781
760 void sweep () 782 void sweep ()
761 { 783 {
766 788
767 #if EV_FORK_ENABLE 789 #if EV_FORK_ENABLE
768 EV_BEGIN_WATCHER (fork, fork) 790 EV_BEGIN_WATCHER (fork, fork)
769 void set () throw () { } 791 void set () throw () { }
770 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)
771 #endif 807 #endif
772 808
773 #undef EV_PX 809 #undef EV_PX
774 #undef EV_PX_ 810 #undef EV_PX_
775 #undef EV_CONSTRUCT 811 #undef EV_CONSTRUCT
776 #undef EV_BEGIN_WATCHER 812 #undef EV_BEGIN_WATCHER
777 #undef EV_END_WATCHER 813 #undef EV_END_WATCHER
778
779} 814}
780 815
781#endif 816#endif
782 817

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines