The OpenD Programming Language

1 /**
2  * D header file for Darwin.
3  *
4  * Copyright: Copyright Martin Nowak 2012. Etienne Cimon 2015.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Martin Nowak
7  */
8 
9 /*          Copyright Martin Nowak 2012. Etienne Cimon 2015.
10  * Distributed under the Boost Software License, Version 1.0.
11  *    (See accompanying file LICENSE or copy at
12  *          http://www.boost.org/LICENSE_1_0.txt)
13  */
14 module core.sys.darwin.sys.event;
15 
16 version (OSX)
17     version = Darwin;
18 else version (iOS)
19     version = Darwin;
20 else version (TVOS)
21     version = Darwin;
22 else version (WatchOS)
23     version = Darwin;
24 
25 version (Darwin):
26 extern (C):
27 nothrow:
28 @nogc:
29 
30 import core.stdc.stdint;    // intptr_t, uintptr_t
31 import core.sys.posix.time; // timespec
32 
33 enum : short
34 {
35     EVFILT_READ     =  -1,
36     EVFILT_WRITE    =  -2,
37     EVFILT_AIO      =  -3,
38     EVFILT_VNODE    =  -4,
39     EVFILT_PROC     =  -5,
40     EVFILT_SIGNAL   =  -6,
41     EVFILT_TIMER    =  -7,
42     EVFILT_MACHPORT =  -8,
43     EVFILT_FS       =  -9,
44     EVFILT_USER     = -10,
45     EVFILT_VM       = -12,
46     EVFILT_EXCEPT   = -15,
47 }
48 
49 extern(D) void EV_SET()(kevent_t* kevp, typeof(kevent_t.tupleof) args)
50 {
51     *kevp = kevent_t(args);
52 }
53 
54 extern(D) void EV_SET64()(kevent64_s* kevp, typeof(kevent64_s.tupleof) args)
55 {
56     *kevp = kevent64_s(args);
57 }
58 
59 struct kevent_t
60 {
61     uintptr_t    ident;
62     short       filter;
63     ushort       flags;
64     uint        fflags;
65     intptr_t      data;
66     void        *udata;
67 }
68 
69 struct kevent64_s
70 {
71     ulong        ident;
72     short       filter;
73     ushort       flags;
74     uint        fflags;
75     long          data;
76     ulong        udata;
77     ulong[2]       ext;
78 }
79 
80 enum
81 {
82 
83     KEVENT_FLAG_NONE         = 0x000,
84     KEVENT_FLAG_IMMEDIATE    = 0x001,
85     KEVENT_FLAG_ERROR_EVENTS = 0x002,
86 
87     EV_ADD      = 0x0001,
88     EV_DELETE   = 0x0002,
89     EV_ENABLE   = 0x0004,
90     EV_DISABLE  = 0x0008,
91 
92     EV_ONESHOT        = 0x0010,
93     EV_CLEAR          = 0x0020,
94     EV_RECEIPT        = 0x0040,
95 
96     EV_DISPATCH       = 0x0080,
97     EV_UDATA_SPECIFIC = 0x0100,
98 
99     EV_DISPATCH2      = EV_DISPATCH | EV_UDATA_SPECIFIC,
100 
101     EV_VANISHED       = 0x0200,
102 
103     EV_SYSFLAGS       = 0xF000,
104     EV_FLAG0          = 0x1000,
105     EV_FLAG1          = 0x2000,
106 
107     EV_EOF      = 0x8000,
108     EV_ERROR    = 0x4000,
109 }
110 
111 enum
112 {
113     EV_POLL   = EV_FLAG0,
114     EV_OOBAND = EV_FLAG1,
115 }
116 
117 enum
118 {
119     NOTE_TRIGGER = 0x01000000,
120 
121     NOTE_FFNOP      = 0x00000000,
122     NOTE_FFAND      = 0x40000000,
123     NOTE_FFOR       = 0x80000000,
124     NOTE_FFCOPY     = 0xc0000000,
125     NOTE_FFCTRLMASK = 0xc0000000,
126     NOTE_FFLAGSMASK = 0x00ffffff,
127 
128     NOTE_LOWAT      = 0x0001,
129 
130     NOTE_OOB        = 0x0002,
131 
132     NOTE_DELETE     = 0x0001,
133     NOTE_WRITE      = 0x0002,
134     NOTE_EXTEND     = 0x0004,
135     NOTE_ATTRIB     = 0x0008,
136     NOTE_LINK       = 0x0010,
137     NOTE_RENAME     = 0x0020,
138     NOTE_REVOKE     = 0x0040,
139     NOTE_NONE       = 0x0080,
140     NOTE_FUNLOCK    = 0x0100,
141 
142     NOTE_EXIT        = 0x80000000,
143     NOTE_FORK        = 0x40000000,
144     NOTE_EXEC        = 0x20000000,
145     NOTE_REAP        = 0x10000000,
146     NOTE_SIGNAL      = 0x08000000,
147     NOTE_EXITSTATUS  = 0x04000000,
148     NOTE_EXIT_DETAIL = 0x02000000,
149     NOTE_PDATAMASK   = 0x000fffff,
150     NOTE_PCTRLMASK   = ~NOTE_PDATAMASK,
151 
152     NOTE_EXIT_REPARENTED = 0x00080000,
153 
154     NOTE_EXIT_DETAIL_MASK = 0x00070000,
155     NOTE_EXIT_DECRYPTFAIL = 0x00010000,
156     NOTE_EXIT_MEMORY      = 0x00020000,
157     NOTE_EXIT_CSERROR     = 0x00040000,
158 
159     NOTE_VM_PRESSURE                  = 0x80000000,
160     NOTE_VM_PRESSURE_TERMINATE        = 0x40000000,
161     NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000,
162     NOTE_VM_ERROR                     = 0x10000000,
163 
164     NOTE_SECONDS              = 0x00000001,
165     NOTE_USECONDS             = 0x00000002,
166     NOTE_NSECONDS             = 0x00000004,
167     NOTE_ABSOLUTE             = 0x00000008,
168 
169     NOTE_LEEWAY               = 0x00000010,
170     NOTE_CRITICAL             = 0x00000020,
171     NOTE_BACKGROUND           = 0x00000040,
172     NOTE_MACH_CONTINUOUS_TIME = 0x00000080,
173 
174     NOTE_TRACK      = 0x00000001,
175     NOTE_TRACKERR   = 0x00000002,
176     NOTE_CHILD      = 0x00000004,
177 }
178 
179 int kqueue();
180 int kevent(int kq, const kevent_t *changelist, int nchanges,
181            kevent_t *eventlist, int nevents,
182            const timespec *timeout);
183 int kevent64(int kq,
184              const kevent64_s *changelist, int nchanges,
185              kevent64_s *eventlist, int nevents,
186              uint flags,
187              const timespec *timeout);