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

Comparing libev/ev++.h (file contents):
Revision 1.44 by root, Wed Dec 3 15:23:44 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,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 *
62 { 62 {
63 UNDEF = EV_UNDEF, 63 UNDEF = EV_UNDEF,
64 NONE = EV_NONE, 64 NONE = EV_NONE,
65 READ = EV_READ, 65 READ = EV_READ,
66 WRITE = EV_WRITE, 66 WRITE = EV_WRITE,
67#if EV_COMPAT3
67 TIMEOUT = EV_TIMEOUT, 68 TIMEOUT = EV_TIMEOUT,
69#endif
70 TIMER = EV_TIMER,
68 PERIODIC = EV_PERIODIC, 71 PERIODIC = EV_PERIODIC,
69 SIGNAL = EV_SIGNAL, 72 SIGNAL = EV_SIGNAL,
70 CHILD = EV_CHILD, 73 CHILD = EV_CHILD,
71 STAT = EV_STAT, 74 STAT = EV_STAT,
72 IDLE = EV_IDLE, 75 IDLE = EV_IDLE,
74 PREPARE = EV_PREPARE, 77 PREPARE = EV_PREPARE,
75 FORK = EV_FORK, 78 FORK = EV_FORK,
76 ASYNC = EV_ASYNC, 79 ASYNC = EV_ASYNC,
77 EMBED = EV_EMBED, 80 EMBED = EV_EMBED,
78# undef ERROR // some systems stupidly #define ERROR 81# undef ERROR // some systems stupidly #define ERROR
79 ERROR = EV_ERROR, 82 ERROR = EV_ERROR
80 }; 83 };
81 84
82 enum 85 enum
83 { 86 {
84 AUTO = EVFLAG_AUTO, 87 AUTO = EVFLAG_AUTO,
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 struct bad_loop 115 struct bad_loop
109#if EV_USE_STDEXCEPT 116#if EV_USE_STDEXCEPT
110 : std::runtime_error 117 : std::runtime_error
186 { 193 {
187 return EV_AX == ev_default_loop (0); 194 return EV_AX == ev_default_loop (0);
188 } 195 }
189#endif 196#endif
190 197
198#if EV_COMPAT3
191 void loop (int flags = 0) 199 void loop (int flags = 0)
192 { 200 {
193 ev_loop (EV_AX_ flags); 201 ev_run (EV_AX_ flags);
194 } 202 }
195 203
196 void unloop (how_t how = ONE) throw () 204 void unloop (how_t how = ONE) throw ()
197 { 205 {
198 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);
199 } 218 }
200 219
201 void post_fork () throw () 220 void post_fork () throw ()
202 { 221 {
203#if EV_MULTIPLICITY
204 ev_loop_fork (EV_AX); 222 ev_loop_fork (EV_AX);
205#else
206 ev_default_fork ();
207#endif
208 }
209
210 unsigned int count () const throw ()
211 {
212 return ev_loop_count (EV_AX);
213 } 223 }
214 224
215 unsigned int backend () const throw () 225 unsigned int backend () const throw ()
216 { 226 {
217 return ev_backend (EV_AX); 227 return ev_backend (EV_AX);
230 void unref () throw () 240 void unref () throw ()
231 { 241 {
232 ev_unref (EV_AX); 242 ev_unref (EV_AX);
233 } 243 }
234 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
235 void set_io_collect_interval (tstamp interval) throw () 256 void set_io_collect_interval (tstamp interval) throw ()
236 { 257 {
237 ev_set_io_collect_interval (EV_AX_ interval); 258 ev_set_io_collect_interval (EV_AX_ interval);
238 } 259 }
239 260
240 void set_timeout_collect_interval (tstamp interval) throw () 261 void set_timeout_collect_interval (tstamp interval) throw ()
241 { 262 {
242 ev_set_timeout_collect_interval (EV_AX_ interval); 263 ev_set_timeout_collect_interval (EV_AX_ interval);
243 } 264 }
265#endif
244 266
245 // function callback 267 // function callback
246 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 ()
247 { 269 {
248 ev_once (EV_AX_ fd, events, timeout, cb, arg); 270 ev_once (EV_AX_ fd, events, timeout, cb, arg);
366#else 388#else
367 !ev_default_loop (flags) 389 !ev_default_loop (flags)
368#endif 390#endif
369 ) 391 )
370 throw bad_loop (); 392 throw bad_loop ();
371 }
372
373 ~default_loop () throw ()
374 {
375 ev_default_destroy ();
376 } 393 }
377 394
378 private: 395 private:
379 default_loop (const default_loop &); 396 default_loop (const default_loop &);
380 default_loop &operator = (const default_loop &); 397 default_loop &operator = (const default_loop &);
406 struct base : ev_watcher 423 struct base : ev_watcher
407 { 424 {
408 #if EV_MULTIPLICITY 425 #if EV_MULTIPLICITY
409 EV_PX; 426 EV_PX;
410 427
428 // loop set
411 void set (EV_P) throw () 429 void set (EV_P) throw ()
412 { 430 {
413 this->EV_A = EV_A; 431 this->EV_A = EV_A;
414 } 432 }
415 #endif 433 #endif
471 } 489 }
472 490
473 template<class K, void (K::*method)()> 491 template<class K, void (K::*method)()>
474 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)
475 { 493 {
476 static_cast<K *>(w->data)->*method 494 (static_cast<K *>(w->data)->*method)
477 (); 495 ();
478 } 496 }
479 497
480 void operator ()(int events = EV_UNDEF) 498 void operator ()(int events = EV_UNDEF)
481 { 499 {
635 653
636 void again () throw () 654 void again () throw ()
637 { 655 {
638 ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); 656 ev_timer_again (EV_A_ static_cast<ev_timer *>(this));
639 } 657 }
658
659 ev_tstamp remaining ()
660 {
661 return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this));
662 }
640 EV_END_WATCHER (timer, timer) 663 EV_END_WATCHER (timer, timer)
641 664
642 #if EV_PERIODIC_ENABLE 665 #if EV_PERIODIC_ENABLE
643 EV_BEGIN_WATCHER (periodic, periodic) 666 EV_BEGIN_WATCHER (periodic, periodic)
644 void set (ev_tstamp at, ev_tstamp interval = 0.) throw () 667 void set (ev_tstamp at, ev_tstamp interval = 0.) throw ()
660 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); 683 ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this));
661 } 684 }
662 EV_END_WATCHER (periodic, periodic) 685 EV_END_WATCHER (periodic, periodic)
663 #endif 686 #endif
664 687
688 #if EV_SIGNAL_ENABLE
665 EV_BEGIN_WATCHER (sig, signal) 689 EV_BEGIN_WATCHER (sig, signal)
666 void set (int signum) throw () 690 void set (int signum) throw ()
667 { 691 {
668 int active = is_active (); 692 int active = is_active ();
669 if (active) stop (); 693 if (active) stop ();
675 { 699 {
676 set (signum); 700 set (signum);
677 start (); 701 start ();
678 } 702 }
679 EV_END_WATCHER (sig, signal) 703 EV_END_WATCHER (sig, signal)
704 #endif
680 705
706 #if EV_CHILD_ENABLE
681 EV_BEGIN_WATCHER (child, child) 707 EV_BEGIN_WATCHER (child, child)
682 void set (int pid, int trace = 0) throw () 708 void set (int pid, int trace = 0) throw ()
683 { 709 {
684 int active = is_active (); 710 int active = is_active ();
685 if (active) stop (); 711 if (active) stop ();
691 { 717 {
692 set (pid, trace); 718 set (pid, trace);
693 start (); 719 start ();
694 } 720 }
695 EV_END_WATCHER (child, child) 721 EV_END_WATCHER (child, child)
722 #endif
696 723
697 #if EV_STAT_ENABLE 724 #if EV_STAT_ENABLE
698 EV_BEGIN_WATCHER (stat, stat) 725 EV_BEGIN_WATCHER (stat, stat)
699 void set (const char *path, ev_tstamp interval = 0.) throw () 726 void set (const char *path, ev_tstamp interval = 0.) throw ()
700 { 727 {
716 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); 743 ev_stat_stat (EV_A_ static_cast<ev_stat *>(this));
717 } 744 }
718 EV_END_WATCHER (stat, stat) 745 EV_END_WATCHER (stat, stat)
719 #endif 746 #endif
720 747
748 #if EV_IDLE_ENABLE
721 EV_BEGIN_WATCHER (idle, idle) 749 EV_BEGIN_WATCHER (idle, idle)
722 void set () throw () { } 750 void set () throw () { }
723 EV_END_WATCHER (idle, idle) 751 EV_END_WATCHER (idle, idle)
752 #endif
724 753
754 #if EV_PREPARE_ENABLE
725 EV_BEGIN_WATCHER (prepare, prepare) 755 EV_BEGIN_WATCHER (prepare, prepare)
726 void set () throw () { } 756 void set () throw () { }
727 EV_END_WATCHER (prepare, prepare) 757 EV_END_WATCHER (prepare, prepare)
758 #endif
728 759
760 #if EV_CHECK_ENABLE
729 EV_BEGIN_WATCHER (check, check) 761 EV_BEGIN_WATCHER (check, check)
730 void set () throw () { } 762 void set () throw () { }
731 EV_END_WATCHER (check, check) 763 EV_END_WATCHER (check, check)
764 #endif
732 765
733 #if EV_EMBED_ENABLE 766 #if EV_EMBED_ENABLE
734 EV_BEGIN_WATCHER (embed, embed) 767 EV_BEGIN_WATCHER (embed, embed)
735 void set (struct ev_loop *embedded_loop) throw () 768 void set (struct ev_loop *embedded_loop) throw ()
736 { 769 {
759 EV_END_WATCHER (fork, fork) 792 EV_END_WATCHER (fork, fork)
760 #endif 793 #endif
761 794
762 #if EV_ASYNC_ENABLE 795 #if EV_ASYNC_ENABLE
763 EV_BEGIN_WATCHER (async, async) 796 EV_BEGIN_WATCHER (async, async)
764 void set () throw () { }
765
766 void send () throw () 797 void send () throw ()
767 { 798 {
768 ev_async_send (EV_A_ static_cast<ev_async *>(this)); 799 ev_async_send (EV_A_ static_cast<ev_async *>(this));
769 } 800 }
770 801

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines