]> git.saurik.com Git - apple/cf.git/blob - CFRunLoop.h
CF-550.tar.gz
[apple/cf.git] / CFRunLoop.h
1 /*
2 * Copyright (c) 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* CFRunLoop.h
24 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
25 */
26
27 #if !defined(__COREFOUNDATION_CFRUNLOOP__)
28 #define __COREFOUNDATION_CFRUNLOOP__ 1
29
30 #include <CoreFoundation/CFBase.h>
31 #include <CoreFoundation/CFArray.h>
32 #include <CoreFoundation/CFDate.h>
33 #include <CoreFoundation/CFString.h>
34 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
35 #include <mach/port.h>
36 #endif
37
38 CF_EXTERN_C_BEGIN
39
40 typedef struct __CFRunLoop * CFRunLoopRef;
41
42 typedef struct __CFRunLoopSource * CFRunLoopSourceRef;
43
44 typedef struct __CFRunLoopObserver * CFRunLoopObserverRef;
45
46 typedef struct __CFRunLoopTimer * CFRunLoopTimerRef;
47
48 /* Reasons for CFRunLoopRunInMode() to Return */
49 enum {
50 kCFRunLoopRunFinished = 1,
51 kCFRunLoopRunStopped = 2,
52 kCFRunLoopRunTimedOut = 3,
53 kCFRunLoopRunHandledSource = 4
54 };
55
56 /* Run Loop Observer Activities */
57 enum {
58 kCFRunLoopEntry = (1UL << 0),
59 kCFRunLoopBeforeTimers = (1UL << 1),
60 kCFRunLoopBeforeSources = (1UL << 2),
61 kCFRunLoopBeforeWaiting = (1UL << 5),
62 kCFRunLoopAfterWaiting = (1UL << 6),
63 kCFRunLoopExit = (1UL << 7),
64 kCFRunLoopAllActivities = 0x0FFFFFFFU
65 };
66 typedef CFOptionFlags CFRunLoopActivity;
67
68 CF_EXPORT const CFStringRef kCFRunLoopDefaultMode;
69 CF_EXPORT const CFStringRef kCFRunLoopCommonModes;
70
71 CF_EXPORT CFTypeID CFRunLoopGetTypeID(void);
72
73 CF_EXPORT CFRunLoopRef CFRunLoopGetCurrent(void);
74 CF_EXPORT CFRunLoopRef CFRunLoopGetMain(void) AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER;
75
76 CF_EXPORT CFStringRef CFRunLoopCopyCurrentMode(CFRunLoopRef rl);
77
78 CF_EXPORT CFArrayRef CFRunLoopCopyAllModes(CFRunLoopRef rl);
79
80 CF_EXPORT void CFRunLoopAddCommonMode(CFRunLoopRef rl, CFStringRef mode);
81
82 CF_EXPORT CFAbsoluteTime CFRunLoopGetNextTimerFireDate(CFRunLoopRef rl, CFStringRef mode);
83
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);
89
90 #if __BLOCKS__ && MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED
91 CF_EXPORT void CFRunLoopPerformBlock(CFRunLoopRef rl, CFTypeRef mode, void (^block)(void)) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
92 #endif
93
94 CF_EXPORT Boolean CFRunLoopContainsSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);
95 CF_EXPORT void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);
96 CF_EXPORT void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);
97
98 CF_EXPORT Boolean CFRunLoopContainsObserver(CFRunLoopRef rl, CFRunLoopObserverRef observer, CFStringRef mode);
99 CF_EXPORT void CFRunLoopAddObserver(CFRunLoopRef rl, CFRunLoopObserverRef observer, CFStringRef mode);
100 CF_EXPORT void CFRunLoopRemoveObserver(CFRunLoopRef rl, CFRunLoopObserverRef observer, CFStringRef mode);
101
102 CF_EXPORT Boolean CFRunLoopContainsTimer(CFRunLoopRef rl, CFRunLoopTimerRef timer, CFStringRef mode);
103 CF_EXPORT void CFRunLoopAddTimer(CFRunLoopRef rl, CFRunLoopTimerRef timer, CFStringRef mode);
104 CF_EXPORT void CFRunLoopRemoveTimer(CFRunLoopRef rl, CFRunLoopTimerRef timer, CFStringRef mode);
105
106 typedef struct {
107 CFIndex version;
108 void * info;
109 const void *(*retain)(const void *info);
110 void (*release)(const void *info);
111 CFStringRef (*copyDescription)(const void *info);
112 Boolean (*equal)(const void *info1, const void *info2);
113 CFHashCode (*hash)(const void *info);
114 void (*schedule)(void *info, CFRunLoopRef rl, CFStringRef mode);
115 void (*cancel)(void *info, CFRunLoopRef rl, CFStringRef mode);
116 void (*perform)(void *info);
117 } CFRunLoopSourceContext;
118
119 typedef struct {
120 CFIndex version;
121 void * info;
122 const void *(*retain)(const void *info);
123 void (*release)(const void *info);
124 CFStringRef (*copyDescription)(const void *info);
125 Boolean (*equal)(const void *info1, const void *info2);
126 CFHashCode (*hash)(const void *info);
127 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
128 mach_port_t (*getPort)(void *info);
129 void * (*perform)(void *msg, CFIndex size, CFAllocatorRef allocator, void *info);
130 #else
131 void * (*getPort)(void *info);
132 void (*perform)(void *info);
133 #endif
134 } CFRunLoopSourceContext1;
135
136 CF_EXPORT CFTypeID CFRunLoopSourceGetTypeID(void);
137
138 CF_EXPORT CFRunLoopSourceRef CFRunLoopSourceCreate(CFAllocatorRef allocator, CFIndex order, CFRunLoopSourceContext *context);
139
140 CF_EXPORT CFIndex CFRunLoopSourceGetOrder(CFRunLoopSourceRef source);
141 CF_EXPORT void CFRunLoopSourceInvalidate(CFRunLoopSourceRef source);
142 CF_EXPORT Boolean CFRunLoopSourceIsValid(CFRunLoopSourceRef source);
143 CF_EXPORT void CFRunLoopSourceGetContext(CFRunLoopSourceRef source, CFRunLoopSourceContext *context);
144 CF_EXPORT void CFRunLoopSourceSignal(CFRunLoopSourceRef source);
145
146 typedef struct {
147 CFIndex version;
148 void * info;
149 const void *(*retain)(const void *info);
150 void (*release)(const void *info);
151 CFStringRef (*copyDescription)(const void *info);
152 } CFRunLoopObserverContext;
153
154 typedef void (*CFRunLoopObserverCallBack)(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info);
155
156 CF_EXPORT CFTypeID CFRunLoopObserverGetTypeID(void);
157
158 CF_EXPORT CFRunLoopObserverRef CFRunLoopObserverCreate(CFAllocatorRef allocator, CFOptionFlags activities, Boolean repeats, CFIndex order, CFRunLoopObserverCallBack callout, CFRunLoopObserverContext *context);
159
160 CF_EXPORT CFOptionFlags CFRunLoopObserverGetActivities(CFRunLoopObserverRef observer);
161 CF_EXPORT Boolean CFRunLoopObserverDoesRepeat(CFRunLoopObserverRef observer);
162 CF_EXPORT CFIndex CFRunLoopObserverGetOrder(CFRunLoopObserverRef observer);
163 CF_EXPORT void CFRunLoopObserverInvalidate(CFRunLoopObserverRef observer);
164 CF_EXPORT Boolean CFRunLoopObserverIsValid(CFRunLoopObserverRef observer);
165 CF_EXPORT void CFRunLoopObserverGetContext(CFRunLoopObserverRef observer, CFRunLoopObserverContext *context);
166
167 typedef struct {
168 CFIndex version;
169 void * info;
170 const void *(*retain)(const void *info);
171 void (*release)(const void *info);
172 CFStringRef (*copyDescription)(const void *info);
173 } CFRunLoopTimerContext;
174
175 typedef void (*CFRunLoopTimerCallBack)(CFRunLoopTimerRef timer, void *info);
176
177 CF_EXPORT CFTypeID CFRunLoopTimerGetTypeID(void);
178
179 CF_EXPORT CFRunLoopTimerRef CFRunLoopTimerCreate(CFAllocatorRef allocator, CFAbsoluteTime fireDate, CFTimeInterval interval, CFOptionFlags flags, CFIndex order, CFRunLoopTimerCallBack callout, CFRunLoopTimerContext *context);
180 CF_EXPORT CFAbsoluteTime CFRunLoopTimerGetNextFireDate(CFRunLoopTimerRef timer);
181 CF_EXPORT void CFRunLoopTimerSetNextFireDate(CFRunLoopTimerRef timer, CFAbsoluteTime fireDate);
182 CF_EXPORT CFTimeInterval CFRunLoopTimerGetInterval(CFRunLoopTimerRef timer);
183 CF_EXPORT Boolean CFRunLoopTimerDoesRepeat(CFRunLoopTimerRef timer);
184 CF_EXPORT CFIndex CFRunLoopTimerGetOrder(CFRunLoopTimerRef timer);
185 CF_EXPORT void CFRunLoopTimerInvalidate(CFRunLoopTimerRef timer);
186 CF_EXPORT Boolean CFRunLoopTimerIsValid(CFRunLoopTimerRef timer);
187 CF_EXPORT void CFRunLoopTimerGetContext(CFRunLoopTimerRef timer, CFRunLoopTimerContext *context);
188
189 CF_EXTERN_C_END
190
191 #endif /* ! __COREFOUNDATION_CFRUNLOOP__ */
192