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