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