1 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT 2 // file at the top-level directory of this distribution. 3 // 4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your 7 // option. This file may not be copied, modified, or distributed 8 // except according to those terms. 9 10 use std::os::raw::c_void; 11 12 use array::CFArrayRef; 13 use base::{Boolean, CFIndex, CFTypeID, CFAllocatorRef, CFOptionFlags, CFHashCode, mach_port_t}; 14 use date::{CFAbsoluteTime, CFTimeInterval}; 15 use string::CFStringRef; 16 17 #[repr(C)] 18 pub struct __CFRunLoop(c_void); 19 20 pub type CFRunLoopRef = *mut __CFRunLoop; 21 22 #[repr(C)] 23 pub struct __CFRunLoopSource(c_void); 24 25 pub type CFRunLoopSourceRef = *mut __CFRunLoopSource; 26 27 #[repr(C)] 28 pub struct __CFRunLoopObserver(c_void); 29 30 pub type CFRunLoopObserverRef = *mut __CFRunLoopObserver; 31 32 // Reasons for CFRunLoopRunInMode() to Return 33 pub const kCFRunLoopRunFinished: i32 = 1; 34 pub const kCFRunLoopRunStopped: i32 = 2; 35 pub const kCFRunLoopRunTimedOut: i32 = 3; 36 pub const kCFRunLoopRunHandledSource: i32 = 4; 37 38 // Run Loop Observer Activities 39 //typedef CF_OPTIONS(CFOptionFlags, CFRunLoopActivity) { 40 pub type CFRunLoopActivity = CFOptionFlags; 41 pub const kCFRunLoopEntry: CFOptionFlags = 1 << 0; 42 pub const kCFRunLoopBeforeTimers: CFOptionFlags = 1 << 1; 43 pub const kCFRunLoopBeforeSources: CFOptionFlags = 1 << 2; 44 pub const kCFRunLoopBeforeWaiting: CFOptionFlags = 1 << 5; 45 pub const kCFRunLoopAfterWaiting: CFOptionFlags = 1 << 6; 46 pub const kCFRunLoopExit: CFOptionFlags = 1 << 7; 47 pub const kCFRunLoopAllActivities: CFOptionFlags = 0x0FFFFFFF; 48 49 #[repr(C)] 50 pub struct CFRunLoopSourceContext { 51 pub version: CFIndex, 52 pub info: *mut c_void, 53 pub retain: extern "C" fn (info: *const c_void) -> *const c_void, 54 pub release: extern "C" fn (info: *const c_void), 55 pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, 56 pub equal: extern "C" fn (info1: *const c_void, info2: *const c_void) -> Boolean, 57 pub hash: extern "C" fn (info: *const c_void) -> CFHashCode, 58 pub schedule: extern "C" fn (info: *const c_void, rl: CFRunLoopRef, mode: CFStringRef), 59 pub cancel: extern "C" fn (info: *const c_void, rl: CFRunLoopRef, mode: CFStringRef), 60 pub perform: extern "C" fn (info: *const c_void), 61 } 62 63 #[repr(C)] 64 pub struct CFRunLoopSourceContext1 { 65 pub version: CFIndex, 66 pub info: *mut c_void, 67 pub retain: extern "C" fn (info: *const c_void) -> *const c_void, 68 pub release: extern "C" fn (info: *const c_void), 69 pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, 70 pub equal: extern "C" fn (info1: *const c_void, info2: *const c_void) -> Boolean, 71 pub hash: extern "C" fn (info: *const c_void) -> CFHashCode, 72 // note that the following two fields are platform dependent in the C header, the ones here are for OS X 73 pub getPort: extern "C" fn (info: *mut c_void) -> mach_port_t, 74 pub perform: extern "C" fn (msg: *mut c_void, size: CFIndex, allocator: CFAllocatorRef, info: *mut c_void) -> *mut c_void, 75 } 76 77 #[repr(C)] 78 pub struct CFRunLoopObserverContext { 79 pub version: CFIndex, 80 pub info: *mut c_void, 81 pub retain: extern "C" fn (info: *const c_void) -> *const c_void, 82 pub release: extern "C" fn (info: *const c_void), 83 pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, 84 } 85 86 pub type CFRunLoopObserverCallBack = extern "C" fn (observer: CFRunLoopObserverRef, activity: CFRunLoopActivity, info: *mut c_void); 87 88 #[repr(C)] 89 pub struct CFRunLoopTimerContext { 90 pub version: CFIndex, 91 pub info: *mut c_void, 92 pub retain: extern "C" fn (info: *const c_void) -> *const c_void, 93 pub release: extern "C" fn (info: *const c_void), 94 pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, 95 } 96 97 pub type CFRunLoopTimerCallBack = extern "C" fn (timer: CFRunLoopTimerRef, info: *mut c_void); 98 99 #[repr(C)] 100 pub struct __CFRunLoopTimer; 101 102 pub type CFRunLoopTimerRef = *mut __CFRunLoopTimer; 103 104 extern { 105 /* 106 * CFRunLoop.h 107 */ 108 pub static kCFRunLoopDefaultMode: CFStringRef; 109 pub static kCFRunLoopCommonModes: CFStringRef; CFRunLoopGetTypeID() -> CFTypeID110 pub fn CFRunLoopGetTypeID() -> CFTypeID; CFRunLoopGetCurrent() -> CFRunLoopRef111 pub fn CFRunLoopGetCurrent() -> CFRunLoopRef; CFRunLoopGetMain() -> CFRunLoopRef112 pub fn CFRunLoopGetMain() -> CFRunLoopRef; CFRunLoopCopyCurrentMode(rl: CFRunLoopRef) -> CFStringRef113 pub fn CFRunLoopCopyCurrentMode(rl: CFRunLoopRef) -> CFStringRef; CFRunLoopCopyAllModes(rl: CFRunLoopRef) -> CFArrayRef114 pub fn CFRunLoopCopyAllModes(rl: CFRunLoopRef) -> CFArrayRef; CFRunLoopAddCommonMode(rl: CFRunLoopRef, mode: CFStringRef)115 pub fn CFRunLoopAddCommonMode(rl: CFRunLoopRef, mode: CFStringRef); CFRunLoopGetNextTimerFireDate(rl: CFRunLoopRef, mode: CFStringRef) -> CFAbsoluteTime116 pub fn CFRunLoopGetNextTimerFireDate(rl: CFRunLoopRef, mode: CFStringRef) -> CFAbsoluteTime; CFRunLoopRun()117 pub fn CFRunLoopRun(); CFRunLoopRunInMode(mode: CFStringRef, seconds: CFTimeInterval, returnAfterSourceHandled: Boolean) -> i32118 pub fn CFRunLoopRunInMode(mode: CFStringRef, seconds: CFTimeInterval, returnAfterSourceHandled: Boolean) -> i32; CFRunLoopIsWaiting(rl: CFRunLoopRef) -> Boolean119 pub fn CFRunLoopIsWaiting(rl: CFRunLoopRef) -> Boolean; CFRunLoopWakeUp(rl: CFRunLoopRef)120 pub fn CFRunLoopWakeUp(rl: CFRunLoopRef); CFRunLoopStop(rl: CFRunLoopRef)121 pub fn CFRunLoopStop(rl: CFRunLoopRef); 122 // fn CFRunLoopPerformBlock(rl: CFRunLoopRef, mode: CFTypeRef, block: void (^)(void)); CFRunLoopContainsSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef) -> Boolean123 pub fn CFRunLoopContainsSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef) -> Boolean; CFRunLoopAddSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef)124 pub fn CFRunLoopAddSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef); CFRunLoopRemoveSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef)125 pub fn CFRunLoopRemoveSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef); CFRunLoopContainsObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef) -> Boolean126 pub fn CFRunLoopContainsObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef) -> Boolean; CFRunLoopAddObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef)127 pub fn CFRunLoopAddObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef); CFRunLoopRemoveObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef)128 pub fn CFRunLoopRemoveObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef); CFRunLoopContainsTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef) -> Boolean129 pub fn CFRunLoopContainsTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef) -> Boolean; CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef)130 pub fn CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef); CFRunLoopRemoveTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef)131 pub fn CFRunLoopRemoveTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef); 132 CFRunLoopSourceGetTypeID() -> CFTypeID133 pub fn CFRunLoopSourceGetTypeID() -> CFTypeID; CFRunLoopSourceCreate(allocator: CFAllocatorRef, order: CFIndex, context: *mut CFRunLoopSourceContext) -> CFRunLoopSourceRef134 pub fn CFRunLoopSourceCreate(allocator: CFAllocatorRef, order: CFIndex, context: *mut CFRunLoopSourceContext) -> CFRunLoopSourceRef; CFRunLoopSourceGetOrder(source: CFRunLoopSourceRef) -> CFIndex135 pub fn CFRunLoopSourceGetOrder(source: CFRunLoopSourceRef) -> CFIndex; CFRunLoopSourceInvalidate(source: CFRunLoopSourceRef)136 pub fn CFRunLoopSourceInvalidate(source: CFRunLoopSourceRef); CFRunLoopSourceIsValid(source: CFRunLoopSourceRef) -> Boolean137 pub fn CFRunLoopSourceIsValid(source: CFRunLoopSourceRef) -> Boolean; CFRunLoopSourceGetContext(source: CFRunLoopSourceRef, context: *mut CFRunLoopSourceContext)138 pub fn CFRunLoopSourceGetContext(source: CFRunLoopSourceRef, context: *mut CFRunLoopSourceContext); CFRunLoopSourceSignal(source: CFRunLoopSourceRef)139 pub fn CFRunLoopSourceSignal(source: CFRunLoopSourceRef); 140 CFRunLoopObserverGetTypeID() -> CFTypeID141 pub fn CFRunLoopObserverGetTypeID() -> CFTypeID; CFRunLoopObserverCreate(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, callout: CFRunLoopObserverCallBack, context: *mut CFRunLoopObserverContext) -> CFRunLoopObserverRef142 pub fn CFRunLoopObserverCreate(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, callout: CFRunLoopObserverCallBack, context: *mut CFRunLoopObserverContext) -> CFRunLoopObserverRef; 143 // fn CFRunLoopObserverCreateWithHandler(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, block: void (^) (CFRunLoopObserverRef observer, CFRunLoopActivity activity)) -> CFRunLoopObserverRef; CFRunLoopObserverGetActivities(observer: CFRunLoopObserverRef) -> CFOptionFlags144 pub fn CFRunLoopObserverGetActivities(observer: CFRunLoopObserverRef) -> CFOptionFlags; CFRunLoopObserverDoesRepeat(observer: CFRunLoopObserverRef) -> Boolean145 pub fn CFRunLoopObserverDoesRepeat(observer: CFRunLoopObserverRef) -> Boolean; CFRunLoopObserverGetOrder(observer: CFRunLoopObserverRef) -> CFIndex146 pub fn CFRunLoopObserverGetOrder(observer: CFRunLoopObserverRef) -> CFIndex; CFRunLoopObserverInvalidate(observer: CFRunLoopObserverRef)147 pub fn CFRunLoopObserverInvalidate(observer: CFRunLoopObserverRef); CFRunLoopObserverIsValid(observer: CFRunLoopObserverRef) -> Boolean148 pub fn CFRunLoopObserverIsValid(observer: CFRunLoopObserverRef) -> Boolean; CFRunLoopObserverGetContext(observer: CFRunLoopObserverRef, context: *mut CFRunLoopObserverContext)149 pub fn CFRunLoopObserverGetContext(observer: CFRunLoopObserverRef, context: *mut CFRunLoopObserverContext); 150 CFRunLoopTimerGetTypeID() -> CFTypeID151 pub fn CFRunLoopTimerGetTypeID() -> CFTypeID; CFRunLoopTimerCreate(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack, context: *mut CFRunLoopTimerContext) -> CFRunLoopTimerRef152 pub fn CFRunLoopTimerCreate(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack, context: *mut CFRunLoopTimerContext) -> CFRunLoopTimerRef; 153 // fn CFRunLoopTimerCreateWithHandler(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, block: void (^) (CFRunLoopTimerRef timer)) -> CFRunLoopTimerRef; CFRunLoopTimerGetNextFireDate(timer: CFRunLoopTimerRef) -> CFAbsoluteTime154 pub fn CFRunLoopTimerGetNextFireDate(timer: CFRunLoopTimerRef) -> CFAbsoluteTime; CFRunLoopTimerSetNextFireDate(timer: CFRunLoopTimerRef, fireDate: CFAbsoluteTime)155 pub fn CFRunLoopTimerSetNextFireDate(timer: CFRunLoopTimerRef, fireDate: CFAbsoluteTime); CFRunLoopTimerGetInterval(timer: CFRunLoopTimerRef) -> CFTimeInterval156 pub fn CFRunLoopTimerGetInterval(timer: CFRunLoopTimerRef) -> CFTimeInterval; CFRunLoopTimerDoesRepeat(timer: CFRunLoopTimerRef) -> Boolean157 pub fn CFRunLoopTimerDoesRepeat(timer: CFRunLoopTimerRef) -> Boolean; CFRunLoopTimerGetOrder(timer: CFRunLoopTimerRef) -> CFIndex158 pub fn CFRunLoopTimerGetOrder(timer: CFRunLoopTimerRef) -> CFIndex; CFRunLoopTimerInvalidate(timer: CFRunLoopTimerRef)159 pub fn CFRunLoopTimerInvalidate(timer: CFRunLoopTimerRef); CFRunLoopTimerIsValid(timer: CFRunLoopTimerRef) -> Boolean160 pub fn CFRunLoopTimerIsValid(timer: CFRunLoopTimerRef) -> Boolean; CFRunLoopTimerGetContext(timer: CFRunLoopTimerRef, context: *mut CFRunLoopTimerContext)161 pub fn CFRunLoopTimerGetContext(timer: CFRunLoopTimerRef, context: *mut CFRunLoopTimerContext); CFRunLoopTimerGetTolerance(timer: CFRunLoopTimerRef) -> CFTimeInterval162 pub fn CFRunLoopTimerGetTolerance(timer: CFRunLoopTimerRef) -> CFTimeInterval; CFRunLoopTimerSetTolerance(timer: CFRunLoopTimerRef, tolerance: CFTimeInterval)163 pub fn CFRunLoopTimerSetTolerance(timer: CFRunLoopTimerRef, tolerance: CFTimeInterval); 164 } 165