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.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 *
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,
67#if EV_COMPAT3
70 TIMEOUT = EV_TIMEOUT, 68 TIMEOUT = EV_TIMEOUT,
69#endif
70 TIMER = EV_TIMER,
71 PERIODIC = EV_PERIODIC, 71 PERIODIC = EV_PERIODIC,
72 SIGNAL = EV_SIGNAL, 72 SIGNAL = EV_SIGNAL,
73 CHILD = EV_CHILD, 73 CHILD = EV_CHILD,
74 STAT = EV_STAT, 74 STAT = EV_STAT,
75 IDLE = EV_IDLE, 75 IDLE = EV_IDLE,
76 CHECK = EV_CHECK, 76 CHECK = EV_CHECK,
77 PREPARE = EV_PREPARE, 77 PREPARE = EV_PREPARE,
78 FORK = EV_FORK, 78 FORK = EV_FORK,
79 ASYNC = EV_ASYNC,
79 EMBED = EV_EMBED, 80 EMBED = EV_EMBED,
81# undef ERROR // some systems stupidly #define ERROR
80 ERROR = EV_ERROR, 82 ERROR = EV_ERROR
81 }; 83 };
82 84
83 enum 85 enum
84 { 86 {
85 AUTO = EVFLAG_AUTO, 87 AUTO = EVFLAG_AUTO,
86 NOENV = EVFLAG_NOENV, 88 NOENV = EVFLAG_NOENV,
87 FORKCHECK = EVFLAG_FORKCHECK, 89 FORKCHECK = EVFLAG_FORKCHECK,
90
88 SELECT = EVBACKEND_SELECT, 91 SELECT = EVBACKEND_SELECT,
89 POLL = EVBACKEND_POLL, 92 POLL = EVBACKEND_POLL,
90 EPOLL = EVBACKEND_EPOLL, 93 EPOLL = EVBACKEND_EPOLL,
91 KQUEUE = EVBACKEND_KQUEUE, 94 KQUEUE = EVBACKEND_KQUEUE,
92 DEVPOLL = EVBACKEND_DEVPOLL, 95 DEVPOLL = EVBACKEND_DEVPOLL,
93 PORT = EVBACKEND_PORT 96 PORT = EVBACKEND_PORT
94 }; 97 };
95 98
96 enum 99 enum
97 { 100 {
101#if EV_COMPAT3
98 NONBLOCK = EVLOOP_NONBLOCK, 102 NONBLOCK = EVLOOP_NONBLOCK,
99 ONESHOT = EVLOOP_ONESHOT 103 ONESHOT = EVLOOP_ONESHOT,
104#endif
105 NOWAIT = EVRUN_NOWAIT,
106 ONCE = EVRUN_ONCE
100 }; 107 };
101 108
102 enum how_t 109 enum how_t
103 { 110 {
104 ONE = EVUNLOOP_ONE, 111 ONE = EVBREAK_ONE,
105 ALL = EVUNLOOP_ALL 112 ALL = EVBREAK_ALL
106 }; 113 };
107 114
108#if EV_CXX_EXCEPTIONS 115 struct bad_loop
109 struct bad_loop : std::runtime_error 116#if EV_USE_STDEXCEPT
117 : std::runtime_error
118#endif
110 { 119 {
120#if EV_USE_STDEXCEPT
111 bad_loop () 121 bad_loop ()
112 : std::runtime_error ("loop can't be initialized") 122 : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?")
113 {
114 } 123 {
115 }; 124 }
116#endif 125#endif
126 };
117 127
118#ifdef EV_AX 128#ifdef EV_AX
119# undef EV_AX 129# undef EV_AX
120#endif 130#endif
121 131
131# define EV_AX_ 141# define EV_AX_
132#endif 142#endif
133 143
134 struct loop_ref 144 struct loop_ref
135 { 145 {
136
137 loop_ref (EV_P) 146 loop_ref (EV_P) throw ()
138#if EV_MULTIPLICITY 147#if EV_MULTIPLICITY
139 EV_THROW (bad_loop) : EV_AX (EV_A) 148 : EV_AX (EV_A)
140#endif 149#endif
141 {
142#if EV_MULTIPLICIY && EV_CXX_EXCEPTIONS
143 if (!EV_A)
144 throw bad_loop ();
145#endif
146 } 150 {
151 }
147 152
148 bool operator== (const loop_ref &other) const throw () 153 bool operator == (const loop_ref &other) const throw ()
149 { 154 {
150#if EV_MULTIPLICITY 155#if EV_MULTIPLICITY
151 return this->EV_AX == other.EV_AX; 156 return EV_AX == other.EV_AX;
152#else 157#else
153 return true; 158 return true;
154#endif 159#endif
155 } 160 }
156 161
157 bool operator!= (const loop_ref &other) const throw () 162 bool operator != (const loop_ref &other) const throw ()
158 { 163 {
159#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
160 return ! (*this == other); 165 return ! (*this == other);
161#else 166#else
162 return false; 167 return false;
163#endif 168#endif
164 } 169 }
165 170
166#if EV_MULTIPLICITY 171#if EV_MULTIPLICITY
167 bool operator== (struct ev_loop *other) const throw () 172 bool operator == (const EV_P) const throw ()
168 { 173 {
169 return this->EV_AX == other; 174 return this->EV_AX == EV_A;
170 }
171
172 bool operator!= (struct ev_loop *other) const throw ()
173 { 175 }
174 return ! (*this == other); 176
177 bool operator != (const EV_P) const throw ()
175 } 178 {
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); 179 return (*this == EV_A);
185 } 180 }
186 181
187 operator struct ev_loop * () const throw () 182 operator struct ev_loop * () const throw ()
188 { 183 {
189 return EV_AX; 184 return EV_AX;
198 { 193 {
199 return EV_AX == ev_default_loop (0); 194 return EV_AX == ev_default_loop (0);
200 } 195 }
201#endif 196#endif
202 197
198#if EV_COMPAT3
203 void loop (int flags = 0) 199 void loop (int flags = 0)
204 { 200 {
205 ev_loop (EV_AX_ flags); 201 ev_run (EV_AX_ flags);
206 } 202 }
207 203
208 void unloop (how_t how = ONE) throw () 204 void unloop (how_t how = ONE) throw ()
209 { 205 {
210 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);
211 } 218 }
212 219
213 void post_fork () throw () 220 void post_fork () throw ()
214 { 221 {
215#if EV_MULTIPLICITY
216 ev_loop_fork (EV_AX); 222 ev_loop_fork (EV_AX);
217#else
218 ev_default_fork ();
219#endif
220 }
221
222 unsigned int count () const throw ()
223 {
224 return ev_loop_count (EV_AX);
225 } 223 }
226 224
227 unsigned int backend () const throw () 225 unsigned int backend () const throw ()
228 { 226 {
229 return ev_backend (EV_AX); 227 return ev_backend (EV_AX);
242 void unref () throw () 240 void unref () throw ()
243 { 241 {
244 ev_unref (EV_AX); 242 ev_unref (EV_AX);
245 } 243 }
246 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
247 void set_io_collect_interval (tstamp interval) throw () 256 void set_io_collect_interval (tstamp interval) throw ()
248 { 257 {
249 ev_set_io_collect_interval (EV_AX_ interval); 258 ev_set_io_collect_interval (EV_AX_ interval);
250 } 259 }
251 260
252 void set_timeout_collect_interval (tstamp interval) throw () 261 void set_timeout_collect_interval (tstamp interval) throw ()
253 { 262 {
254 ev_set_timeout_collect_interval (EV_AX_ interval); 263 ev_set_timeout_collect_interval (EV_AX_ interval);
255 } 264 }
265#endif
256 266
257 // function callback 267 // function callback
258 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 ()
259 { 269 {
260 ev_once (EV_AX_ fd, events, timeout, cb, arg); 270 ev_once (EV_AX_ fd, events, timeout, cb, arg);
261 } 271 }
262 272
263 // method callback 273 // method callback
265 void once (int fd, int events, tstamp timeout, K *object) throw () 275 void once (int fd, int events, tstamp timeout, K *object) throw ()
266 { 276 {
267 once (fd, events, timeout, method_thunk<K, method>, object); 277 once (fd, events, timeout, method_thunk<K, method>, object);
268 } 278 }
269 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
270 template<class K, void (K::*method)(int)> 287 template<class K, void (K::*method)(int)>
271 static void method_thunk (int revents, void* arg) 288 static void method_thunk (int revents, void *arg)
272 {
273 K *obj = static_cast<K *>(arg);
274 (obj->*method) (revents);
275 } 289 {
290 static_cast<K *>(arg)->*method
291 (revents);
292 }
276 293
277 // const method callback 294 // 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)()> 295 template<class K, void (K::*method)()>
293 void once (int fd, int events, tstamp timeout, K *object) throw () 296 void once (int fd, int events, tstamp timeout, K *object) throw ()
294 { 297 {
295 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 298 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
296 } 299 }
297 300
298 template<class K, void (K::*method)()> 301 template<class K, void (K::*method)()>
299 static void method_noargs_thunk (int revents, void* arg) 302 static void method_noargs_thunk (int revents, void *arg)
300 { 303 {
301 K *obj = static_cast<K *>(arg); 304 static_cast<K *>(arg)->*method
302 (obj->*method) (); 305 ();
303 } 306 }
304 307
305 // simpler function callback 308 // simpler function callback
306 template<void (*cb)(int)> 309 template<void (*cb)(int)>
307 void once (int fd, int events, tstamp timeout) throw () 310 void once (int fd, int events, tstamp timeout) throw ()
308 { 311 {
309 once (fd, events, timeout, simpler_func_thunk<cb>); 312 once (fd, events, timeout, simpler_func_thunk<cb>);
310 } 313 }
311 314
312 template<void (*cb)(int)> 315 template<void (*cb)(int)>
313 static void simpler_func_thunk (int revents, void* arg) 316 static void simpler_func_thunk (int revents, void *arg)
314 { 317 {
318 (*cb)
315 (*cb) (revents); 319 (revents);
316 } 320 }
317 321
318 // simplest function callback 322 // simplest function callback
319 template<void (*cb)()> 323 template<void (*cb)()>
320 void once (int fd, int events, tstamp timeout) throw () 324 void once (int fd, int events, tstamp timeout) throw ()
321 { 325 {
322 once (fd, events, timeout, simplest_func_thunk<cb>); 326 once (fd, events, timeout, simplest_func_thunk<cb>);
323 } 327 }
324 328
325 template<void (*cb)()> 329 template<void (*cb)()>
326 static void simplest_func_thunk (int revents, void* arg) 330 static void simplest_func_thunk (int revents, void *arg)
327 { 331 {
328 (*cb) (); 332 (*cb)
333 ();
329 } 334 }
330 335
331 void feed_fd_event (int fd, int revents) throw () 336 void feed_fd_event (int fd, int revents) throw ()
332 { 337 {
333 ev_feed_fd_event (EV_AX_ fd, revents); 338 ev_feed_fd_event (EV_AX_ fd, revents);
343#endif 348#endif
344 349
345 }; 350 };
346 351
347#if EV_MULTIPLICITY 352#if EV_MULTIPLICITY
348 struct dynamic_loop: loop_ref 353 struct dynamic_loop : loop_ref
349 { 354 {
350 355
351 dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 356 dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
352 : loop_ref (ev_loop_new (flags)) 357 : loop_ref (ev_loop_new (flags))
353 { 358 {
359 if (!EV_AX)
360 throw bad_loop ();
354 } 361 }
355 362
356 ~dynamic_loop () throw () 363 ~dynamic_loop () throw ()
357 { 364 {
358 ev_loop_destroy (EV_AX); 365 ev_loop_destroy (EV_AX);
366 dynamic_loop & operator= (const dynamic_loop &); 373 dynamic_loop & operator= (const dynamic_loop &);
367 374
368 }; 375 };
369#endif 376#endif
370 377
371 struct default_loop: loop_ref 378 struct default_loop : loop_ref
372 { 379 {
373
374 default_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) 380 default_loop (unsigned int flags = AUTO) throw (bad_loop)
375#if EV_MULTIPLICITY 381#if EV_MULTIPLICITY
376 : loop_ref (ev_default_loop (flags)) 382 : loop_ref (ev_default_loop (flags))
377 { 383#endif
378 } 384 {
385 if (
386#if EV_MULTIPLICITY
387 !EV_AX
379#else 388#else
380 {
381 #if EV_CXX_EXCEPTIONS
382 int r =
383 #endif
384 ev_default_loop (flags); 389 !ev_default_loop (flags)
385 #if EV_CXX_EXCEPTIONS 390#endif
386 if (!r) 391 )
387 throw bad_loop (); 392 throw bad_loop ();
388 #endif
389 }
390#endif
391
392 ~default_loop () throw ()
393 {
394 ev_default_destroy ();
395#if EV_MULTIPLICITY
396 EV_AX = 0;
397#endif
398 } 393 }
399 394
400 private: 395 private:
401
402 default_loop (const default_loop &); 396 default_loop (const default_loop &);
403
404 default_loop & operator= (const default_loop &); 397 default_loop &operator = (const default_loop &);
405
406 }; 398 };
407 399
408 inline loop_ref get_default_loop () throw () 400 inline loop_ref get_default_loop () throw ()
409 { 401 {
410#if EV_MULTIPLICITY 402#if EV_MULTIPLICITY
431 struct base : ev_watcher 423 struct base : ev_watcher
432 { 424 {
433 #if EV_MULTIPLICITY 425 #if EV_MULTIPLICITY
434 EV_PX; 426 EV_PX;
435 427
428 // loop set
436 void set (EV_PX) throw () 429 void set (EV_P) throw ()
437 { 430 {
438 this->EV_A = EV_A; 431 this->EV_A = EV_A;
439 } 432 }
440 #endif 433 #endif
441 434
445 #endif 438 #endif
446 { 439 {
447 ev_init (this, 0); 440 ev_init (this, 0);
448 } 441 }
449 442
450 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 ()
451 { 444 {
452 this->data = data; 445 this->data = (void *)data;
453 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);
454 } 461 }
455 462
456 // method callback 463 // method callback
457 template<class K, void (K::*method)(watcher &w, int)> 464 template<class K, void (K::*method)(watcher &w, int)>
458 void set (K *object) throw () 465 void set (K *object) throw ()
459 { 466 {
460 set_ (object, method_thunk<K, method>); 467 set_ (object, method_thunk<K, method>);
461 } 468 }
462 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
463 template<class K, void (K::*method)(watcher &w, int)> 477 template<class K, void (K::*method)(watcher &w, int)>
464 static void method_thunk (EV_P_ ev_watcher *w, int revents) 478 static void method_thunk (EV_P_ ev_watcher *w, int revents)
465 { 479 {
466 K *obj = static_cast<K *>(w->data); 480 (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); 481 (*static_cast<watcher *>(w), revents);
495 } 482 }
496 483
497 // simple callback 484 // no-argument callback
498 template<class K, void (K::*method)()> 485 template<class K, void (K::*method)()>
499 void set (K *object) throw () 486 void set (K *object) throw ()
500 { 487 {
501 set_ (object, method_noargs_thunk<K, method>); 488 set_ (object, method_noargs_thunk<K, method>);
502 } 489 }
503 490
504 template<class K, void (K::*method)()> 491 template<class K, void (K::*method)()>
505 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)
506 { 493 {
507 K *obj = static_cast<K *>(w->data); 494 (static_cast<K *>(w->data)->*method)
508 (obj->*method) (); 495 ();
509 } 496 }
510 497
511 void operator ()(int events = EV_UNDEF) 498 void operator ()(int events = EV_UNDEF)
512 { 499 {
500 return
513 return ev_cb (static_cast<ev_watcher *>(this)) 501 ev_cb (static_cast<ev_watcher *>(this))
514 (static_cast<ev_watcher *>(this), events); 502 (static_cast<ev_watcher *>(this), events);
515 } 503 }
516 504
517 bool is_active () const throw () 505 bool is_active () const throw ()
518 { 506 {
519 return ev_is_active (static_cast<const ev_watcher *>(this)); 507 return ev_is_active (static_cast<const ev_watcher *>(this));
575 ev_set_syserr_cb (cb); 563 ev_set_syserr_cb (cb);
576 } 564 }
577 565
578 #if EV_MULTIPLICITY 566 #if EV_MULTIPLICITY
579 #define EV_CONSTRUCT(cppstem,cstem) \ 567 #define EV_CONSTRUCT(cppstem,cstem) \
580 (EV_PX = get_default_loop ()) throw () \ 568 (EV_PX = get_default_loop ()) throw () \
581 : base<ev_ ## cstem, cppstem> (EV_A) \ 569 : base<ev_ ## cstem, cppstem> (EV_A) \
582 { \ 570 { \
583 } 571 }
584 #else 572 #else
585 #define EV_CONSTRUCT(cppstem,cstem) \ 573 #define EV_CONSTRUCT(cppstem,cstem) \
586 () throw () \ 574 () throw () \
587 { \ 575 { \
588 } 576 }
589 #endif 577 #endif
590 578
591 /* using a template here would require quite a bit more lines, 579 /* using a template here would require quite a bit more lines,
592 * so a macro solution was chosen */ 580 * so a macro solution was chosen */
593 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 581 #define EV_BEGIN_WATCHER(cppstem,cstem) \
594 \ 582 \
595 struct cppstem : base<ev_ ## cstem, cppstem> \ 583 struct cppstem : base<ev_ ## cstem, cppstem> \
596 { \ 584 { \
597 void start () throw () \ 585 void start () throw () \
598 { \ 586 { \
599 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 587 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
600 } \ 588 } \
601 \ 589 \
602 void stop () throw () \ 590 void stop () throw () \
603 { \ 591 { \
604 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 592 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
605 } \ 593 } \
606 \ 594 \
607 cppstem EV_CONSTRUCT(cppstem,cstem) \ 595 cppstem EV_CONSTRUCT(cppstem,cstem) \
608 \ 596 \
609 ~cppstem () throw () \ 597 ~cppstem () throw () \
610 { \ 598 { \
611 stop (); \ 599 stop (); \
612 } \ 600 } \
613 \ 601 \
614 using base<ev_ ## cstem, cppstem>::set; \ 602 using base<ev_ ## cstem, cppstem>::set; \
615 \ 603 \
616 private: \ 604 private: \
617 \ 605 \
618 cppstem (const cppstem &o); \ 606 cppstem (const cppstem &o); \
619 \ 607 \
620 cppstem & operator =(const cppstem &o); \ 608 cppstem &operator =(const cppstem &o); \
621 \ 609 \
622 public: 610 public:
623 611
624 #define EV_END_WATCHER(cppstem,cstem) \ 612 #define EV_END_WATCHER(cppstem,cstem) \
625 }; 613 };
665 653
666 void again () throw () 654 void again () throw ()
667 { 655 {
668 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 656 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
669 } 657 }
658
659 ev_tstamp remaining ()
660 {
661 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
662 }
670 EV_END_WATCHER (timer, timer) 663 EV_END_WATCHER (timer, timer)
671 664
672 #if EV_PERIODIC_ENABLE 665 #if EV_PERIODIC_ENABLE
673 EV_BEGIN_WATCHER (periodic, periodic) 666 EV_BEGIN_WATCHER (periodic, periodic)
674 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 667 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
690 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 683 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
691 } 684 }
692 EV_END_WATCHER (periodic, periodic) 685 EV_END_WATCHER (periodic, periodic)
693 #endif 686 #endif
694 687
688 #if EV_SIGNAL_ENABLE
695 EV_BEGIN_WATCHER (sig, signal) 689 EV_BEGIN_WATCHER (sig, signal)
696 void set (int signum) throw () 690 void set (int signum) throw ()
697 { 691 {
698 int active = is_active (); 692 int active = is_active ();
699 if (active) stop (); 693 if (active) stop ();
705 { 699 {
706 set (signum); 700 set (signum);
707 start (); 701 start ();
708 } 702 }
709 EV_END_WATCHER (sig, signal) 703 EV_END_WATCHER (sig, signal)
704 #endif
710 705
706 #if EV_CHILD_ENABLE
711 EV_BEGIN_WATCHER (child, child) 707 EV_BEGIN_WATCHER (child, child)
712 void set (int pid) throw () 708 void set (int pid, int trace = 0) throw ()
713 { 709 {
714 int active = is_active (); 710 int active = is_active ();
715 if (active) stop (); 711 if (active) stop ();
716 ev_child_set (static_cast<ev_child *>(this), pid); 712 ev_child_set (static_cast<ev_child *>(this), pid, trace);
717 if (active) start (); 713 if (active) start ();
718 } 714 }
719 715
720 void start (int pid) throw () 716 void start (int pid, int trace = 0) throw ()
721 { 717 {
722 set (pid); 718 set (pid, trace);
723 start (); 719 start ();
724 } 720 }
725 EV_END_WATCHER (child, child) 721 EV_END_WATCHER (child, child)
722 #endif
726 723
727 #if EV_STAT_ENABLE 724 #if EV_STAT_ENABLE
728 EV_BEGIN_WATCHER (stat, stat) 725 EV_BEGIN_WATCHER (stat, stat)
729 void set (const char *path, ev_tstamp interval = 0.) throw () 726 void set (const char *path, ev_tstamp interval = 0.) throw ()
730 { 727 {
746 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 743 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
747 } 744 }
748 EV_END_WATCHER (stat, stat) 745 EV_END_WATCHER (stat, stat)
749 #endif 746 #endif
750 747
748 #if EV_IDLE_ENABLE
751 EV_BEGIN_WATCHER (idle, idle) 749 EV_BEGIN_WATCHER (idle, idle)
752 void set () throw () { } 750 void set () throw () { }
753 EV_END_WATCHER (idle, idle) 751 EV_END_WATCHER (idle, idle)
752 #endif
754 753
754 #if EV_PREPARE_ENABLE
755 EV_BEGIN_WATCHER (prepare, prepare) 755 EV_BEGIN_WATCHER (prepare, prepare)
756 void set () throw () { } 756 void set () throw () { }
757 EV_END_WATCHER (prepare, prepare) 757 EV_END_WATCHER (prepare, prepare)
758 #endif
758 759
760 #if EV_CHECK_ENABLE
759 EV_BEGIN_WATCHER (check, check) 761 EV_BEGIN_WATCHER (check, check)
760 void set () throw () { } 762 void set () throw () { }
761 EV_END_WATCHER (check, check) 763 EV_END_WATCHER (check, check)
764 #endif
762 765
763 #if EV_EMBED_ENABLE 766 #if EV_EMBED_ENABLE
764 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
765 void start (struct ev_loop *embedded_loop) throw () 776 void start (struct ev_loop *embedded_loop) throw ()
766 { 777 {
767 stop (); 778 set (embedded_loop);
768 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
769 start (); 779 start ();
770 } 780 }
771 781
772 void sweep () 782 void sweep ()
773 { 783 {
778 788
779 #if EV_FORK_ENABLE 789 #if EV_FORK_ENABLE
780 EV_BEGIN_WATCHER (fork, fork) 790 EV_BEGIN_WATCHER (fork, fork)
781 void set () throw () { } 791 void set () throw () { }
782 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)
783 #endif 807 #endif
784 808
785 #undef EV_PX 809 #undef EV_PX
786 #undef EV_PX_ 810 #undef EV_PX_
787 #undef EV_CONSTRUCT 811 #undef EV_CONSTRUCT
788 #undef EV_BEGIN_WATCHER 812 #undef EV_BEGIN_WATCHER
789 #undef EV_END_WATCHER 813 #undef EV_END_WATCHER
790
791} 814}
792 815
793#undef EV_THROW
794
795#endif 816#endif
796 817

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines