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) 1998-2007, Apple Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFRUNLOOP__)
28 #define __COREFOUNDATION_CFRUNLOOP__ 1
30 #include <CoreFoundation/CFBase.h>
31 #include <CoreFoundation/CFArray.h>
32 #include <CoreFoundation/CFDate.h>
33 #include <CoreFoundation/CFString.h>
35 #include <mach/port.h>
40 typedef struct __CFRunLoop
* CFRunLoopRef
;
42 typedef struct __CFRunLoopSource
* CFRunLoopSourceRef
;
44 typedef struct __CFRunLoopObserver
* CFRunLoopObserverRef
;
46 typedef struct __CFRunLoopTimer
* CFRunLoopTimerRef
;
48 /* Reasons for CFRunLoopRunInMode() to Return */
50 kCFRunLoopRunFinished
= 1,
51 kCFRunLoopRunStopped
= 2,
52 kCFRunLoopRunTimedOut
= 3,
53 kCFRunLoopRunHandledSource
= 4
56 /* Run Loop Observer Activities */
58 kCFRunLoopEntry
= (1 << 0),
59 kCFRunLoopBeforeTimers
= (1 << 1),
60 kCFRunLoopBeforeSources
= (1 << 2),
61 kCFRunLoopBeforeWaiting
= (1 << 5),
62 kCFRunLoopAfterWaiting
= (1 << 6),
63 kCFRunLoopExit
= (1 << 7),
64 kCFRunLoopAllActivities
= 0x0FFFFFFFU
66 typedef CFOptionFlags CFRunLoopActivity
;
68 CF_EXPORT
const CFStringRef kCFRunLoopDefaultMode
;
69 CF_EXPORT
const CFStringRef kCFRunLoopCommonModes
;
71 CF_EXPORT CFTypeID
CFRunLoopGetTypeID(void);
73 CF_EXPORT CFRunLoopRef
CFRunLoopGetCurrent(void);
74 CF_EXPORT CFRunLoopRef
CFRunLoopGetMain(void) AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER
;
76 CF_EXPORT CFStringRef
CFRunLoopCopyCurrentMode(CFRunLoopRef rl
);
78 CF_EXPORT CFArrayRef
CFRunLoopCopyAllModes(CFRunLoopRef rl
);
80 CF_EXPORT
void CFRunLoopAddCommonMode(CFRunLoopRef rl
, CFStringRef mode
);
82 CF_EXPORT CFAbsoluteTime
CFRunLoopGetNextTimerFireDate(CFRunLoopRef rl
, CFStringRef mode
);
84 CF_EXPORT
void CFRunLoopRun(void);
85 CF_EXPORT SInt32
CFRunLoopRunInMode(CFStringRef mode
, CFTimeInterval seconds
, Boolean returnAfterSourceHandled
);
86 CF_EXPORT Boolean
CFRunLoopIsWaiting(CFRunLoopRef rl
);
87 CF_EXPORT
void CFRunLoopWakeUp(CFRunLoopRef rl
);
88 CF_EXPORT
void CFRunLoopStop(CFRunLoopRef rl
);
90 CF_EXPORT Boolean
CFRunLoopContainsSource(CFRunLoopRef rl
, CFRunLoopSourceRef source
, CFStringRef mode
);
91 CF_EXPORT
void CFRunLoopAddSource(CFRunLoopRef rl
, CFRunLoopSourceRef source
, CFStringRef mode
);
92 CF_EXPORT
void CFRunLoopRemoveSource(CFRunLoopRef rl
, CFRunLoopSourceRef source
, CFStringRef mode
);
94 CF_EXPORT Boolean
CFRunLoopContainsObserver(CFRunLoopRef rl
, CFRunLoopObserverRef observer
, CFStringRef mode
);
95 CF_EXPORT
void CFRunLoopAddObserver(CFRunLoopRef rl
, CFRunLoopObserverRef observer
, CFStringRef mode
);
96 CF_EXPORT
void CFRunLoopRemoveObserver(CFRunLoopRef rl
, CFRunLoopObserverRef observer
, CFStringRef mode
);
98 CF_EXPORT Boolean
CFRunLoopContainsTimer(CFRunLoopRef rl
, CFRunLoopTimerRef timer
, CFStringRef mode
);
99 CF_EXPORT
void CFRunLoopAddTimer(CFRunLoopRef rl
, CFRunLoopTimerRef timer
, CFStringRef mode
);
100 CF_EXPORT
void CFRunLoopRemoveTimer(CFRunLoopRef rl
, CFRunLoopTimerRef timer
, CFStringRef mode
);
105 const void *(*retain
)(const void *info
);
106 void (*release
)(const void *info
);
107 CFStringRef (*copyDescription
)(const void *info
);
108 Boolean (*equal
)(const void *info1
, const void *info2
);
109 CFHashCode (*hash
)(const void *info
);
110 void (*schedule
)(void *info
, CFRunLoopRef rl
, CFStringRef mode
);
111 void (*cancel
)(void *info
, CFRunLoopRef rl
, CFStringRef mode
);
112 void (*perform
)(void *info
);
113 } CFRunLoopSourceContext
;
118 const void *(*retain
)(const void *info
);
119 void (*release
)(const void *info
);
120 CFStringRef (*copyDescription
)(const void *info
);
121 Boolean (*equal
)(const void *info1
, const void *info2
);
122 CFHashCode (*hash
)(const void *info
);
123 #if defined(__MACH__)
124 mach_port_t (*getPort
)(void *info
);
125 void * (*perform
)(void *msg
, CFIndex size
, CFAllocatorRef allocator
, void *info
);
127 HANDLE (*getPort
)(void *info
);
128 void (*perform
)(void *info
);
130 } CFRunLoopSourceContext1
;
132 CF_EXPORT CFTypeID
CFRunLoopSourceGetTypeID(void);
134 CF_EXPORT CFRunLoopSourceRef
CFRunLoopSourceCreate(CFAllocatorRef allocator
, CFIndex order
, CFRunLoopSourceContext
*context
);
136 CF_EXPORT CFIndex
CFRunLoopSourceGetOrder(CFRunLoopSourceRef source
);
137 CF_EXPORT
void CFRunLoopSourceInvalidate(CFRunLoopSourceRef source
);
138 CF_EXPORT Boolean
CFRunLoopSourceIsValid(CFRunLoopSourceRef source
);
139 CF_EXPORT
void CFRunLoopSourceGetContext(CFRunLoopSourceRef source
, CFRunLoopSourceContext
*context
);
140 CF_EXPORT
void CFRunLoopSourceSignal(CFRunLoopSourceRef source
);
145 const void *(*retain
)(const void *info
);
146 void (*release
)(const void *info
);
147 CFStringRef (*copyDescription
)(const void *info
);
148 } CFRunLoopObserverContext
;
150 typedef void (*CFRunLoopObserverCallBack
)(CFRunLoopObserverRef observer
, CFRunLoopActivity activity
, void *info
);
152 CF_EXPORT CFTypeID
CFRunLoopObserverGetTypeID(void);
154 CF_EXPORT CFRunLoopObserverRef
CFRunLoopObserverCreate(CFAllocatorRef allocator
, CFOptionFlags activities
, Boolean repeats
, CFIndex order
, CFRunLoopObserverCallBack callout
, CFRunLoopObserverContext
*context
);
156 CF_EXPORT CFOptionFlags
CFRunLoopObserverGetActivities(CFRunLoopObserverRef observer
);
157 CF_EXPORT Boolean
CFRunLoopObserverDoesRepeat(CFRunLoopObserverRef observer
);
158 CF_EXPORT CFIndex
CFRunLoopObserverGetOrder(CFRunLoopObserverRef observer
);
159 CF_EXPORT
void CFRunLoopObserverInvalidate(CFRunLoopObserverRef observer
);
160 CF_EXPORT Boolean
CFRunLoopObserverIsValid(CFRunLoopObserverRef observer
);
161 CF_EXPORT
void CFRunLoopObserverGetContext(CFRunLoopObserverRef observer
, CFRunLoopObserverContext
*context
);
166 const void *(*retain
)(const void *info
);
167 void (*release
)(const void *info
);
168 CFStringRef (*copyDescription
)(const void *info
);
169 } CFRunLoopTimerContext
;
171 typedef void (*CFRunLoopTimerCallBack
)(CFRunLoopTimerRef timer
, void *info
);
173 CF_EXPORT CFTypeID
CFRunLoopTimerGetTypeID(void);
175 CF_EXPORT CFRunLoopTimerRef
CFRunLoopTimerCreate(CFAllocatorRef allocator
, CFAbsoluteTime fireDate
, CFTimeInterval interval
, CFOptionFlags flags
, CFIndex order
, CFRunLoopTimerCallBack callout
, CFRunLoopTimerContext
*context
);
176 CF_EXPORT CFAbsoluteTime
CFRunLoopTimerGetNextFireDate(CFRunLoopTimerRef timer
);
177 CF_EXPORT
void CFRunLoopTimerSetNextFireDate(CFRunLoopTimerRef timer
, CFAbsoluteTime fireDate
);
178 CF_EXPORT CFTimeInterval
CFRunLoopTimerGetInterval(CFRunLoopTimerRef timer
);
179 CF_EXPORT Boolean
CFRunLoopTimerDoesRepeat(CFRunLoopTimerRef timer
);
180 CF_EXPORT CFIndex
CFRunLoopTimerGetOrder(CFRunLoopTimerRef timer
);
181 CF_EXPORT
void CFRunLoopTimerInvalidate(CFRunLoopTimerRef timer
);
182 CF_EXPORT Boolean
CFRunLoopTimerIsValid(CFRunLoopTimerRef timer
);
183 CF_EXPORT
void CFRunLoopTimerGetContext(CFRunLoopTimerRef timer
, CFRunLoopTimerContext
*context
);
187 #endif /* ! __COREFOUNDATION_CFRUNLOOP__ */