2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 Copyright (c) 2006-2007, Apple Inc. All rights reserved.
27 #if (DEPLOYMENT_TARGET_MACOSX || 0)
29 /* -------- -------- -------- -------- -------- -------- -------- -------- */
32 #include <CoreFoundation/CFRunLoop.h>
33 #include <CoreFoundation/CFMachPort.h>
34 #include <CoreFoundation/CFSocket.h>
35 #include <CoreFoundation/CFArray.h>
36 #include <CoreFoundation/CFBag.h>
37 #include <mach/mach.h>
38 #include <sys/event.h>
41 @
class CFRunLoopSourceSet
;
42 typedef CFRunLoopSourceContext CFRunLoopSourceContext0
;
43 typedef CFMachPortContext CFRunLoopMachPortContext
;
44 typedef CFSocketContext CFRunLoopSocketContext
;
46 /* -------- -------- -------- -------- -------- -------- -------- -------- */
48 @interface CFRunLoopSource
: CFObject
{
49 uint8_t _cfruntime_
[8]; // large enough for 32-bit or 64-bit
61 - (mach_port_t
)machPortSet
;
62 - (mach_port_t
)machPort
;
64 - (void)setOrder
:(CFIndex
)o
;
67 - (void)setAsyncStrategy
:(uint8_t)s
;
68 - (uint8_t)asyncStrategy
;
70 - (void)perform
:(mach_msg_header_t
*)msg
;
75 - (void)noteAddedToSourceSet
:(CFRunLoopSourceSet
*)ss
;
76 - (void)noteRemovedFromSourceSet
:(CFRunLoopSourceSet
*)ss
;
78 - (CFStringRef
)copyPartialDebugDescription
; // subclasses override
79 - (CFStringRef
)copyDebugDescription
;
83 @interface CFRunLoopVersion0SourceCFRef
: CFRunLoopSource
{
84 CFRunLoopSourceContext0 _context
;
87 - (Boolean
)setContext
:(CFRunLoopSourceContext0
)c
;
88 - (CFRunLoopSourceContext0
)context
;
93 - (void)scheduleInRunLoop
:(CFRunLoopRef
)rl mode
:(CFStringRef
)n
;
94 - (void)cancelFromRunLoop
:(CFRunLoopRef
)rl mode
:(CFStringRef
)n
;
98 @interface CFRunLoopVersion1SourceCFRef
: CFRunLoopSource
{
99 CFRunLoopSourceContext1 _context
;
102 - (Boolean
)setContext
:(CFRunLoopSourceContext1
)c
;
103 - (CFRunLoopSourceContext1
)context
;
106 - (void)handle
:(mach_msg_header_t
*)msg
;
110 /* -------- -------- -------- -------- -------- -------- -------- -------- */
112 @interface CFRunLoopTimerSource
: CFRunLoopSource
{
113 CFAbsoluteTime _fireAT
;
114 CFTimeInterval _interval
;
117 - (void)setFireTime
:(CFAbsoluteTime
)at
;
118 - (CFAbsoluteTime
)fireTime
;
120 - (void)setInterval
:(CFTimeInterval
)i
;
121 - (CFTimeInterval
)interval
;
127 @interface CFRunLoopTimerSourceCFRef
: CFRunLoopTimerSource
{
129 CFRunLoopTimerContext _context
;
132 - (void)setFunction
:(void *)f
;
135 - (Boolean
)setContext
:(CFRunLoopTimerContext
)c
;
136 - (CFRunLoopTimerContext
)context
;
140 /* -------- -------- -------- -------- -------- -------- -------- -------- */
142 @interface CFRunLoopMachPortSource
: CFRunLoopSource
{
143 mach_port_t _notifyPort
;
144 mach_port_t _oldNotifyPort
;
147 + (id
)newWithPort
:(mach_port_t
)p
;
149 - (void)handle
:(mach_msg_header_t
*)msg
;
153 @interface CFRunLoopMachPortSourceCFRef
: CFRunLoopMachPortSource
{
155 CFRunLoopMachPortContext _context
;
159 - (void)setFunction
:(void *)f
;
162 - (Boolean
)setContext
:(CFRunLoopMachPortContext
)c
;
163 - (CFRunLoopMachPortContext
)context
;
165 - (void)setInvalidationFunction
:(void *)f
;
166 - (void *)invalidationFunction
;
170 /* -------- -------- -------- -------- -------- -------- -------- -------- */
172 @interface CFRunLoopKEventSource
: CFRunLoopSource
{
173 struct kevent _filter
;
176 - (Boolean
)setFilter
:(struct kevent
)kev
;
177 - (struct kevent
)filter
;
179 - (void)handle
:(struct kevent
*)kev
;
183 /* -------- -------- -------- -------- -------- -------- -------- -------- */
185 @interface CFRunLoopSignalSource
: CFRunLoopSource
{
189 - (Boolean
)setSignal
:(int)sig
;
194 - (void)handle
:(long)n
;
198 /* -------- -------- -------- -------- -------- -------- -------- -------- */
200 @interface CFRunLoopProcessDeathSource
: CFRunLoopSource
{
204 - (Boolean
)setProcessID
:(int)pid
;
211 /* -------- -------- -------- -------- -------- -------- -------- -------- */
213 @interface CFRunLoopSocketSource
: CFRunLoopSource
{
220 + (id
)newWithSocket
:(int)s
;
223 - (CFDataRef
)copyLocalAddress
;
224 - (CFDataRef
)copyRemoteAddress
;
226 - (void)setReadEventsEnabled
:(Boolean
)b
;
227 - (Boolean
)readEventsEnabled
;
229 - (void)setWriteEventsEnabled
:(Boolean
)b
;
230 - (Boolean
)writeEventsEnabled
;
232 - (void)handleReadability
:(CFIndex
)amt endOfFile
:(Boolean
)b
;
233 - (void)performRead
:(struct kevent
*)kev
;
235 - (void)handleWritability
:(CFIndex
)amt endOfFile
:(Boolean
)b
;
236 - (void)performWrite
:(struct kevent
*)kev
;
240 @interface CFRunLoopSocketSourceCFRef
: CFRunLoopSocketSource
{
242 CFRunLoopSocketContext _context
;
248 - (void)setFunction
:(void *)f
;
251 - (Boolean
)setContext
:(CFRunLoopSocketContext
)c
;
252 - (CFRunLoopSocketContext
)context
;
254 - (void)setCallBackTypes
:(uint8_t)f
;
255 - (uint8_t)callBackTypes
;
257 - (void)setFlags
:(uint8_t)f
;
260 - (void)setDisabledFlags
:(uint8_t)f
;
261 - (uint8_t)disabledFlags
;
263 - (Boolean
)handleAcceptError
:(int)err
;
264 - (Boolean
)handleReadError
:(int)err
;
268 /* -------- -------- -------- -------- -------- -------- -------- -------- */
270 @interface CFRunLoopObserver
: CFRunLoopSource
{
273 - (void)observeEntry
:(CFRunLoopSourceSet
*)ss
;
274 - (void)observeBeforeWaiting
:(CFRunLoopSourceSet
*)ss
;
275 - (void)observeAfterWaiting
:(CFRunLoopSourceSet
*)ss
;
276 - (void)observeExit
:(CFRunLoopSourceSet
*)ss
;
280 @interface CFRunLoopObserverCFRef
: CFRunLoopObserver
{
282 CFRunLoopObserverContext _context
;
283 CFOptionFlags _activities
;
287 - (void)setFunction
:(void *)f
;
290 - (Boolean
)setContext
:(CFRunLoopObserverContext
)c
;
291 - (CFRunLoopObserverContext
)context
;
293 - (void)setActivities
:(CFOptionFlags
)a
;
294 - (CFOptionFlags
)activities
;
296 - (void)setOneshot
:(Boolean
)b
;
301 /* -------- -------- -------- -------- -------- -------- -------- -------- */
303 @interface CFRunLoopSourceSet
: CFRunLoopObserver
{
304 CFMutableBagRef _sources
;
307 CFMutableArrayRef _observers
[4];
308 CFRunLoopTimerSource
*_timeoutTimer
;
309 CFRunLoopMachPortSource
*_wakeupPort
;
314 + (void)removeSourceFromAllSets
:(CFRunLoopSource
*)src
;
316 - (void)setName
:(CFStringRef
)n
;
319 - (void)setAffineThread
:(pthread_t
)t
;
320 - (pthread_t
)affineThread
;
322 - (Boolean
)containsObserver
:(CFRunLoopObserver
*)o
;
323 - (void)addObserver
:(CFRunLoopObserver
*)o activities
:(CFRunLoopActivity
)a
;
324 - (void)removeObserver
:(CFRunLoopObserver
*)o activities
:(CFRunLoopActivity
)a
;
326 - (Boolean
)containsSource
:(CFRunLoopSource
*)src
;
327 - (void)addSource
:(CFRunLoopSource
*)src
;
328 - (void)removeSource
:(CFRunLoopSource
*)src
;
330 - (void)forEachSource
:(Boolean (*)(CFRunLoopSource
*, void *))f context
:(void *)c
;
334 - (Boolean
)isWaiting
;
336 - (Boolean
)hasInputAvailable
;
338 - (int32_t)serviceUntil
:(CFAbsoluteTime
)at handleOne
:(Boolean
)handleOne
;
342 /* -------- -------- -------- -------- -------- -------- -------- -------- */
344 @interface CFRunLoopCFRef
: CFObject
{
345 uint8_t _cfruntime_
[8]; // large enough for 32-bit or 64-bit
348 CFMutableArrayRef _sourceSets
;
349 CFRunLoopSourceSet
*_currentSet
;
353 - (void)setAffineThread
:(pthread_t
)t
;
354 - (pthread_t
)affineThread
;
356 - (void)setCounterpart
:(void *)c
;
357 - (void *)counterpart
;
362 - (CFArrayRef
)copySourceSets
;
364 - (void)setCurrentSourceSet
:(CFRunLoopSourceSet
*)ss
;
365 - (CFRunLoopSourceSet
*)currentSourceSet
;
367 - (CFRunLoopSourceSet
*)lookupSourceSetWithName
:(CFStringRef
)n
;
368 - (CFRunLoopSourceSet
*)lookupOrCreateSourceSetWithName
:(CFStringRef
)n
;
370 - (CFStringRef
)copyDebugDescription
;
374 /* -------- -------- -------- -------- -------- -------- -------- -------- */