blob: 7a442d46c80deb27cd467a2822a16243eb3cdba0 [file] [log] [blame]
David 'Digit' Turnerb1c2c952009-05-18 17:07:46 +02001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __FDEVENT_H
18#define __FDEVENT_H
19
20/* events that may be observed */
21#define FDE_READ 0x0001
22#define FDE_WRITE 0x0002
23#define FDE_ERROR 0x0004
24
25/* features that may be set (via the events set/add/del interface) */
26#define FDE_DONT_CLOSE 0x0080
27
28typedef struct fdevent fdevent;
29
30typedef void (*fd_func)(int fd, unsigned events, void *userdata);
31
32/* Allocate and initialize a new fdevent object
33*/
34fdevent *fdevent_create(int fd, fd_func func, void *arg);
35
36/* Uninitialize and deallocate an fdevent object that was
37** created by fdevent_create()
38*/
39void fdevent_destroy(fdevent *fde);
40
41/* Initialize an fdevent object that was externally allocated
42*/
43void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg);
44
45/* Uninitialize an fdevent object that was initialized by
46** fdevent_install()
47*/
48void fdevent_remove(fdevent *item);
49
50/* Change which events should cause notifications
51*/
52void fdevent_set(fdevent *fde, unsigned events);
53void fdevent_add(fdevent *fde, unsigned events);
54void fdevent_del(fdevent *fde, unsigned events);
55
56/* loop forever, handling events.
57*/
58void fdevent_loop();
59
60struct fdevent
61{
62 fdevent *next;
63 fdevent *prev;
64
65 int fd;
66 unsigned short state;
67 unsigned short events;
68
69 fd_func func;
70 void *arg;
71};
72
73
74#endif