core_foundation_sys/
mach_port.rs

1// Copyright 2023 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
10use crate::base::{mach_port_t, Boolean};
11pub use crate::base::{CFAllocatorRef, CFIndex, CFTypeID};
12use crate::runloop::CFRunLoopSourceRef;
13use crate::string::CFStringRef;
14use std::os::raw::c_void;
15
16#[repr(C)]
17pub struct __CFMachPort(c_void);
18pub type CFMachPortRef = *mut __CFMachPort;
19
20pub type CFMachPortCallBack =
21    extern "C" fn(port: CFMachPortRef, msg: *mut c_void, size: CFIndex, info: *mut c_void);
22pub type CFMachPortInvalidationCallBack = extern "C" fn(port: CFMachPortRef, info: *mut c_void);
23
24#[repr(C)]
25#[derive(Clone, Copy)]
26pub struct CFMachPortContext {
27    pub version: CFIndex,
28    pub info: *mut c_void,
29    pub retain: extern "C" fn(info: *const c_void) -> *const c_void,
30    pub release: extern "C" fn(info: *const c_void),
31    pub copyDescription: extern "C" fn(info: *const c_void) -> CFStringRef,
32}
33
34extern "C" {
35    /*
36     * CFMachPort.h
37     */
38
39    /* Creating a CFMachPort Object */
40    pub fn CFMachPortCreate(
41        allocator: CFAllocatorRef,
42        callout: CFMachPortCallBack,
43        context: *mut CFMachPortContext,
44        shouldFreeInfo: *mut Boolean,
45    ) -> CFMachPortRef;
46    pub fn CFMachPortCreateWithPort(
47        allocator: CFAllocatorRef,
48        portNum: mach_port_t,
49        callout: CFMachPortCallBack,
50        context: *mut CFMachPortContext,
51        shouldFreeInfo: *mut Boolean,
52    ) -> CFMachPortRef;
53
54    /* Configuring a CFMachPort Object */
55    pub fn CFMachPortInvalidate(port: CFMachPortRef);
56    pub fn CFMachPortCreateRunLoopSource(
57        allocator: CFAllocatorRef,
58        port: CFMachPortRef,
59        order: CFIndex,
60    ) -> CFRunLoopSourceRef;
61    pub fn CFMachPortSetInvalidationCallBack(
62        port: CFMachPortRef,
63        callout: CFMachPortInvalidationCallBack,
64    );
65
66    /* Examining a CFMachPort Object */
67    pub fn CFMachPortGetContext(port: CFMachPortRef, context: *mut CFMachPortContext);
68    pub fn CFMachPortGetInvalidationCallBack(port: CFMachPortRef)
69        -> CFMachPortInvalidationCallBack;
70    pub fn CFMachPortGetPort(port: CFMachPortRef) -> mach_port_t;
71    pub fn CFMachPortIsValid(port: CFMachPortRef) -> Boolean;
72
73    /* Getting the CFMachPort Type ID */
74    pub fn CFMachPortGetTypeID() -> CFTypeID;
75}