ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV/EVAPI.h
Revision: 1.4
Committed: Wed Oct 31 10:50:05 2007 UTC (16 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.3: +27 -6 lines
Log Message:
EV first rough cut

File Contents

# Content
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 /* you MUST NOT call any of the libev functions, ALWAYS use GEVAPI */
16 #include <ev.h>
17
18 struct EVAPI {
19 I32 ver;
20 I32 rev;
21 #define EV_API_VERSION 1
22 #define EV_API_REVISION 0
23
24 /* wait for a single event, without registering an event watcher */
25 /* if timeout is < 0, do wait indefinitely */
26 void (*once)(int fd, short events, double timeout, void (*cb)(int, short, void *), void *arg);
27
28 /* 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 void (*periodic_start)(struct ev_periodic *);
46 void (*periodic_stop) (struct ev_periodic *);
47 void (*signal_start)(struct ev_signal *);
48 void (*signal_stop) (struct ev_signal *);
49 void (*idle_start)(struct ev_idle *);
50 void (*idle_stop) (struct ev_idle *);
51 void (*check_start)(struct ev_check *);
52 void (*check_stop) (struct ev_check *);
53 };
54
55 /*
56 * usage examples:
57 *
58 * now = GEVAPI->now ();
59 * GEVAPI->once (5, EV_READ, 60, my_cb, (void *)mysv);
60 */
61
62 static struct EVAPI *GEVAPI;
63
64 #define I_EV_API(YourName) \
65 STMT_START { \
66 SV *sv = perl_get_sv ("EV::API", 0); \
67 if (!sv) croak ("EV::API not found"); \
68 GEVAPI = (struct CoroAPI*) SvIV (sv); \
69 if (GEVAPI->ver != EV_API_VERSION \
70 || GEVAPI->rev < EV_API_REVISION) \
71 croak ("EV::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \
72 GEVAPI->ver, GEVAPI->rev, EV_API_VERSION, EV_API_REVISION, YourName); \
73 } STMT_END
74
75 #endif
76