1 |
root |
1.1 |
#ifndef EV_API_H |
2 |
|
|
#define EV_API_H |
3 |
|
|
|
4 |
|
|
#include "EXTERN.h" |
5 |
|
|
#include "perl.h" |
6 |
|
|
#include "XSUB.h" |
7 |
|
|
|
8 |
|
|
#ifndef pTHX_ |
9 |
|
|
# define pTHX_ |
10 |
|
|
# define aTHX_ |
11 |
|
|
# define pTHX |
12 |
|
|
# define aTHX |
13 |
|
|
#endif |
14 |
|
|
|
15 |
root |
1.4 |
/* you MUST NOT call any of the libev functions, ALWAYS use GEVAPI */ |
16 |
|
|
#include <ev.h> |
17 |
root |
1.1 |
|
18 |
|
|
struct EVAPI { |
19 |
|
|
I32 ver; |
20 |
|
|
I32 rev; |
21 |
root |
1.5 |
#define EV_API_VERSION 2 |
22 |
root |
1.1 |
#define EV_API_REVISION 0 |
23 |
|
|
|
24 |
root |
1.2 |
/* wait for a single event, without registering an event watcher */ |
25 |
|
|
/* if timeout is < 0, do wait indefinitely */ |
26 |
root |
1.1 |
void (*once)(int fd, short events, double timeout, void (*cb)(int, short, void *), void *arg); |
27 |
root |
1.3 |
|
28 |
root |
1.4 |
/* perl fh or fd int to fd */ |
29 |
|
|
int (*sv_fileno) (SV *fh); |
30 |
|
|
/* signal number/name to signum */ |
31 |
|
|
int (*sv_signum) (SV *fh); |
32 |
|
|
|
33 |
|
|
/* libev global variables (note: references!) */ |
34 |
|
|
ev_tstamp *now; |
35 |
|
|
int *method; |
36 |
|
|
int *loop_done; |
37 |
|
|
|
38 |
|
|
/* same as libev functions */ |
39 |
|
|
ev_tstamp (*(time))(void); |
40 |
|
|
void (*loop)(int flags); |
41 |
|
|
void (*io_start)(struct ev_io *); |
42 |
|
|
void (*io_stop) (struct ev_io *); |
43 |
|
|
void (*timer_start)(struct ev_timer *); |
44 |
|
|
void (*timer_stop) (struct ev_timer *); |
45 |
root |
1.6 |
void (*timer_again)(struct ev_timer *); |
46 |
root |
1.4 |
void (*periodic_start)(struct ev_periodic *); |
47 |
|
|
void (*periodic_stop) (struct ev_periodic *); |
48 |
|
|
void (*signal_start)(struct ev_signal *); |
49 |
|
|
void (*signal_stop) (struct ev_signal *); |
50 |
|
|
void (*idle_start)(struct ev_idle *); |
51 |
|
|
void (*idle_stop) (struct ev_idle *); |
52 |
|
|
void (*check_start)(struct ev_check *); |
53 |
|
|
void (*check_stop) (struct ev_check *); |
54 |
root |
1.1 |
}; |
55 |
|
|
|
56 |
root |
1.2 |
/* |
57 |
|
|
* usage examples: |
58 |
|
|
* |
59 |
|
|
* now = GEVAPI->now (); |
60 |
|
|
* GEVAPI->once (5, EV_READ, 60, my_cb, (void *)mysv); |
61 |
|
|
*/ |
62 |
|
|
|
63 |
root |
1.1 |
static struct EVAPI *GEVAPI; |
64 |
|
|
|
65 |
|
|
#define I_EV_API(YourName) \ |
66 |
|
|
STMT_START { \ |
67 |
|
|
SV *sv = perl_get_sv ("EV::API", 0); \ |
68 |
|
|
if (!sv) croak ("EV::API not found"); \ |
69 |
root |
1.5 |
GEVAPI = (struct EVAPI*) SvIV (sv); \ |
70 |
root |
1.1 |
if (GEVAPI->ver != EV_API_VERSION \ |
71 |
|
|
|| GEVAPI->rev < EV_API_REVISION) \ |
72 |
|
|
croak ("EV::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \ |
73 |
|
|
GEVAPI->ver, GEVAPI->rev, EV_API_VERSION, EV_API_REVISION, YourName); \ |
74 |
|
|
} STMT_END |
75 |
|
|
|
76 |
|
|
#endif |
77 |
|
|
|