ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
Revision: 1.38
Committed: Mon Jan 28 11:43:37 2008 UTC (16 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_2, rel-3_1, rel-3_0
Changes since 1.37: +0 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.21 /*
2     * libev simple C++ wrapper classes
3     *
4     * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5     * All rights reserved.
6     *
7     * Redistribution and use in source and binary forms, with or without modifica-
8     * tion, are permitted provided that the following conditions are met:
9     *
10     * 1. Redistributions of source code must retain the above copyright notice,
11     * this list of conditions and the following disclaimer.
12     *
13     * 2. Redistributions in binary form must reproduce the above copyright
14     * notice, this list of conditions and the following disclaimer in the
15     * documentation and/or other materials provided with the distribution.
16     *
17     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19     * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20     * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21     * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25     * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26     * OF THE POSSIBILITY OF SUCH DAMAGE.
27     *
28     * Alternatively, the contents of this file may be used under the terms of
29     * the GNU General Public License ("GPL") version 2 or any later version,
30     * in which case the provisions of the GPL are applicable instead of
31     * the above. If you wish to allow the use of your version of this file
32     * only under the terms of the GPL and not to allow others to use your
33     * version of this file under the BSD license, indicate your decision
34     * by deleting the provisions above and replace them with the notice
35     * and other provisions required by the GPL. If you do not delete the
36     * provisions above, a recipient may use your version of this file under
37     * either the BSD or the GPL.
38     */
39    
40 root 1.1 #ifndef EVPP_H__
41     #define EVPP_H__
42    
43 root 1.20 #ifdef EV_H
44     # include EV_H
45     #else
46 root 1.22 # include "ev.h"
47 root 1.20 #endif
48 root 1.1
49 root 1.32 #ifndef EV_USE_STDEXCEPT
50     # define EV_USE_STDEXCEPT 1
51 llucax 1.30 #endif
52    
53 root 1.32 #if EV_USE_STDEXCEPT
54     # include <stdexcept>
55 llucax 1.30 #endif
56    
57 root 1.1 namespace ev {
58    
59 llucax 1.24 typedef ev_tstamp tstamp;
60    
61     enum {
62     UNDEF = EV_UNDEF,
63     NONE = EV_NONE,
64     READ = EV_READ,
65     WRITE = EV_WRITE,
66     TIMEOUT = EV_TIMEOUT,
67     PERIODIC = EV_PERIODIC,
68     SIGNAL = EV_SIGNAL,
69     CHILD = EV_CHILD,
70     STAT = EV_STAT,
71     IDLE = EV_IDLE,
72     CHECK = EV_CHECK,
73     PREPARE = EV_PREPARE,
74     FORK = EV_FORK,
75     EMBED = EV_EMBED,
76     ERROR = EV_ERROR,
77     };
78    
79 llucax 1.25 enum
80     {
81     AUTO = EVFLAG_AUTO,
82     NOENV = EVFLAG_NOENV,
83     FORKCHECK = EVFLAG_FORKCHECK,
84     SELECT = EVBACKEND_SELECT,
85     POLL = EVBACKEND_POLL,
86     EPOLL = EVBACKEND_EPOLL,
87     KQUEUE = EVBACKEND_KQUEUE,
88     DEVPOLL = EVBACKEND_DEVPOLL,
89     PORT = EVBACKEND_PORT
90     };
91    
92     enum
93     {
94     NONBLOCK = EVLOOP_NONBLOCK,
95     ONESHOT = EVLOOP_ONESHOT
96     };
97    
98     enum how_t
99     {
100     ONE = EVUNLOOP_ONE,
101     ALL = EVUNLOOP_ALL
102     };
103    
104 root 1.32 struct bad_loop
105     #if EV_USE_STDEXCEPT
106     : std::runtime_error
107     #endif
108 llucax 1.30 {
109 root 1.32 #if EV_USE_STDEXCEPT
110 root 1.31 bad_loop ()
111 root 1.32 : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?")
112 root 1.31 {
113     }
114 root 1.32 #endif
115 llucax 1.30 };
116    
117 llucax 1.28 #ifdef EV_AX
118     # undef EV_AX
119     #endif
120    
121     #ifdef EV_AX_
122     # undef EV_AX_
123     #endif
124    
125     #if EV_MULTIPLICITY
126     # define EV_AX raw_loop
127     # define EV_AX_ raw_loop,
128     #else
129     # define EV_AX
130     # define EV_AX_
131     #endif
132    
133     struct loop_ref
134     {
135 root 1.36 loop_ref (EV_P) throw ()
136 llucax 1.28 #if EV_MULTIPLICITY
137 root 1.36 : EV_AX (EV_A)
138     #endif
139 llucax 1.33 {
140     }
141 llucax 1.28
142 root 1.32 bool operator == (const loop_ref &other) const throw ()
143 llucax 1.28 {
144     #if EV_MULTIPLICITY
145 root 1.32 return EV_AX == other.EV_AX;
146 llucax 1.28 #else
147     return true;
148     #endif
149     }
150    
151 root 1.32 bool operator != (const loop_ref &other) const throw ()
152 llucax 1.28 {
153     #if EV_MULTIPLICITY
154     return ! (*this == other);
155     #else
156     return false;
157     #endif
158     }
159    
160     #if EV_MULTIPLICITY
161 root 1.37 bool operator == (struct ev_loop *other) const throw ()
162 llucax 1.28 {
163     return this->EV_AX == other;
164     }
165    
166 root 1.37 bool operator != (struct ev_loop *other) const throw ()
167 llucax 1.28 {
168     return ! (*this == other);
169     }
170    
171 root 1.37 bool operator == (const struct ev_loop *other) const throw ()
172 llucax 1.28 {
173     return this->EV_AX == other;
174     }
175    
176 root 1.37 bool operator != (const struct ev_loop *other) const throw ()
177 llucax 1.28 {
178     return (*this == other);
179     }
180    
181 root 1.31 operator struct ev_loop * () const throw ()
182 llucax 1.28 {
183     return EV_AX;
184     }
185    
186 root 1.31 operator const struct ev_loop * () const throw ()
187 llucax 1.28 {
188     return EV_AX;
189     }
190    
191 root 1.31 bool is_default () const throw ()
192 llucax 1.28 {
193     return EV_AX == ev_default_loop (0);
194     }
195     #endif
196    
197     void loop (int flags = 0)
198     {
199     ev_loop (EV_AX_ flags);
200     }
201    
202 root 1.31 void unloop (how_t how = ONE) throw ()
203 llucax 1.28 {
204     ev_unloop (EV_AX_ how);
205     }
206    
207 root 1.31 void post_fork () throw ()
208 llucax 1.28 {
209     #if EV_MULTIPLICITY
210     ev_loop_fork (EV_AX);
211     #else
212     ev_default_fork ();
213     #endif
214     }
215    
216 root 1.31 unsigned int count () const throw ()
217 llucax 1.28 {
218     return ev_loop_count (EV_AX);
219     }
220    
221 root 1.31 unsigned int backend () const throw ()
222 llucax 1.28 {
223     return ev_backend (EV_AX);
224     }
225    
226 root 1.31 tstamp now () const throw ()
227 llucax 1.28 {
228     return ev_now (EV_AX);
229     }
230    
231 root 1.31 void ref () throw ()
232 llucax 1.28 {
233     ev_ref (EV_AX);
234     }
235    
236 root 1.31 void unref () throw ()
237 llucax 1.28 {
238     ev_unref (EV_AX);
239     }
240    
241 root 1.31 void set_io_collect_interval (tstamp interval) throw ()
242 llucax 1.28 {
243     ev_set_io_collect_interval (EV_AX_ interval);
244     }
245    
246 root 1.31 void set_timeout_collect_interval (tstamp interval) throw ()
247 llucax 1.28 {
248     ev_set_timeout_collect_interval (EV_AX_ interval);
249     }
250    
251     // function callback
252 root 1.31 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw ()
253 llucax 1.28 {
254     ev_once (EV_AX_ fd, events, timeout, cb, arg);
255     }
256    
257     // method callback
258     template<class K, void (K::*method)(int)>
259 root 1.31 void once (int fd, int events, tstamp timeout, K *object) throw ()
260 llucax 1.28 {
261     once (fd, events, timeout, method_thunk<K, method>, object);
262     }
263    
264     template<class K, void (K::*method)(int)>
265     static void method_thunk (int revents, void* arg)
266     {
267     K *obj = static_cast<K *>(arg);
268     (obj->*method) (revents);
269     }
270    
271     // const method callback
272     template<class K, void (K::*method)(int) const>
273 root 1.31 void once (int fd, int events, tstamp timeout, const K *object) throw ()
274 llucax 1.28 {
275     once (fd, events, timeout, const_method_thunk<K, method>, object);
276     }
277    
278     template<class K, void (K::*method)(int) const>
279     static void const_method_thunk (int revents, void* arg)
280     {
281     K *obj = static_cast<K *>(arg);
282     (obj->*method) (revents);
283     }
284    
285     // simple method callback
286     template<class K, void (K::*method)()>
287 root 1.31 void once (int fd, int events, tstamp timeout, K *object) throw ()
288 llucax 1.28 {
289     once (fd, events, timeout, method_noargs_thunk<K, method>, object);
290     }
291    
292     template<class K, void (K::*method)()>
293     static void method_noargs_thunk (int revents, void* arg)
294     {
295     K *obj = static_cast<K *>(arg);
296     (obj->*method) ();
297     }
298    
299     // simpler function callback
300     template<void (*cb)(int)>
301 root 1.31 void once (int fd, int events, tstamp timeout) throw ()
302 llucax 1.28 {
303     once (fd, events, timeout, simpler_func_thunk<cb>);
304     }
305    
306     template<void (*cb)(int)>
307     static void simpler_func_thunk (int revents, void* arg)
308     {
309     (*cb) (revents);
310     }
311    
312     // simplest function callback
313     template<void (*cb)()>
314 root 1.31 void once (int fd, int events, tstamp timeout) throw ()
315 llucax 1.28 {
316     once (fd, events, timeout, simplest_func_thunk<cb>);
317     }
318    
319     template<void (*cb)()>
320     static void simplest_func_thunk (int revents, void* arg)
321     {
322     (*cb) ();
323     }
324    
325 root 1.31 void feed_fd_event (int fd, int revents) throw ()
326 llucax 1.28 {
327     ev_feed_fd_event (EV_AX_ fd, revents);
328     }
329    
330 root 1.31 void feed_signal_event (int signum) throw ()
331 llucax 1.28 {
332     ev_feed_signal_event (EV_AX_ signum);
333     }
334    
335     #if EV_MULTIPLICITY
336     struct ev_loop* EV_AX;
337     #endif
338    
339     };
340    
341     #if EV_MULTIPLICITY
342 root 1.36 struct dynamic_loop : loop_ref
343 llucax 1.28 {
344    
345 llucax 1.34 dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
346 root 1.36 : loop_ref (ev_loop_new (flags))
347 llucax 1.28 {
348 root 1.36 if (!EV_AX)
349     throw bad_loop ();
350 llucax 1.28 }
351    
352 root 1.31 ~dynamic_loop () throw ()
353 llucax 1.28 {
354     ev_loop_destroy (EV_AX);
355     EV_AX = 0;
356     }
357    
358     private:
359    
360     dynamic_loop (const dynamic_loop &);
361    
362     dynamic_loop & operator= (const dynamic_loop &);
363    
364     };
365     #endif
366    
367 root 1.36 struct default_loop : loop_ref
368 llucax 1.28 {
369 root 1.32 default_loop (unsigned int flags = AUTO) throw (bad_loop)
370 llucax 1.28 #if EV_MULTIPLICITY
371 root 1.32 : loop_ref (ev_default_loop (flags))
372     #endif
373 llucax 1.28 {
374 root 1.36 if (
375     #if EV_MULTIPLICITY
376     !EV_AX
377     #else
378     !ev_default_loop (flags)
379 root 1.32 #endif
380 root 1.36 )
381     throw bad_loop ();
382 llucax 1.28 }
383    
384 root 1.31 ~default_loop () throw ()
385 llucax 1.28 {
386     ev_default_destroy ();
387     }
388    
389     private:
390     default_loop (const default_loop &);
391 root 1.32 default_loop &operator = (const default_loop &);
392 llucax 1.28 };
393    
394 root 1.31 inline loop_ref get_default_loop () throw ()
395 llucax 1.28 {
396     #if EV_MULTIPLICITY
397     return ev_default_loop (0);
398     #else
399     return loop_ref ();
400     #endif
401     }
402    
403     #undef EV_AX
404     #undef EV_AX_
405    
406     #undef EV_PX
407     #undef EV_PX_
408     #if EV_MULTIPLICITY
409     # define EV_PX loop_ref EV_A
410     # define EV_PX_ loop_ref EV_A_
411     #else
412     # define EV_PX
413     # define EV_PX_
414     #endif
415    
416 root 1.13 template<class ev_watcher, class watcher>
417     struct base : ev_watcher
418 root 1.1 {
419 root 1.13 #if EV_MULTIPLICITY
420 llucax 1.28 EV_PX;
421 root 1.1
422 root 1.31 void set (EV_PX) throw ()
423 root 1.13 {
424     this->EV_A = EV_A;
425     }
426     #endif
427 root 1.1
428 root 1.31 base (EV_PX) throw ()
429 llucax 1.28 #if EV_MULTIPLICITY
430     : EV_A (EV_A)
431     #endif
432 root 1.13 {
433     ev_init (this, 0);
434     }
435    
436 root 1.31 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
437 root 1.13 {
438 root 1.17 this->data = data;
439 root 1.18 ev_set_cb (static_cast<ev_watcher *>(this), cb);
440 root 1.13 }
441    
442 root 1.19 // method callback
443 root 1.13 template<class K, void (K::*method)(watcher &w, int)>
444 root 1.31 void set (K *object) throw ()
445 root 1.13 {
446     set_ (object, method_thunk<K, method>);
447     }
448    
449     template<class K, void (K::*method)(watcher &w, int)>
450 root 1.18 static void method_thunk (EV_P_ ev_watcher *w, int revents)
451 root 1.13 {
452 root 1.17 K *obj = static_cast<K *>(w->data);
453 root 1.18 (obj->*method) (*static_cast<watcher *>(w), revents);
454 root 1.13 }
455    
456 root 1.19 // const method callback
457 root 1.13 template<class K, void (K::*method)(watcher &w, int) const>
458 root 1.31 void set (const K *object) throw ()
459 root 1.13 {
460     set_ (object, const_method_thunk<K, method>);
461     }
462    
463     template<class K, void (K::*method)(watcher &w, int) const>
464 root 1.18 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
465 root 1.13 {
466 root 1.17 K *obj = static_cast<K *>(w->data);
467 root 1.18 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
468 root 1.13 }
469    
470 root 1.19 // function callback
471 root 1.17 template<void (*function)(watcher &w, int)>
472 root 1.31 void set (void *data = 0) throw ()
473 root 1.13 {
474 root 1.16 set_ (data, function_thunk<function>);
475 root 1.13 }
476    
477     template<void (*function)(watcher &w, int)>
478 root 1.18 static void function_thunk (EV_P_ ev_watcher *w, int revents)
479 root 1.13 {
480 root 1.18 function (*static_cast<watcher *>(w), revents);
481 root 1.13 }
482    
483 root 1.19 // simple callback
484     template<class K, void (K::*method)()>
485 root 1.31 void set (K *object) throw ()
486 root 1.19 {
487     set_ (object, method_noargs_thunk<K, method>);
488     }
489    
490     template<class K, void (K::*method)()>
491     static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
492     {
493     K *obj = static_cast<K *>(w->data);
494     (obj->*method) ();
495     }
496    
497 root 1.13 void operator ()(int events = EV_UNDEF)
498     {
499 root 1.14 return ev_cb (static_cast<ev_watcher *>(this))
500     (static_cast<ev_watcher *>(this), events);
501 root 1.13 }
502    
503 root 1.31 bool is_active () const throw ()
504 root 1.1 {
505 root 1.13 return ev_is_active (static_cast<const ev_watcher *>(this));
506 root 1.1 }
507    
508 root 1.31 bool is_pending () const throw ()
509 root 1.1 {
510 root 1.13 return ev_is_pending (static_cast<const ev_watcher *>(this));
511 root 1.1 }
512 llucax 1.27
513 root 1.31 void feed_event (int revents) throw ()
514 llucax 1.27 {
515     ev_feed_event (EV_A_ static_cast<const ev_watcher *>(this), revents);
516     }
517 root 1.1 };
518    
519 root 1.31 inline tstamp now () throw ()
520 llucax 1.29 {
521     return ev_time ();
522     }
523    
524 root 1.31 inline void delay (tstamp interval) throw ()
525 llucax 1.26 {
526     ev_sleep (interval);
527     }
528    
529 root 1.31 inline int version_major () throw ()
530 llucax 1.26 {
531     return ev_version_major ();
532     }
533    
534 root 1.31 inline int version_minor () throw ()
535 llucax 1.26 {
536     return ev_version_minor ();
537     }
538    
539 root 1.31 inline unsigned int supported_backends () throw ()
540 llucax 1.26 {
541     return ev_supported_backends ();
542     }
543    
544 root 1.31 inline unsigned int recommended_backends () throw ()
545 llucax 1.26 {
546     return ev_recommended_backends ();
547     }
548    
549 root 1.31 inline unsigned int embeddable_backends () throw ()
550 llucax 1.26 {
551     return ev_embeddable_backends ();
552     }
553    
554 root 1.31 inline void set_allocator (void *(*cb)(void *ptr, long size)) throw ()
555 llucax 1.26 {
556     ev_set_allocator (cb);
557     }
558    
559 root 1.31 inline void set_syserr_cb (void (*cb)(const char *msg)) throw ()
560 llucax 1.26 {
561     ev_set_syserr_cb (cb);
562     }
563    
564 root 1.1 #if EV_MULTIPLICITY
565 llucax 1.28 #define EV_CONSTRUCT(cppstem,cstem) \
566 root 1.31 (EV_PX = get_default_loop ()) throw () \
567 llucax 1.28 : base<ev_ ## cstem, cppstem> (EV_A) \
568 root 1.1 { \
569 root 1.13 }
570 root 1.1 #else
571 llucax 1.28 #define EV_CONSTRUCT(cppstem,cstem) \
572 root 1.31 () throw () \
573 root 1.13 { \
574     }
575 root 1.1 #endif
576    
577     /* using a template here would require quite a bit more lines,
578     * so a macro solution was chosen */
579 root 1.4 #define EV_BEGIN_WATCHER(cppstem,cstem) \
580 root 1.1 \
581 root 1.13 struct cppstem : base<ev_ ## cstem, cppstem> \
582 root 1.1 { \
583 root 1.31 void start () throw () \
584 root 1.1 { \
585     ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
586     } \
587     \
588 root 1.31 void stop () throw () \
589 root 1.1 { \
590     ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
591     } \
592     \
593 llucax 1.28 cppstem EV_CONSTRUCT(cppstem,cstem) \
594 root 1.1 \
595 root 1.31 ~cppstem () throw () \
596 root 1.3 { \
597     stop (); \
598     } \
599     \
600 root 1.13 using base<ev_ ## cstem, cppstem>::set; \
601     \
602 root 1.1 private: \
603     \
604 llucax 1.23 cppstem (const cppstem &o); \
605 root 1.6 \
606 llucax 1.23 cppstem & operator =(const cppstem &o); \
607 root 1.1 \
608     public:
609    
610 root 1.4 #define EV_END_WATCHER(cppstem,cstem) \
611 root 1.6 };
612 root 1.4
613     EV_BEGIN_WATCHER (io, io)
614 root 1.31 void set (int fd, int events) throw ()
615 root 1.1 {
616     int active = is_active ();
617     if (active) stop ();
618     ev_io_set (static_cast<ev_io *>(this), fd, events);
619     if (active) start ();
620     }
621    
622 root 1.31 void set (int events) throw ()
623 root 1.1 {
624     int active = is_active ();
625     if (active) stop ();
626     ev_io_set (static_cast<ev_io *>(this), fd, events);
627     if (active) start ();
628     }
629    
630 root 1.31 void start (int fd, int events) throw ()
631 root 1.1 {
632     set (fd, events);
633     start ();
634     }
635 root 1.4 EV_END_WATCHER (io, io)
636 root 1.1
637 root 1.4 EV_BEGIN_WATCHER (timer, timer)
638 root 1.31 void set (ev_tstamp after, ev_tstamp repeat = 0.) throw ()
639 root 1.1 {
640     int active = is_active ();
641     if (active) stop ();
642     ev_timer_set (static_cast<ev_timer *>(this), after, repeat);
643     if (active) start ();
644     }
645    
646 root 1.31 void start (ev_tstamp after, ev_tstamp repeat = 0.) throw ()
647 root 1.1 {
648     set (after, repeat);
649     start ();
650     }
651    
652 root 1.31 void again () throw ()
653 root 1.1 {
654     ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
655     }
656 root 1.4 EV_END_WATCHER (timer, timer)
657 root 1.1
658 root 1.8 #if EV_PERIODIC_ENABLE
659 root 1.4 EV_BEGIN_WATCHER (periodic, periodic)
660 root 1.31 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
661 root 1.1 {
662     int active = is_active ();
663     if (active) stop ();
664     ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0);
665     if (active) start ();
666     }
667    
668 root 1.31 void start (ev_tstamp at, ev_tstamp interval = 0.) throw ()
669 root 1.1 {
670     set (at, interval);
671     start ();
672     }
673    
674 root 1.31 void again () throw ()
675 root 1.1 {
676     ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
677     }
678 root 1.4 EV_END_WATCHER (periodic, periodic)
679 root 1.3 #endif
680 root 1.1
681 root 1.4 EV_BEGIN_WATCHER (sig, signal)
682 root 1.31 void set (int signum) throw ()
683 root 1.1 {
684     int active = is_active ();
685     if (active) stop ();
686     ev_signal_set (static_cast<ev_signal *>(this), signum);
687     if (active) start ();
688     }
689    
690 root 1.31 void start (int signum) throw ()
691 root 1.1 {
692     set (signum);
693     start ();
694     }
695 root 1.4 EV_END_WATCHER (sig, signal)
696 root 1.1
697 root 1.4 EV_BEGIN_WATCHER (child, child)
698 root 1.37 void set (int pid, int trace = 0) throw ()
699 root 1.1 {
700     int active = is_active ();
701     if (active) stop ();
702 root 1.37 ev_child_set (static_cast<ev_child *>(this), pid, trace);
703 root 1.1 if (active) start ();
704     }
705    
706 root 1.37 void start (int pid, int trace = 0) throw ()
707 root 1.1 {
708 root 1.37 set (pid, trace);
709 root 1.1 start ();
710     }
711 root 1.4 EV_END_WATCHER (child, child)
712 root 1.1
713 root 1.8 #if EV_STAT_ENABLE
714     EV_BEGIN_WATCHER (stat, stat)
715 root 1.31 void set (const char *path, ev_tstamp interval = 0.) throw ()
716 root 1.8 {
717     int active = is_active ();
718     if (active) stop ();
719     ev_stat_set (static_cast<ev_stat *>(this), path, interval);
720     if (active) start ();
721     }
722    
723 root 1.31 void start (const char *path, ev_tstamp interval = 0.) throw ()
724 root 1.8 {
725 root 1.12 stop ();
726 root 1.8 set (path, interval);
727     start ();
728     }
729    
730 root 1.31 void update () throw ()
731 root 1.8 {
732     ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
733     }
734     EV_END_WATCHER (stat, stat)
735     #endif
736    
737     EV_BEGIN_WATCHER (idle, idle)
738 root 1.31 void set () throw () { }
739 root 1.8 EV_END_WATCHER (idle, idle)
740 root 1.7
741 root 1.8 EV_BEGIN_WATCHER (prepare, prepare)
742 root 1.31 void set () throw () { }
743 root 1.8 EV_END_WATCHER (prepare, prepare)
744    
745     EV_BEGIN_WATCHER (check, check)
746 root 1.31 void set () throw () { }
747 root 1.8 EV_END_WATCHER (check, check)
748    
749     #if EV_EMBED_ENABLE
750 root 1.7 EV_BEGIN_WATCHER (embed, embed)
751 root 1.31 void start (struct ev_loop *embedded_loop) throw ()
752 root 1.7 {
753 root 1.12 stop ();
754     ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
755 root 1.7 start ();
756     }
757    
758     void sweep ()
759     {
760     ev_embed_sweep (EV_A_ static_cast<ev_embed *>(this));
761     }
762     EV_END_WATCHER (embed, embed)
763     #endif
764    
765 root 1.10 #if EV_FORK_ENABLE
766     EV_BEGIN_WATCHER (fork, fork)
767 root 1.31 void set () throw () { }
768 root 1.10 EV_END_WATCHER (fork, fork)
769     #endif
770    
771 llucax 1.28 #undef EV_PX
772     #undef EV_PX_
773 root 1.1 #undef EV_CONSTRUCT
774 root 1.4 #undef EV_BEGIN_WATCHER
775 root 1.7 #undef EV_END_WATCHER
776 root 1.1 }
777    
778     #endif
779