ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/event.h
Revision: 1.14
Committed: Fri Nov 9 17:07:59 2007 UTC (16 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +7 -3 lines
Log Message:
move event_base predeclaration higher in the file

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