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

Comparing libev/ev++.h (file contents):
Revision 1.43 by root, Wed Nov 5 14:36:18 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,2008 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 *
74 PREPARE = EV_PREPARE, 74 PREPARE = EV_PREPARE,
75 FORK = EV_FORK, 75 FORK = EV_FORK,
76 ASYNC = EV_ASYNC, 76 ASYNC = EV_ASYNC,
77 EMBED = EV_EMBED, 77 EMBED = EV_EMBED,
78# undef ERROR // some systems stupidly #define ERROR 78# undef ERROR // some systems stupidly #define ERROR
79 ERROR = EV_ERROR, 79 ERROR = EV_ERROR
80 }; 80 };
81 81
82 enum 82 enum
83 { 83 {
84 AUTO = EVFLAG_AUTO, 84 AUTO = EVFLAG_AUTO,
160 return false; 160 return false;
161#endif 161#endif
162 } 162 }
163 163
164#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
165 bool operator == (struct ev_loop *other) const throw () 165 bool operator == (const EV_P) const throw ()
166 { 166 {
167 return this->EV_AX == other; 167 return this->EV_AX == EV_A;
168 }
169
170 bool operator != (struct ev_loop *other) const throw ()
171 { 168 }
172 return ! (*this == other); 169
170 bool operator != (const EV_P) const throw ()
173 } 171 {
174
175 bool operator == (const struct ev_loop *other) const throw ()
176 {
177 return this->EV_AX == other;
178 }
179
180 bool operator != (const struct ev_loop *other) const throw ()
181 {
182 return (*this == other); 172 return (*this == EV_A);
183 } 173 }
184 174
185 operator struct ev_loop * () const throw () 175 operator struct ev_loop * () const throw ()
186 { 176 {
187 return EV_AX; 177 return EV_AX;
215#else 205#else
216 ev_default_fork (); 206 ev_default_fork ();
217#endif 207#endif
218 } 208 }
219 209
220 unsigned int count () const throw ()
221 {
222 return ev_loop_count (EV_AX);
223 }
224
225 unsigned int backend () const throw () 210 unsigned int backend () const throw ()
226 { 211 {
227 return ev_backend (EV_AX); 212 return ev_backend (EV_AX);
228 } 213 }
229 214
240 void unref () throw () 225 void unref () throw ()
241 { 226 {
242 ev_unref (EV_AX); 227 ev_unref (EV_AX);
243 } 228 }
244 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
245 void set_io_collect_interval (tstamp interval) throw () 241 void set_io_collect_interval (tstamp interval) throw ()
246 { 242 {
247 ev_set_io_collect_interval (EV_AX_ interval); 243 ev_set_io_collect_interval (EV_AX_ interval);
248 } 244 }
249 245
250 void set_timeout_collect_interval (tstamp interval) throw () 246 void set_timeout_collect_interval (tstamp interval) throw ()
251 { 247 {
252 ev_set_timeout_collect_interval (EV_AX_ interval); 248 ev_set_timeout_collect_interval (EV_AX_ interval);
253 } 249 }
250#endif
254 251
255 // function callback 252 // function callback
256 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 ()
257 { 254 {
258 ev_once (EV_AX_ fd, events, timeout, cb, arg); 255 ev_once (EV_AX_ fd, events, timeout, cb, arg);
259 } 256 }
260 257
261 // method callback 258 // method callback
263 void once (int fd, int events, tstamp timeout, K *object) throw () 260 void once (int fd, int events, tstamp timeout, K *object) throw ()
264 { 261 {
265 once (fd, events, timeout, method_thunk<K, method>, object); 262 once (fd, events, timeout, method_thunk<K, method>, object);
266 } 263 }
267 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
268 template<class K, void (K::*method)(int)> 272 template<class K, void (K::*method)(int)>
269 static void method_thunk (int revents, void* arg) 273 static void method_thunk (int revents, void *arg)
270 {
271 K *obj = static_cast<K *>(arg);
272 (obj->*method) (revents);
273 } 274 {
275 static_cast<K *>(arg)->*method
276 (revents);
277 }
274 278
275 // const method callback 279 // no-argument method callback
276 template<class K, void (K::*method)(int) const>
277 void once (int fd, int events, tstamp timeout, const K *object) throw ()
278 {
279 once (fd, events, timeout, const_method_thunk<K, method>, object);
280 }
281
282 template<class K, void (K::*method)(int) const>
283 static void const_method_thunk (int revents, void* arg)
284 {
285 K *obj = static_cast<K *>(arg);
286 (obj->*method) (revents);
287 }
288
289 // simple method callback
290 template<class K, void (K::*method)()> 280 template<class K, void (K::*method)()>
291 void once (int fd, int events, tstamp timeout, K *object) throw () 281 void once (int fd, int events, tstamp timeout, K *object) throw ()
292 { 282 {
293 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 283 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
294 } 284 }
295 285
296 template<class K, void (K::*method)()> 286 template<class K, void (K::*method)()>
297 static void method_noargs_thunk (int revents, void* arg) 287 static void method_noargs_thunk (int revents, void *arg)
298 { 288 {
299 K *obj = static_cast<K *>(arg); 289 static_cast<K *>(arg)->*method
300 (obj->*method) (); 290 ();
301 } 291 }
302 292
303 // simpler function callback 293 // simpler function callback
304 template<void (*cb)(int)> 294 template<void (*cb)(int)>
305 void once (int fd, int events, tstamp timeout) throw () 295 void once (int fd, int events, tstamp timeout) throw ()
306 { 296 {
307 once (fd, events, timeout, simpler_func_thunk<cb>); 297 once (fd, events, timeout, simpler_func_thunk<cb>);
308 } 298 }
309 299
310 template<void (*cb)(int)> 300 template<void (*cb)(int)>
311 static void simpler_func_thunk (int revents, void* arg) 301 static void simpler_func_thunk (int revents, void *arg)
312 { 302 {
303 (*cb)
313 (*cb) (revents); 304 (revents);
314 } 305 }
315 306
316 // simplest function callback 307 // simplest function callback
317 template<void (*cb)()> 308 template<void (*cb)()>
318 void once (int fd, int events, tstamp timeout) throw () 309 void once (int fd, int events, tstamp timeout) throw ()
319 { 310 {
320 once (fd, events, timeout, simplest_func_thunk<cb>); 311 once (fd, events, timeout, simplest_func_thunk<cb>);
321 } 312 }
322 313
323 template<void (*cb)()> 314 template<void (*cb)()>
324 static void simplest_func_thunk (int revents, void* arg) 315 static void simplest_func_thunk (int revents, void *arg)
325 { 316 {
326 (*cb) (); 317 (*cb)
318 ();
327 } 319 }
328 320
329 void feed_fd_event (int fd, int revents) throw () 321 void feed_fd_event (int fd, int revents) throw ()
330 { 322 {
331 ev_feed_fd_event (EV_AX_ fd, revents); 323 ev_feed_fd_event (EV_AX_ fd, revents);
421 struct base : ev_watcher 413 struct base : ev_watcher
422 { 414 {
423 #if EV_MULTIPLICITY 415 #if EV_MULTIPLICITY
424 EV_PX; 416 EV_PX;
425 417
418 // loop set
426 void set (EV_PX) throw () 419 void set (EV_P) throw ()
427 { 420 {
428 this->EV_A = EV_A; 421 this->EV_A = EV_A;
429 } 422 }
430 #endif 423 #endif
431 424
435 #endif 428 #endif
436 { 429 {
437 ev_init (this, 0); 430 ev_init (this, 0);
438 } 431 }
439 432
440 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 ()
441 { 434 {
442 this->data = data; 435 this->data = (void *)data;
443 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);
444 } 451 }
445 452
446 // method callback 453 // method callback
447 template<class K, void (K::*method)(watcher &w, int)> 454 template<class K, void (K::*method)(watcher &w, int)>
448 void set (K *object) throw () 455 void set (K *object) throw ()
449 { 456 {
450 set_ (object, method_thunk<K, method>); 457 set_ (object, method_thunk<K, method>);
451 } 458 }
452 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
453 template<class K, void (K::*method)(watcher &w, int)> 467 template<class K, void (K::*method)(watcher &w, int)>
454 static void method_thunk (EV_P_ ev_watcher *w, int revents) 468 static void method_thunk (EV_P_ ev_watcher *w, int revents)
455 { 469 {
456 K *obj = static_cast<K *>(w->data); 470 (static_cast<K *>(w->data)->*method)
457 (obj->*method) (*static_cast<watcher *>(w), revents);
458 }
459
460 // const method callback
461 template<class K, void (K::*method)(watcher &w, int) const>
462 void set (const K *object) throw ()
463 {
464 set_ (object, const_method_thunk<K, method>);
465 }
466
467 template<class K, void (K::*method)(watcher &w, int) const>
468 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
469 {
470 K *obj = static_cast<K *>(w->data);
471 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
472 }
473
474 // function callback
475 template<void (*function)(watcher &w, int)>
476 void set (void *data = 0) throw ()
477 {
478 set_ (data, function_thunk<function>);
479 }
480
481 template<void (*function)(watcher &w, int)>
482 static void function_thunk (EV_P_ ev_watcher *w, int revents)
483 {
484 function (*static_cast<watcher *>(w), revents); 471 (*static_cast<watcher *>(w), revents);
485 } 472 }
486 473
487 // simple callback 474 // no-argument callback
488 template<class K, void (K::*method)()> 475 template<class K, void (K::*method)()>
489 void set (K *object) throw () 476 void set (K *object) throw ()
490 { 477 {
491 set_ (object, method_noargs_thunk<K, method>); 478 set_ (object, method_noargs_thunk<K, method>);
492 } 479 }
493 480
494 template<class K, void (K::*method)()> 481 template<class K, void (K::*method)()>
495 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)
496 { 483 {
497 K *obj = static_cast<K *>(w->data); 484 (static_cast<K *>(w->data)->*method)
498 (obj->*method) (); 485 ();
499 } 486 }
500 487
501 void operator ()(int events = EV_UNDEF) 488 void operator ()(int events = EV_UNDEF)
502 { 489 {
490 return
503 return ev_cb (static_cast<ev_watcher *>(this)) 491 ev_cb (static_cast<ev_watcher *>(this))
504 (static_cast<ev_watcher *>(this), events); 492 (static_cast<ev_watcher *>(this), events);
505 } 493 }
506 494
507 bool is_active () const throw () 495 bool is_active () const throw ()
508 { 496 {
509 return ev_is_active (static_cast<const ev_watcher *>(this)); 497 return ev_is_active (static_cast<const ev_watcher *>(this));
655 643
656 void again () throw () 644 void again () throw ()
657 { 645 {
658 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 646 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
659 } 647 }
648
649 ev_tstamp remaining ()
650 {
651 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
652 }
660 EV_END_WATCHER (timer, timer) 653 EV_END_WATCHER (timer, timer)
661 654
662 #if EV_PERIODIC_ENABLE 655 #if EV_PERIODIC_ENABLE
663 EV_BEGIN_WATCHER (periodic, periodic) 656 EV_BEGIN_WATCHER (periodic, periodic)
664 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 657 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
680 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 673 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
681 } 674 }
682 EV_END_WATCHER (periodic, periodic) 675 EV_END_WATCHER (periodic, periodic)
683 #endif 676 #endif
684 677
678 #if EV_SIGNAL_ENABLE
685 EV_BEGIN_WATCHER (sig, signal) 679 EV_BEGIN_WATCHER (sig, signal)
686 void set (int signum) throw () 680 void set (int signum) throw ()
687 { 681 {
688 int active = is_active (); 682 int active = is_active ();
689 if (active) stop (); 683 if (active) stop ();
695 { 689 {
696 set (signum); 690 set (signum);
697 start (); 691 start ();
698 } 692 }
699 EV_END_WATCHER (sig, signal) 693 EV_END_WATCHER (sig, signal)
694 #endif
700 695
696 #if EV_CHILD_ENABLE
701 EV_BEGIN_WATCHER (child, child) 697 EV_BEGIN_WATCHER (child, child)
702 void set (int pid, int trace = 0) throw () 698 void set (int pid, int trace = 0) throw ()
703 { 699 {
704 int active = is_active (); 700 int active = is_active ();
705 if (active) stop (); 701 if (active) stop ();
711 { 707 {
712 set (pid, trace); 708 set (pid, trace);
713 start (); 709 start ();
714 } 710 }
715 EV_END_WATCHER (child, child) 711 EV_END_WATCHER (child, child)
712 #endif
716 713
717 #if EV_STAT_ENABLE 714 #if EV_STAT_ENABLE
718 EV_BEGIN_WATCHER (stat, stat) 715 EV_BEGIN_WATCHER (stat, stat)
719 void set (const char *path, ev_tstamp interval = 0.) throw () 716 void set (const char *path, ev_tstamp interval = 0.) throw ()
720 { 717 {
736 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 733 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
737 } 734 }
738 EV_END_WATCHER (stat, stat) 735 EV_END_WATCHER (stat, stat)
739 #endif 736 #endif
740 737
738 #if EV_IDLE_ENABLE
741 EV_BEGIN_WATCHER (idle, idle) 739 EV_BEGIN_WATCHER (idle, idle)
742 void set () throw () { } 740 void set () throw () { }
743 EV_END_WATCHER (idle, idle) 741 EV_END_WATCHER (idle, idle)
742 #endif
744 743
744 #if EV_PREPARE_ENABLE
745 EV_BEGIN_WATCHER (prepare, prepare) 745 EV_BEGIN_WATCHER (prepare, prepare)
746 void set () throw () { } 746 void set () throw () { }
747 EV_END_WATCHER (prepare, prepare) 747 EV_END_WATCHER (prepare, prepare)
748 #endif
748 749
750 #if EV_CHECK_ENABLE
749 EV_BEGIN_WATCHER (check, check) 751 EV_BEGIN_WATCHER (check, check)
750 void set () throw () { } 752 void set () throw () { }
751 EV_END_WATCHER (check, check) 753 EV_END_WATCHER (check, check)
754 #endif
752 755
753 #if EV_EMBED_ENABLE 756 #if EV_EMBED_ENABLE
754 EV_BEGIN_WATCHER (embed, embed) 757 EV_BEGIN_WATCHER (embed, embed)
755 void set (struct ev_loop *embedded_loop) throw () 758 void set (struct ev_loop *embedded_loop) throw ()
756 { 759 {
779 EV_END_WATCHER (fork, fork) 782 EV_END_WATCHER (fork, fork)
780 #endif 783 #endif
781 784
782 #if EV_ASYNC_ENABLE 785 #if EV_ASYNC_ENABLE
783 EV_BEGIN_WATCHER (async, async) 786 EV_BEGIN_WATCHER (async, async)
784 void set () throw () { }
785
786 void send () throw () 787 void send () throw ()
787 { 788 {
788 ev_async_send (EV_A_ static_cast<ev_async *>(this)); 789 ev_async_send (EV_A_ static_cast<ev_async *>(this));
789 } 790 }
790 791

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines