objc2_core_foundation/generated/
CFNotificationCenter.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/cfnotificationname?language=objc)
13// NS_TYPED_EXTENSIBLE_ENUM
14pub type CFNotificationName = CFString;
15
16/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationcenter?language=objc)
17#[doc(alias = "CFNotificationCenterRef")]
18#[repr(C)]
19pub struct CFNotificationCenter {
20    inner: [u8; 0],
21    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
22}
23
24cf_type!(
25    unsafe impl CFNotificationCenter {}
26);
27#[cfg(feature = "objc2")]
28cf_objc2_type!(
29    unsafe impl RefEncode<"__CFNotificationCenter"> for CFNotificationCenter {}
30);
31
32/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationcallback?language=objc)
33#[cfg(feature = "CFDictionary")]
34pub type CFNotificationCallback = Option<
35    unsafe extern "C-unwind" fn(
36        *mut CFNotificationCenter,
37        *mut c_void,
38        *const CFNotificationName,
39        *const c_void,
40        *const CFDictionary,
41    ),
42>;
43
44/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationsuspensionbehavior?language=objc)
45// NS_ENUM
46#[repr(transparent)]
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
48pub struct CFNotificationSuspensionBehavior(pub CFIndex);
49impl CFNotificationSuspensionBehavior {
50    #[doc(alias = "CFNotificationSuspensionBehaviorDrop")]
51    pub const Drop: Self = Self(1);
52    #[doc(alias = "CFNotificationSuspensionBehaviorCoalesce")]
53    pub const Coalesce: Self = Self(2);
54    #[doc(alias = "CFNotificationSuspensionBehaviorHold")]
55    pub const Hold: Self = Self(3);
56    #[doc(alias = "CFNotificationSuspensionBehaviorDeliverImmediately")]
57    pub const DeliverImmediately: Self = Self(4);
58}
59
60#[cfg(feature = "objc2")]
61unsafe impl Encode for CFNotificationSuspensionBehavior {
62    const ENCODING: Encoding = CFIndex::ENCODING;
63}
64
65#[cfg(feature = "objc2")]
66unsafe impl RefEncode for CFNotificationSuspensionBehavior {
67    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
68}
69
70unsafe impl ConcreteType for CFNotificationCenter {
71    #[doc(alias = "CFNotificationCenterGetTypeID")]
72    #[inline]
73    fn type_id() -> CFTypeID {
74        extern "C-unwind" {
75            fn CFNotificationCenterGetTypeID() -> CFTypeID;
76        }
77        unsafe { CFNotificationCenterGetTypeID() }
78    }
79}
80
81impl CFNotificationCenter {
82    #[doc(alias = "CFNotificationCenterGetLocalCenter")]
83    #[inline]
84    pub fn local_center() -> Option<CFRetained<CFNotificationCenter>> {
85        extern "C-unwind" {
86            fn CFNotificationCenterGetLocalCenter() -> Option<NonNull<CFNotificationCenter>>;
87        }
88        let ret = unsafe { CFNotificationCenterGetLocalCenter() };
89        ret.map(|ret| unsafe { CFRetained::retain(ret) })
90    }
91
92    #[doc(alias = "CFNotificationCenterGetDistributedCenter")]
93    #[inline]
94    pub fn distributed_center() -> Option<CFRetained<CFNotificationCenter>> {
95        extern "C-unwind" {
96            fn CFNotificationCenterGetDistributedCenter() -> Option<NonNull<CFNotificationCenter>>;
97        }
98        let ret = unsafe { CFNotificationCenterGetDistributedCenter() };
99        ret.map(|ret| unsafe { CFRetained::retain(ret) })
100    }
101
102    #[doc(alias = "CFNotificationCenterGetDarwinNotifyCenter")]
103    #[inline]
104    pub fn darwin_notify_center() -> Option<CFRetained<CFNotificationCenter>> {
105        extern "C-unwind" {
106            fn CFNotificationCenterGetDarwinNotifyCenter() -> Option<NonNull<CFNotificationCenter>>;
107        }
108        let ret = unsafe { CFNotificationCenterGetDarwinNotifyCenter() };
109        ret.map(|ret| unsafe { CFRetained::retain(ret) })
110    }
111
112    /// # Safety
113    ///
114    /// - `observer` must be a valid pointer.
115    /// - `call_back` must be implemented correctly.
116    /// - `name` might not allow `None`.
117    /// - `object` must be a valid pointer.
118    #[doc(alias = "CFNotificationCenterAddObserver")]
119    #[cfg(feature = "CFDictionary")]
120    #[inline]
121    pub unsafe fn add_observer(
122        &self,
123        observer: *const c_void,
124        call_back: CFNotificationCallback,
125        name: Option<&CFString>,
126        object: *const c_void,
127        suspension_behavior: CFNotificationSuspensionBehavior,
128    ) {
129        extern "C-unwind" {
130            fn CFNotificationCenterAddObserver(
131                center: &CFNotificationCenter,
132                observer: *const c_void,
133                call_back: CFNotificationCallback,
134                name: Option<&CFString>,
135                object: *const c_void,
136                suspension_behavior: CFNotificationSuspensionBehavior,
137            );
138        }
139        unsafe {
140            CFNotificationCenterAddObserver(
141                self,
142                observer,
143                call_back,
144                name,
145                object,
146                suspension_behavior,
147            )
148        }
149    }
150
151    /// # Safety
152    ///
153    /// - `observer` must be a valid pointer.
154    /// - `name` might not allow `None`.
155    /// - `object` must be a valid pointer.
156    #[doc(alias = "CFNotificationCenterRemoveObserver")]
157    #[inline]
158    pub unsafe fn remove_observer(
159        &self,
160        observer: *const c_void,
161        name: Option<&CFNotificationName>,
162        object: *const c_void,
163    ) {
164        extern "C-unwind" {
165            fn CFNotificationCenterRemoveObserver(
166                center: &CFNotificationCenter,
167                observer: *const c_void,
168                name: Option<&CFNotificationName>,
169                object: *const c_void,
170            );
171        }
172        unsafe { CFNotificationCenterRemoveObserver(self, observer, name, object) }
173    }
174
175    /// # Safety
176    ///
177    /// `observer` must be a valid pointer.
178    #[doc(alias = "CFNotificationCenterRemoveEveryObserver")]
179    #[inline]
180    pub unsafe fn remove_every_observer(&self, observer: *const c_void) {
181        extern "C-unwind" {
182            fn CFNotificationCenterRemoveEveryObserver(
183                center: &CFNotificationCenter,
184                observer: *const c_void,
185            );
186        }
187        unsafe { CFNotificationCenterRemoveEveryObserver(self, observer) }
188    }
189
190    /// # Safety
191    ///
192    /// - `name` might not allow `None`.
193    /// - `object` must be a valid pointer.
194    /// - `user_info` generics must be of the correct type.
195    /// - `user_info` might not allow `None`.
196    #[doc(alias = "CFNotificationCenterPostNotification")]
197    #[cfg(feature = "CFDictionary")]
198    #[inline]
199    pub unsafe fn post_notification(
200        &self,
201        name: Option<&CFNotificationName>,
202        object: *const c_void,
203        user_info: Option<&CFDictionary>,
204        deliver_immediately: bool,
205    ) {
206        extern "C-unwind" {
207            fn CFNotificationCenterPostNotification(
208                center: &CFNotificationCenter,
209                name: Option<&CFNotificationName>,
210                object: *const c_void,
211                user_info: Option<&CFDictionary>,
212                deliver_immediately: Boolean,
213            );
214        }
215        unsafe {
216            CFNotificationCenterPostNotification(
217                self,
218                name,
219                object,
220                user_info,
221                deliver_immediately as _,
222            )
223        }
224    }
225}
226
227/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnotificationdeliverimmediately?language=objc)
228pub const kCFNotificationDeliverImmediately: CFOptionFlags = 1 << 0;
229/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnotificationposttoallsessions?language=objc)
230pub const kCFNotificationPostToAllSessions: CFOptionFlags = 1 << 1;
231
232impl CFNotificationCenter {
233    /// # Safety
234    ///
235    /// - `name` might not allow `None`.
236    /// - `object` must be a valid pointer.
237    /// - `user_info` generics must be of the correct type.
238    /// - `user_info` might not allow `None`.
239    #[doc(alias = "CFNotificationCenterPostNotificationWithOptions")]
240    #[cfg(feature = "CFDictionary")]
241    #[inline]
242    pub unsafe fn post_notification_with_options(
243        &self,
244        name: Option<&CFNotificationName>,
245        object: *const c_void,
246        user_info: Option<&CFDictionary>,
247        options: CFOptionFlags,
248    ) {
249        extern "C-unwind" {
250            fn CFNotificationCenterPostNotificationWithOptions(
251                center: &CFNotificationCenter,
252                name: Option<&CFNotificationName>,
253                object: *const c_void,
254                user_info: Option<&CFDictionary>,
255                options: CFOptionFlags,
256            );
257        }
258        unsafe {
259            CFNotificationCenterPostNotificationWithOptions(self, name, object, user_info, options)
260        }
261    }
262}
263
264#[deprecated = "renamed to `CFNotificationCenter::local_center`"]
265#[inline]
266pub extern "C-unwind" fn CFNotificationCenterGetLocalCenter(
267) -> Option<CFRetained<CFNotificationCenter>> {
268    extern "C-unwind" {
269        fn CFNotificationCenterGetLocalCenter() -> Option<NonNull<CFNotificationCenter>>;
270    }
271    let ret = unsafe { CFNotificationCenterGetLocalCenter() };
272    ret.map(|ret| unsafe { CFRetained::retain(ret) })
273}
274
275#[deprecated = "renamed to `CFNotificationCenter::distributed_center`"]
276#[inline]
277pub extern "C-unwind" fn CFNotificationCenterGetDistributedCenter(
278) -> Option<CFRetained<CFNotificationCenter>> {
279    extern "C-unwind" {
280        fn CFNotificationCenterGetDistributedCenter() -> Option<NonNull<CFNotificationCenter>>;
281    }
282    let ret = unsafe { CFNotificationCenterGetDistributedCenter() };
283    ret.map(|ret| unsafe { CFRetained::retain(ret) })
284}
285
286#[deprecated = "renamed to `CFNotificationCenter::darwin_notify_center`"]
287#[inline]
288pub extern "C-unwind" fn CFNotificationCenterGetDarwinNotifyCenter(
289) -> Option<CFRetained<CFNotificationCenter>> {
290    extern "C-unwind" {
291        fn CFNotificationCenterGetDarwinNotifyCenter() -> Option<NonNull<CFNotificationCenter>>;
292    }
293    let ret = unsafe { CFNotificationCenterGetDarwinNotifyCenter() };
294    ret.map(|ret| unsafe { CFRetained::retain(ret) })
295}
296
297extern "C-unwind" {
298    #[cfg(feature = "CFDictionary")]
299    #[deprecated = "renamed to `CFNotificationCenter::add_observer`"]
300    pub fn CFNotificationCenterAddObserver(
301        center: &CFNotificationCenter,
302        observer: *const c_void,
303        call_back: CFNotificationCallback,
304        name: Option<&CFString>,
305        object: *const c_void,
306        suspension_behavior: CFNotificationSuspensionBehavior,
307    );
308}
309
310extern "C-unwind" {
311    #[deprecated = "renamed to `CFNotificationCenter::remove_observer`"]
312    pub fn CFNotificationCenterRemoveObserver(
313        center: &CFNotificationCenter,
314        observer: *const c_void,
315        name: Option<&CFNotificationName>,
316        object: *const c_void,
317    );
318}
319
320extern "C-unwind" {
321    #[deprecated = "renamed to `CFNotificationCenter::remove_every_observer`"]
322    pub fn CFNotificationCenterRemoveEveryObserver(
323        center: &CFNotificationCenter,
324        observer: *const c_void,
325    );
326}
327
328#[cfg(feature = "CFDictionary")]
329#[deprecated = "renamed to `CFNotificationCenter::post_notification`"]
330#[inline]
331pub unsafe extern "C-unwind" fn CFNotificationCenterPostNotification(
332    center: &CFNotificationCenter,
333    name: Option<&CFNotificationName>,
334    object: *const c_void,
335    user_info: Option<&CFDictionary>,
336    deliver_immediately: bool,
337) {
338    extern "C-unwind" {
339        fn CFNotificationCenterPostNotification(
340            center: &CFNotificationCenter,
341            name: Option<&CFNotificationName>,
342            object: *const c_void,
343            user_info: Option<&CFDictionary>,
344            deliver_immediately: Boolean,
345        );
346    }
347    unsafe {
348        CFNotificationCenterPostNotification(
349            center,
350            name,
351            object,
352            user_info,
353            deliver_immediately as _,
354        )
355    }
356}
357
358extern "C-unwind" {
359    #[cfg(feature = "CFDictionary")]
360    #[deprecated = "renamed to `CFNotificationCenter::post_notification_with_options`"]
361    pub fn CFNotificationCenterPostNotificationWithOptions(
362        center: &CFNotificationCenter,
363        name: Option<&CFNotificationName>,
364        object: *const c_void,
365        user_info: Option<&CFDictionary>,
366        options: CFOptionFlags,
367    );
368}