Skip to content

Commit f358825

Browse files
burtonageodcuddeback
authored andcommitted
Add CFRunLoop
1 parent 1d23865 commit f358825

File tree

5 files changed

+210
-1
lines changed

5 files changed

+210
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ build = "build.rs"
1414

1515
[dependencies]
1616
libc = "0.2"
17+
mach = "0.0.5"

src/base.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ pub struct __CFAllocator {
6565

6666
pub type CFAllocatorRef = *const __CFAllocator;
6767

68+
pub type CFAllocatorAllocateCallBack = extern "C" fn(allocSize: CFIndex, hint: CFOptionFlags, info: *mut c_void)
69+
-> *mut c_void;
70+
pub type CFAllocatorCopyDescriptionCallBack = extern "C" fn(info: *const c_void) -> CFStringRef;
71+
pub type CFAllocatorDeallocateCallBack = extern "C" fn(ptr: *mut c_void, info: *mut c_void);
72+
pub type CFAllocatorPreferredSizeCallBack = extern "C" fn(size: CFIndex, hint: CFOptionFlags, info: *mut c_void)
73+
-> CFIndex;
74+
pub type CFAllocatorReallocateCallBack = extern "C" fn(ptr: *mut c_void, newSize: CFIndex, hint: CFOptionFlags,
75+
info: *mut c_void) -> *mut c_void;
76+
pub type CFAllocatorReleaseCallBack = extern "C" fn(info: *const c_void);
77+
pub type CFAllocatorRetainCallBack = extern "C" fn(info: *const c_void) -> *const c_void;
78+
6879
extern "C" {
6980
pub static kCFAllocatorDefault: CFAllocatorRef;
7081
pub static kCFAllocatorSystemDefault: CFAllocatorRef;

src/date.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use libc::c_double;
2+
3+
pub type CFAbsoluteTime = CFTimeInterval;
4+
pub type CFTimeInterval = c_double;

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
#![allow(non_upper_case_globals,non_snake_case)]
1+
#![allow(non_upper_case_globals, non_snake_case)]
22

33
extern crate libc;
4+
extern crate mach;
45

56
pub use array::*;
67
pub use base::*;
78
pub use character_set::*;
89
pub use data::*;
10+
pub use date::*;
911
pub use dictionary::*;
1012
pub use locale::*;
1113
pub use number::*;
14+
pub use runloop::*;
1215
pub use set::*;
1316
pub use string::*;
1417
pub use uuid::*;
@@ -18,9 +21,11 @@ pub mod array;
1821
pub mod base;
1922
pub mod character_set;
2023
pub mod data;
24+
pub mod date;
2125
pub mod dictionary;
2226
pub mod locale;
2327
pub mod number;
28+
pub mod runloop;
2429
pub mod set;
2530
pub mod string;
2631
pub mod uuid;

src/runloop.rs

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
use libc::c_void;
2+
use mach::port::mach_port_t;
3+
use ::{Boolean, CFAbsoluteTime, CFAllocatorRef, CFAllocatorCopyDescriptionCallBack, CFAllocatorReleaseCallBack,
4+
CFAllocatorRetainCallBack, CFArrayRef, CFHashCode, CFIndex, CFOptionFlags, CFStringRef, CFTimeInterval,
5+
CFTypeID, CFTypeRef};
6+
7+
#[doc(hidden)]
8+
#[repr(C)]
9+
pub struct __CFRunLoop {
10+
__private: c_void
11+
}
12+
13+
pub type CFRunLoopRef = *mut __CFRunLoop;
14+
15+
pub type CFRunLoopRunResult = i32;
16+
17+
pub const kCFRunLoopRunFinished: CFRunLoopRunResult = 1;
18+
pub const kCFRunLoopRunStopped: CFRunLoopRunResult = 2;
19+
pub const kCFRunLoopRunTimedOut: CFRunLoopRunResult = 3;
20+
pub const kCFRunLoopRunHandledSource: CFRunLoopRunResult = 4;
21+
22+
extern "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)]
60+
pub struct __CFRunLoopSource {
61+
__private: c_void
62+
}
63+
64+
pub type CFRunLoopSourceRef = *mut __CFRunLoopSource;
65+
66+
#[repr(C)]
67+
pub 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)]
81+
pub 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+
94+
extern "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)]
107+
pub struct __CFRunLoopObserver {
108+
__private: c_void
109+
}
110+
111+
pub type CFRunLoopObserverRef = *mut __CFRunLoopObserver;
112+
113+
#[repr(C)]
114+
pub 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+
122+
pub type CFRunLoopObserverCallBack = extern "C" fn(observer: CFRunLoopObserverRef, activity: CFRunLoopActivity,
123+
info: *mut c_void);
124+
125+
pub type CFRunLoopActivity = CFOptionFlags;
126+
127+
pub const kCFRunLoopEntry: CFRunLoopActivity = (1 << 0);
128+
pub const kCFRunLoopBeforeTimers: CFRunLoopActivity = (1 << 1);
129+
pub const kCFRunLoopBeforeSources: CFRunLoopActivity = (1 << 2);
130+
pub const kCFRunLoopBeforeWaiting: CFRunLoopActivity = (1 << 5);
131+
pub const kCFRunLoopAfterWaiting: CFRunLoopActivity = (1 << 6);
132+
pub const kCFRunLoopExit: CFRunLoopActivity = (1 << 7);
133+
pub const kCFRunLoopAllActivities: CFRunLoopActivity = 0x0FFFFFFF;
134+
135+
extern "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)]
155+
pub struct __CFRunLoopTimer {
156+
__private: c_void
157+
}
158+
159+
pub type CFRunLoopTimerRef = *mut __CFRunLoopTimer;
160+
161+
pub type CFRunLoopTimerCallBack = extern "C" fn(timer: CFRunLoopTimerRef, info: *mut c_void);
162+
163+
#[repr(C)]
164+
pub 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+
172+
extern "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+
}

0 commit comments

Comments
 (0)