]> git.saurik.com Git - apple/cf.git/blob - CFRunLoop.h
CF-476.15.tar.gz
[apple/cf.git] / CFRunLoop.h
1 /*
2 * Copyright (c) 2008 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-2007, 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 defined(__MACH__)
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 = (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
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 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);
93
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);
97
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);
101
102 typedef struct {
103 CFIndex version;
104 void * info;
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;
114
115 typedef struct {
116 CFIndex version;
117 void * info;
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);
126 #else
127 HANDLE (*getPort)(void *info);
128 void (*perform)(void *info);
129 #endif
130 } CFRunLoopSourceContext1;
131
132 CF_EXPORT CFTypeID CFRunLoopSourceGetTypeID(void);
133
134 CF_EXPORT CFRunLoopSourceRef CFRunLoopSourceCreate(CFAllocatorRef allocator, CFIndex order, CFRunLoopSourceContext *context);
135
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);
141
142 typedef struct {
143 CFIndex version;
144 void * info;
145 const void *(*retain)(const void *info);
146 void (*release)(const void *info);
147 CFStringRef (*copyDescription)(const void *info);
148 } CFRunLoopObserverContext;
149
150 typedef void (*CFRunLoopObserverCallBack)(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info);
151
152 CF_EXPORT CFTypeID CFRunLoopObserverGetTypeID(void);
153
154 CF_EXPORT CFRunLoopObserverRef CFRunLoopObserverCreate(CFAllocatorRef allocator, CFOptionFlags activities, Boolean repeats, CFIndex order, CFRunLoopObserverCallBack callout, CFRunLoopObserverContext *context);
155
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);
162
163 typedef struct {
164 CFIndex version;
165 void * info;
166 const void *(*retain)(const void *info);
167 void (*release)(const void *info);
168 CFStringRef (*copyDescription)(const void *info);
169 } CFRunLoopTimerContext;
170
171 typedef void (*CFRunLoopTimerCallBack)(CFRunLoopTimerRef timer, void *info);
172
173 CF_EXPORT CFTypeID CFRunLoopTimerGetTypeID(void);
174
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);
184
185 CF_EXTERN_C_END
186
187 #endif /* ! __COREFOUNDATION_CFRUNLOOP__ */
188