objc2_core_foundation/generated/
CFFileDescriptor.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/cffiledescriptornativedescriptor?language=objc)
13pub type CFFileDescriptorNativeDescriptor = c_int;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptor?language=objc)
16#[repr(C)]
17pub struct CFFileDescriptor {
18    inner: [u8; 0],
19    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
20}
21
22cf_type!(
23    #[encoding_name = "__CFFileDescriptor"]
24    unsafe impl CFFileDescriptor {}
25);
26
27/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcffiledescriptorreadcallback?language=objc)
28#[cfg(feature = "CFBase")]
29pub const kCFFileDescriptorReadCallBack: CFOptionFlags = 1 << 0;
30/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcffiledescriptorwritecallback?language=objc)
31#[cfg(feature = "CFBase")]
32pub const kCFFileDescriptorWriteCallBack: CFOptionFlags = 1 << 1;
33
34/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptorcallback?language=objc)
35#[cfg(feature = "CFBase")]
36pub type CFFileDescriptorCallBack =
37    Option<unsafe extern "C-unwind" fn(*mut CFFileDescriptor, CFOptionFlags, *mut c_void)>;
38
39/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptorcontext?language=objc)
40#[cfg(feature = "CFBase")]
41#[repr(C)]
42#[derive(Clone, Copy, Debug, PartialEq)]
43pub struct CFFileDescriptorContext {
44    pub version: CFIndex,
45    pub info: *mut c_void,
46    pub retain: Option<unsafe extern "C-unwind" fn(*mut c_void) -> *mut c_void>,
47    pub release: Option<unsafe extern "C-unwind" fn(*mut c_void)>,
48    pub copyDescription: Option<unsafe extern "C-unwind" fn(*mut c_void) -> *const CFString>,
49}
50
51#[cfg(all(feature = "CFBase", feature = "objc2"))]
52unsafe impl Encode for CFFileDescriptorContext {
53    const ENCODING: Encoding = Encoding::Struct(
54        "?",
55        &[
56            <CFIndex>::ENCODING,
57            <*mut c_void>::ENCODING,
58            <Option<unsafe extern "C-unwind" fn(*mut c_void) -> *mut c_void>>::ENCODING,
59            <Option<unsafe extern "C-unwind" fn(*mut c_void)>>::ENCODING,
60            <Option<unsafe extern "C-unwind" fn(*mut c_void) -> *const CFString>>::ENCODING,
61        ],
62    );
63}
64
65#[cfg(all(feature = "CFBase", feature = "objc2"))]
66unsafe impl RefEncode for CFFileDescriptorContext {
67    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
68}
69
70#[cfg(feature = "CFBase")]
71unsafe impl ConcreteType for CFFileDescriptor {
72    #[doc(alias = "CFFileDescriptorGetTypeID")]
73    #[inline]
74    fn type_id() -> CFTypeID {
75        extern "C-unwind" {
76            fn CFFileDescriptorGetTypeID() -> CFTypeID;
77        }
78        unsafe { CFFileDescriptorGetTypeID() }
79    }
80}
81
82#[cfg(feature = "CFBase")]
83#[inline]
84pub unsafe extern "C-unwind" fn CFFileDescriptorCreate(
85    allocator: Option<&CFAllocator>,
86    fd: CFFileDescriptorNativeDescriptor,
87    close_on_invalidate: bool,
88    callout: CFFileDescriptorCallBack,
89    context: *const CFFileDescriptorContext,
90) -> Option<CFRetained<CFFileDescriptor>> {
91    extern "C-unwind" {
92        fn CFFileDescriptorCreate(
93            allocator: Option<&CFAllocator>,
94            fd: CFFileDescriptorNativeDescriptor,
95            close_on_invalidate: Boolean,
96            callout: CFFileDescriptorCallBack,
97            context: *const CFFileDescriptorContext,
98        ) -> Option<NonNull<CFFileDescriptor>>;
99    }
100    let ret = unsafe {
101        CFFileDescriptorCreate(allocator, fd, close_on_invalidate as _, callout, context)
102    };
103    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
104}
105
106extern "C-unwind" {
107    pub fn CFFileDescriptorGetNativeDescriptor(
108        f: &CFFileDescriptor,
109    ) -> CFFileDescriptorNativeDescriptor;
110}
111
112extern "C-unwind" {
113    #[cfg(feature = "CFBase")]
114    pub fn CFFileDescriptorGetContext(f: &CFFileDescriptor, context: *mut CFFileDescriptorContext);
115}
116
117extern "C-unwind" {
118    #[cfg(feature = "CFBase")]
119    pub fn CFFileDescriptorEnableCallBacks(f: &CFFileDescriptor, call_back_types: CFOptionFlags);
120}
121
122extern "C-unwind" {
123    #[cfg(feature = "CFBase")]
124    pub fn CFFileDescriptorDisableCallBacks(f: &CFFileDescriptor, call_back_types: CFOptionFlags);
125}
126
127extern "C-unwind" {
128    pub fn CFFileDescriptorInvalidate(f: &CFFileDescriptor);
129}
130
131#[inline]
132pub unsafe extern "C-unwind" fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> bool {
133    extern "C-unwind" {
134        fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> Boolean;
135    }
136    let ret = unsafe { CFFileDescriptorIsValid(f) };
137    ret != 0
138}
139
140#[cfg(all(feature = "CFBase", feature = "CFRunLoop"))]
141#[inline]
142pub unsafe extern "C-unwind" fn CFFileDescriptorCreateRunLoopSource(
143    allocator: Option<&CFAllocator>,
144    f: Option<&CFFileDescriptor>,
145    order: CFIndex,
146) -> Option<CFRetained<CFRunLoopSource>> {
147    extern "C-unwind" {
148        fn CFFileDescriptorCreateRunLoopSource(
149            allocator: Option<&CFAllocator>,
150            f: Option<&CFFileDescriptor>,
151            order: CFIndex,
152        ) -> Option<NonNull<CFRunLoopSource>>;
153    }
154    let ret = unsafe { CFFileDescriptorCreateRunLoopSource(allocator, f, order) };
155    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
156}