1use 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::*;
11use objc2_core_foundation::*;
12#[cfg(feature = "objc2-security")]
13use objc2_security::*;
14
15use crate::*;
16
17#[doc(alias = "SCPreferencesRef")]
22#[repr(C)]
23pub struct SCPreferences {
24 inner: [u8; 0],
25 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
26}
27
28cf_type!(
29 unsafe impl SCPreferences {}
30);
31#[cfg(feature = "objc2")]
32cf_objc2_type!(
33 unsafe impl RefEncode<"__SCPreferences"> for SCPreferences {}
34);
35
36#[repr(transparent)]
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
48pub struct SCPreferencesNotification(pub u32);
49bitflags::bitflags! {
50 impl SCPreferencesNotification: u32 {
51 #[doc(alias = "kSCPreferencesNotificationCommit")]
52 const Commit = 1<<0;
53 #[doc(alias = "kSCPreferencesNotificationApply")]
54 const Apply = 1<<1;
55 }
56}
57
58#[cfg(feature = "objc2")]
59unsafe impl Encode for SCPreferencesNotification {
60 const ENCODING: Encoding = u32::ENCODING;
61}
62
63#[cfg(feature = "objc2")]
64unsafe impl RefEncode for SCPreferencesNotification {
65 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
66}
67
68#[repr(C)]
87#[allow(unpredictable_function_pointer_comparisons)]
88#[derive(Clone, Copy, Debug, PartialEq)]
89pub struct SCPreferencesContext {
90 pub version: CFIndex,
91 pub info: *mut c_void,
92 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
93 pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
94 pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
95}
96
97#[cfg(feature = "objc2")]
98unsafe impl Encode for SCPreferencesContext {
99 const ENCODING: Encoding = Encoding::Struct(
100 "?",
101 &[
102 <CFIndex>::ENCODING,
103 <*mut c_void>::ENCODING,
104 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
105 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
106 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
107 ],
108 );
109}
110
111#[cfg(feature = "objc2")]
112unsafe impl RefEncode for SCPreferencesContext {
113 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
114}
115
116pub type SCPreferencesCallBack = Option<
128 unsafe extern "C-unwind" fn(NonNull<SCPreferences>, SCPreferencesNotification, *mut c_void),
129>;
130
131unsafe impl ConcreteType for SCPreferences {
132 #[doc(alias = "SCPreferencesGetTypeID")]
134 #[inline]
135 fn type_id() -> CFTypeID {
136 extern "C-unwind" {
137 fn SCPreferencesGetTypeID() -> CFTypeID;
138 }
139 unsafe { SCPreferencesGetTypeID() }
140 }
141}
142
143impl SCPreferences {
144 #[doc(alias = "SCPreferencesCreate")]
163 #[inline]
164 pub fn new(
165 allocator: Option<&CFAllocator>,
166 name: &CFString,
167 prefs_id: Option<&CFString>,
168 ) -> Option<CFRetained<SCPreferences>> {
169 extern "C-unwind" {
170 fn SCPreferencesCreate(
171 allocator: Option<&CFAllocator>,
172 name: &CFString,
173 prefs_id: Option<&CFString>,
174 ) -> Option<NonNull<SCPreferences>>;
175 }
176 let ret = unsafe { SCPreferencesCreate(allocator, name, prefs_id) };
177 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
178 }
179
180 #[doc(alias = "SCPreferencesCreateWithAuthorization")]
207 #[cfg(feature = "objc2-security")]
208 #[inline]
209 pub unsafe fn with_authorization(
210 allocator: Option<&CFAllocator>,
211 name: &CFString,
212 prefs_id: Option<&CFString>,
213 authorization: AuthorizationRef,
214 ) -> Option<CFRetained<SCPreferences>> {
215 extern "C-unwind" {
216 fn SCPreferencesCreateWithAuthorization(
217 allocator: Option<&CFAllocator>,
218 name: &CFString,
219 prefs_id: Option<&CFString>,
220 authorization: AuthorizationRef,
221 ) -> Option<NonNull<SCPreferences>>;
222 }
223 let ret = unsafe {
224 SCPreferencesCreateWithAuthorization(allocator, name, prefs_id, authorization)
225 };
226 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
227 }
228
229 #[doc(alias = "SCPreferencesLock")]
245 #[inline]
246 pub fn lock(&self, wait: bool) -> bool {
247 extern "C-unwind" {
248 fn SCPreferencesLock(prefs: &SCPreferences, wait: Boolean) -> Boolean;
249 }
250 let ret = unsafe { SCPreferencesLock(self, wait as _) };
251 ret != 0
252 }
253
254 #[doc(alias = "SCPreferencesCommitChanges")]
271 #[inline]
272 pub fn commit_changes(&self) -> bool {
273 extern "C-unwind" {
274 fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> Boolean;
275 }
276 let ret = unsafe { SCPreferencesCommitChanges(self) };
277 ret != 0
278 }
279
280 #[doc(alias = "SCPreferencesApplyChanges")]
288 #[inline]
289 pub fn apply_changes(&self) -> bool {
290 extern "C-unwind" {
291 fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> Boolean;
292 }
293 let ret = unsafe { SCPreferencesApplyChanges(self) };
294 ret != 0
295 }
296
297 #[doc(alias = "SCPreferencesUnlock")]
308 #[inline]
309 pub fn unlock(&self) -> bool {
310 extern "C-unwind" {
311 fn SCPreferencesUnlock(prefs: &SCPreferences) -> Boolean;
312 }
313 let ret = unsafe { SCPreferencesUnlock(self) };
314 ret != 0
315 }
316
317 #[doc(alias = "SCPreferencesGetSignature")]
325 #[inline]
326 pub fn signature(&self) -> Option<CFRetained<CFData>> {
327 extern "C-unwind" {
328 fn SCPreferencesGetSignature(prefs: &SCPreferences) -> Option<NonNull<CFData>>;
329 }
330 let ret = unsafe { SCPreferencesGetSignature(self) };
331 ret.map(|ret| unsafe { CFRetained::retain(ret) })
332 }
333
334 #[doc(alias = "SCPreferencesCopyKeyList")]
341 #[inline]
342 pub fn key_list(&self) -> Option<CFRetained<CFArray>> {
343 extern "C-unwind" {
344 fn SCPreferencesCopyKeyList(prefs: &SCPreferences) -> Option<NonNull<CFArray>>;
345 }
346 let ret = unsafe { SCPreferencesCopyKeyList(self) };
347 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
348 }
349
350 #[doc(alias = "SCPreferencesGetValue")]
365 #[inline]
366 pub fn value(&self, key: &CFString) -> Option<CFRetained<CFPropertyList>> {
367 extern "C-unwind" {
368 fn SCPreferencesGetValue(
369 prefs: &SCPreferences,
370 key: &CFString,
371 ) -> Option<NonNull<CFPropertyList>>;
372 }
373 let ret = unsafe { SCPreferencesGetValue(self, key) };
374 ret.map(|ret| unsafe { CFRetained::retain(ret) })
375 }
376
377 #[doc(alias = "SCPreferencesAddValue")]
398 #[inline]
399 pub unsafe fn add_value(&self, key: &CFString, value: &CFPropertyList) -> bool {
400 extern "C-unwind" {
401 fn SCPreferencesAddValue(
402 prefs: &SCPreferences,
403 key: &CFString,
404 value: &CFPropertyList,
405 ) -> Boolean;
406 }
407 let ret = unsafe { SCPreferencesAddValue(self, key, value) };
408 ret != 0
409 }
410
411 #[doc(alias = "SCPreferencesSetValue")]
431 #[inline]
432 pub unsafe fn set_value(&self, key: &CFString, value: &CFPropertyList) -> bool {
433 extern "C-unwind" {
434 fn SCPreferencesSetValue(
435 prefs: &SCPreferences,
436 key: &CFString,
437 value: &CFPropertyList,
438 ) -> Boolean;
439 }
440 let ret = unsafe { SCPreferencesSetValue(self, key, value) };
441 ret != 0
442 }
443
444 #[doc(alias = "SCPreferencesRemoveValue")]
457 #[inline]
458 pub fn remove_value(&self, key: &CFString) -> bool {
459 extern "C-unwind" {
460 fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> Boolean;
461 }
462 let ret = unsafe { SCPreferencesRemoveValue(self, key) };
463 ret != 0
464 }
465
466 #[doc(alias = "SCPreferencesSetCallback")]
486 #[inline]
487 pub unsafe fn set_callback(
488 &self,
489 callout: SCPreferencesCallBack,
490 context: *mut SCPreferencesContext,
491 ) -> bool {
492 extern "C-unwind" {
493 fn SCPreferencesSetCallback(
494 prefs: &SCPreferences,
495 callout: SCPreferencesCallBack,
496 context: *mut SCPreferencesContext,
497 ) -> Boolean;
498 }
499 let ret = unsafe { SCPreferencesSetCallback(self, callout, context) };
500 ret != 0
501 }
502
503 #[doc(alias = "SCPreferencesScheduleWithRunLoop")]
518 #[inline]
519 pub fn schedule_with_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
520 extern "C-unwind" {
521 fn SCPreferencesScheduleWithRunLoop(
522 prefs: &SCPreferences,
523 run_loop: &CFRunLoop,
524 run_loop_mode: &CFString,
525 ) -> Boolean;
526 }
527 let ret = unsafe { SCPreferencesScheduleWithRunLoop(self, run_loop, run_loop_mode) };
528 ret != 0
529 }
530
531 #[doc(alias = "SCPreferencesUnscheduleFromRunLoop")]
546 #[inline]
547 pub fn unschedule_from_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
548 extern "C-unwind" {
549 fn SCPreferencesUnscheduleFromRunLoop(
550 prefs: &SCPreferences,
551 run_loop: &CFRunLoop,
552 run_loop_mode: &CFString,
553 ) -> Boolean;
554 }
555 let ret = unsafe { SCPreferencesUnscheduleFromRunLoop(self, run_loop, run_loop_mode) };
556 ret != 0
557 }
558
559 #[doc(alias = "SCPreferencesSetDispatchQueue")]
573 #[cfg(feature = "dispatch2")]
574 #[inline]
575 pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool {
576 extern "C-unwind" {
577 fn SCPreferencesSetDispatchQueue(
578 prefs: &SCPreferences,
579 queue: Option<&DispatchQueue>,
580 ) -> Boolean;
581 }
582 let ret = unsafe { SCPreferencesSetDispatchQueue(self, queue) };
583 ret != 0
584 }
585
586 #[doc(alias = "SCPreferencesSynchronize")]
596 #[inline]
597 pub fn synchronize(&self) {
598 extern "C-unwind" {
599 fn SCPreferencesSynchronize(prefs: &SCPreferences);
600 }
601 unsafe { SCPreferencesSynchronize(self) }
602 }
603}
604
605#[deprecated = "renamed to `SCPreferences::new`"]
606#[inline]
607pub extern "C-unwind" fn SCPreferencesCreate(
608 allocator: Option<&CFAllocator>,
609 name: &CFString,
610 prefs_id: Option<&CFString>,
611) -> Option<CFRetained<SCPreferences>> {
612 extern "C-unwind" {
613 fn SCPreferencesCreate(
614 allocator: Option<&CFAllocator>,
615 name: &CFString,
616 prefs_id: Option<&CFString>,
617 ) -> Option<NonNull<SCPreferences>>;
618 }
619 let ret = unsafe { SCPreferencesCreate(allocator, name, prefs_id) };
620 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
621}
622
623#[cfg(feature = "objc2-security")]
624#[deprecated = "renamed to `SCPreferences::with_authorization`"]
625#[inline]
626pub unsafe extern "C-unwind" fn SCPreferencesCreateWithAuthorization(
627 allocator: Option<&CFAllocator>,
628 name: &CFString,
629 prefs_id: Option<&CFString>,
630 authorization: AuthorizationRef,
631) -> Option<CFRetained<SCPreferences>> {
632 extern "C-unwind" {
633 fn SCPreferencesCreateWithAuthorization(
634 allocator: Option<&CFAllocator>,
635 name: &CFString,
636 prefs_id: Option<&CFString>,
637 authorization: AuthorizationRef,
638 ) -> Option<NonNull<SCPreferences>>;
639 }
640 let ret =
641 unsafe { SCPreferencesCreateWithAuthorization(allocator, name, prefs_id, authorization) };
642 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
643}
644
645#[deprecated = "renamed to `SCPreferences::lock`"]
646#[inline]
647pub extern "C-unwind" fn SCPreferencesLock(prefs: &SCPreferences, wait: bool) -> bool {
648 extern "C-unwind" {
649 fn SCPreferencesLock(prefs: &SCPreferences, wait: Boolean) -> Boolean;
650 }
651 let ret = unsafe { SCPreferencesLock(prefs, wait as _) };
652 ret != 0
653}
654
655#[deprecated = "renamed to `SCPreferences::commit_changes`"]
656#[inline]
657pub extern "C-unwind" fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> bool {
658 extern "C-unwind" {
659 fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> Boolean;
660 }
661 let ret = unsafe { SCPreferencesCommitChanges(prefs) };
662 ret != 0
663}
664
665#[deprecated = "renamed to `SCPreferences::apply_changes`"]
666#[inline]
667pub extern "C-unwind" fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> bool {
668 extern "C-unwind" {
669 fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> Boolean;
670 }
671 let ret = unsafe { SCPreferencesApplyChanges(prefs) };
672 ret != 0
673}
674
675#[deprecated = "renamed to `SCPreferences::unlock`"]
676#[inline]
677pub extern "C-unwind" fn SCPreferencesUnlock(prefs: &SCPreferences) -> bool {
678 extern "C-unwind" {
679 fn SCPreferencesUnlock(prefs: &SCPreferences) -> Boolean;
680 }
681 let ret = unsafe { SCPreferencesUnlock(prefs) };
682 ret != 0
683}
684
685#[deprecated = "renamed to `SCPreferences::signature`"]
686#[inline]
687pub extern "C-unwind" fn SCPreferencesGetSignature(
688 prefs: &SCPreferences,
689) -> Option<CFRetained<CFData>> {
690 extern "C-unwind" {
691 fn SCPreferencesGetSignature(prefs: &SCPreferences) -> Option<NonNull<CFData>>;
692 }
693 let ret = unsafe { SCPreferencesGetSignature(prefs) };
694 ret.map(|ret| unsafe { CFRetained::retain(ret) })
695}
696
697#[deprecated = "renamed to `SCPreferences::key_list`"]
698#[inline]
699pub extern "C-unwind" fn SCPreferencesCopyKeyList(
700 prefs: &SCPreferences,
701) -> Option<CFRetained<CFArray>> {
702 extern "C-unwind" {
703 fn SCPreferencesCopyKeyList(prefs: &SCPreferences) -> Option<NonNull<CFArray>>;
704 }
705 let ret = unsafe { SCPreferencesCopyKeyList(prefs) };
706 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
707}
708
709#[deprecated = "renamed to `SCPreferences::value`"]
710#[inline]
711pub extern "C-unwind" fn SCPreferencesGetValue(
712 prefs: &SCPreferences,
713 key: &CFString,
714) -> Option<CFRetained<CFPropertyList>> {
715 extern "C-unwind" {
716 fn SCPreferencesGetValue(
717 prefs: &SCPreferences,
718 key: &CFString,
719 ) -> Option<NonNull<CFPropertyList>>;
720 }
721 let ret = unsafe { SCPreferencesGetValue(prefs, key) };
722 ret.map(|ret| unsafe { CFRetained::retain(ret) })
723}
724
725#[deprecated = "renamed to `SCPreferences::add_value`"]
726#[inline]
727pub unsafe extern "C-unwind" fn SCPreferencesAddValue(
728 prefs: &SCPreferences,
729 key: &CFString,
730 value: &CFPropertyList,
731) -> bool {
732 extern "C-unwind" {
733 fn SCPreferencesAddValue(
734 prefs: &SCPreferences,
735 key: &CFString,
736 value: &CFPropertyList,
737 ) -> Boolean;
738 }
739 let ret = unsafe { SCPreferencesAddValue(prefs, key, value) };
740 ret != 0
741}
742
743#[deprecated = "renamed to `SCPreferences::set_value`"]
744#[inline]
745pub unsafe extern "C-unwind" fn SCPreferencesSetValue(
746 prefs: &SCPreferences,
747 key: &CFString,
748 value: &CFPropertyList,
749) -> bool {
750 extern "C-unwind" {
751 fn SCPreferencesSetValue(
752 prefs: &SCPreferences,
753 key: &CFString,
754 value: &CFPropertyList,
755 ) -> Boolean;
756 }
757 let ret = unsafe { SCPreferencesSetValue(prefs, key, value) };
758 ret != 0
759}
760
761#[deprecated = "renamed to `SCPreferences::remove_value`"]
762#[inline]
763pub extern "C-unwind" fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> bool {
764 extern "C-unwind" {
765 fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> Boolean;
766 }
767 let ret = unsafe { SCPreferencesRemoveValue(prefs, key) };
768 ret != 0
769}
770
771#[deprecated = "renamed to `SCPreferences::set_callback`"]
772#[inline]
773pub unsafe extern "C-unwind" fn SCPreferencesSetCallback(
774 prefs: &SCPreferences,
775 callout: SCPreferencesCallBack,
776 context: *mut SCPreferencesContext,
777) -> bool {
778 extern "C-unwind" {
779 fn SCPreferencesSetCallback(
780 prefs: &SCPreferences,
781 callout: SCPreferencesCallBack,
782 context: *mut SCPreferencesContext,
783 ) -> Boolean;
784 }
785 let ret = unsafe { SCPreferencesSetCallback(prefs, callout, context) };
786 ret != 0
787}
788
789#[deprecated = "renamed to `SCPreferences::schedule_with_run_loop`"]
790#[inline]
791pub extern "C-unwind" fn SCPreferencesScheduleWithRunLoop(
792 prefs: &SCPreferences,
793 run_loop: &CFRunLoop,
794 run_loop_mode: &CFString,
795) -> bool {
796 extern "C-unwind" {
797 fn SCPreferencesScheduleWithRunLoop(
798 prefs: &SCPreferences,
799 run_loop: &CFRunLoop,
800 run_loop_mode: &CFString,
801 ) -> Boolean;
802 }
803 let ret = unsafe { SCPreferencesScheduleWithRunLoop(prefs, run_loop, run_loop_mode) };
804 ret != 0
805}
806
807#[deprecated = "renamed to `SCPreferences::unschedule_from_run_loop`"]
808#[inline]
809pub extern "C-unwind" fn SCPreferencesUnscheduleFromRunLoop(
810 prefs: &SCPreferences,
811 run_loop: &CFRunLoop,
812 run_loop_mode: &CFString,
813) -> bool {
814 extern "C-unwind" {
815 fn SCPreferencesUnscheduleFromRunLoop(
816 prefs: &SCPreferences,
817 run_loop: &CFRunLoop,
818 run_loop_mode: &CFString,
819 ) -> Boolean;
820 }
821 let ret = unsafe { SCPreferencesUnscheduleFromRunLoop(prefs, run_loop, run_loop_mode) };
822 ret != 0
823}
824
825#[cfg(feature = "dispatch2")]
826#[deprecated = "renamed to `SCPreferences::set_dispatch_queue`"]
827#[inline]
828pub unsafe extern "C-unwind" fn SCPreferencesSetDispatchQueue(
829 prefs: &SCPreferences,
830 queue: Option<&DispatchQueue>,
831) -> bool {
832 extern "C-unwind" {
833 fn SCPreferencesSetDispatchQueue(
834 prefs: &SCPreferences,
835 queue: Option<&DispatchQueue>,
836 ) -> Boolean;
837 }
838 let ret = unsafe { SCPreferencesSetDispatchQueue(prefs, queue) };
839 ret != 0
840}
841
842#[deprecated = "renamed to `SCPreferences::synchronize`"]
843#[inline]
844pub extern "C-unwind" fn SCPreferencesSynchronize(prefs: &SCPreferences) {
845 extern "C-unwind" {
846 fn SCPreferencesSynchronize(prefs: &SCPreferences);
847 }
848 unsafe { SCPreferencesSynchronize(prefs) }
849}