objc2_core_foundation/generated/
CFMessagePort.rs1use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "dispatch2")]
8use dispatch2::*;
9#[cfg(feature = "objc2")]
10use objc2::__framework_prelude::*;
11
12use crate::*;
13
14#[doc(alias = "CFMessagePortRef")]
18#[repr(C)]
19pub struct CFMessagePort {
20 inner: [u8; 0],
21 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
22}
23
24cf_type!(
25 unsafe impl CFMessagePort {}
26);
27#[cfg(feature = "objc2")]
28cf_objc2_type!(
29 unsafe impl RefEncode<"__CFMessagePort"> for CFMessagePort {}
30);
31
32pub const kCFMessagePortSuccess: i32 = 0;
34pub const kCFMessagePortSendTimeout: i32 = -1;
36pub const kCFMessagePortReceiveTimeout: i32 = -2;
38pub const kCFMessagePortIsInvalid: i32 = -3;
40pub const kCFMessagePortTransportError: i32 = -4;
42pub const kCFMessagePortBecameInvalidError: i32 = -5;
44
45#[repr(C)]
47#[allow(unpredictable_function_pointer_comparisons)]
48#[derive(Clone, Copy, Debug, PartialEq)]
49pub struct CFMessagePortContext {
50 pub version: CFIndex,
51 pub info: *mut c_void,
52 pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
53 pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
54 pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
55}
56
57#[cfg(feature = "objc2")]
58unsafe impl Encode for CFMessagePortContext {
59 const ENCODING: Encoding = Encoding::Struct(
60 "?",
61 &[
62 <CFIndex>::ENCODING,
63 <*mut c_void>::ENCODING,
64 <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
65 <Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
66 <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
67 ],
68 );
69}
70
71#[cfg(feature = "objc2")]
72unsafe impl RefEncode for CFMessagePortContext {
73 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
74}
75
76#[cfg(feature = "CFData")]
78pub type CFMessagePortCallBack = Option<
79 unsafe extern "C-unwind" fn(
80 *mut CFMessagePort,
81 i32,
82 *const CFData,
83 *mut c_void,
84 ) -> *const CFData,
85>;
86
87pub type CFMessagePortInvalidationCallBack =
89 Option<unsafe extern "C-unwind" fn(*mut CFMessagePort, *mut c_void)>;
90
91unsafe impl ConcreteType for CFMessagePort {
92 #[doc(alias = "CFMessagePortGetTypeID")]
93 #[inline]
94 fn type_id() -> CFTypeID {
95 extern "C-unwind" {
96 fn CFMessagePortGetTypeID() -> CFTypeID;
97 }
98 unsafe { CFMessagePortGetTypeID() }
99 }
100}
101
102impl CFMessagePort {
103 #[doc(alias = "CFMessagePortCreateLocal")]
111 #[cfg(feature = "CFData")]
112 #[inline]
113 pub unsafe fn new_local(
114 allocator: Option<&CFAllocator>,
115 name: Option<&CFString>,
116 callout: CFMessagePortCallBack,
117 context: *mut CFMessagePortContext,
118 should_free_info: *mut Boolean,
119 ) -> Option<CFRetained<CFMessagePort>> {
120 extern "C-unwind" {
121 fn CFMessagePortCreateLocal(
122 allocator: Option<&CFAllocator>,
123 name: Option<&CFString>,
124 callout: CFMessagePortCallBack,
125 context: *mut CFMessagePortContext,
126 should_free_info: *mut Boolean,
127 ) -> Option<NonNull<CFMessagePort>>;
128 }
129 let ret = unsafe {
130 CFMessagePortCreateLocal(allocator, name, callout, context, should_free_info)
131 };
132 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
133 }
134
135 #[doc(alias = "CFMessagePortCreateRemote")]
136 #[inline]
137 pub fn new_remote(
138 allocator: Option<&CFAllocator>,
139 name: Option<&CFString>,
140 ) -> Option<CFRetained<CFMessagePort>> {
141 extern "C-unwind" {
142 fn CFMessagePortCreateRemote(
143 allocator: Option<&CFAllocator>,
144 name: Option<&CFString>,
145 ) -> Option<NonNull<CFMessagePort>>;
146 }
147 let ret = unsafe { CFMessagePortCreateRemote(allocator, name) };
148 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
149 }
150
151 #[doc(alias = "CFMessagePortIsRemote")]
152 #[inline]
153 pub fn is_remote(&self) -> bool {
154 extern "C-unwind" {
155 fn CFMessagePortIsRemote(ms: &CFMessagePort) -> Boolean;
156 }
157 let ret = unsafe { CFMessagePortIsRemote(self) };
158 ret != 0
159 }
160
161 #[doc(alias = "CFMessagePortGetName")]
162 #[inline]
163 pub fn name(&self) -> Option<CFRetained<CFString>> {
164 extern "C-unwind" {
165 fn CFMessagePortGetName(ms: &CFMessagePort) -> Option<NonNull<CFString>>;
166 }
167 let ret = unsafe { CFMessagePortGetName(self) };
168 ret.map(|ret| unsafe { CFRetained::retain(ret) })
169 }
170
171 #[doc(alias = "CFMessagePortSetName")]
172 #[inline]
173 pub fn set_name(&self, new_name: Option<&CFString>) -> bool {
174 extern "C-unwind" {
175 fn CFMessagePortSetName(ms: &CFMessagePort, new_name: Option<&CFString>) -> Boolean;
176 }
177 let ret = unsafe { CFMessagePortSetName(self, new_name) };
178 ret != 0
179 }
180
181 #[doc(alias = "CFMessagePortGetContext")]
185 #[inline]
186 pub unsafe fn context(&self, context: *mut CFMessagePortContext) {
187 extern "C-unwind" {
188 fn CFMessagePortGetContext(ms: &CFMessagePort, context: *mut CFMessagePortContext);
189 }
190 unsafe { CFMessagePortGetContext(self, context) }
191 }
192
193 #[doc(alias = "CFMessagePortInvalidate")]
194 #[inline]
195 pub fn invalidate(&self) {
196 extern "C-unwind" {
197 fn CFMessagePortInvalidate(ms: &CFMessagePort);
198 }
199 unsafe { CFMessagePortInvalidate(self) }
200 }
201
202 #[doc(alias = "CFMessagePortIsValid")]
203 #[inline]
204 pub fn is_valid(&self) -> bool {
205 extern "C-unwind" {
206 fn CFMessagePortIsValid(ms: &CFMessagePort) -> Boolean;
207 }
208 let ret = unsafe { CFMessagePortIsValid(self) };
209 ret != 0
210 }
211
212 #[doc(alias = "CFMessagePortGetInvalidationCallBack")]
213 #[inline]
214 pub fn invalidation_call_back(&self) -> CFMessagePortInvalidationCallBack {
215 extern "C-unwind" {
216 fn CFMessagePortGetInvalidationCallBack(
217 ms: &CFMessagePort,
218 ) -> CFMessagePortInvalidationCallBack;
219 }
220 unsafe { CFMessagePortGetInvalidationCallBack(self) }
221 }
222
223 #[doc(alias = "CFMessagePortSetInvalidationCallBack")]
227 #[inline]
228 pub unsafe fn set_invalidation_call_back(&self, callout: CFMessagePortInvalidationCallBack) {
229 extern "C-unwind" {
230 fn CFMessagePortSetInvalidationCallBack(
231 ms: &CFMessagePort,
232 callout: CFMessagePortInvalidationCallBack,
233 );
234 }
235 unsafe { CFMessagePortSetInvalidationCallBack(self, callout) }
236 }
237
238 #[doc(alias = "CFMessagePortSendRequest")]
244 #[cfg(all(feature = "CFData", feature = "CFDate"))]
245 #[inline]
246 pub unsafe fn send_request(
247 &self,
248 msgid: i32,
249 data: Option<&CFData>,
250 send_timeout: CFTimeInterval,
251 rcv_timeout: CFTimeInterval,
252 reply_mode: Option<&CFString>,
253 return_data: *mut *const CFData,
254 ) -> i32 {
255 extern "C-unwind" {
256 fn CFMessagePortSendRequest(
257 remote: &CFMessagePort,
258 msgid: i32,
259 data: Option<&CFData>,
260 send_timeout: CFTimeInterval,
261 rcv_timeout: CFTimeInterval,
262 reply_mode: Option<&CFString>,
263 return_data: *mut *const CFData,
264 ) -> i32;
265 }
266 unsafe {
267 CFMessagePortSendRequest(
268 self,
269 msgid,
270 data,
271 send_timeout,
272 rcv_timeout,
273 reply_mode,
274 return_data,
275 )
276 }
277 }
278
279 #[doc(alias = "CFMessagePortCreateRunLoopSource")]
280 #[cfg(feature = "CFRunLoop")]
281 #[inline]
282 pub fn new_run_loop_source(
283 allocator: Option<&CFAllocator>,
284 local: Option<&CFMessagePort>,
285 order: CFIndex,
286 ) -> Option<CFRetained<CFRunLoopSource>> {
287 extern "C-unwind" {
288 fn CFMessagePortCreateRunLoopSource(
289 allocator: Option<&CFAllocator>,
290 local: Option<&CFMessagePort>,
291 order: CFIndex,
292 ) -> Option<NonNull<CFRunLoopSource>>;
293 }
294 let ret = unsafe { CFMessagePortCreateRunLoopSource(allocator, local, order) };
295 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
296 }
297
298 #[doc(alias = "CFMessagePortSetDispatchQueue")]
303 #[cfg(feature = "dispatch2")]
304 #[inline]
305 pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) {
306 extern "C-unwind" {
307 fn CFMessagePortSetDispatchQueue(ms: &CFMessagePort, queue: Option<&DispatchQueue>);
308 }
309 unsafe { CFMessagePortSetDispatchQueue(self, queue) }
310 }
311}
312
313#[cfg(feature = "CFData")]
314#[deprecated = "renamed to `CFMessagePort::new_local`"]
315#[inline]
316pub unsafe extern "C-unwind" fn CFMessagePortCreateLocal(
317 allocator: Option<&CFAllocator>,
318 name: Option<&CFString>,
319 callout: CFMessagePortCallBack,
320 context: *mut CFMessagePortContext,
321 should_free_info: *mut Boolean,
322) -> Option<CFRetained<CFMessagePort>> {
323 extern "C-unwind" {
324 fn CFMessagePortCreateLocal(
325 allocator: Option<&CFAllocator>,
326 name: Option<&CFString>,
327 callout: CFMessagePortCallBack,
328 context: *mut CFMessagePortContext,
329 should_free_info: *mut Boolean,
330 ) -> Option<NonNull<CFMessagePort>>;
331 }
332 let ret =
333 unsafe { CFMessagePortCreateLocal(allocator, name, callout, context, should_free_info) };
334 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
335}
336
337#[deprecated = "renamed to `CFMessagePort::new_remote`"]
338#[inline]
339pub extern "C-unwind" fn CFMessagePortCreateRemote(
340 allocator: Option<&CFAllocator>,
341 name: Option<&CFString>,
342) -> Option<CFRetained<CFMessagePort>> {
343 extern "C-unwind" {
344 fn CFMessagePortCreateRemote(
345 allocator: Option<&CFAllocator>,
346 name: Option<&CFString>,
347 ) -> Option<NonNull<CFMessagePort>>;
348 }
349 let ret = unsafe { CFMessagePortCreateRemote(allocator, name) };
350 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
351}
352
353#[deprecated = "renamed to `CFMessagePort::is_remote`"]
354#[inline]
355pub extern "C-unwind" fn CFMessagePortIsRemote(ms: &CFMessagePort) -> bool {
356 extern "C-unwind" {
357 fn CFMessagePortIsRemote(ms: &CFMessagePort) -> Boolean;
358 }
359 let ret = unsafe { CFMessagePortIsRemote(ms) };
360 ret != 0
361}
362
363#[deprecated = "renamed to `CFMessagePort::name`"]
364#[inline]
365pub extern "C-unwind" fn CFMessagePortGetName(ms: &CFMessagePort) -> Option<CFRetained<CFString>> {
366 extern "C-unwind" {
367 fn CFMessagePortGetName(ms: &CFMessagePort) -> Option<NonNull<CFString>>;
368 }
369 let ret = unsafe { CFMessagePortGetName(ms) };
370 ret.map(|ret| unsafe { CFRetained::retain(ret) })
371}
372
373#[deprecated = "renamed to `CFMessagePort::set_name`"]
374#[inline]
375pub extern "C-unwind" fn CFMessagePortSetName(
376 ms: &CFMessagePort,
377 new_name: Option<&CFString>,
378) -> bool {
379 extern "C-unwind" {
380 fn CFMessagePortSetName(ms: &CFMessagePort, new_name: Option<&CFString>) -> Boolean;
381 }
382 let ret = unsafe { CFMessagePortSetName(ms, new_name) };
383 ret != 0
384}
385
386extern "C-unwind" {
387 #[deprecated = "renamed to `CFMessagePort::context`"]
388 pub fn CFMessagePortGetContext(ms: &CFMessagePort, context: *mut CFMessagePortContext);
389}
390
391#[deprecated = "renamed to `CFMessagePort::invalidate`"]
392#[inline]
393pub extern "C-unwind" fn CFMessagePortInvalidate(ms: &CFMessagePort) {
394 extern "C-unwind" {
395 fn CFMessagePortInvalidate(ms: &CFMessagePort);
396 }
397 unsafe { CFMessagePortInvalidate(ms) }
398}
399
400#[deprecated = "renamed to `CFMessagePort::is_valid`"]
401#[inline]
402pub extern "C-unwind" fn CFMessagePortIsValid(ms: &CFMessagePort) -> bool {
403 extern "C-unwind" {
404 fn CFMessagePortIsValid(ms: &CFMessagePort) -> Boolean;
405 }
406 let ret = unsafe { CFMessagePortIsValid(ms) };
407 ret != 0
408}
409
410#[deprecated = "renamed to `CFMessagePort::invalidation_call_back`"]
411#[inline]
412pub extern "C-unwind" fn CFMessagePortGetInvalidationCallBack(
413 ms: &CFMessagePort,
414) -> CFMessagePortInvalidationCallBack {
415 extern "C-unwind" {
416 fn CFMessagePortGetInvalidationCallBack(
417 ms: &CFMessagePort,
418 ) -> CFMessagePortInvalidationCallBack;
419 }
420 unsafe { CFMessagePortGetInvalidationCallBack(ms) }
421}
422
423extern "C-unwind" {
424 #[deprecated = "renamed to `CFMessagePort::set_invalidation_call_back`"]
425 pub fn CFMessagePortSetInvalidationCallBack(
426 ms: &CFMessagePort,
427 callout: CFMessagePortInvalidationCallBack,
428 );
429}
430
431extern "C-unwind" {
432 #[cfg(all(feature = "CFData", feature = "CFDate"))]
433 #[deprecated = "renamed to `CFMessagePort::send_request`"]
434 pub fn CFMessagePortSendRequest(
435 remote: &CFMessagePort,
436 msgid: i32,
437 data: Option<&CFData>,
438 send_timeout: CFTimeInterval,
439 rcv_timeout: CFTimeInterval,
440 reply_mode: Option<&CFString>,
441 return_data: *mut *const CFData,
442 ) -> i32;
443}
444
445#[cfg(feature = "CFRunLoop")]
446#[deprecated = "renamed to `CFMessagePort::new_run_loop_source`"]
447#[inline]
448pub extern "C-unwind" fn CFMessagePortCreateRunLoopSource(
449 allocator: Option<&CFAllocator>,
450 local: Option<&CFMessagePort>,
451 order: CFIndex,
452) -> Option<CFRetained<CFRunLoopSource>> {
453 extern "C-unwind" {
454 fn CFMessagePortCreateRunLoopSource(
455 allocator: Option<&CFAllocator>,
456 local: Option<&CFMessagePort>,
457 order: CFIndex,
458 ) -> Option<NonNull<CFRunLoopSource>>;
459 }
460 let ret = unsafe { CFMessagePortCreateRunLoopSource(allocator, local, order) };
461 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
462}
463
464extern "C-unwind" {
465 #[cfg(feature = "dispatch2")]
466 #[deprecated = "renamed to `CFMessagePort::set_dispatch_queue`"]
467 pub fn CFMessagePortSetDispatchQueue(ms: &CFMessagePort, queue: Option<&DispatchQueue>);
468}