1 |
/* |
2 |
* libevent compatibility header, only core events supported |
3 |
* |
4 |
* Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
5 |
* All rights reserved. |
6 |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions are |
9 |
* met: |
10 |
* |
11 |
* * Redistributions of source code must retain the above copyright |
12 |
* notice, this list of conditions and the following disclaimer. |
13 |
* |
14 |
* * Redistributions in binary form must reproduce the above |
15 |
* copyright notice, this list of conditions and the following |
16 |
* disclaimer in the documentation and/or other materials provided |
17 |
* with the distribution. |
18 |
* |
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 |
*/ |
31 |
#ifndef EVENT_H__ |
32 |
#define EVENT_H__ |
33 |
|
34 |
#ifdef EV_H |
35 |
# include EV_H |
36 |
#else |
37 |
# include <ev.h> |
38 |
#endif |
39 |
|
40 |
#ifdef __cplusplus |
41 |
extern "C" { |
42 |
#endif |
43 |
|
44 |
struct event_base; |
45 |
|
46 |
#define EVLIST_TIMEOUT 0x01 |
47 |
#define EVLIST_INSERTED 0x02 |
48 |
#define EVLIST_SIGNAL 0x04 |
49 |
#define EVLIST_ACTIVE 0x08 |
50 |
#define EVLIST_INTERNAL 0x10 |
51 |
#define EVLIST_INIT 0x80 |
52 |
|
53 |
struct event |
54 |
{ |
55 |
/* libev watchers we map onto */ |
56 |
union { |
57 |
struct ev_io io; |
58 |
struct ev_signal sig; |
59 |
} iosig; |
60 |
struct ev_timer to; |
61 |
|
62 |
/* compatibility slots */ |
63 |
struct event_base *ev_base; |
64 |
void (*ev_callback)(int, short, void *arg); |
65 |
void *ev_arg; |
66 |
int ev_fd; |
67 |
int ev_pri; |
68 |
int ev_res; |
69 |
int ev_flags; |
70 |
short ev_events; |
71 |
}; |
72 |
|
73 |
#define EV_PERSIST 0x10 |
74 |
|
75 |
#define EVENT_SIGNAL(ev) ((int) (ev)->ev_fd) |
76 |
#define EVENT_FD(ev) ((int) (ev)->ev_fd) |
77 |
|
78 |
#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) |
79 |
|
80 |
#define evtimer_add(ev,tv) event_add (ev, tv) |
81 |
#define evtimer_set(ev,cb,data) event_set (ev, -1, 0, cb, data) |
82 |
#define evtimer_del(ev) event_del (ev) |
83 |
#define evtimer_pending(ev,tv) event_pending (ev, EV_TIMEOUT, tv) |
84 |
#define evtimer_initialized(ev) event_initialized (ev) |
85 |
|
86 |
#define timeout_add(ev,tv) evtimer_add (ev, tv) |
87 |
#define timeout_set(ev,cb,data) evtimer_set (ev, cb, data) |
88 |
#define timeout_del(ev) evtimer_del (ev) |
89 |
#define timeout_pending(ev,tv) evtimer_pending (ev, tv) |
90 |
#define timeout_initialized(ev) evtimer_initialized (ev) |
91 |
|
92 |
#define signal_add(ev,tv) event_add (ev, tv) |
93 |
#define signal_set(ev,sig,cb,data) event_set (ev, sig, EV_SIGNAL | EV_PERSIST, cb, data) |
94 |
#define signal_del(ev) event_del (ev) |
95 |
#define signal_pending(ev,tv) event_pending (ev, EV_SIGNAL, tv) |
96 |
#define signal_initialized(ev) event_initialized (ev) |
97 |
|
98 |
const char *event_get_version (void); |
99 |
const char *event_get_method (void); |
100 |
|
101 |
void *event_init (void); |
102 |
void event_base_free (struct event_base *base); |
103 |
|
104 |
#define EVLOOP_ONCE EVLOOP_ONESHOT |
105 |
int event_loop (int); |
106 |
int event_loopexit (struct timeval *tv); |
107 |
int event_dispatch (void); |
108 |
|
109 |
#define _EVENT_LOG_DEBUG 0 |
110 |
#define _EVENT_LOG_MSG 1 |
111 |
#define _EVENT_LOG_WARN 2 |
112 |
#define _EVENT_LOG_ERR 3 |
113 |
typedef void (*event_log_cb)(int severity, const char *msg); |
114 |
void event_set_log_callback(event_log_cb cb); |
115 |
|
116 |
void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg); |
117 |
int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv); |
118 |
|
119 |
int event_add (struct event *ev, struct timeval *tv); |
120 |
int event_del (struct event *ev); |
121 |
void event_active (struct event *ev, int res, short ncalls); /* ncalls is being ignored */ |
122 |
|
123 |
int event_pending (struct event *ev, short, struct timeval *tv); |
124 |
|
125 |
int event_priority_init (int npri); |
126 |
int event_priority_set (struct event *ev, int pri); |
127 |
|
128 |
int event_base_set (struct event_base *base, struct event *ev); |
129 |
int event_base_loop (struct event_base *base, int); |
130 |
int event_base_loopexit (struct event_base *base, struct timeval *tv); |
131 |
int event_base_dispatch (struct event_base *base); |
132 |
int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv); |
133 |
int event_base_priority_init (struct event_base *base, int fd); |
134 |
|
135 |
#ifndef EV_STANDALONE |
136 |
# include <event_compat.h> |
137 |
#endif |
138 |
|
139 |
#ifdef __cplusplus |
140 |
} |
141 |
#endif |
142 |
|
143 |
#endif |
144 |
|