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

File Contents

# User Rev Content
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     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 root 1.1 };
54    
55 root 1.2 /*
56     * usage examples:
57     *
58     * now = GEVAPI->now ();
59     * GEVAPI->once (5, EV_READ, 60, my_cb, (void *)mysv);
60     */
61    
62 root 1.1 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 root 1.5 GEVAPI = (struct EVAPI*) SvIV (sv); \
69 root 1.1 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