objc2-system-configuration 0.3.2

Bindings to the SystemConfiguration framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
#[cfg(feature = "objc2-security")]
use objc2_security::*;

use crate::*;

/// This is the handle to an open preferences session for
/// accessing system configuration preferences.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferences?language=objc)
#[doc(alias = "SCPreferencesRef")]
#[repr(C)]
pub struct SCPreferences {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl SCPreferences {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"__SCPreferences"> for SCPreferences {}
);

/// Used with the SCPreferencesCallBack callback
/// to describe the type of notification.
///
/// preferences have been saved.
///
/// request has been made to apply the currently saved
/// preferences to the active system configuration.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferencesnotification?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SCPreferencesNotification(pub u32);
bitflags::bitflags! {
    impl SCPreferencesNotification: u32 {
        #[doc(alias = "kSCPreferencesNotificationCommit")]
        const Commit = 1<<0;
        #[doc(alias = "kSCPreferencesNotificationApply")]
        const Apply = 1<<1;
    }
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SCPreferencesNotification {
    const ENCODING: Encoding = u32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SCPreferencesNotification {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Structure containing user-specified data and callbacks for SCPreferences.
/// Field: version The version number of the structure type being passed
/// in as a parameter to the SCPreferencesSetCallback function.
/// This structure is version 0.
/// Field: info A C pointer to a user-specified block of data.
/// Field: retain The callback used to add a retain for the info field.
/// If this parameter is not a pointer to a function of the correct
/// prototype, the behavior is undefined.
/// The value may be NULL.
/// Field: release The calllback used to remove a retain previously added
/// for the info field.
/// If this parameter is not a pointer to a function of the
/// correct prototype, the behavior is undefined.
/// The value may be NULL.
/// Field: copyDescription The callback used to provide a description of
/// the info field.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferencescontext?language=objc)
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SCPreferencesContext {
    pub version: CFIndex,
    pub info: *mut c_void,
    pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
    pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
    pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SCPreferencesContext {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <CFIndex>::ENCODING,
            <*mut c_void>::ENCODING,
            <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
            <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
            <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SCPreferencesContext {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Type of the callback function used when the
/// preferences have been updated and/or applied.
///
/// Parameter `prefs`: The preferences session.
///
/// Parameter `notificationType`: The type of notification, such as changes
/// committed, changes applied, etc.
///
/// Parameter `info`: A C pointer to a user-specified block of data.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferencescallback?language=objc)
pub type SCPreferencesCallBack = Option<
    unsafe extern "C-unwind" fn(NonNull<SCPreferences>, SCPreferencesNotification, *mut c_void),
>;

unsafe impl ConcreteType for SCPreferences {
    /// Returns the type identifier of all SCPreferences instances.
    #[doc(alias = "SCPreferencesGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn SCPreferencesGetTypeID() -> CFTypeID;
        }
        unsafe { SCPreferencesGetTypeID() }
    }
}

impl SCPreferences {
    /// Initiates access to the per-system set of configuration
    /// preferences.
    ///
    /// Parameter `allocator`: The CFAllocator that should be used to allocate
    /// memory for this preferences session.
    /// This parameter may be NULL in which case the current
    /// default CFAllocator is used.
    /// If this reference is not a valid CFAllocator, the behavior
    /// is undefined.
    ///
    /// Parameter `name`: A string that describes the name of the calling
    /// process.
    ///
    /// Parameter `prefsID`: A string that identifies the name of the
    /// group of preferences to be accessed or updated.
    ///
    /// Returns: Returns a reference to the new SCPreferences.
    /// You must release the returned value.
    #[doc(alias = "SCPreferencesCreate")]
    #[inline]
    pub fn new(
        allocator: Option<&CFAllocator>,
        name: &CFString,
        prefs_id: Option<&CFString>,
    ) -> Option<CFRetained<SCPreferences>> {
        extern "C-unwind" {
            fn SCPreferencesCreate(
                allocator: Option<&CFAllocator>,
                name: &CFString,
                prefs_id: Option<&CFString>,
            ) -> Option<NonNull<SCPreferences>>;
        }
        let ret = unsafe { SCPreferencesCreate(allocator, name, prefs_id) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Initiates access to the per-system set of configuration
    /// preferences.
    ///
    /// Parameter `allocator`: The CFAllocator that should be used to allocate
    /// memory for this preferences session.
    /// This parameter may be NULL in which case the current
    /// default CFAllocator is used.
    /// If this reference is not a valid CFAllocator, the behavior
    /// is undefined.
    ///
    /// Parameter `name`: A string that describes the name of the calling
    /// process.
    ///
    /// Parameter `prefsID`: A string that identifies the name of the
    /// group of preferences to be accessed or updated.
    ///
    /// Parameter `authorization`: An authorization reference that is used to
    /// authorize any access to the enhanced privileges needed
    /// to manage the preferences session.
    ///
    /// Returns: Returns a reference to the new SCPreferences.
    /// You must release the returned value.
    ///
    /// # Safety
    ///
    /// `authorization` must be a valid pointer or null.
    #[doc(alias = "SCPreferencesCreateWithAuthorization")]
    #[cfg(feature = "objc2-security")]
    #[inline]
    pub unsafe fn with_authorization(
        allocator: Option<&CFAllocator>,
        name: &CFString,
        prefs_id: Option<&CFString>,
        authorization: AuthorizationRef,
    ) -> Option<CFRetained<SCPreferences>> {
        extern "C-unwind" {
            fn SCPreferencesCreateWithAuthorization(
                allocator: Option<&CFAllocator>,
                name: &CFString,
                prefs_id: Option<&CFString>,
                authorization: AuthorizationRef,
            ) -> Option<NonNull<SCPreferences>>;
        }
        let ret = unsafe {
            SCPreferencesCreateWithAuthorization(allocator, name, prefs_id, authorization)
        };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Locks access to the configuration preferences.
    ///
    /// This function obtains exclusive access to the configuration
    /// preferences.  Clients attempting to obtain exclusive access
    /// to the preferences will either receive a kSCStatusPrefsBusy
    /// error or block waiting for the lock to be released.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `wait`: A boolean flag indicating whether the calling process
    /// should block waiting for another process to complete its update
    /// operation and release its lock.
    ///
    /// Returns: Returns TRUE if the lock was obtained;
    /// FALSE if an error occurred.
    #[doc(alias = "SCPreferencesLock")]
    #[inline]
    pub fn lock(&self, wait: bool) -> bool {
        extern "C-unwind" {
            fn SCPreferencesLock(prefs: &SCPreferences, wait: Boolean) -> Boolean;
        }
        let ret = unsafe { SCPreferencesLock(self, wait as _) };
        ret != 0
    }

    /// Commits changes made to the configuration preferences to
    /// persistent storage.
    ///
    /// This function commits any changes to permanent storage.
    /// Implicit calls to the SCPreferencesLock and SCPreferencesUnlock
    /// functions will be made if exclusive access has not already been
    /// established.
    ///
    /// Note: This routine commits changes to persistent storage.
    /// Call the SCPreferencesApplyChanges function to apply the
    /// changes to the running system.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Returns: Returns TRUE if the lock was obtained;
    /// FALSE if an error occurred.
    #[doc(alias = "SCPreferencesCommitChanges")]
    #[inline]
    pub fn commit_changes(&self) -> bool {
        extern "C-unwind" {
            fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> Boolean;
        }
        let ret = unsafe { SCPreferencesCommitChanges(self) };
        ret != 0
    }

    /// Requests that the currently stored configuration
    /// preferences be applied to the active configuration.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Returns: Returns TRUE if the lock was obtained;
    /// FALSE if an error occurred.
    #[doc(alias = "SCPreferencesApplyChanges")]
    #[inline]
    pub fn apply_changes(&self) -> bool {
        extern "C-unwind" {
            fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> Boolean;
        }
        let ret = unsafe { SCPreferencesApplyChanges(self) };
        ret != 0
    }

    /// Releases exclusive access to the configuration preferences.
    ///
    /// This function releases the exclusive access lock to the
    /// preferences.  Other clients will be now be able to establish
    /// exclusive access to the preferences.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Returns: Returns TRUE if the lock was obtained;
    /// FALSE if an error occurred.
    #[doc(alias = "SCPreferencesUnlock")]
    #[inline]
    pub fn unlock(&self) -> bool {
        extern "C-unwind" {
            fn SCPreferencesUnlock(prefs: &SCPreferences) -> Boolean;
        }
        let ret = unsafe { SCPreferencesUnlock(self) };
        ret != 0
    }

    /// Returns a sequence of bytes that can be used to determine
    /// if the saved configuration preferences have changed.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Returns: Returns a CFDataRef that reflects the signature of the configuration
    /// preferences at the time of the call to the SCPreferencesCreate function.
    #[doc(alias = "SCPreferencesGetSignature")]
    #[inline]
    pub fn signature(&self) -> Option<CFRetained<CFData>> {
        extern "C-unwind" {
            fn SCPreferencesGetSignature(prefs: &SCPreferences) -> Option<NonNull<CFData>>;
        }
        let ret = unsafe { SCPreferencesGetSignature(self) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// Returns an array of currently defined preference keys.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Returns: Returns the list of keys.
    /// You must release the returned value.
    #[doc(alias = "SCPreferencesCopyKeyList")]
    #[inline]
    pub fn key_list(&self) -> Option<CFRetained<CFArray>> {
        extern "C-unwind" {
            fn SCPreferencesCopyKeyList(prefs: &SCPreferences) -> Option<NonNull<CFArray>>;
        }
        let ret = unsafe { SCPreferencesCopyKeyList(self) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Returns the data associated with a preference key.
    ///
    /// This function retrieves data associated with the specified
    /// key.
    ///
    /// Note: To avoid inadvertantly reading stale data, first call
    /// the SCPreferencesLock function.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `key`: The preference key to be returned.
    ///
    /// Returns: Returns the value associated with the specified preference key;
    /// NULL if no value was located.
    #[doc(alias = "SCPreferencesGetValue")]
    #[inline]
    pub fn value(&self, key: &CFString) -> Option<CFRetained<CFPropertyList>> {
        extern "C-unwind" {
            fn SCPreferencesGetValue(
                prefs: &SCPreferences,
                key: &CFString,
            ) -> Option<NonNull<CFPropertyList>>;
        }
        let ret = unsafe { SCPreferencesGetValue(self, key) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// Adds data for a preference key.
    ///
    /// This function associates new data with the specified key.
    /// To commit these changes to permanent storage, a call must
    /// be made to the SCPreferencesCommitChanges function.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `key`: The preference key to be updated.
    ///
    /// Parameter `value`: The CFPropertyListRef object containing the
    /// value to be associated with the specified preference key.
    ///
    /// Returns: Returns TRUE if the value was added;
    /// FALSE if the key already exists or
    /// if an error occurred.
    ///
    /// # Safety
    ///
    /// `value` should be of the correct type.
    #[doc(alias = "SCPreferencesAddValue")]
    #[inline]
    pub unsafe fn add_value(&self, key: &CFString, value: &CFPropertyList) -> bool {
        extern "C-unwind" {
            fn SCPreferencesAddValue(
                prefs: &SCPreferences,
                key: &CFString,
                value: &CFPropertyList,
            ) -> Boolean;
        }
        let ret = unsafe { SCPreferencesAddValue(self, key, value) };
        ret != 0
    }

    /// Updates the data associated with a preference key.
    ///
    /// This function adds or replaces the value associated with the
    /// specified key.  To commit these changes to permanent storage
    /// a call must be made to the SCPreferencesCommitChanges function.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `key`: The preference key to be updated.
    ///
    /// Parameter `value`: The CFPropertyListRef object containing the
    /// data to be associated with the specified preference key.
    ///
    /// Returns: Returns TRUE if the value was set;
    /// FALSE if an error occurred.
    ///
    /// # Safety
    ///
    /// `value` should be of the correct type.
    #[doc(alias = "SCPreferencesSetValue")]
    #[inline]
    pub unsafe fn set_value(&self, key: &CFString, value: &CFPropertyList) -> bool {
        extern "C-unwind" {
            fn SCPreferencesSetValue(
                prefs: &SCPreferences,
                key: &CFString,
                value: &CFPropertyList,
            ) -> Boolean;
        }
        let ret = unsafe { SCPreferencesSetValue(self, key, value) };
        ret != 0
    }

    /// Removes the data associated with a preference key.
    ///
    /// This function removes the data associated with the specified
    /// key.  To commit these changes to permanent storage a call must
    /// be made to the SCPreferencesCommitChanges function.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `key`: The preference key to be removed.
    ///
    /// Returns: Returns TRUE if the value was removed;
    /// FALSE if the key did not exist or if an error occurred.
    #[doc(alias = "SCPreferencesRemoveValue")]
    #[inline]
    pub fn remove_value(&self, key: &CFString) -> bool {
        extern "C-unwind" {
            fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> Boolean;
        }
        let ret = unsafe { SCPreferencesRemoveValue(self, key) };
        ret != 0
    }

    /// Assigns a callback to a preferences session.  The function
    /// is called when the changes to the preferences have been
    /// committed or applied.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `callout`: The function to be called when the preferences have
    /// been changed or applied.
    /// If NULL, the current callback is removed.
    ///
    /// Parameter `context`: The SCPreferencesContext associated with
    /// the callout.
    ///
    /// Returns: Returns TRUE if the notification client was successfully set.
    ///
    /// # Safety
    ///
    /// - `callout` must be implemented correctly.
    /// - `context` must be a valid pointer or null.
    #[doc(alias = "SCPreferencesSetCallback")]
    #[inline]
    pub unsafe fn set_callback(
        &self,
        callout: SCPreferencesCallBack,
        context: *mut SCPreferencesContext,
    ) -> bool {
        extern "C-unwind" {
            fn SCPreferencesSetCallback(
                prefs: &SCPreferences,
                callout: SCPreferencesCallBack,
                context: *mut SCPreferencesContext,
            ) -> Boolean;
        }
        let ret = unsafe { SCPreferencesSetCallback(self, callout, context) };
        ret != 0
    }

    /// Schedule commit and apply notifications for the specified
    /// preferences session using the specified run loop and mode.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `runLoop`: A reference to a run loop on which the notification
    /// should be scheduled.
    /// Must be non-NULL.
    ///
    /// Parameter `runLoopMode`: The mode on which to schedule the notification.
    /// Must be non-NULL.
    ///
    /// Returns: Returns TRUE if the notifications are successfully scheduled;
    /// FALSE otherwise.
    #[doc(alias = "SCPreferencesScheduleWithRunLoop")]
    #[inline]
    pub fn schedule_with_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
        extern "C-unwind" {
            fn SCPreferencesScheduleWithRunLoop(
                prefs: &SCPreferences,
                run_loop: &CFRunLoop,
                run_loop_mode: &CFString,
            ) -> Boolean;
        }
        let ret = unsafe { SCPreferencesScheduleWithRunLoop(self, run_loop, run_loop_mode) };
        ret != 0
    }

    /// Unschedule commit and apply notifications for the specified
    /// preferences session from the specified run loop and mode.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `runLoop`: A reference to a run loop from which the notification
    /// should be unscheduled.
    /// Must be non-NULL.
    ///
    /// Parameter `runLoopMode`: The mode on which to unschedule the notification.
    /// Must be non-NULL.
    ///
    /// Returns: Returns TRUE if the notifications are successfully unscheduled;
    /// FALSE otherwise.
    #[doc(alias = "SCPreferencesUnscheduleFromRunLoop")]
    #[inline]
    pub fn unschedule_from_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
        extern "C-unwind" {
            fn SCPreferencesUnscheduleFromRunLoop(
                prefs: &SCPreferences,
                run_loop: &CFRunLoop,
                run_loop_mode: &CFString,
            ) -> Boolean;
        }
        let ret = unsafe { SCPreferencesUnscheduleFromRunLoop(self, run_loop, run_loop_mode) };
        ret != 0
    }

    /// Schedule commit and apply notifications for the specified
    /// preferences session.
    ///
    /// Parameter `prefs`: The preferences session.
    ///
    /// Parameter `queue`: The dispatch queue to run the callback function on.
    ///
    /// Returns: Returns TRUE if the notifications are successfully scheduled;
    /// FALSE otherwise.
    ///
    /// # Safety
    ///
    /// `queue` possibly has additional threading requirements.
    #[doc(alias = "SCPreferencesSetDispatchQueue")]
    #[cfg(feature = "dispatch2")]
    #[inline]
    pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool {
        extern "C-unwind" {
            fn SCPreferencesSetDispatchQueue(
                prefs: &SCPreferences,
                queue: Option<&DispatchQueue>,
            ) -> Boolean;
        }
        let ret = unsafe { SCPreferencesSetDispatchQueue(self, queue) };
        ret != 0
    }

    /// Synchronizes accessed preferences with committed changes.
    ///
    /// Any references to preference values returned by calls to the
    /// SCPreferencesGetValue function are no longer valid unless they
    /// were explicitly retained or copied.  Any preference values
    /// that were updated (add, set, remove) but not committed will
    /// be discarded.
    ///
    /// Parameter `prefs`: The preferences session.
    #[doc(alias = "SCPreferencesSynchronize")]
    #[inline]
    pub fn synchronize(&self) {
        extern "C-unwind" {
            fn SCPreferencesSynchronize(prefs: &SCPreferences);
        }
        unsafe { SCPreferencesSynchronize(self) }
    }
}

#[deprecated = "renamed to `SCPreferences::new`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesCreate(
    allocator: Option<&CFAllocator>,
    name: &CFString,
    prefs_id: Option<&CFString>,
) -> Option<CFRetained<SCPreferences>> {
    extern "C-unwind" {
        fn SCPreferencesCreate(
            allocator: Option<&CFAllocator>,
            name: &CFString,
            prefs_id: Option<&CFString>,
        ) -> Option<NonNull<SCPreferences>>;
    }
    let ret = unsafe { SCPreferencesCreate(allocator, name, prefs_id) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "objc2-security")]
#[deprecated = "renamed to `SCPreferences::with_authorization`"]
#[inline]
pub unsafe extern "C-unwind" fn SCPreferencesCreateWithAuthorization(
    allocator: Option<&CFAllocator>,
    name: &CFString,
    prefs_id: Option<&CFString>,
    authorization: AuthorizationRef,
) -> Option<CFRetained<SCPreferences>> {
    extern "C-unwind" {
        fn SCPreferencesCreateWithAuthorization(
            allocator: Option<&CFAllocator>,
            name: &CFString,
            prefs_id: Option<&CFString>,
            authorization: AuthorizationRef,
        ) -> Option<NonNull<SCPreferences>>;
    }
    let ret =
        unsafe { SCPreferencesCreateWithAuthorization(allocator, name, prefs_id, authorization) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `SCPreferences::lock`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesLock(prefs: &SCPreferences, wait: bool) -> bool {
    extern "C-unwind" {
        fn SCPreferencesLock(prefs: &SCPreferences, wait: Boolean) -> Boolean;
    }
    let ret = unsafe { SCPreferencesLock(prefs, wait as _) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::commit_changes`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> bool {
    extern "C-unwind" {
        fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> Boolean;
    }
    let ret = unsafe { SCPreferencesCommitChanges(prefs) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::apply_changes`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> bool {
    extern "C-unwind" {
        fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> Boolean;
    }
    let ret = unsafe { SCPreferencesApplyChanges(prefs) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::unlock`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesUnlock(prefs: &SCPreferences) -> bool {
    extern "C-unwind" {
        fn SCPreferencesUnlock(prefs: &SCPreferences) -> Boolean;
    }
    let ret = unsafe { SCPreferencesUnlock(prefs) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::signature`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesGetSignature(
    prefs: &SCPreferences,
) -> Option<CFRetained<CFData>> {
    extern "C-unwind" {
        fn SCPreferencesGetSignature(prefs: &SCPreferences) -> Option<NonNull<CFData>>;
    }
    let ret = unsafe { SCPreferencesGetSignature(prefs) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

#[deprecated = "renamed to `SCPreferences::key_list`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesCopyKeyList(
    prefs: &SCPreferences,
) -> Option<CFRetained<CFArray>> {
    extern "C-unwind" {
        fn SCPreferencesCopyKeyList(prefs: &SCPreferences) -> Option<NonNull<CFArray>>;
    }
    let ret = unsafe { SCPreferencesCopyKeyList(prefs) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `SCPreferences::value`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesGetValue(
    prefs: &SCPreferences,
    key: &CFString,
) -> Option<CFRetained<CFPropertyList>> {
    extern "C-unwind" {
        fn SCPreferencesGetValue(
            prefs: &SCPreferences,
            key: &CFString,
        ) -> Option<NonNull<CFPropertyList>>;
    }
    let ret = unsafe { SCPreferencesGetValue(prefs, key) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

#[deprecated = "renamed to `SCPreferences::add_value`"]
#[inline]
pub unsafe extern "C-unwind" fn SCPreferencesAddValue(
    prefs: &SCPreferences,
    key: &CFString,
    value: &CFPropertyList,
) -> bool {
    extern "C-unwind" {
        fn SCPreferencesAddValue(
            prefs: &SCPreferences,
            key: &CFString,
            value: &CFPropertyList,
        ) -> Boolean;
    }
    let ret = unsafe { SCPreferencesAddValue(prefs, key, value) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::set_value`"]
#[inline]
pub unsafe extern "C-unwind" fn SCPreferencesSetValue(
    prefs: &SCPreferences,
    key: &CFString,
    value: &CFPropertyList,
) -> bool {
    extern "C-unwind" {
        fn SCPreferencesSetValue(
            prefs: &SCPreferences,
            key: &CFString,
            value: &CFPropertyList,
        ) -> Boolean;
    }
    let ret = unsafe { SCPreferencesSetValue(prefs, key, value) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::remove_value`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> bool {
    extern "C-unwind" {
        fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> Boolean;
    }
    let ret = unsafe { SCPreferencesRemoveValue(prefs, key) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::set_callback`"]
#[inline]
pub unsafe extern "C-unwind" fn SCPreferencesSetCallback(
    prefs: &SCPreferences,
    callout: SCPreferencesCallBack,
    context: *mut SCPreferencesContext,
) -> bool {
    extern "C-unwind" {
        fn SCPreferencesSetCallback(
            prefs: &SCPreferences,
            callout: SCPreferencesCallBack,
            context: *mut SCPreferencesContext,
        ) -> Boolean;
    }
    let ret = unsafe { SCPreferencesSetCallback(prefs, callout, context) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::schedule_with_run_loop`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesScheduleWithRunLoop(
    prefs: &SCPreferences,
    run_loop: &CFRunLoop,
    run_loop_mode: &CFString,
) -> bool {
    extern "C-unwind" {
        fn SCPreferencesScheduleWithRunLoop(
            prefs: &SCPreferences,
            run_loop: &CFRunLoop,
            run_loop_mode: &CFString,
        ) -> Boolean;
    }
    let ret = unsafe { SCPreferencesScheduleWithRunLoop(prefs, run_loop, run_loop_mode) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::unschedule_from_run_loop`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesUnscheduleFromRunLoop(
    prefs: &SCPreferences,
    run_loop: &CFRunLoop,
    run_loop_mode: &CFString,
) -> bool {
    extern "C-unwind" {
        fn SCPreferencesUnscheduleFromRunLoop(
            prefs: &SCPreferences,
            run_loop: &CFRunLoop,
            run_loop_mode: &CFString,
        ) -> Boolean;
    }
    let ret = unsafe { SCPreferencesUnscheduleFromRunLoop(prefs, run_loop, run_loop_mode) };
    ret != 0
}

#[cfg(feature = "dispatch2")]
#[deprecated = "renamed to `SCPreferences::set_dispatch_queue`"]
#[inline]
pub unsafe extern "C-unwind" fn SCPreferencesSetDispatchQueue(
    prefs: &SCPreferences,
    queue: Option<&DispatchQueue>,
) -> bool {
    extern "C-unwind" {
        fn SCPreferencesSetDispatchQueue(
            prefs: &SCPreferences,
            queue: Option<&DispatchQueue>,
        ) -> Boolean;
    }
    let ret = unsafe { SCPreferencesSetDispatchQueue(prefs, queue) };
    ret != 0
}

#[deprecated = "renamed to `SCPreferences::synchronize`"]
#[inline]
pub extern "C-unwind" fn SCPreferencesSynchronize(prefs: &SCPreferences) {
    extern "C-unwind" {
        fn SCPreferencesSynchronize(prefs: &SCPreferences);
    }
    unsafe { SCPreferencesSynchronize(prefs) }
}