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 | * |
… | |
… | |
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 | { |
… | |
… | |
642 | |
643 | |
643 | void again () throw () |
644 | void again () throw () |
644 | { |
645 | { |
645 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
646 | ev_timer_again (EV_A_ static_cast<ev_timer *>(this)); |
646 | } |
647 | } |
|
|
648 | |
|
|
649 | ev_tstamp remaining () |
|
|
650 | { |
|
|
651 | return ev_timer_remaining (EV_A_ static_cast<ev_timer *>(this)); |
|
|
652 | } |
647 | EV_END_WATCHER (timer, timer) |
653 | EV_END_WATCHER (timer, timer) |
648 | |
654 | |
649 | #if EV_PERIODIC_ENABLE |
655 | #if EV_PERIODIC_ENABLE |
650 | EV_BEGIN_WATCHER (periodic, periodic) |
656 | EV_BEGIN_WATCHER (periodic, periodic) |
651 | void set (ev_tstamp at, ev_tstamp interval = 0.) throw () |
657 | void set (ev_tstamp at, ev_tstamp interval = 0.) throw () |
… | |
… | |
667 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
673 | ev_periodic_again (EV_A_ static_cast<ev_periodic *>(this)); |
668 | } |
674 | } |
669 | EV_END_WATCHER (periodic, periodic) |
675 | EV_END_WATCHER (periodic, periodic) |
670 | #endif |
676 | #endif |
671 | |
677 | |
|
|
678 | #if EV_SIGNAL_ENABLE |
672 | EV_BEGIN_WATCHER (sig, signal) |
679 | EV_BEGIN_WATCHER (sig, signal) |
673 | void set (int signum) throw () |
680 | void set (int signum) throw () |
674 | { |
681 | { |
675 | int active = is_active (); |
682 | int active = is_active (); |
676 | if (active) stop (); |
683 | if (active) stop (); |
… | |
… | |
682 | { |
689 | { |
683 | set (signum); |
690 | set (signum); |
684 | start (); |
691 | start (); |
685 | } |
692 | } |
686 | EV_END_WATCHER (sig, signal) |
693 | EV_END_WATCHER (sig, signal) |
|
|
694 | #endif |
687 | |
695 | |
|
|
696 | #if EV_CHILD_ENABLE |
688 | EV_BEGIN_WATCHER (child, child) |
697 | EV_BEGIN_WATCHER (child, child) |
689 | void set (int pid, int trace = 0) throw () |
698 | void set (int pid, int trace = 0) throw () |
690 | { |
699 | { |
691 | int active = is_active (); |
700 | int active = is_active (); |
692 | if (active) stop (); |
701 | if (active) stop (); |
… | |
… | |
698 | { |
707 | { |
699 | set (pid, trace); |
708 | set (pid, trace); |
700 | start (); |
709 | start (); |
701 | } |
710 | } |
702 | EV_END_WATCHER (child, child) |
711 | EV_END_WATCHER (child, child) |
|
|
712 | #endif |
703 | |
713 | |
704 | #if EV_STAT_ENABLE |
714 | #if EV_STAT_ENABLE |
705 | EV_BEGIN_WATCHER (stat, stat) |
715 | EV_BEGIN_WATCHER (stat, stat) |
706 | void set (const char *path, ev_tstamp interval = 0.) throw () |
716 | void set (const char *path, ev_tstamp interval = 0.) throw () |
707 | { |
717 | { |
… | |
… | |
723 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
733 | ev_stat_stat (EV_A_ static_cast<ev_stat *>(this)); |
724 | } |
734 | } |
725 | EV_END_WATCHER (stat, stat) |
735 | EV_END_WATCHER (stat, stat) |
726 | #endif |
736 | #endif |
727 | |
737 | |
|
|
738 | #if EV_IDLE_ENABLE |
728 | EV_BEGIN_WATCHER (idle, idle) |
739 | EV_BEGIN_WATCHER (idle, idle) |
729 | void set () throw () { } |
740 | void set () throw () { } |
730 | EV_END_WATCHER (idle, idle) |
741 | EV_END_WATCHER (idle, idle) |
|
|
742 | #endif |
731 | |
743 | |
|
|
744 | #if EV_PREPARE_ENABLE |
732 | EV_BEGIN_WATCHER (prepare, prepare) |
745 | EV_BEGIN_WATCHER (prepare, prepare) |
733 | void set () throw () { } |
746 | void set () throw () { } |
734 | EV_END_WATCHER (prepare, prepare) |
747 | EV_END_WATCHER (prepare, prepare) |
|
|
748 | #endif |
735 | |
749 | |
|
|
750 | #if EV_CHECK_ENABLE |
736 | EV_BEGIN_WATCHER (check, check) |
751 | EV_BEGIN_WATCHER (check, check) |
737 | void set () throw () { } |
752 | void set () throw () { } |
738 | EV_END_WATCHER (check, check) |
753 | EV_END_WATCHER (check, check) |
|
|
754 | #endif |
739 | |
755 | |
740 | #if EV_EMBED_ENABLE |
756 | #if EV_EMBED_ENABLE |
741 | EV_BEGIN_WATCHER (embed, embed) |
757 | EV_BEGIN_WATCHER (embed, embed) |
742 | void set (struct ev_loop *embedded_loop) throw () |
758 | void set (struct ev_loop *embedded_loop) throw () |
743 | { |
759 | { |
… | |
… | |
766 | EV_END_WATCHER (fork, fork) |
782 | EV_END_WATCHER (fork, fork) |
767 | #endif |
783 | #endif |
768 | |
784 | |
769 | #if EV_ASYNC_ENABLE |
785 | #if EV_ASYNC_ENABLE |
770 | EV_BEGIN_WATCHER (async, async) |
786 | EV_BEGIN_WATCHER (async, async) |
771 | void set () throw () { } |
|
|
772 | |
|
|
773 | void send () throw () |
787 | void send () throw () |
774 | { |
788 | { |
775 | ev_async_send (EV_A_ static_cast<ev_async *>(this)); |
789 | ev_async_send (EV_A_ static_cast<ev_async *>(this)); |
776 | } |
790 | } |
777 | |
791 | |