Skip to content

Commit edb187a

Browse files
committed
core-foundation: Add basic CFMachPort
1 parent 48dd601 commit edb187a

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

core-foundation-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ pub mod string;
2929
pub mod timezone;
3030
pub mod url;
3131
pub mod uuid;
32+
pub mod mach_port;

core-foundation-sys/src/mach_port.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub use base::{CFAllocatorRef, CFIndex, CFTypeID};
2+
use runloop::CFRunLoopSourceRef;
3+
use std::os::raw::c_void;
4+
5+
#[repr(C)]
6+
pub struct __CFMachPort(c_void);
7+
pub type CFMachPortRef = *const __CFMachPort;
8+
9+
extern "C" {
10+
/*
11+
* CFMachPort.h
12+
*/
13+
pub fn CFMachPortCreateRunLoopSource(
14+
allocator: CFAllocatorRef,
15+
port: CFMachPortRef,
16+
order: CFIndex,
17+
) -> CFRunLoopSourceRef;
18+
19+
pub fn CFMachPortGetTypeID() -> CFTypeID;
20+
}

core-foundation/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,4 @@ pub mod propertylist;
233233
pub mod runloop;
234234
pub mod timezone;
235235
pub mod uuid;
236+
pub mod mach_port;

core-foundation/src/mach_port.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use base::TCFType;
2+
use core_foundation_sys::base::kCFAllocatorDefault;
3+
use runloop::CFRunLoopSource;
4+
pub use core_foundation_sys::mach_port::*;
5+
6+
7+
declare_TCFType! {
8+
/// An immutable numeric value.
9+
CFMachPort, CFMachPortRef
10+
}
11+
impl_TCFType!(CFMachPort, CFMachPortRef, CFMachPortGetTypeID);
12+
impl_CFTypeDescription!(CFMachPort);
13+
14+
impl CFMachPort {
15+
pub fn create_runloop_source(
16+
&self,
17+
order: CFIndex,
18+
) -> Result<CFRunLoopSource, ()> {
19+
unsafe {
20+
let runloop_source_ref = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.0, order);
21+
if runloop_source_ref.is_null() {
22+
Err(())
23+
} else {
24+
Ok(CFRunLoopSource::wrap_under_create_rule(runloop_source_ref))
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)