Skip to content

Commit 60ddf27

Browse files
committed
Added Sources.
1 parent e8f5380 commit 60ddf27

File tree

5 files changed

+640
-26
lines changed

5 files changed

+640
-26
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ exclude = [
1717
"travis_test.sh",
1818
"tests-ios/**",
1919
]
20+
21+
[dependencies]
22+
bitflags = "0.7"
23+
libc = "0.2"

src/ffi.rs

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#![allow(missing_docs)]
22
#![allow(non_camel_case_types)]
33

4+
use libc::uintptr_t;
45
use std::os::raw::{c_char, c_long, c_ulong, c_void};
56

67
#[repr(C)]
78
pub struct dispatch_object_s { _private: [u8; 0] }
89

10+
#[repr(C)]
11+
pub struct dispatch_source_type_s { _private: [u8; 0] }
12+
913
// dispatch_block_t
1014
pub type dispatch_function_t = extern fn(*mut c_void);
1115
pub type dispatch_semaphore_t = *mut dispatch_object_s;
@@ -14,7 +18,8 @@ pub type dispatch_object_t = *mut dispatch_object_s;
1418
pub type dispatch_once_t = c_long;
1519
pub type dispatch_queue_t = *mut dispatch_object_s;
1620
pub type dispatch_time_t = u64;
17-
// dispatch_source_type_t
21+
pub type dispatch_source_t = *mut dispatch_object_s;
22+
pub type dispatch_source_type_t = *const dispatch_source_type_s;
1823
// dispatch_fd_t
1924
// dispatch_data_t
2025
// dispatch_data_applier_t
@@ -77,20 +82,32 @@ extern {
7782
// void dispatch_barrier_sync ( dispatch_queue_t queue, dispatch_block_t block );
7883
pub fn dispatch_barrier_sync_f(queue: dispatch_queue_t, context: *mut c_void, work: dispatch_function_t);
7984

80-
// void dispatch_source_cancel ( dispatch_source_t source );
81-
// dispatch_source_t dispatch_source_create ( dispatch_source_type_t type, uintptr_t handle, unsigned long mask, dispatch_queue_t queue );
82-
// unsigned long dispatch_source_get_data ( dispatch_source_t source );
83-
// uintptr_t dispatch_source_get_handle ( dispatch_source_t source );
84-
// unsigned long dispatch_source_get_mask ( dispatch_source_t source );
85-
// void dispatch_source_merge_data ( dispatch_source_t source, unsigned long value );
85+
static _dispatch_source_type_data_add: dispatch_source_type_s;
86+
static _dispatch_source_type_data_or: dispatch_source_type_s;
87+
static _dispatch_source_type_mach_send: dispatch_source_type_s;
88+
static _dispatch_source_type_mach_recv: dispatch_source_type_s;
89+
static _dispatch_source_type_memorypressure: dispatch_source_type_s;
90+
static _dispatch_source_type_proc: dispatch_source_type_s;
91+
static _dispatch_source_type_read: dispatch_source_type_s;
92+
static _dispatch_source_type_signal: dispatch_source_type_s;
93+
static _dispatch_source_type_timer: dispatch_source_type_s;
94+
static _dispatch_source_type_vnode: dispatch_source_type_s;
95+
static _dispatch_source_type_write: dispatch_source_type_s;
96+
97+
pub fn dispatch_source_cancel(source: dispatch_source_t);
98+
pub fn dispatch_source_create(type_: dispatch_source_type_t, handle: uintptr_t, mask: c_ulong, queue: dispatch_queue_t) -> dispatch_source_t;
99+
pub fn dispatch_source_get_data(source: dispatch_source_t) -> c_ulong;
100+
pub fn dispatch_source_get_handle(source: dispatch_source_t) -> uintptr_t;
101+
pub fn dispatch_source_get_mask(source: dispatch_source_t) -> c_ulong;
102+
pub fn dispatch_source_merge_data(source: dispatch_source_t, value: c_ulong);
86103
// void dispatch_source_set_registration_handler ( dispatch_source_t source, dispatch_block_t handler );
87-
// void dispatch_source_set_registration_handler_f ( dispatch_source_t source, dispatch_function_t handler );
104+
pub fn dispatch_source_set_registration_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
88105
// void dispatch_source_set_cancel_handler ( dispatch_source_t source, dispatch_block_t handler );
89-
// void dispatch_source_set_cancel_handler_f ( dispatch_source_t source, dispatch_function_t handler );
106+
pub fn dispatch_source_set_cancel_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
90107
// void dispatch_source_set_event_handler ( dispatch_source_t source, dispatch_block_t handler );
91-
// void dispatch_source_set_event_handler_f ( dispatch_source_t source, dispatch_function_t handler );
92-
// void dispatch_source_set_timer ( dispatch_source_t source, dispatch_time_t start, uint64_t interval, uint64_t leeway );
93-
// long dispatch_source_testcancel ( dispatch_source_t source );
108+
pub fn dispatch_source_set_event_handler_f(source: dispatch_source_t, handler: dispatch_function_t);
109+
pub fn dispatch_source_set_timer(source: dispatch_source_t, start: dispatch_time_t, interval: u64, leeway: u64);
110+
pub fn dispatch_source_testcancel(source: dispatch_source_t) -> c_long;
94111

95112
// void dispatch_read ( dispatch_fd_t fd, size_t length, dispatch_queue_t queue, void (^handler)(dispatch_data_t data, int error) );
96113
// void dispatch_write ( dispatch_fd_t fd, dispatch_data_t data, dispatch_queue_t queue, void (^handler)(dispatch_data_t data, int error) );
@@ -146,6 +163,49 @@ pub const DISPATCH_QUEUE_PRIORITY_BACKGROUND: c_long = -1 << 15;
146163
pub const DISPATCH_TIME_NOW: dispatch_time_t = 0;
147164
pub const DISPATCH_TIME_FOREVER: dispatch_time_t = !0;
148165

166+
pub type dispatch_source_mach_send_flags_t = c_ulong;
167+
168+
pub const DISPATCH_MACH_SEND_DEAD: dispatch_source_mach_send_flags_t = 1;
169+
170+
pub type dispatch_source_memorypressure_flags_t = c_ulong;
171+
172+
pub const DISPATCH_MEMORYPRESSURE_NORMAL: dispatch_source_memorypressure_flags_t = 0x1;
173+
pub const DISPATCH_MEMORYPRESSURE_WARN: dispatch_source_memorypressure_flags_t = 0x2;
174+
pub const DISPATCH_MEMORYPRESSURE_CRITICAL: dispatch_source_memorypressure_flags_t = 0x4;
175+
176+
pub type dispatch_source_proc_flags_t = c_ulong;
177+
178+
pub const DISPATCH_PROC_EXIT: dispatch_source_proc_flags_t = 0x80000000;
179+
pub const DISPATCH_PROC_FORK: dispatch_source_proc_flags_t = 0x40000000;
180+
pub const DISPATCH_PROC_EXEC: dispatch_source_proc_flags_t = 0x20000000;
181+
pub const DISPATCH_PROC_SIGNAL: dispatch_source_proc_flags_t = 0x08000000;
182+
183+
pub type dispatch_source_timer_flags_t = c_ulong;
184+
185+
pub const DISPATCH_TIMER_STRICT: dispatch_source_timer_flags_t = 0x1;
186+
187+
pub type dispatch_source_vnode_flags_t = c_ulong;
188+
189+
pub const DISPATCH_VNODE_DELETE: dispatch_source_vnode_flags_t = 0x1;
190+
pub const DISPATCH_VNODE_WRITE: dispatch_source_vnode_flags_t = 0x2;
191+
pub const DISPATCH_VNODE_EXTEND: dispatch_source_vnode_flags_t = 0x4;
192+
pub const DISPATCH_VNODE_ATTRIB: dispatch_source_vnode_flags_t = 0x8;
193+
pub const DISPATCH_VNODE_LINK: dispatch_source_vnode_flags_t = 0x10;
194+
pub const DISPATCH_VNODE_RENAME: dispatch_source_vnode_flags_t = 0x20;
195+
pub const DISPATCH_VNODE_REVOKE: dispatch_source_vnode_flags_t = 0x40;
196+
197+
pub static DISPATCH_SOURCE_TYPE_DATA_ADD: &'static dispatch_source_type_s = &_dispatch_source_type_data_add;
198+
pub static DISPATCH_SOURCE_TYPE_DATA_OR: &'static dispatch_source_type_s = &_dispatch_source_type_data_or;
199+
pub static DISPATCH_SOURCE_TYPE_MACH_SEND: &'static dispatch_source_type_s = &_dispatch_source_type_mach_send;
200+
pub static DISPATCH_SOURCE_TYPE_MACH_RECV: &'static dispatch_source_type_s = &_dispatch_source_type_mach_recv;
201+
pub static DISPATCH_SOURCE_TYPE_MEMORYPRESSURE: &'static dispatch_source_type_s = &_dispatch_source_type_memorypressure;
202+
pub static DISPATCH_SOURCE_TYPE_PROC: &'static dispatch_source_type_s = &_dispatch_source_type_proc;
203+
pub static DISPATCH_SOURCE_TYPE_READ: &'static dispatch_source_type_s = &_dispatch_source_type_read;
204+
pub static DISPATCH_SOURCE_TYPE_SIGNAL: &'static dispatch_source_type_s = &_dispatch_source_type_signal;
205+
pub static DISPATCH_SOURCE_TYPE_TIMER: &'static dispatch_source_type_s = &_dispatch_source_type_timer;
206+
pub static DISPATCH_SOURCE_TYPE_VNODE: &'static dispatch_source_type_s = &_dispatch_source_type_vnode;
207+
pub static DISPATCH_SOURCE_TYPE_WRITE: &'static dispatch_source_type_s = &_dispatch_source_type_write;
208+
149209
#[cfg(test)]
150210
mod tests {
151211
use super::*;

0 commit comments

Comments
 (0)