jpayne@69: /* jpayne@69: * libev simple C++ wrapper classes jpayne@69: * jpayne@69: * Copyright (c) 2007,2008,2010,2018,2020 Marc Alexander Lehmann jpayne@69: * All rights reserved. jpayne@69: * jpayne@69: * Redistribution and use in source and binary forms, with or without modifica- jpayne@69: * tion, are permitted provided that the following conditions are met: jpayne@69: * jpayne@69: * 1. Redistributions of source code must retain the above copyright notice, jpayne@69: * this list of conditions and the following disclaimer. jpayne@69: * jpayne@69: * 2. Redistributions in binary form must reproduce the above copyright jpayne@69: * notice, this list of conditions and the following disclaimer in the jpayne@69: * documentation and/or other materials provided with the distribution. jpayne@69: * jpayne@69: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED jpayne@69: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- jpayne@69: * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO jpayne@69: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- jpayne@69: * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, jpayne@69: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; jpayne@69: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, jpayne@69: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- jpayne@69: * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED jpayne@69: * OF THE POSSIBILITY OF SUCH DAMAGE. jpayne@69: * jpayne@69: * Alternatively, the contents of this file may be used under the terms of jpayne@69: * the GNU General Public License ("GPL") version 2 or any later version, jpayne@69: * in which case the provisions of the GPL are applicable instead of jpayne@69: * the above. If you wish to allow the use of your version of this file jpayne@69: * only under the terms of the GPL and not to allow others to use your jpayne@69: * version of this file under the BSD license, indicate your decision jpayne@69: * by deleting the provisions above and replace them with the notice jpayne@69: * and other provisions required by the GPL. If you do not delete the jpayne@69: * provisions above, a recipient may use your version of this file under jpayne@69: * either the BSD or the GPL. jpayne@69: */ jpayne@69: jpayne@69: #ifndef EVPP_H__ jpayne@69: #define EVPP_H__ jpayne@69: jpayne@69: #ifdef EV_H jpayne@69: # include EV_H jpayne@69: #else jpayne@69: # include "ev.h" jpayne@69: #endif jpayne@69: jpayne@69: #ifndef EV_USE_STDEXCEPT jpayne@69: # define EV_USE_STDEXCEPT 1 jpayne@69: #endif jpayne@69: jpayne@69: #if EV_USE_STDEXCEPT jpayne@69: # include jpayne@69: #endif jpayne@69: jpayne@69: namespace ev { jpayne@69: jpayne@69: typedef ev_tstamp tstamp; jpayne@69: jpayne@69: enum { jpayne@69: UNDEF = EV_UNDEF, jpayne@69: NONE = EV_NONE, jpayne@69: READ = EV_READ, jpayne@69: WRITE = EV_WRITE, jpayne@69: #if EV_COMPAT3 jpayne@69: TIMEOUT = EV_TIMEOUT, jpayne@69: #endif jpayne@69: TIMER = EV_TIMER, jpayne@69: PERIODIC = EV_PERIODIC, jpayne@69: SIGNAL = EV_SIGNAL, jpayne@69: CHILD = EV_CHILD, jpayne@69: STAT = EV_STAT, jpayne@69: IDLE = EV_IDLE, jpayne@69: CHECK = EV_CHECK, jpayne@69: PREPARE = EV_PREPARE, jpayne@69: FORK = EV_FORK, jpayne@69: ASYNC = EV_ASYNC, jpayne@69: EMBED = EV_EMBED, jpayne@69: # undef ERROR // some systems stupidly #define ERROR jpayne@69: ERROR = EV_ERROR jpayne@69: }; jpayne@69: jpayne@69: enum jpayne@69: { jpayne@69: AUTO = EVFLAG_AUTO, jpayne@69: NOENV = EVFLAG_NOENV, jpayne@69: FORKCHECK = EVFLAG_FORKCHECK, jpayne@69: jpayne@69: SELECT = EVBACKEND_SELECT, jpayne@69: POLL = EVBACKEND_POLL, jpayne@69: EPOLL = EVBACKEND_EPOLL, jpayne@69: KQUEUE = EVBACKEND_KQUEUE, jpayne@69: DEVPOLL = EVBACKEND_DEVPOLL, jpayne@69: PORT = EVBACKEND_PORT jpayne@69: }; jpayne@69: jpayne@69: enum jpayne@69: { jpayne@69: #if EV_COMPAT3 jpayne@69: NONBLOCK = EVLOOP_NONBLOCK, jpayne@69: ONESHOT = EVLOOP_ONESHOT, jpayne@69: #endif jpayne@69: NOWAIT = EVRUN_NOWAIT, jpayne@69: ONCE = EVRUN_ONCE jpayne@69: }; jpayne@69: jpayne@69: enum how_t jpayne@69: { jpayne@69: ONE = EVBREAK_ONE, jpayne@69: ALL = EVBREAK_ALL jpayne@69: }; jpayne@69: jpayne@69: struct bad_loop jpayne@69: #if EV_USE_STDEXCEPT jpayne@69: : std::exception jpayne@69: #endif jpayne@69: { jpayne@69: #if EV_USE_STDEXCEPT jpayne@69: const char *what () const EV_NOEXCEPT jpayne@69: { jpayne@69: return "libev event loop cannot be initialized, bad value of LIBEV_FLAGS?"; jpayne@69: } jpayne@69: #endif jpayne@69: }; jpayne@69: jpayne@69: #ifdef EV_AX jpayne@69: # undef EV_AX jpayne@69: #endif jpayne@69: jpayne@69: #ifdef EV_AX_ jpayne@69: # undef EV_AX_ jpayne@69: #endif jpayne@69: jpayne@69: #if EV_MULTIPLICITY jpayne@69: # define EV_AX raw_loop jpayne@69: # define EV_AX_ raw_loop, jpayne@69: #else jpayne@69: # define EV_AX jpayne@69: # define EV_AX_ jpayne@69: #endif jpayne@69: jpayne@69: struct loop_ref jpayne@69: { jpayne@69: loop_ref (EV_P) EV_NOEXCEPT jpayne@69: #if EV_MULTIPLICITY jpayne@69: : EV_AX (EV_A) jpayne@69: #endif jpayne@69: { jpayne@69: } jpayne@69: jpayne@69: bool operator == (const loop_ref &other) const EV_NOEXCEPT jpayne@69: { jpayne@69: #if EV_MULTIPLICITY jpayne@69: return EV_AX == other.EV_AX; jpayne@69: #else jpayne@69: return true; jpayne@69: #endif jpayne@69: } jpayne@69: jpayne@69: bool operator != (const loop_ref &other) const EV_NOEXCEPT jpayne@69: { jpayne@69: #if EV_MULTIPLICITY jpayne@69: return ! (*this == other); jpayne@69: #else jpayne@69: return false; jpayne@69: #endif jpayne@69: } jpayne@69: jpayne@69: #if EV_MULTIPLICITY jpayne@69: bool operator == (const EV_P) const EV_NOEXCEPT jpayne@69: { jpayne@69: return this->EV_AX == EV_A; jpayne@69: } jpayne@69: jpayne@69: bool operator != (const EV_P) const EV_NOEXCEPT jpayne@69: { jpayne@69: return ! (*this == EV_A); jpayne@69: } jpayne@69: jpayne@69: operator struct ev_loop * () const EV_NOEXCEPT jpayne@69: { jpayne@69: return EV_AX; jpayne@69: } jpayne@69: jpayne@69: operator const struct ev_loop * () const EV_NOEXCEPT jpayne@69: { jpayne@69: return EV_AX; jpayne@69: } jpayne@69: jpayne@69: bool is_default () const EV_NOEXCEPT jpayne@69: { jpayne@69: return EV_AX == ev_default_loop (0); jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: #if EV_COMPAT3 jpayne@69: void loop (int flags = 0) jpayne@69: { jpayne@69: ev_run (EV_AX_ flags); jpayne@69: } jpayne@69: jpayne@69: void unloop (how_t how = ONE) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_break (EV_AX_ how); jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: void run (int flags = 0) jpayne@69: { jpayne@69: ev_run (EV_AX_ flags); jpayne@69: } jpayne@69: jpayne@69: void break_loop (how_t how = ONE) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_break (EV_AX_ how); jpayne@69: } jpayne@69: jpayne@69: void post_fork () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_loop_fork (EV_AX); jpayne@69: } jpayne@69: jpayne@69: unsigned int backend () const EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_backend (EV_AX); jpayne@69: } jpayne@69: jpayne@69: tstamp now () const EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_now (EV_AX); jpayne@69: } jpayne@69: jpayne@69: void ref () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_ref (EV_AX); jpayne@69: } jpayne@69: jpayne@69: void unref () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_unref (EV_AX); jpayne@69: } jpayne@69: jpayne@69: #if EV_FEATURE_API jpayne@69: unsigned int iteration () const EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_iteration (EV_AX); jpayne@69: } jpayne@69: jpayne@69: unsigned int depth () const EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_depth (EV_AX); jpayne@69: } jpayne@69: jpayne@69: void set_io_collect_interval (tstamp interval) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_set_io_collect_interval (EV_AX_ interval); jpayne@69: } jpayne@69: jpayne@69: void set_timeout_collect_interval (tstamp interval) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_set_timeout_collect_interval (EV_AX_ interval); jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: // function callback jpayne@69: void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_once (EV_AX_ fd, events, timeout, cb, arg); jpayne@69: } jpayne@69: jpayne@69: // method callback jpayne@69: template jpayne@69: void once (int fd, int events, tstamp timeout, K *object) EV_NOEXCEPT jpayne@69: { jpayne@69: once (fd, events, timeout, method_thunk, object); jpayne@69: } jpayne@69: jpayne@69: // default method == operator () jpayne@69: template jpayne@69: void once (int fd, int events, tstamp timeout, K *object) EV_NOEXCEPT jpayne@69: { jpayne@69: once (fd, events, timeout, method_thunk, object); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void method_thunk (int revents, void *arg) jpayne@69: { jpayne@69: (static_cast(arg)->*method) jpayne@69: (revents); jpayne@69: } jpayne@69: jpayne@69: // no-argument method callback jpayne@69: template jpayne@69: void once (int fd, int events, tstamp timeout, K *object) EV_NOEXCEPT jpayne@69: { jpayne@69: once (fd, events, timeout, method_noargs_thunk, object); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void method_noargs_thunk (int revents, void *arg) jpayne@69: { jpayne@69: (static_cast(arg)->*method) jpayne@69: (); jpayne@69: } jpayne@69: jpayne@69: // simpler function callback jpayne@69: template jpayne@69: void once (int fd, int events, tstamp timeout) EV_NOEXCEPT jpayne@69: { jpayne@69: once (fd, events, timeout, simpler_func_thunk); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void simpler_func_thunk (int revents, void *arg) jpayne@69: { jpayne@69: (*cb) jpayne@69: (revents); jpayne@69: } jpayne@69: jpayne@69: // simplest function callback jpayne@69: template jpayne@69: void once (int fd, int events, tstamp timeout) EV_NOEXCEPT jpayne@69: { jpayne@69: once (fd, events, timeout, simplest_func_thunk); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void simplest_func_thunk (int revents, void *arg) jpayne@69: { jpayne@69: (*cb) jpayne@69: (); jpayne@69: } jpayne@69: jpayne@69: void feed_fd_event (int fd, int revents) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_feed_fd_event (EV_AX_ fd, revents); jpayne@69: } jpayne@69: jpayne@69: void feed_signal_event (int signum) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_feed_signal_event (EV_AX_ signum); jpayne@69: } jpayne@69: jpayne@69: #if EV_MULTIPLICITY jpayne@69: struct ev_loop* EV_AX; jpayne@69: #endif jpayne@69: jpayne@69: }; jpayne@69: jpayne@69: #if EV_MULTIPLICITY jpayne@69: struct dynamic_loop : loop_ref jpayne@69: { jpayne@69: jpayne@69: dynamic_loop (unsigned int flags = AUTO) jpayne@69: : loop_ref (ev_loop_new (flags)) jpayne@69: { jpayne@69: if (!EV_AX) jpayne@69: throw bad_loop (); jpayne@69: } jpayne@69: jpayne@69: ~dynamic_loop () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_loop_destroy (EV_AX); jpayne@69: EV_AX = 0; jpayne@69: } jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: dynamic_loop (const dynamic_loop &); jpayne@69: jpayne@69: dynamic_loop & operator= (const dynamic_loop &); jpayne@69: jpayne@69: }; jpayne@69: #endif jpayne@69: jpayne@69: struct default_loop : loop_ref jpayne@69: { jpayne@69: default_loop (unsigned int flags = AUTO) jpayne@69: #if EV_MULTIPLICITY jpayne@69: : loop_ref (ev_default_loop (flags)) jpayne@69: #endif jpayne@69: { jpayne@69: if ( jpayne@69: #if EV_MULTIPLICITY jpayne@69: !EV_AX jpayne@69: #else jpayne@69: !ev_default_loop (flags) jpayne@69: #endif jpayne@69: ) jpayne@69: throw bad_loop (); jpayne@69: } jpayne@69: jpayne@69: private: jpayne@69: default_loop (const default_loop &); jpayne@69: default_loop &operator = (const default_loop &); jpayne@69: }; jpayne@69: jpayne@69: inline loop_ref get_default_loop () EV_NOEXCEPT jpayne@69: { jpayne@69: #if EV_MULTIPLICITY jpayne@69: return ev_default_loop (0); jpayne@69: #else jpayne@69: return loop_ref (); jpayne@69: #endif jpayne@69: } jpayne@69: jpayne@69: #undef EV_AX jpayne@69: #undef EV_AX_ jpayne@69: jpayne@69: #undef EV_PX jpayne@69: #undef EV_PX_ jpayne@69: #if EV_MULTIPLICITY jpayne@69: # define EV_PX loop_ref EV_A jpayne@69: # define EV_PX_ loop_ref EV_A_ jpayne@69: #else jpayne@69: # define EV_PX jpayne@69: # define EV_PX_ jpayne@69: #endif jpayne@69: jpayne@69: template jpayne@69: struct base : ev_watcher jpayne@69: { jpayne@69: // scoped pause/unpause of a watcher jpayne@69: struct freeze_guard jpayne@69: { jpayne@69: watcher &w; jpayne@69: bool active; jpayne@69: jpayne@69: freeze_guard (watcher *self) EV_NOEXCEPT jpayne@69: : w (*self), active (w.is_active ()) jpayne@69: { jpayne@69: if (active) w.stop (); jpayne@69: } jpayne@69: jpayne@69: ~freeze_guard () jpayne@69: { jpayne@69: if (active) w.start (); jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: #if EV_MULTIPLICITY jpayne@69: EV_PX; jpayne@69: jpayne@69: // loop set jpayne@69: void set (EV_P) EV_NOEXCEPT jpayne@69: { jpayne@69: this->EV_A = EV_A; jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: base (EV_PX) EV_NOEXCEPT jpayne@69: #if EV_MULTIPLICITY jpayne@69: : EV_A (EV_A) jpayne@69: #endif jpayne@69: { jpayne@69: ev_init (this, 0); jpayne@69: } jpayne@69: jpayne@69: void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) EV_NOEXCEPT jpayne@69: { jpayne@69: this->data = (void *)data; jpayne@69: ev_set_cb (static_cast(this), cb); jpayne@69: } jpayne@69: jpayne@69: // function callback jpayne@69: template jpayne@69: void set (void *data = 0) EV_NOEXCEPT jpayne@69: { jpayne@69: set_ (data, function_thunk); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void function_thunk (EV_P_ ev_watcher *w, int revents) jpayne@69: { jpayne@69: function jpayne@69: (*static_cast(w), revents); jpayne@69: } jpayne@69: jpayne@69: // method callback jpayne@69: template jpayne@69: void set (K *object) EV_NOEXCEPT jpayne@69: { jpayne@69: set_ (object, method_thunk); jpayne@69: } jpayne@69: jpayne@69: // default method == operator () jpayne@69: template jpayne@69: void set (K *object) EV_NOEXCEPT jpayne@69: { jpayne@69: set_ (object, method_thunk); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void method_thunk (EV_P_ ev_watcher *w, int revents) jpayne@69: { jpayne@69: (static_cast(w->data)->*method) jpayne@69: (*static_cast(w), revents); jpayne@69: } jpayne@69: jpayne@69: // no-argument callback jpayne@69: template jpayne@69: void set (K *object) EV_NOEXCEPT jpayne@69: { jpayne@69: set_ (object, method_noargs_thunk); jpayne@69: } jpayne@69: jpayne@69: template jpayne@69: static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) jpayne@69: { jpayne@69: (static_cast(w->data)->*method) jpayne@69: (); jpayne@69: } jpayne@69: jpayne@69: void operator ()(int events = EV_UNDEF) jpayne@69: { jpayne@69: return jpayne@69: ev_cb (static_cast(this)) jpayne@69: (static_cast(this), events); jpayne@69: } jpayne@69: jpayne@69: bool is_active () const EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_is_active (static_cast(this)); jpayne@69: } jpayne@69: jpayne@69: bool is_pending () const EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_is_pending (static_cast(this)); jpayne@69: } jpayne@69: jpayne@69: void feed_event (int revents) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_feed_event (EV_A_ static_cast(this), revents); jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: inline tstamp now (EV_P) EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_now (EV_A); jpayne@69: } jpayne@69: jpayne@69: inline void delay (tstamp interval) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_sleep (interval); jpayne@69: } jpayne@69: jpayne@69: inline int version_major () EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_version_major (); jpayne@69: } jpayne@69: jpayne@69: inline int version_minor () EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_version_minor (); jpayne@69: } jpayne@69: jpayne@69: inline unsigned int supported_backends () EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_supported_backends (); jpayne@69: } jpayne@69: jpayne@69: inline unsigned int recommended_backends () EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_recommended_backends (); jpayne@69: } jpayne@69: jpayne@69: inline unsigned int embeddable_backends () EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_embeddable_backends (); jpayne@69: } jpayne@69: jpayne@69: inline void set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_set_allocator (cb); jpayne@69: } jpayne@69: jpayne@69: inline void set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT jpayne@69: { jpayne@69: ev_set_syserr_cb (cb); jpayne@69: } jpayne@69: jpayne@69: #if EV_MULTIPLICITY jpayne@69: #define EV_CONSTRUCT(cppstem,cstem) \ jpayne@69: (EV_PX = get_default_loop ()) EV_NOEXCEPT \ jpayne@69: : base (EV_A) \ jpayne@69: { \ jpayne@69: } jpayne@69: #else jpayne@69: #define EV_CONSTRUCT(cppstem,cstem) \ jpayne@69: () EV_NOEXCEPT \ jpayne@69: { \ jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: /* using a template here would require quite a few more lines, jpayne@69: * so a macro solution was chosen */ jpayne@69: #define EV_BEGIN_WATCHER(cppstem,cstem) \ jpayne@69: \ jpayne@69: struct cppstem : base \ jpayne@69: { \ jpayne@69: void start () EV_NOEXCEPT \ jpayne@69: { \ jpayne@69: ev_ ## cstem ## _start (EV_A_ static_cast(this)); \ jpayne@69: } \ jpayne@69: \ jpayne@69: void stop () EV_NOEXCEPT \ jpayne@69: { \ jpayne@69: ev_ ## cstem ## _stop (EV_A_ static_cast(this)); \ jpayne@69: } \ jpayne@69: \ jpayne@69: cppstem EV_CONSTRUCT(cppstem,cstem) \ jpayne@69: \ jpayne@69: ~cppstem () EV_NOEXCEPT \ jpayne@69: { \ jpayne@69: stop (); \ jpayne@69: } \ jpayne@69: \ jpayne@69: using base::set; \ jpayne@69: \ jpayne@69: private: \ jpayne@69: \ jpayne@69: cppstem (const cppstem &o); \ jpayne@69: \ jpayne@69: cppstem &operator =(const cppstem &o); \ jpayne@69: \ jpayne@69: public: jpayne@69: jpayne@69: #define EV_END_WATCHER(cppstem,cstem) \ jpayne@69: }; jpayne@69: jpayne@69: EV_BEGIN_WATCHER (io, io) jpayne@69: void set (int fd, int events) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_io_set (static_cast(this), fd, events); jpayne@69: } jpayne@69: jpayne@69: void set (int events) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_io_modify (static_cast(this), events); jpayne@69: } jpayne@69: jpayne@69: void start (int fd, int events) EV_NOEXCEPT jpayne@69: { jpayne@69: set (fd, events); jpayne@69: start (); jpayne@69: } jpayne@69: EV_END_WATCHER (io, io) jpayne@69: jpayne@69: EV_BEGIN_WATCHER (timer, timer) jpayne@69: void set (ev_tstamp after, ev_tstamp repeat = 0.) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_timer_set (static_cast(this), after, repeat); jpayne@69: } jpayne@69: jpayne@69: void start (ev_tstamp after, ev_tstamp repeat = 0.) EV_NOEXCEPT jpayne@69: { jpayne@69: set (after, repeat); jpayne@69: start (); jpayne@69: } jpayne@69: jpayne@69: void again () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_timer_again (EV_A_ static_cast(this)); jpayne@69: } jpayne@69: jpayne@69: ev_tstamp remaining () jpayne@69: { jpayne@69: return ev_timer_remaining (EV_A_ static_cast(this)); jpayne@69: } jpayne@69: EV_END_WATCHER (timer, timer) jpayne@69: jpayne@69: #if EV_PERIODIC_ENABLE jpayne@69: EV_BEGIN_WATCHER (periodic, periodic) jpayne@69: void set (ev_tstamp at, ev_tstamp interval = 0.) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_periodic_set (static_cast(this), at, interval, 0); jpayne@69: } jpayne@69: jpayne@69: void start (ev_tstamp at, ev_tstamp interval = 0.) EV_NOEXCEPT jpayne@69: { jpayne@69: set (at, interval); jpayne@69: start (); jpayne@69: } jpayne@69: jpayne@69: void again () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_periodic_again (EV_A_ static_cast(this)); jpayne@69: } jpayne@69: EV_END_WATCHER (periodic, periodic) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_SIGNAL_ENABLE jpayne@69: EV_BEGIN_WATCHER (sig, signal) jpayne@69: void set (int signum) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_signal_set (static_cast(this), signum); jpayne@69: } jpayne@69: jpayne@69: void start (int signum) EV_NOEXCEPT jpayne@69: { jpayne@69: set (signum); jpayne@69: start (); jpayne@69: } jpayne@69: EV_END_WATCHER (sig, signal) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_CHILD_ENABLE jpayne@69: EV_BEGIN_WATCHER (child, child) jpayne@69: void set (int pid, int trace = 0) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_child_set (static_cast(this), pid, trace); jpayne@69: } jpayne@69: jpayne@69: void start (int pid, int trace = 0) EV_NOEXCEPT jpayne@69: { jpayne@69: set (pid, trace); jpayne@69: start (); jpayne@69: } jpayne@69: EV_END_WATCHER (child, child) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_STAT_ENABLE jpayne@69: EV_BEGIN_WATCHER (stat, stat) jpayne@69: void set (const char *path, ev_tstamp interval = 0.) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_stat_set (static_cast(this), path, interval); jpayne@69: } jpayne@69: jpayne@69: void start (const char *path, ev_tstamp interval = 0.) EV_NOEXCEPT jpayne@69: { jpayne@69: stop (); jpayne@69: set (path, interval); jpayne@69: start (); jpayne@69: } jpayne@69: jpayne@69: void update () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_stat_stat (EV_A_ static_cast(this)); jpayne@69: } jpayne@69: EV_END_WATCHER (stat, stat) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_IDLE_ENABLE jpayne@69: EV_BEGIN_WATCHER (idle, idle) jpayne@69: void set () EV_NOEXCEPT { } jpayne@69: EV_END_WATCHER (idle, idle) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_PREPARE_ENABLE jpayne@69: EV_BEGIN_WATCHER (prepare, prepare) jpayne@69: void set () EV_NOEXCEPT { } jpayne@69: EV_END_WATCHER (prepare, prepare) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_CHECK_ENABLE jpayne@69: EV_BEGIN_WATCHER (check, check) jpayne@69: void set () EV_NOEXCEPT { } jpayne@69: EV_END_WATCHER (check, check) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_EMBED_ENABLE jpayne@69: EV_BEGIN_WATCHER (embed, embed) jpayne@69: void set_embed (struct ev_loop *embedded_loop) EV_NOEXCEPT jpayne@69: { jpayne@69: freeze_guard freeze (this); jpayne@69: ev_embed_set (static_cast(this), embedded_loop); jpayne@69: } jpayne@69: jpayne@69: void start (struct ev_loop *embedded_loop) EV_NOEXCEPT jpayne@69: { jpayne@69: set (embedded_loop); jpayne@69: start (); jpayne@69: } jpayne@69: jpayne@69: void sweep () jpayne@69: { jpayne@69: ev_embed_sweep (EV_A_ static_cast(this)); jpayne@69: } jpayne@69: EV_END_WATCHER (embed, embed) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_FORK_ENABLE jpayne@69: EV_BEGIN_WATCHER (fork, fork) jpayne@69: void set () EV_NOEXCEPT { } jpayne@69: EV_END_WATCHER (fork, fork) jpayne@69: #endif jpayne@69: jpayne@69: #if EV_ASYNC_ENABLE jpayne@69: EV_BEGIN_WATCHER (async, async) jpayne@69: void send () EV_NOEXCEPT jpayne@69: { jpayne@69: ev_async_send (EV_A_ static_cast(this)); jpayne@69: } jpayne@69: jpayne@69: bool async_pending () EV_NOEXCEPT jpayne@69: { jpayne@69: return ev_async_pending (static_cast(this)); jpayne@69: } jpayne@69: EV_END_WATCHER (async, async) jpayne@69: #endif jpayne@69: jpayne@69: #undef EV_PX jpayne@69: #undef EV_PX_ jpayne@69: #undef EV_CONSTRUCT jpayne@69: #undef EV_BEGIN_WATCHER jpayne@69: #undef EV_END_WATCHER jpayne@69: } jpayne@69: jpayne@69: #endif jpayne@69: