Tizen 2.1 base
[platform/upstream/gcd.git] / kqueue-1.0.4 / include / sys / event.h
1 /*-
2  * Copyright (c) 2009 Mark Heily <mark@heily.com>
3  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD SVN Revision 197533$
28  */
29
30 #ifndef _SYS_EVENT_H_
31 #define _SYS_EVENT_H_
32
33 #include <sys/types.h>
34
35 #ifdef __KERNEL__
36 #define intptr_t long
37 #else
38 #include <sys/queue.h> 
39 #include <sys/types.h> 
40 #include <stdint.h> 
41 #define LIBKQUEUE       1
42 #endif
43
44 struct timespec;
45
46 #define EVFILT_READ             (-1)
47 #define EVFILT_WRITE            (-2)
48 #define EVFILT_AIO              (-3)    /* attached to aio requests */
49 #define EVFILT_VNODE            (-4)    /* attached to vnodes */
50 #define EVFILT_PROC             (-5)    /* attached to struct proc */
51 #define EVFILT_SIGNAL           (-6)    /* attached to struct proc */
52 #define EVFILT_TIMER            (-7)    /* timers */
53 #define EVFILT_NETDEV           (-8)    /* network devices */
54 #define EVFILT_FS               (-9)    /* filesystem events */
55 #define EVFILT_LIO              (-10)   /* attached to lio requests */
56 #define EVFILT_USER             (-11)   /* User events */
57 #define EVFILT_SYSCOUNT         11
58
59 #define EV_SET(kevp_, a, b, c, d, e, f) do {    \
60         struct kevent *kevp = (kevp_);          \
61         (kevp)->ident = (a);                    \
62         (kevp)->filter = (b);                   \
63         (kevp)->flags = (c);                    \
64         (kevp)->fflags = (d);                   \
65         (kevp)->data = (e);                     \
66         (kevp)->udata = (f);                    \
67 } while(0)
68
69 struct kevent {
70         uintptr_t       ident;          /* identifier for this event */
71         short           filter;         /* filter for event */
72         unsigned short flags;
73         unsigned int fflags;
74         intptr_t        data;
75         void            *udata;         /* opaque user data identifier */
76 };
77
78 /* actions */
79 #define EV_ADD          0x0001          /* add event to kq (implies enable) */
80 #define EV_DELETE       0x0002          /* delete event from kq */
81 #define EV_ENABLE       0x0004          /* enable event */
82 #define EV_DISABLE      0x0008          /* disable event (not reported) */
83
84 /* flags */
85 #define EV_ONESHOT      0x0010          /* only report one occurrence */
86 #define EV_CLEAR        0x0020          /* clear event state after reporting */
87 #define EV_RECEIPT      0x0040          /* force EV_ERROR on success, data=0 */
88 #define EV_DISPATCH     0x0080          /* disable event after reporting */
89
90 #define EV_SYSFLAGS     0xF000          /* reserved by system */
91 #define EV_FLAG1        0x2000          /* filter-specific flag */
92
93 /* returned values */
94 #define EV_EOF          0x8000          /* EOF detected */
95 #define EV_ERROR        0x4000          /* error, data contains errno */
96
97  /*
98   * data/hint flags/masks for EVFILT_USER
99   *
100   * On input, the top two bits of fflags specifies how the lower twenty four
101   * bits should be applied to the stored value of fflags.
102   *
103   * On output, the top two bits will always be set to NOTE_FFNOP and the
104   * remaining twenty four bits will contain the stored fflags value.
105   */
106 #define NOTE_FFNOP      0x00000000              /* ignore input fflags */
107 #define NOTE_FFAND      0x40000000              /* AND fflags */
108 #define NOTE_FFOR       0x80000000              /* OR fflags */
109 #define NOTE_FFCOPY     0xc0000000              /* copy fflags */
110 #define NOTE_FFCTRLMASK 0xc0000000              /* masks for operations */
111 #define NOTE_FFLAGSMASK 0x00ffffff
112
113 #define NOTE_TRIGGER    0x01000000              /* Cause the event to be
114                                                    triggered for output. */
115
116 /*
117  * data/hint flags for EVFILT_{READ|WRITE}
118  */
119 #define NOTE_LOWAT      0x0001                  /* low water mark */
120 #undef  NOTE_LOWAT                  /* Not supported on Linux */
121
122 /*
123  * data/hint flags for EVFILT_VNODE
124  */
125 #define NOTE_DELETE     0x0001                  /* vnode was removed */
126 #define NOTE_WRITE      0x0002                  /* data contents changed */
127 #define NOTE_EXTEND     0x0004                  /* size increased */
128 #define NOTE_ATTRIB     0x0008                  /* attributes changed */
129 #define NOTE_LINK       0x0010                  /* link count changed */
130 #define NOTE_RENAME     0x0020                  /* vnode was renamed */
131 #define NOTE_REVOKE     0x0040                  /* vnode access was revoked */
132 #undef  NOTE_REVOKE                 /* Not supported on Linux */
133
134 /*
135  * data/hint flags for EVFILT_PROC
136  */
137 #define NOTE_EXIT       0x80000000              /* process exited */
138 #define NOTE_FORK       0x40000000              /* process forked */
139 #define NOTE_EXEC       0x20000000              /* process exec'd */
140 #define NOTE_PCTRLMASK  0xf0000000              /* mask for hint bits */
141 #define NOTE_PDATAMASK  0x000fffff              /* mask for pid */
142
143 /* additional flags for EVFILT_PROC */
144 #define NOTE_TRACK      0x00000001              /* follow across forks */
145 #define NOTE_TRACKERR   0x00000002              /* could not track child */
146 #define NOTE_CHILD      0x00000004              /* am a child process */
147
148 /*
149  * data/hint flags for EVFILT_NETDEV
150  */
151 #define NOTE_LINKUP     0x0001                  /* link is up */
152 #define NOTE_LINKDOWN   0x0002                  /* link is down */
153 #define NOTE_LINKINV    0x0004                  /* link state is invalid */
154
155 /* KLUDGE: This is from <sys/mount.h> on FreeBSD and is used by 
156            the EVFILT_FS filter. */
157 /* vfsquery flags */
158 #define VQ_NOTRESP      0x0001  /* server down */
159 #define VQ_NEEDAUTH     0x0002  /* server bad auth */
160 #define VQ_LOWDISK      0x0004  /* we're low on space */
161 #define VQ_MOUNT        0x0008  /* new filesystem arrived */
162 #define VQ_UNMOUNT      0x0010  /* filesystem has left */
163 #define VQ_DEAD         0x0020  /* filesystem is dead, needs force unmount */
164 #define VQ_ASSIST       0x0040  /* filesystem needs assistance from external
165                                    program */
166 #define VQ_NOTRESPLOCK  0x0080  /* server lockd down */
167
168
169 #ifndef __KERNEL__
170 #ifdef  __cplusplus
171 extern "C" {
172 #endif
173
174 int     kqueue(void);
175 int     kevent(int kq, const struct kevent *changelist, int nchanges,
176             struct kevent *eventlist, int nevents,
177             const struct timespec *timeout);
178
179 #ifdef  __cplusplus
180 }
181 #endif
182 #endif /* !__KERNEL__* */
183
184 #endif /* !_SYS_EVENT_H_ */