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, |
… | |
… | |
225 | void unref () throw () |
225 | void unref () throw () |
226 | { |
226 | { |
227 | ev_unref (EV_AX); |
227 | ev_unref (EV_AX); |
228 | } |
228 | } |
229 | |
229 | |
230 | #if EV_MINIMAL < 2 |
230 | #if EV_FEATURE_API |
231 | unsigned int count () const throw () |
231 | unsigned int iteration () const throw () |
232 | { |
232 | { |
233 | return ev_loop_count (EV_AX); |
233 | return ev_iteration (EV_AX); |
234 | } |
234 | } |
235 | |
235 | |
236 | unsigned int depth () const throw () |
236 | unsigned int depth () const throw () |
237 | { |
237 | { |
238 | return ev_loop_depth (EV_AX); |
238 | return ev_depth (EV_AX); |
239 | } |
239 | } |
240 | |
240 | |
241 | void set_io_collect_interval (tstamp interval) throw () |
241 | void set_io_collect_interval (tstamp interval) throw () |
242 | { |
242 | { |
243 | ev_set_io_collect_interval (EV_AX_ interval); |
243 | ev_set_io_collect_interval (EV_AX_ interval); |
… | |
… | |
413 | struct base : ev_watcher |
413 | struct base : ev_watcher |
414 | { |
414 | { |
415 | #if EV_MULTIPLICITY |
415 | #if EV_MULTIPLICITY |
416 | EV_PX; |
416 | EV_PX; |
417 | |
417 | |
|
|
418 | // loop set |
418 | void set (EV_P) throw () |
419 | void set (EV_P) throw () |
419 | { |
420 | { |
420 | this->EV_A = EV_A; |
421 | this->EV_A = EV_A; |
421 | } |
422 | } |
422 | #endif |
423 | #endif |
… | |
… | |
478 | } |
479 | } |
479 | |
480 | |
480 | template<class K, void (K::*method)()> |
481 | template<class K, void (K::*method)()> |
481 | 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) |
482 | { |
483 | { |
483 | static_cast<K *>(w->data)->*method |
484 | (static_cast<K *>(w->data)->*method) |
484 | (); |
485 | (); |
485 | } |
486 | } |
486 | |
487 | |
487 | void operator ()(int events = EV_UNDEF) |
488 | void operator ()(int events = EV_UNDEF) |
488 | { |
489 | { |
… | |
… | |
672 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
673 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
673 | } |
674 | } |
674 | EV_END_WATCHER (periodic, periodic) |
675 | EV_END_WATCHER (periodic, periodic) |
675 | #endif |
676 | #endif |
676 | |
677 | |
|
|
678 | #if EV_SIGNAL_ENABLE |
677 | EV_BEGIN_WATCHER (sig, signal) |
679 | EV_BEGIN_WATCHER (sig, signal) |
678 | void set (int signum) throw () |
680 | void set (int signum) throw () |
679 | { |
681 | { |
680 | int active = is_active (); |
682 | int active = is_active (); |
681 | if (active) stop (); |
683 | if (active) stop (); |
… | |
… | |
687 | { |
689 | { |
688 | set (signum); |
690 | set (signum); |
689 | start (); |
691 | start (); |
690 | } |
692 | } |
691 | EV_END_WATCHER (sig, signal) |
693 | EV_END_WATCHER (sig, signal) |
|
|
694 | #endif |
692 | |
695 | |
|
|
696 | #if EV_CHILD_ENABLE |
693 | EV_BEGIN_WATCHER (child, child) |
697 | EV_BEGIN_WATCHER (child, child) |
694 | void set (int pid, int trace = 0) throw () |
698 | void set (int pid, int trace = 0) throw () |
695 | { |
699 | { |
696 | int active = is_active (); |
700 | int active = is_active (); |
697 | if (active) stop (); |
701 | if (active) stop (); |
… | |
… | |
703 | { |
707 | { |
704 | set (pid, trace); |
708 | set (pid, trace); |
705 | start (); |
709 | start (); |
706 | } |
710 | } |
707 | EV_END_WATCHER (child, child) |
711 | EV_END_WATCHER (child, child) |
|
|
712 | #endif |
708 | |
713 | |
709 | #if EV_STAT_ENABLE |
714 | #if EV_STAT_ENABLE |
710 | EV_BEGIN_WATCHER (stat, stat) |
715 | EV_BEGIN_WATCHER (stat, stat) |
711 | void set (const char *path, ev_tstamp interval = 0.) throw () |
716 | void set (const char *path, ev_tstamp interval = 0.) throw () |
712 | { |
717 | { |
… | |
… | |
728 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
733 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
729 | } |
734 | } |
730 | EV_END_WATCHER (stat, stat) |
735 | EV_END_WATCHER (stat, stat) |
731 | #endif |
736 | #endif |
732 | |
737 | |
733 | #if EV_IDLE_ENABLE |
738 | #if EV_IDLE_ENABLE |
734 | EV_BEGIN_WATCHER (idle, idle) |
739 | EV_BEGIN_WATCHER (idle, idle) |
735 | void set () throw () { } |
740 | void set () throw () { } |
736 | EV_END_WATCHER (idle, idle) |
741 | EV_END_WATCHER (idle, idle) |
737 | #endif |
742 | #endif |
738 | |
743 | |
|
|
744 | #if EV_PREPARE_ENABLE |
739 | EV_BEGIN_WATCHER (prepare, prepare) |
745 | EV_BEGIN_WATCHER (prepare, prepare) |
740 | void set () throw () { } |
746 | void set () throw () { } |
741 | EV_END_WATCHER (prepare, prepare) |
747 | EV_END_WATCHER (prepare, prepare) |
|
|
748 | #endif |
742 | |
749 | |
|
|
750 | #if EV_CHECK_ENABLE |
743 | EV_BEGIN_WATCHER (check, check) |
751 | EV_BEGIN_WATCHER (check, check) |
744 | void set () throw () { } |
752 | void set () throw () { } |
745 | EV_END_WATCHER (check, check) |
753 | EV_END_WATCHER (check, check) |
|
|
754 | #endif |
746 | |
755 | |
747 | #if EV_EMBED_ENABLE |
756 | #if EV_EMBED_ENABLE |
748 | EV_BEGIN_WATCHER (embed, embed) |
757 | EV_BEGIN_WATCHER (embed, embed) |
749 | void set (struct ev_loop *embedded_loop) throw () |
758 | void set (struct ev_loop *embedded_loop) throw () |
750 | { |
759 | { |
… | |
… | |
773 | EV_END_WATCHER (fork, fork) |
782 | EV_END_WATCHER (fork, fork) |
774 | #endif |
783 | #endif |
775 | |
784 | |
776 | #if EV_ASYNC_ENABLE |
785 | #if EV_ASYNC_ENABLE |
777 | EV_BEGIN_WATCHER (async, async) |
786 | EV_BEGIN_WATCHER (async, async) |
778 | void set () throw () { } |
|
|
779 | |
|
|
780 | void send () throw () |
787 | void send () throw () |
781 | { |
788 | { |
782 | ev_async_send (EV_A_ static_cast<ev_async *>(this)); |
789 | ev_async_send (EV_A_ static_cast<ev_async *>(this)); |
783 | } |
790 | } |
784 | |
791 | |