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#[doc(alias = "CFFileDescriptorRef")]
17#[repr(C)]
18pub struct CFFileDescriptor {
19    inner: [u8; 0],
20    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
21}
22
23cf_type!(
24    unsafe impl CFFileDescriptor {}
25);
26#[cfg(feature = "objc2")]
27cf_objc2_type!(
28    unsafe impl RefEncode<"__CFFileDescriptor"> for CFFileDescriptor {}
29);
30
31/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcffiledescriptorreadcallback?language=objc)
32pub const kCFFileDescriptorReadCallBack: CFOptionFlags = 1 << 0;
33/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcffiledescriptorwritecallback?language=objc)
34pub const kCFFileDescriptorWriteCallBack: CFOptionFlags = 1 << 1;
35
36/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptorcallback?language=objc)
37pub type CFFileDescriptorCallBack =
38    Option<unsafe extern "C-unwind" fn(*mut CFFileDescriptor, CFOptionFlags, *mut c_void)>;
39
40/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptorcontext?language=objc)
41#[repr(C)]
42#[allow(unpredictable_function_pointer_comparisons)]
43#[derive(Clone, Copy, Debug, PartialEq)]
44pub struct CFFileDescriptorContext {
45    pub version: CFIndex,
46    pub info: *mut c_void,
47    pub retain: Option<unsafe extern "C-unwind" fn(*mut c_void) -> *mut c_void>,
48    pub release: Option<unsafe extern "C-unwind" fn(*mut c_void)>,
49    pub copyDescription: Option<unsafe extern "C-unwind" fn(*mut c_void) -> *const CFString>,
50}
51
52#[cfg(feature = "objc2")]
53unsafe impl Encode for CFFileDescriptorContext {
54    const ENCODING: Encoding = Encoding::Struct(
55        "?",
56        &[
57            <CFIndex>::ENCODING,
58            <*mut c_void>::ENCODING,
59            <Option<unsafe extern "C-unwind" fn(*mut c_void) -> *mut c_void>>::ENCODING,
60            <Option<unsafe extern "C-unwind" fn(*mut c_void)>>::ENCODING,
61            <Option<unsafe extern "C-unwind" fn(*mut c_void) -> *const CFString>>::ENCODING,
62        ],
63    );
64}
65
66#[cfg(feature = "objc2")]
67unsafe impl RefEncode for CFFileDescriptorContext {
68    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
69}
70
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
82impl CFFileDescriptor {
83    /// # Safety
84    ///
85    /// - `allocator` might not allow `None`.
86    /// - `callout` must be implemented correctly.
87    /// - `context` must be a valid pointer.
88    #[doc(alias = "CFFileDescriptorCreate")]
89    #[inline]
90    pub unsafe fn new(
91        allocator: Option<&CFAllocator>,
92        fd: CFFileDescriptorNativeDescriptor,
93        close_on_invalidate: bool,
94        callout: CFFileDescriptorCallBack,
95        context: *const CFFileDescriptorContext,
96    ) -> Option<CFRetained<CFFileDescriptor>> {
97        extern "C-unwind" {
98            fn CFFileDescriptorCreate(
99                allocator: Option<&CFAllocator>,
100                fd: CFFileDescriptorNativeDescriptor,
101                close_on_invalidate: Boolean,
102                callout: CFFileDescriptorCallBack,
103                context: *const CFFileDescriptorContext,
104            ) -> Option<NonNull<CFFileDescriptor>>;
105        }
106        let ret = unsafe {
107            CFFileDescriptorCreate(allocator, fd, close_on_invalidate as _, callout, context)
108        };
109        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
110    }
111
112    #[doc(alias = "CFFileDescriptorGetNativeDescriptor")]
113    #[inline]
114    pub fn native_descriptor(&self) -> CFFileDescriptorNativeDescriptor {
115        extern "C-unwind" {
116            fn CFFileDescriptorGetNativeDescriptor(
117                f: &CFFileDescriptor,
118            ) -> CFFileDescriptorNativeDescriptor;
119        }
120        unsafe { CFFileDescriptorGetNativeDescriptor(self) }
121    }
122
123    /// # Safety
124    ///
125    /// `context` must be a valid pointer.
126    #[doc(alias = "CFFileDescriptorGetContext")]
127    #[inline]
128    pub unsafe fn context(&self, context: *mut CFFileDescriptorContext) {
129        extern "C-unwind" {
130            fn CFFileDescriptorGetContext(
131                f: &CFFileDescriptor,
132                context: *mut CFFileDescriptorContext,
133            );
134        }
135        unsafe { CFFileDescriptorGetContext(self, context) }
136    }
137
138    #[doc(alias = "CFFileDescriptorEnableCallBacks")]
139    #[inline]
140    pub fn enable_call_backs(&self, call_back_types: CFOptionFlags) {
141        extern "C-unwind" {
142            fn CFFileDescriptorEnableCallBacks(
143                f: &CFFileDescriptor,
144                call_back_types: CFOptionFlags,
145            );
146        }
147        unsafe { CFFileDescriptorEnableCallBacks(self, call_back_types) }
148    }
149
150    #[doc(alias = "CFFileDescriptorDisableCallBacks")]
151    #[inline]
152    pub fn disable_call_backs(&self, call_back_types: CFOptionFlags) {
153        extern "C-unwind" {
154            fn CFFileDescriptorDisableCallBacks(
155                f: &CFFileDescriptor,
156                call_back_types: CFOptionFlags,
157            );
158        }
159        unsafe { CFFileDescriptorDisableCallBacks(self, call_back_types) }
160    }
161
162    #[doc(alias = "CFFileDescriptorInvalidate")]
163    #[inline]
164    pub fn invalidate(&self) {
165        extern "C-unwind" {
166            fn CFFileDescriptorInvalidate(f: &CFFileDescriptor);
167        }
168        unsafe { CFFileDescriptorInvalidate(self) }
169    }
170
171    #[doc(alias = "CFFileDescriptorIsValid")]
172    #[inline]
173    pub fn is_valid(&self) -> bool {
174        extern "C-unwind" {
175            fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> Boolean;
176        }
177        let ret = unsafe { CFFileDescriptorIsValid(self) };
178        ret != 0
179    }
180
181    #[doc(alias = "CFFileDescriptorCreateRunLoopSource")]
182    #[cfg(feature = "CFRunLoop")]
183    #[inline]
184    pub fn new_run_loop_source(
185        allocator: Option<&CFAllocator>,
186        f: Option<&CFFileDescriptor>,
187        order: CFIndex,
188    ) -> Option<CFRetained<CFRunLoopSource>> {
189        extern "C-unwind" {
190            fn CFFileDescriptorCreateRunLoopSource(
191                allocator: Option<&CFAllocator>,
192                f: Option<&CFFileDescriptor>,
193                order: CFIndex,
194            ) -> Option<NonNull<CFRunLoopSource>>;
195        }
196        let ret = unsafe { CFFileDescriptorCreateRunLoopSource(allocator, f, order) };
197        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
198    }
199}
200
201#[deprecated = "renamed to `CFFileDescriptor::new`"]
202#[inline]
203pub unsafe extern "C-unwind" fn CFFileDescriptorCreate(
204    allocator: Option<&CFAllocator>,
205    fd: CFFileDescriptorNativeDescriptor,
206    close_on_invalidate: bool,
207    callout: CFFileDescriptorCallBack,
208    context: *const CFFileDescriptorContext,
209) -> Option<CFRetained<CFFileDescriptor>> {
210    extern "C-unwind" {
211        fn CFFileDescriptorCreate(
212            allocator: Option<&CFAllocator>,
213            fd: CFFileDescriptorNativeDescriptor,
214            close_on_invalidate: Boolean,
215            callout: CFFileDescriptorCallBack,
216            context: *const CFFileDescriptorContext,
217        ) -> Option<NonNull<CFFileDescriptor>>;
218    }
219    let ret = unsafe {
220        CFFileDescriptorCreate(allocator, fd, close_on_invalidate as _, callout, context)
221    };
222    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
223}
224
225#[deprecated = "renamed to `CFFileDescriptor::native_descriptor`"]
226#[inline]
227pub extern "C-unwind" fn CFFileDescriptorGetNativeDescriptor(
228    f: &CFFileDescriptor,
229) -> CFFileDescriptorNativeDescriptor {
230    extern "C-unwind" {
231        fn CFFileDescriptorGetNativeDescriptor(
232            f: &CFFileDescriptor,
233        ) -> CFFileDescriptorNativeDescriptor;
234    }
235    unsafe { CFFileDescriptorGetNativeDescriptor(f) }
236}
237
238extern "C-unwind" {
239    #[deprecated = "renamed to `CFFileDescriptor::context`"]
240    pub fn CFFileDescriptorGetContext(f: &CFFileDescriptor, context: *mut CFFileDescriptorContext);
241}
242
243#[deprecated = "renamed to `CFFileDescriptor::enable_call_backs`"]
244#[inline]
245pub extern "C-unwind" fn CFFileDescriptorEnableCallBacks(
246    f: &CFFileDescriptor,
247    call_back_types: CFOptionFlags,
248) {
249    extern "C-unwind" {
250        fn CFFileDescriptorEnableCallBacks(f: &CFFileDescriptor, call_back_types: CFOptionFlags);
251    }
252    unsafe { CFFileDescriptorEnableCallBacks(f, call_back_types) }
253}
254
255#[deprecated = "renamed to `CFFileDescriptor::disable_call_backs`"]
256#[inline]
257pub extern "C-unwind" fn CFFileDescriptorDisableCallBacks(
258    f: &CFFileDescriptor,
259    call_back_types: CFOptionFlags,
260) {
261    extern "C-unwind" {
262        fn CFFileDescriptorDisableCallBacks(f: &CFFileDescriptor, call_back_types: CFOptionFlags);
263    }
264    unsafe { CFFileDescriptorDisableCallBacks(f, call_back_types) }
265}
266
267#[deprecated = "renamed to `CFFileDescriptor::invalidate`"]
268#[inline]
269pub extern "C-unwind" fn CFFileDescriptorInvalidate(f: &CFFileDescriptor) {
270    extern "C-unwind" {
271        fn CFFileDescriptorInvalidate(f: &CFFileDescriptor);
272    }
273    unsafe { CFFileDescriptorInvalidate(f) }
274}
275
276#[deprecated = "renamed to `CFFileDescriptor::is_valid`"]
277#[inline]
278pub extern "C-unwind" fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> bool {
279    extern "C-unwind" {
280        fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> Boolean;
281    }
282    let ret = unsafe { CFFileDescriptorIsValid(f) };
283    ret != 0
284}
285
286#[cfg(feature = "CFRunLoop")]
287#[deprecated = "renamed to `CFFileDescriptor::new_run_loop_source`"]
288#[inline]
289pub extern "C-unwind" fn CFFileDescriptorCreateRunLoopSource(
290    allocator: Option<&CFAllocator>,
291    f: Option<&CFFileDescriptor>,
292    order: CFIndex,
293) -> Option<CFRetained<CFRunLoopSource>> {
294    extern "C-unwind" {
295        fn CFFileDescriptorCreateRunLoopSource(
296            allocator: Option<&CFAllocator>,
297            f: Option<&CFFileDescriptor>,
298            order: CFIndex,
299        ) -> Option<NonNull<CFRunLoopSource>>;
300    }
301    let ret = unsafe { CFFileDescriptorCreateRunLoopSource(allocator, f, order) };
302    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
303}