CoreFoundation_sys/
runloop.rs

1use libc::c_void;
2use mach::port::mach_port_t;
3use ::{Boolean, CFAbsoluteTime, CFAllocatorRef, CFAllocatorCopyDescriptionCallBack, CFAllocatorReleaseCallBack,
4       CFAllocatorRetainCallBack, CFArrayRef, CFHashCode, CFIndex, CFOptionFlags, CFStringRef, CFTimeInterval,
5       CFTypeID, CFTypeRef};
6
7#[doc(hidden)]
8#[repr(C)]
9pub struct __CFRunLoop {
10    __private: c_void
11}
12
13pub type CFRunLoopRef = *mut __CFRunLoop;
14
15pub type CFRunLoopRunResult = i32;
16
17pub const kCFRunLoopRunFinished: CFRunLoopRunResult = 1;
18pub const kCFRunLoopRunStopped: CFRunLoopRunResult = 2;
19pub const kCFRunLoopRunTimedOut: CFRunLoopRunResult = 3;
20pub const kCFRunLoopRunHandledSource: CFRunLoopRunResult = 4;
21
22extern "C" {
23    pub static kCFRunLoopCommonModes: CFStringRef;
24    pub static kCFRunLoopDefaultMode: CFStringRef;
25
26    pub fn CFRunLoopGetCurrent() -> CFRunLoopRef;
27    pub fn CFRunLoopGetMain() -> CFRunLoopRef;
28
29    pub fn CFRunLoopRun();
30    pub fn CFRunLoopRunInMode(mode: CFStringRef, seconds: CFTimeInterval, returnAfterSourceHandled: Boolean)
31                              -> CFRunLoopRunResult;
32
33    pub fn CFRunLoopWakeUp(rl: CFRunLoopRef);
34    pub fn CFRunLoopStop(rl: CFRunLoopRef);
35    pub fn CFRunLoopIsWaiting(rl: CFRunLoopRef) -> Boolean;
36
37    pub fn CFRunLoopAddSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef);
38    pub fn CFRunLoopContainsSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef) -> Boolean;
39    pub fn CFRunLoopRemoveSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef);
40
41    pub fn CFRunLoopAddObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef);
42    pub fn CFRunLoopContainsObserver(rl: CFRunLoopRef, source: CFRunLoopObserverRef, mode: CFStringRef) -> Boolean;
43    pub fn CFRunLoopRemoveObserver(rl: CFRunLoopRef, source: CFRunLoopObserverRef, mode: CFStringRef);
44
45    pub fn CFRunLoopAddCommonMode(rl: CFRunLoopRef, mode: CFStringRef);
46    pub fn CFRunLoopCopyAllModes(rl: CFRunLoopRef) -> CFArrayRef;
47    pub fn CFRunLoopCopyCurrentMode(rl: CFRunLoopRef) -> CFStringRef;
48
49    pub fn CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef);
50    pub fn CFRunLoopGetNextTimerFireDate(rl: CFRunLoopRef, mode: CFStringRef) -> CFAbsoluteTime;
51    pub fn CFRunLoopRemoveTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef);
52    pub fn CFRunLoopContainsTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef) -> Boolean;
53
54    pub fn CFRunLoopPerformBlock(rl: CFRunLoopRef, mode: CFTypeRef, block: *mut c_void);
55    pub fn CFRunLoopGetTypeID() -> CFTypeID;
56}
57
58#[doc(hidden)]
59#[repr(C)]
60pub struct __CFRunLoopSource {
61    __private: c_void
62}
63
64pub type CFRunLoopSourceRef = *mut __CFRunLoopSource;
65
66#[repr(C)]
67pub struct CFRunLoopSourceContext {
68    pub version: CFIndex,
69    pub info: *mut c_void,
70    pub retain: extern "C" fn(info: *const c_void) -> *const c_void,
71    pub release: extern "C" fn(info: *const c_void),
72    pub copyDescription: extern "C" fn(info: *const c_void) -> CFStringRef,
73    pub equal: extern "C" fn(info1: *const c_void, info2: *const c_void) -> Boolean,
74    pub hash: extern "C" fn(info: *const c_void) -> CFHashCode,
75    pub schedule: extern "C" fn(info: *mut c_void, rl: CFRunLoopRef, mode: CFStringRef),
76    pub cancel: extern "C" fn(info: *mut c_void, rl: CFRunLoopRef, mode: CFStringRef),
77    pub perform: extern "C" fn(info: *mut c_void)
78}
79
80#[repr(C)]
81pub struct CFRunLoopSourceContext1 {
82    pub version: CFIndex,
83    pub info: *mut c_void,
84    pub retain: extern "C" fn(info: *const c_void) -> *const c_void,
85    pub release: extern "C" fn(info: *const c_void),
86    pub copyDescription: extern "C" fn(info: *const c_void) -> CFStringRef,
87    pub equal: extern "C" fn(info1: *const c_void, info2: *const c_void) -> Boolean,
88    pub hash: extern "C" fn(info: *const c_void) -> CFHashCode,
89    pub getPort: extern "C" fn(info: *mut c_void) -> mach_port_t,
90    pub perform: extern "C" fn(msg: *mut c_void, size: CFIndex, allocator: CFAllocatorRef,
91                               info: *mut c_void) -> *mut c_void
92}
93
94extern "C" {
95    pub fn CFRunLoopSourceCreate(allocator: CFAllocatorRef, order: CFIndex, context: *mut CFRunLoopSourceContext)
96                                 -> CFRunLoopSourceRef;
97    pub fn CFRunLoopSourceGetContext(source: CFRunLoopSourceRef, context: *mut CFRunLoopSourceContext);
98    pub fn CFRunLoopSourceGetOrder(source: CFRunLoopSourceRef) -> CFIndex;
99    pub fn CFRunLoopSourceGetTypeID() -> CFTypeID;
100    pub fn CFRunLoopSourceInvalidate(source: CFRunLoopSourceRef);
101    pub fn CFRunLoopSourceIsValid(source: CFRunLoopSourceRef) -> Boolean;
102    pub fn CFRunLoopSourceSignal(source: CFRunLoopSourceRef);
103}
104
105#[doc(hidden)]
106#[repr(C)]
107pub struct __CFRunLoopObserver {
108    __private: c_void
109}
110
111pub type CFRunLoopObserverRef = *mut __CFRunLoopObserver;
112
113#[repr(C)]
114pub struct CFRunLoopObserverContext {
115    pub version: CFIndex,
116    pub info: *mut c_void,
117    pub retain: extern "C" fn(info: *const c_void) -> *const c_void,
118    pub release: extern "C" fn(info: *const c_void),
119    pub copyDescription: extern "C" fn(info: *const c_void) -> CFStringRef,
120}
121
122pub type CFRunLoopObserverCallBack = extern "C" fn(observer: CFRunLoopObserverRef, activity: CFRunLoopActivity,
123                                                   info: *mut c_void);
124
125pub type CFRunLoopActivity = CFOptionFlags;
126
127pub const kCFRunLoopEntry: CFRunLoopActivity = (1 << 0);
128pub const kCFRunLoopBeforeTimers: CFRunLoopActivity = (1 << 1);
129pub const kCFRunLoopBeforeSources: CFRunLoopActivity = (1 << 2);
130pub const kCFRunLoopBeforeWaiting: CFRunLoopActivity = (1 << 5);
131pub const kCFRunLoopAfterWaiting: CFRunLoopActivity = (1 << 6);
132pub const kCFRunLoopExit: CFRunLoopActivity = (1 << 7);
133pub const kCFRunLoopAllActivities: CFRunLoopActivity = 0x0FFFFFFF;
134
135extern "C" {
136    pub fn CFRunLoopObserverCreateWithHandler(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean,
137                                              order: CFIndex, block: *mut c_void) -> CFRunLoopObserverRef;
138    pub fn CFRunLoopObserverCreate(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean,
139                                   order: CFIndex, callout: CFRunLoopObserverCallBack,
140                                   context: *mut CFRunLoopObserverContext) -> CFRunLoopObserverRef;
141
142    pub fn CFRunLoopObserverDoesRepeat(observer: CFRunLoopObserverRef) -> Boolean;
143    pub fn CFRunLoopObserverGetActivities(observer: CFRunLoopObserverRef) -> CFOptionFlags;
144    pub fn CFRunLoopObserverGetContext(observer: CFRunLoopObserverRef, context: *mut CFRunLoopObserverContext);
145    pub fn CFRunLoopObserverGetOrder(observer: CFRunLoopObserverRef) -> CFIndex;
146
147    pub fn CFRunLoopObserverGetTypeID() -> CFTypeID;
148
149    pub fn CFRunLoopObserverInvalidate(observer: CFRunLoopObserverRef);
150    pub fn CFRunLoopObserverIsValid(observer: CFRunLoopObserverRef) -> Boolean;
151}
152
153#[doc(hidden)]
154#[repr(C)]
155pub struct __CFRunLoopTimer {
156    __private: c_void
157}
158
159pub type CFRunLoopTimerRef = *mut __CFRunLoopTimer;
160
161pub type CFRunLoopTimerCallBack = extern "C" fn(timer: CFRunLoopTimerRef, info: *mut c_void);
162
163#[repr(C)]
164pub struct CFRunLoopTimerContext {
165    pub version: CFIndex,
166    pub info: *mut c_void,
167    pub retain: CFAllocatorRetainCallBack,
168    pub release: CFAllocatorReleaseCallBack,
169    pub copyDescription: CFAllocatorCopyDescriptionCallBack
170}
171
172extern "C" {
173    pub fn CFRunLoopTimerCreateWithHandler(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval,
174                                           flags: CFOptionFlags, order: CFIndex, block: *mut c_void) -> CFRunLoopTimerRef;
175    pub fn CFRunLoopTimerCreate(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval,
176                                flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack,
177                                context: *mut CFRunLoopTimerContext) -> CFRunLoopTimerRef;
178
179    pub fn CFRunLoopTimerDoesRepeat(timer: CFRunLoopTimerRef) -> Boolean;
180    pub fn CFRunLoopTimerGetContext(timer: CFRunLoopTimerRef, context: *mut CFRunLoopTimerContext);
181    pub fn CFRunLoopTimerGetInterval(timer: CFRunLoopTimerRef) -> CFTimeInterval;
182    pub fn CFRunLoopTimerGetNextFireDate(timer: CFRunLoopTimerRef) -> CFAbsoluteTime;
183    pub fn CFRunLoopTimerGetOrder(timer: CFRunLoopTimerRef) -> CFIndex;
184    pub fn CFRunLoopTimerGetTypeID() -> CFTypeID;
185    pub fn CFRunLoopTimerInvalidate(timer: CFRunLoopTimerRef);
186    pub fn CFRunLoopTimerIsValid(timer: CFRunLoopTimerRef) -> Boolean;
187    pub fn CFRunLoopTimerSetNextFireDate(timer: CFRunLoopTimerRef, fireDate: CFAbsoluteTime);
188}