Skip to main content

objc2_core_foundation/generated/
CFMachPort.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachport?language=objc)
13///
14/// This is toll-free bridged with `NSMachPort`.
15#[doc(alias = "CFMachPortRef")]
16#[repr(C)]
17pub struct CFMachPort {
18    inner: [u8; 0],
19    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
20}
21
22cf_type!(
23    unsafe impl CFMachPort {}
24);
25#[cfg(feature = "objc2")]
26cf_objc2_type!(
27    unsafe impl RefEncode<"__CFMachPort"> for CFMachPort {}
28);
29
30/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachportcontext?language=objc)
31#[repr(C)]
32#[allow(unpredictable_function_pointer_comparisons)]
33#[derive(Clone, Copy, Debug, PartialEq)]
34pub struct CFMachPortContext {
35    pub version: CFIndex,
36    pub info: *mut c_void,
37    pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
38    pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
39    pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
40}
41
42#[cfg(feature = "objc2")]
43unsafe impl Encode for CFMachPortContext {
44    const ENCODING: Encoding = Encoding::Struct(
45        "?",
46        &[
47            <CFIndex>::ENCODING,
48            <*mut c_void>::ENCODING,
49            <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
50            <Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
51            <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
52        ],
53    );
54}
55
56#[cfg(feature = "objc2")]
57unsafe impl RefEncode for CFMachPortContext {
58    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
59}
60
61/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachportcallback?language=objc)
62pub type CFMachPortCallBack =
63    Option<unsafe extern "C-unwind" fn(*mut CFMachPort, *mut c_void, CFIndex, *mut c_void)>;
64
65/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachportinvalidationcallback?language=objc)
66pub type CFMachPortInvalidationCallBack =
67    Option<unsafe extern "C-unwind" fn(*mut CFMachPort, *mut c_void)>;
68
69unsafe impl ConcreteType for CFMachPort {
70    #[doc(alias = "CFMachPortGetTypeID")]
71    #[inline]
72    fn type_id() -> CFTypeID {
73        extern "C-unwind" {
74            fn CFMachPortGetTypeID() -> CFTypeID;
75        }
76        unsafe { CFMachPortGetTypeID() }
77    }
78}
79
80impl CFMachPort {
81    /// # Safety
82    ///
83    /// - `allocator` might not allow `None`.
84    /// - `callout` must be implemented correctly.
85    /// - `context` must be a valid pointer.
86    /// - `should_free_info` must be a valid pointer.
87    #[doc(alias = "CFMachPortCreate")]
88    #[inline]
89    pub unsafe fn new(
90        allocator: Option<&CFAllocator>,
91        callout: CFMachPortCallBack,
92        context: *mut CFMachPortContext,
93        should_free_info: *mut Boolean,
94    ) -> Option<CFRetained<CFMachPort>> {
95        extern "C-unwind" {
96            fn CFMachPortCreate(
97                allocator: Option<&CFAllocator>,
98                callout: CFMachPortCallBack,
99                context: *mut CFMachPortContext,
100                should_free_info: *mut Boolean,
101            ) -> Option<NonNull<CFMachPort>>;
102        }
103        let ret = unsafe { CFMachPortCreate(allocator, callout, context, should_free_info) };
104        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
105    }
106
107    /// # Safety
108    ///
109    /// - `allocator` might not allow `None`.
110    /// - `callout` must be implemented correctly.
111    /// - `context` must be a valid pointer.
112    /// - `should_free_info` must be a valid pointer.
113    #[doc(alias = "CFMachPortCreateWithPort")]
114    #[cfg(feature = "libc")]
115    #[inline]
116    pub unsafe fn with_port(
117        allocator: Option<&CFAllocator>,
118        port_num: libc::mach_port_t,
119        callout: CFMachPortCallBack,
120        context: *mut CFMachPortContext,
121        should_free_info: *mut Boolean,
122    ) -> Option<CFRetained<CFMachPort>> {
123        extern "C-unwind" {
124            fn CFMachPortCreateWithPort(
125                allocator: Option<&CFAllocator>,
126                port_num: libc::mach_port_t,
127                callout: CFMachPortCallBack,
128                context: *mut CFMachPortContext,
129                should_free_info: *mut Boolean,
130            ) -> Option<NonNull<CFMachPort>>;
131        }
132        let ret = unsafe {
133            CFMachPortCreateWithPort(allocator, port_num, callout, context, should_free_info)
134        };
135        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
136    }
137
138    #[doc(alias = "CFMachPortGetPort")]
139    #[cfg(feature = "libc")]
140    #[inline]
141    pub fn port(&self) -> libc::mach_port_t {
142        extern "C-unwind" {
143            fn CFMachPortGetPort(port: &CFMachPort) -> libc::mach_port_t;
144        }
145        unsafe { CFMachPortGetPort(self) }
146    }
147
148    /// # Safety
149    ///
150    /// `context` must be a valid pointer.
151    #[doc(alias = "CFMachPortGetContext")]
152    #[inline]
153    pub unsafe fn context(&self, context: *mut CFMachPortContext) {
154        extern "C-unwind" {
155            fn CFMachPortGetContext(port: &CFMachPort, context: *mut CFMachPortContext);
156        }
157        unsafe { CFMachPortGetContext(self, context) }
158    }
159
160    #[doc(alias = "CFMachPortInvalidate")]
161    #[inline]
162    pub fn invalidate(&self) {
163        extern "C-unwind" {
164            fn CFMachPortInvalidate(port: &CFMachPort);
165        }
166        unsafe { CFMachPortInvalidate(self) }
167    }
168
169    #[doc(alias = "CFMachPortIsValid")]
170    #[inline]
171    pub fn is_valid(&self) -> bool {
172        extern "C-unwind" {
173            fn CFMachPortIsValid(port: &CFMachPort) -> Boolean;
174        }
175        let ret = unsafe { CFMachPortIsValid(self) };
176        ret != 0
177    }
178
179    #[doc(alias = "CFMachPortGetInvalidationCallBack")]
180    #[inline]
181    pub fn invalidation_call_back(&self) -> CFMachPortInvalidationCallBack {
182        extern "C-unwind" {
183            fn CFMachPortGetInvalidationCallBack(
184                port: &CFMachPort,
185            ) -> CFMachPortInvalidationCallBack;
186        }
187        unsafe { CFMachPortGetInvalidationCallBack(self) }
188    }
189
190    /// # Safety
191    ///
192    /// `callout` must be implemented correctly.
193    #[doc(alias = "CFMachPortSetInvalidationCallBack")]
194    #[inline]
195    pub unsafe fn set_invalidation_call_back(&self, callout: CFMachPortInvalidationCallBack) {
196        extern "C-unwind" {
197            fn CFMachPortSetInvalidationCallBack(
198                port: &CFMachPort,
199                callout: CFMachPortInvalidationCallBack,
200            );
201        }
202        unsafe { CFMachPortSetInvalidationCallBack(self, callout) }
203    }
204
205    #[doc(alias = "CFMachPortCreateRunLoopSource")]
206    #[cfg(feature = "CFRunLoop")]
207    #[inline]
208    pub fn new_run_loop_source(
209        allocator: Option<&CFAllocator>,
210        port: Option<&CFMachPort>,
211        order: CFIndex,
212    ) -> Option<CFRetained<CFRunLoopSource>> {
213        extern "C-unwind" {
214            fn CFMachPortCreateRunLoopSource(
215                allocator: Option<&CFAllocator>,
216                port: Option<&CFMachPort>,
217                order: CFIndex,
218            ) -> Option<NonNull<CFRunLoopSource>>;
219        }
220        let ret = unsafe { CFMachPortCreateRunLoopSource(allocator, port, order) };
221        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
222    }
223}
224
225#[deprecated = "renamed to `CFMachPort::new`"]
226#[inline]
227pub unsafe extern "C-unwind" fn CFMachPortCreate(
228    allocator: Option<&CFAllocator>,
229    callout: CFMachPortCallBack,
230    context: *mut CFMachPortContext,
231    should_free_info: *mut Boolean,
232) -> Option<CFRetained<CFMachPort>> {
233    extern "C-unwind" {
234        fn CFMachPortCreate(
235            allocator: Option<&CFAllocator>,
236            callout: CFMachPortCallBack,
237            context: *mut CFMachPortContext,
238            should_free_info: *mut Boolean,
239        ) -> Option<NonNull<CFMachPort>>;
240    }
241    let ret = unsafe { CFMachPortCreate(allocator, callout, context, should_free_info) };
242    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
243}
244
245#[cfg(feature = "libc")]
246#[deprecated = "renamed to `CFMachPort::with_port`"]
247#[inline]
248pub unsafe extern "C-unwind" fn CFMachPortCreateWithPort(
249    allocator: Option<&CFAllocator>,
250    port_num: libc::mach_port_t,
251    callout: CFMachPortCallBack,
252    context: *mut CFMachPortContext,
253    should_free_info: *mut Boolean,
254) -> Option<CFRetained<CFMachPort>> {
255    extern "C-unwind" {
256        fn CFMachPortCreateWithPort(
257            allocator: Option<&CFAllocator>,
258            port_num: libc::mach_port_t,
259            callout: CFMachPortCallBack,
260            context: *mut CFMachPortContext,
261            should_free_info: *mut Boolean,
262        ) -> Option<NonNull<CFMachPort>>;
263    }
264    let ret = unsafe {
265        CFMachPortCreateWithPort(allocator, port_num, callout, context, should_free_info)
266    };
267    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
268}
269
270#[cfg(feature = "libc")]
271#[deprecated = "renamed to `CFMachPort::port`"]
272#[inline]
273pub extern "C-unwind" fn CFMachPortGetPort(port: &CFMachPort) -> libc::mach_port_t {
274    extern "C-unwind" {
275        fn CFMachPortGetPort(port: &CFMachPort) -> libc::mach_port_t;
276    }
277    unsafe { CFMachPortGetPort(port) }
278}
279
280extern "C-unwind" {
281    #[deprecated = "renamed to `CFMachPort::context`"]
282    pub fn CFMachPortGetContext(port: &CFMachPort, context: *mut CFMachPortContext);
283}
284
285#[deprecated = "renamed to `CFMachPort::invalidate`"]
286#[inline]
287pub extern "C-unwind" fn CFMachPortInvalidate(port: &CFMachPort) {
288    extern "C-unwind" {
289        fn CFMachPortInvalidate(port: &CFMachPort);
290    }
291    unsafe { CFMachPortInvalidate(port) }
292}
293
294#[deprecated = "renamed to `CFMachPort::is_valid`"]
295#[inline]
296pub extern "C-unwind" fn CFMachPortIsValid(port: &CFMachPort) -> bool {
297    extern "C-unwind" {
298        fn CFMachPortIsValid(port: &CFMachPort) -> Boolean;
299    }
300    let ret = unsafe { CFMachPortIsValid(port) };
301    ret != 0
302}
303
304#[deprecated = "renamed to `CFMachPort::invalidation_call_back`"]
305#[inline]
306pub extern "C-unwind" fn CFMachPortGetInvalidationCallBack(
307    port: &CFMachPort,
308) -> CFMachPortInvalidationCallBack {
309    extern "C-unwind" {
310        fn CFMachPortGetInvalidationCallBack(port: &CFMachPort) -> CFMachPortInvalidationCallBack;
311    }
312    unsafe { CFMachPortGetInvalidationCallBack(port) }
313}
314
315extern "C-unwind" {
316    #[deprecated = "renamed to `CFMachPort::set_invalidation_call_back`"]
317    pub fn CFMachPortSetInvalidationCallBack(
318        port: &CFMachPort,
319        callout: CFMachPortInvalidationCallBack,
320    );
321}
322
323#[cfg(feature = "CFRunLoop")]
324#[deprecated = "renamed to `CFMachPort::new_run_loop_source`"]
325#[inline]
326pub extern "C-unwind" fn CFMachPortCreateRunLoopSource(
327    allocator: Option<&CFAllocator>,
328    port: Option<&CFMachPort>,
329    order: CFIndex,
330) -> Option<CFRetained<CFRunLoopSource>> {
331    extern "C-unwind" {
332        fn CFMachPortCreateRunLoopSource(
333            allocator: Option<&CFAllocator>,
334            port: Option<&CFMachPort>,
335            order: CFIndex,
336        ) -> Option<NonNull<CFRunLoopSource>>;
337    }
338    let ret = unsafe { CFMachPortCreateRunLoopSource(allocator, port, order) };
339    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
340}