ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/event.h
Revision: 1.7
Committed: Sun Nov 4 00:24:17 2007 UTC (16 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +3 -1 lines
Log Message:
wow the event api is broken

File Contents

# User Rev Content
1 root 1.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 root 1.6 #include "ev.h"
35    
36 root 1.1 #ifdef __cplusplus
37     extern "C" {
38     #endif
39    
40     struct event
41 root 1.4 {
42 root 1.5 /* libev watchers we map onto */
43 root 1.4 union {
44     struct ev_io io;
45     struct ev_signal sig;
46     } iosig;
47 root 1.1 struct ev_timer to;
48    
49 root 1.4 /* compatibility slots */
50 root 1.1 struct event_base *ev_base;
51 root 1.2 void (*ev_callback)(int, short, void *arg);
52     void *ev_arg;
53 root 1.1 int ev_fd;
54     int ev_pri;
55     int ev_res;
56 root 1.2 short ev_events;
57 root 1.7
58     char initialised; /* flag to work around some idiosynchrasies in the API */
59 root 1.1 };
60    
61     #define EV_PERSIST 0x10
62    
63     #define EVENT_SIGNAL(ev) ((int) (ev)->ev_fd)
64     #define EVENT_FD(ev) ((int) (ev)->ev_fd)
65    
66 root 1.7 #define event_initialized(ev) ((ev)->initialised)
67 root 1.1
68     #define evtimer_add(ev,tv) event_add (ev, tv)
69     #define evtimer_set(ev,cb,data) event_set (ev, -1, 0, cb, data)
70     #define evtimer_del(ev) event_del (ev)
71     #define evtimer_pending(ev,tv) event_pending (ev, EV_TIMEOUT, tv)
72     #define evtimer_initialized(ev) event_initialized (ev)
73    
74     #define timeout_add(ev,tv) evtimer_add (ev, tv)
75     #define timeout_set(ev,cb,data) evtimer_set (ev, cb, data)
76     #define timeout_del(ev) evtimer_del (ev)
77     #define timeout_pending(ev,tv) evtimer_pending (ev, tv)
78     #define timeout_initialized(ev) evtimer_initialized (ev)
79    
80     #define signal_add(ev,tv) event_add (ev, tv)
81     #define signal_set(ev,sig,cb,data) event_set (ev, sig, EV_SIGNAL | EV_PERSIST, cb, data)
82     #define signal_del(ev) event_del (ev)
83     #define signal_pending(ev,tv) event_pending (ev, EV_SIGNAL, tv)
84     #define signal_initialized(ev) event_initialized (ev)
85    
86     const char *event_get_version (void);
87     const char *event_get_method (void);
88    
89     void *event_init (void);
90     void event_base_free (struct event_base *base);
91    
92     #define EVLOOP_ONCE EVLOOP_ONESHOT
93     int event_loop (int);
94     int event_loopexit (struct timeval *tv);
95     int event_dispatch (void);
96    
97     #define _EVENT_LOG_DEBUG 0
98     #define _EVENT_LOG_MSG 1
99     #define _EVENT_LOG_WARN 2
100     #define _EVENT_LOG_ERR 3
101     typedef void (*event_log_cb)(int severity, const char *msg);
102     void event_set_log_callback(event_log_cb cb);
103    
104     void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg);
105     int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv);
106    
107     int event_add (struct event *ev, struct timeval *tv);
108     int event_del (struct event *ev);
109    
110     int event_pending (struct event *ev, short, struct timeval *tv);
111    
112     int event_priority_init (int npri);
113     int event_priority_set (struct event *ev, int pri);
114    
115     struct event_base;
116    
117     int event_base_set (struct event_base *base, struct event *ev);
118     int event_base_loop (struct event_base *base, int);
119     int event_base_loopexit (struct event_base *base, struct timeval *tv);
120     int event_base_dispatch (struct event_base *base);
121     int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv);
122     int event_base_priority_init (struct event_base *base, int fd);
123    
124 root 1.6 #ifndef EV_STANDALONE
125     # include "event_compat.h"
126     #endif
127    
128     #ifdef __cplusplus
129     }
130     #endif
131    
132 root 1.1 #endif
133 root 1.5