objc2_system_configuration/generated/
SCPreferences.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::*;
9use objc2_core_foundation::*;
10#[cfg(feature = "objc2-security")]
11use objc2_security::*;
12
13use crate::*;
14
15/// This is the handle to an open preferences session for
16/// accessing system configuration preferences.
17///
18/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferences?language=objc)
19#[repr(C)]
20pub struct SCPreferences {
21    inner: [u8; 0],
22    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
23}
24
25cf_type!(
26    #[encoding_name = "__SCPreferences"]
27    unsafe impl SCPreferences {}
28);
29
30/// Used with the SCPreferencesCallBack callback
31/// to describe the type of notification.
32///
33/// preferences have been saved.
34///
35/// request has been made to apply the currently saved
36/// preferences to the active system configuration.
37///
38/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferencesnotification?language=objc)
39// NS_OPTIONS
40#[repr(transparent)]
41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
42pub struct SCPreferencesNotification(pub u32);
43bitflags::bitflags! {
44    impl SCPreferencesNotification: u32 {
45        #[doc(alias = "kSCPreferencesNotificationCommit")]
46        const Commit = 1<<0;
47        #[doc(alias = "kSCPreferencesNotificationApply")]
48        const Apply = 1<<1;
49    }
50}
51
52#[cfg(feature = "objc2")]
53unsafe impl Encode for SCPreferencesNotification {
54    const ENCODING: Encoding = u32::ENCODING;
55}
56
57#[cfg(feature = "objc2")]
58unsafe impl RefEncode for SCPreferencesNotification {
59    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
60}
61
62/// Structure containing user-specified data and callbacks for SCPreferences.
63/// Field: version The version number of the structure type being passed
64/// in as a parameter to the SCPreferencesSetCallback function.
65/// This structure is version 0.
66/// Field: info A C pointer to a user-specified block of data.
67/// Field: retain The callback used to add a retain for the info field.
68/// If this parameter is not a pointer to a function of the correct
69/// prototype, the behavior is undefined.
70/// The value may be NULL.
71/// Field: release The calllback used to remove a retain previously added
72/// for the info field.
73/// If this parameter is not a pointer to a function of the
74/// correct prototype, the behavior is undefined.
75/// The value may be NULL.
76/// Field: copyDescription The callback used to provide a description of
77/// the info field.
78///
79/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferencescontext?language=objc)
80#[repr(C)]
81#[derive(Clone, Copy, Debug, PartialEq)]
82pub struct SCPreferencesContext {
83    pub version: CFIndex,
84    pub info: *mut c_void,
85    pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
86    pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
87    pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
88}
89
90#[cfg(feature = "objc2")]
91unsafe impl Encode for SCPreferencesContext {
92    const ENCODING: Encoding = Encoding::Struct(
93        "?",
94        &[
95            <CFIndex>::ENCODING,
96            <*mut c_void>::ENCODING,
97            <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
98            <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
99            <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
100        ],
101    );
102}
103
104#[cfg(feature = "objc2")]
105unsafe impl RefEncode for SCPreferencesContext {
106    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
107}
108
109/// Type of the callback function used when the
110/// preferences have been updated and/or applied.
111///
112/// Parameter `prefs`: The preferences session.
113///
114/// Parameter `notificationType`: The type of notification, such as changes
115/// committed, changes applied, etc.
116///
117/// Parameter `info`: A C pointer to a user-specified block of data.
118///
119/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scpreferencescallback?language=objc)
120pub type SCPreferencesCallBack = Option<
121    unsafe extern "C-unwind" fn(NonNull<SCPreferences>, SCPreferencesNotification, *mut c_void),
122>;
123
124unsafe impl ConcreteType for SCPreferences {
125    /// Returns the type identifier of all SCPreferences instances.
126    #[doc(alias = "SCPreferencesGetTypeID")]
127    #[inline]
128    fn type_id() -> CFTypeID {
129        extern "C-unwind" {
130            fn SCPreferencesGetTypeID() -> CFTypeID;
131        }
132        unsafe { SCPreferencesGetTypeID() }
133    }
134}
135
136/// Initiates access to the per-system set of configuration
137/// preferences.
138///
139/// Parameter `allocator`: The CFAllocator that should be used to allocate
140/// memory for this preferences session.
141/// This parameter may be NULL in which case the current
142/// default CFAllocator is used.
143/// If this reference is not a valid CFAllocator, the behavior
144/// is undefined.
145///
146/// Parameter `name`: A string that describes the name of the calling
147/// process.
148///
149/// Parameter `prefsID`: A string that identifies the name of the
150/// group of preferences to be accessed or updated.
151///
152/// Returns: Returns a reference to the new SCPreferences.
153/// You must release the returned value.
154#[inline]
155pub unsafe extern "C-unwind" fn SCPreferencesCreate(
156    allocator: Option<&CFAllocator>,
157    name: &CFString,
158    prefs_id: Option<&CFString>,
159) -> Option<CFRetained<SCPreferences>> {
160    extern "C-unwind" {
161        fn SCPreferencesCreate(
162            allocator: Option<&CFAllocator>,
163            name: &CFString,
164            prefs_id: Option<&CFString>,
165        ) -> Option<NonNull<SCPreferences>>;
166    }
167    let ret = unsafe { SCPreferencesCreate(allocator, name, prefs_id) };
168    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
169}
170
171/// Initiates access to the per-system set of configuration
172/// preferences.
173///
174/// Parameter `allocator`: The CFAllocator that should be used to allocate
175/// memory for this preferences session.
176/// This parameter may be NULL in which case the current
177/// default CFAllocator is used.
178/// If this reference is not a valid CFAllocator, the behavior
179/// is undefined.
180///
181/// Parameter `name`: A string that describes the name of the calling
182/// process.
183///
184/// Parameter `prefsID`: A string that identifies the name of the
185/// group of preferences to be accessed or updated.
186///
187/// Parameter `authorization`: An authorization reference that is used to
188/// authorize any access to the enhanced privileges needed
189/// to manage the preferences session.
190///
191/// Returns: Returns a reference to the new SCPreferences.
192/// You must release the returned value.
193#[cfg(feature = "objc2-security")]
194#[inline]
195pub unsafe extern "C-unwind" fn SCPreferencesCreateWithAuthorization(
196    allocator: Option<&CFAllocator>,
197    name: &CFString,
198    prefs_id: Option<&CFString>,
199    authorization: AuthorizationRef,
200) -> Option<CFRetained<SCPreferences>> {
201    extern "C-unwind" {
202        fn SCPreferencesCreateWithAuthorization(
203            allocator: Option<&CFAllocator>,
204            name: &CFString,
205            prefs_id: Option<&CFString>,
206            authorization: AuthorizationRef,
207        ) -> Option<NonNull<SCPreferences>>;
208    }
209    let ret =
210        unsafe { SCPreferencesCreateWithAuthorization(allocator, name, prefs_id, authorization) };
211    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
212}
213
214/// Locks access to the configuration preferences.
215///
216/// This function obtains exclusive access to the configuration
217/// preferences.  Clients attempting to obtain exclusive access
218/// to the preferences will either receive a kSCStatusPrefsBusy
219/// error or block waiting for the lock to be released.
220///
221/// Parameter `prefs`: The preferences session.
222///
223/// Parameter `wait`: A boolean flag indicating whether the calling process
224/// should block waiting for another process to complete its update
225/// operation and release its lock.
226///
227/// Returns: Returns TRUE if the lock was obtained;
228/// FALSE if an error occurred.
229#[inline]
230pub unsafe extern "C-unwind" fn SCPreferencesLock(prefs: &SCPreferences, wait: bool) -> bool {
231    extern "C-unwind" {
232        fn SCPreferencesLock(prefs: &SCPreferences, wait: Boolean) -> Boolean;
233    }
234    let ret = unsafe { SCPreferencesLock(prefs, wait as _) };
235    ret != 0
236}
237
238/// Commits changes made to the configuration preferences to
239/// persistent storage.
240///
241/// This function commits any changes to permanent storage.
242/// Implicit calls to the SCPreferencesLock and SCPreferencesUnlock
243/// functions will be made if exclusive access has not already been
244/// established.
245///
246/// Note: This routine commits changes to persistent storage.
247/// Call the SCPreferencesApplyChanges function to apply the
248/// changes to the running system.
249///
250/// Parameter `prefs`: The preferences session.
251///
252/// Returns: Returns TRUE if the lock was obtained;
253/// FALSE if an error occurred.
254#[inline]
255pub unsafe extern "C-unwind" fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> bool {
256    extern "C-unwind" {
257        fn SCPreferencesCommitChanges(prefs: &SCPreferences) -> Boolean;
258    }
259    let ret = unsafe { SCPreferencesCommitChanges(prefs) };
260    ret != 0
261}
262
263/// Requests that the currently stored configuration
264/// preferences be applied to the active configuration.
265///
266/// Parameter `prefs`: The preferences session.
267///
268/// Returns: Returns TRUE if the lock was obtained;
269/// FALSE if an error occurred.
270#[inline]
271pub unsafe extern "C-unwind" fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> bool {
272    extern "C-unwind" {
273        fn SCPreferencesApplyChanges(prefs: &SCPreferences) -> Boolean;
274    }
275    let ret = unsafe { SCPreferencesApplyChanges(prefs) };
276    ret != 0
277}
278
279/// Releases exclusive access to the configuration preferences.
280///
281/// This function releases the exclusive access lock to the
282/// preferences.  Other clients will be now be able to establish
283/// exclusive access to the preferences.
284///
285/// Parameter `prefs`: The preferences session.
286///
287/// Returns: Returns TRUE if the lock was obtained;
288/// FALSE if an error occurred.
289#[inline]
290pub unsafe extern "C-unwind" fn SCPreferencesUnlock(prefs: &SCPreferences) -> bool {
291    extern "C-unwind" {
292        fn SCPreferencesUnlock(prefs: &SCPreferences) -> Boolean;
293    }
294    let ret = unsafe { SCPreferencesUnlock(prefs) };
295    ret != 0
296}
297
298/// Returns a sequence of bytes that can be used to determine
299/// if the saved configuration preferences have changed.
300///
301/// Parameter `prefs`: The preferences session.
302///
303/// Returns: Returns a CFDataRef that reflects the signature of the configuration
304/// preferences at the time of the call to the SCPreferencesCreate function.
305#[inline]
306pub unsafe extern "C-unwind" fn SCPreferencesGetSignature(
307    prefs: &SCPreferences,
308) -> Option<CFRetained<CFData>> {
309    extern "C-unwind" {
310        fn SCPreferencesGetSignature(prefs: &SCPreferences) -> Option<NonNull<CFData>>;
311    }
312    let ret = unsafe { SCPreferencesGetSignature(prefs) };
313    ret.map(|ret| unsafe { CFRetained::retain(ret) })
314}
315
316/// Returns an array of currently defined preference keys.
317///
318/// Parameter `prefs`: The preferences session.
319///
320/// Returns: Returns the list of keys.
321/// You must release the returned value.
322#[inline]
323pub unsafe extern "C-unwind" fn SCPreferencesCopyKeyList(
324    prefs: &SCPreferences,
325) -> Option<CFRetained<CFArray>> {
326    extern "C-unwind" {
327        fn SCPreferencesCopyKeyList(prefs: &SCPreferences) -> Option<NonNull<CFArray>>;
328    }
329    let ret = unsafe { SCPreferencesCopyKeyList(prefs) };
330    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
331}
332
333/// Returns the data associated with a preference key.
334///
335/// This function retrieves data associated with the specified
336/// key.
337///
338/// Note: To avoid inadvertantly reading stale data, first call
339/// the SCPreferencesLock function.
340///
341/// Parameter `prefs`: The preferences session.
342///
343/// Parameter `key`: The preference key to be returned.
344///
345/// Returns: Returns the value associated with the specified preference key;
346/// NULL if no value was located.
347#[inline]
348pub unsafe extern "C-unwind" fn SCPreferencesGetValue(
349    prefs: &SCPreferences,
350    key: &CFString,
351) -> Option<CFRetained<CFPropertyList>> {
352    extern "C-unwind" {
353        fn SCPreferencesGetValue(
354            prefs: &SCPreferences,
355            key: &CFString,
356        ) -> Option<NonNull<CFPropertyList>>;
357    }
358    let ret = unsafe { SCPreferencesGetValue(prefs, key) };
359    ret.map(|ret| unsafe { CFRetained::retain(ret) })
360}
361
362/// Adds data for a preference key.
363///
364/// This function associates new data with the specified key.
365/// To commit these changes to permanent storage, a call must
366/// be made to the SCPreferencesCommitChanges function.
367///
368/// Parameter `prefs`: The preferences session.
369///
370/// Parameter `key`: The preference key to be updated.
371///
372/// Parameter `value`: The CFPropertyListRef object containing the
373/// value to be associated with the specified preference key.
374///
375/// Returns: Returns TRUE if the value was added;
376/// FALSE if the key already exists or
377/// if an error occurred.
378#[inline]
379pub unsafe extern "C-unwind" fn SCPreferencesAddValue(
380    prefs: &SCPreferences,
381    key: &CFString,
382    value: &CFPropertyList,
383) -> bool {
384    extern "C-unwind" {
385        fn SCPreferencesAddValue(
386            prefs: &SCPreferences,
387            key: &CFString,
388            value: &CFPropertyList,
389        ) -> Boolean;
390    }
391    let ret = unsafe { SCPreferencesAddValue(prefs, key, value) };
392    ret != 0
393}
394
395/// Updates the data associated with a preference key.
396///
397/// This function adds or replaces the value associated with the
398/// specified key.  To commit these changes to permanent storage
399/// a call must be made to the SCPreferencesCommitChanges function.
400///
401/// Parameter `prefs`: The preferences session.
402///
403/// Parameter `key`: The preference key to be updated.
404///
405/// Parameter `value`: The CFPropertyListRef object containing the
406/// data to be associated with the specified preference key.
407///
408/// Returns: Returns TRUE if the value was set;
409/// FALSE if an error occurred.
410#[inline]
411pub unsafe extern "C-unwind" fn SCPreferencesSetValue(
412    prefs: &SCPreferences,
413    key: &CFString,
414    value: &CFPropertyList,
415) -> bool {
416    extern "C-unwind" {
417        fn SCPreferencesSetValue(
418            prefs: &SCPreferences,
419            key: &CFString,
420            value: &CFPropertyList,
421        ) -> Boolean;
422    }
423    let ret = unsafe { SCPreferencesSetValue(prefs, key, value) };
424    ret != 0
425}
426
427/// Removes the data associated with a preference key.
428///
429/// This function removes the data associated with the specified
430/// key.  To commit these changes to permanent storage a call must
431/// be made to the SCPreferencesCommitChanges function.
432///
433/// Parameter `prefs`: The preferences session.
434///
435/// Parameter `key`: The preference key to be removed.
436///
437/// Returns: Returns TRUE if the value was removed;
438/// FALSE if the key did not exist or if an error occurred.
439#[inline]
440pub unsafe extern "C-unwind" fn SCPreferencesRemoveValue(
441    prefs: &SCPreferences,
442    key: &CFString,
443) -> bool {
444    extern "C-unwind" {
445        fn SCPreferencesRemoveValue(prefs: &SCPreferences, key: &CFString) -> Boolean;
446    }
447    let ret = unsafe { SCPreferencesRemoveValue(prefs, key) };
448    ret != 0
449}
450
451/// Assigns a callback to a preferences session.  The function
452/// is called when the changes to the preferences have been
453/// committed or applied.
454///
455/// Parameter `prefs`: The preferences session.
456///
457/// Parameter `callout`: The function to be called when the preferences have
458/// been changed or applied.
459/// If NULL, the current callback is removed.
460///
461/// Parameter `context`: The SCPreferencesContext associated with
462/// the callout.
463///
464/// Returns: Returns TRUE if the notification client was successfully set.
465#[inline]
466pub unsafe extern "C-unwind" fn SCPreferencesSetCallback(
467    prefs: &SCPreferences,
468    callout: SCPreferencesCallBack,
469    context: *mut SCPreferencesContext,
470) -> bool {
471    extern "C-unwind" {
472        fn SCPreferencesSetCallback(
473            prefs: &SCPreferences,
474            callout: SCPreferencesCallBack,
475            context: *mut SCPreferencesContext,
476        ) -> Boolean;
477    }
478    let ret = unsafe { SCPreferencesSetCallback(prefs, callout, context) };
479    ret != 0
480}
481
482/// Schedule commit and apply notifications for the specified
483/// preferences session using the specified run loop and mode.
484///
485/// Parameter `prefs`: The preferences session.
486///
487/// Parameter `runLoop`: A reference to a run loop on which the notification
488/// should be scheduled.
489/// Must be non-NULL.
490///
491/// Parameter `runLoopMode`: The mode on which to schedule the notification.
492/// Must be non-NULL.
493///
494/// Returns: Returns TRUE if the notifications are successfully scheduled;
495/// FALSE otherwise.
496#[inline]
497pub unsafe extern "C-unwind" fn SCPreferencesScheduleWithRunLoop(
498    prefs: &SCPreferences,
499    run_loop: &CFRunLoop,
500    run_loop_mode: &CFString,
501) -> bool {
502    extern "C-unwind" {
503        fn SCPreferencesScheduleWithRunLoop(
504            prefs: &SCPreferences,
505            run_loop: &CFRunLoop,
506            run_loop_mode: &CFString,
507        ) -> Boolean;
508    }
509    let ret = unsafe { SCPreferencesScheduleWithRunLoop(prefs, run_loop, run_loop_mode) };
510    ret != 0
511}
512
513/// Unschedule commit and apply notifications for the specified
514/// preferences session from the specified run loop and mode.
515///
516/// Parameter `prefs`: The preferences session.
517///
518/// Parameter `runLoop`: A reference to a run loop from which the notification
519/// should be unscheduled.
520/// Must be non-NULL.
521///
522/// Parameter `runLoopMode`: The mode on which to unschedule the notification.
523/// Must be non-NULL.
524///
525/// Returns: Returns TRUE if the notifications are successfully unscheduled;
526/// FALSE otherwise.
527#[inline]
528pub unsafe extern "C-unwind" fn SCPreferencesUnscheduleFromRunLoop(
529    prefs: &SCPreferences,
530    run_loop: &CFRunLoop,
531    run_loop_mode: &CFString,
532) -> bool {
533    extern "C-unwind" {
534        fn SCPreferencesUnscheduleFromRunLoop(
535            prefs: &SCPreferences,
536            run_loop: &CFRunLoop,
537            run_loop_mode: &CFString,
538        ) -> Boolean;
539    }
540    let ret = unsafe { SCPreferencesUnscheduleFromRunLoop(prefs, run_loop, run_loop_mode) };
541    ret != 0
542}
543
544extern "C-unwind" {
545    /// Synchronizes accessed preferences with committed changes.
546    ///
547    /// Any references to preference values returned by calls to the
548    /// SCPreferencesGetValue function are no longer valid unless they
549    /// were explicitly retained or copied.  Any preference values
550    /// that were updated (add, set, remove) but not committed will
551    /// be discarded.
552    ///
553    /// Parameter `prefs`: The preferences session.
554    pub fn SCPreferencesSynchronize(prefs: &SCPreferences);
555}