#ifndef EV_API_H #define EV_API_H #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifndef pTHX_ # define pTHX_ # define aTHX_ # define pTHX # define aTHX #endif /* you MUST NOT call any of the libev functions, ALWAYS use GEVAPI */ #include struct EVAPI { I32 ver; I32 rev; #define EV_API_VERSION 2 #define EV_API_REVISION 0 /* wait for a single event, without registering an event watcher */ /* if timeout is < 0, do wait indefinitely */ void (*once)(int fd, short events, double timeout, void (*cb)(int, short, void *), void *arg); /* perl fh or fd int to fd */ int (*sv_fileno) (SV *fh); /* signal number/name to signum */ int (*sv_signum) (SV *fh); /* libev global variables (note: references!) */ ev_tstamp *now; int *method; int *loop_done; /* same as libev functions */ ev_tstamp (*(time))(void); void (*loop)(int flags); void (*io_start)(struct ev_io *); void (*io_stop) (struct ev_io *); void (*timer_start)(struct ev_timer *); void (*timer_stop) (struct ev_timer *); void (*periodic_start)(struct ev_periodic *); void (*periodic_stop) (struct ev_periodic *); void (*signal_start)(struct ev_signal *); void (*signal_stop) (struct ev_signal *); void (*idle_start)(struct ev_idle *); void (*idle_stop) (struct ev_idle *); void (*check_start)(struct ev_check *); void (*check_stop) (struct ev_check *); }; /* * usage examples: * * now = GEVAPI->now (); * GEVAPI->once (5, EV_READ, 60, my_cb, (void *)mysv); */ static struct EVAPI *GEVAPI; #define I_EV_API(YourName) \ STMT_START { \ SV *sv = perl_get_sv ("EV::API", 0); \ if (!sv) croak ("EV::API not found"); \ GEVAPI = (struct EVAPI*) SvIV (sv); \ if (GEVAPI->ver != EV_API_VERSION \ || GEVAPI->rev < EV_API_REVISION) \ croak ("EV::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \ GEVAPI->ver, GEVAPI->rev, EV_API_VERSION, EV_API_REVISION, YourName); \ } STMT_END #endif