pub struct SCPreferences { /* private fields */ }SCPreferences only.Expand description
This is the handle to an open preferences session for accessing system configuration preferences.
See also Apple’s documentation
Implementations§
Source§impl SCPreferences
impl SCPreferences
Sourcepub fn new(
allocator: Option<&CFAllocator>,
name: &CFString,
prefs_id: Option<&CFString>,
) -> Option<CFRetained<SCPreferences>>
pub fn new( allocator: Option<&CFAllocator>, name: &CFString, prefs_id: Option<&CFString>, ) -> Option<CFRetained<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.
Available on crate feature objc2-security only.
objc2-security only.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.
Sourcepub fn lock(&self, wait: bool) -> bool
pub fn lock(&self, wait: bool) -> bool
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.
Sourcepub fn commit_changes(&self) -> bool
pub fn commit_changes(&self) -> bool
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.
Sourcepub fn apply_changes(&self) -> bool
pub fn apply_changes(&self) -> bool
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.
Sourcepub fn unlock(&self) -> bool
pub fn unlock(&self) -> bool
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.
Sourcepub fn signature(&self) -> Option<CFRetained<CFData>>
pub fn signature(&self) -> Option<CFRetained<CFData>>
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.
Sourcepub fn key_list(&self) -> Option<CFRetained<CFArray>>
pub fn key_list(&self) -> Option<CFRetained<CFArray>>
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.
Sourcepub fn value(&self, key: &CFString) -> Option<CFRetained<CFPropertyList>>
pub fn value(&self, key: &CFString) -> Option<CFRetained<CFPropertyList>>
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.
Sourcepub unsafe fn add_value(&self, key: &CFString, value: &CFPropertyList) -> bool
pub unsafe fn add_value(&self, key: &CFString, value: &CFPropertyList) -> bool
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.
Sourcepub unsafe fn set_value(&self, key: &CFString, value: &CFPropertyList) -> bool
pub unsafe fn set_value(&self, key: &CFString, value: &CFPropertyList) -> bool
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.
Sourcepub fn remove_value(&self, key: &CFString) -> bool
pub fn remove_value(&self, key: &CFString) -> bool
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.
Sourcepub unsafe fn set_callback(
&self,
callout: SCPreferencesCallBack,
context: *mut SCPreferencesContext,
) -> bool
pub unsafe fn set_callback( &self, callout: SCPreferencesCallBack, context: *mut SCPreferencesContext, ) -> bool
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
calloutmust be implemented correctly.contextmust be a valid pointer or null.
Sourcepub fn schedule_with_run_loop(
&self,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> bool
pub fn schedule_with_run_loop( &self, run_loop: &CFRunLoop, run_loop_mode: &CFString, ) -> bool
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.
Sourcepub fn unschedule_from_run_loop(
&self,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> bool
pub fn unschedule_from_run_loop( &self, run_loop: &CFRunLoop, run_loop_mode: &CFString, ) -> bool
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.
Sourcepub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool
Available on crate feature dispatch2 only.
pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool
dispatch2 only.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.
Sourcepub fn synchronize(&self)
pub fn synchronize(&self)
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.
Source§impl SCPreferences
impl SCPreferences
Sourcepub fn path_create_unique_child(
&self,
prefix: &CFString,
) -> Option<CFRetained<CFString>>
Available on crate feature SCPreferencesPath only.
pub fn path_create_unique_child( &self, prefix: &CFString, ) -> Option<CFRetained<CFString>>
SCPreferencesPath only.Creates a new path component within the dictionary hierarchy.
Parameter prefs: The preferences session.
Parameter prefix: A string that represents the parent path.
Returns: Returns a string representing the new (unique) child path; NULL if the specified path does not exist.
Sourcepub fn path_get_value(
&self,
path: &CFString,
) -> Option<CFRetained<CFDictionary>>
Available on crate feature SCPreferencesPath only.
pub fn path_get_value( &self, path: &CFString, ) -> Option<CFRetained<CFDictionary>>
SCPreferencesPath only.Returns the dictionary associated with the specified path.
Parameter prefs: The preferences session.
Parameter path: A string that represents the path to be returned.
Returns: Returns the dictionary associated with the specified path; NULL if the path does not exist.
Sourcepub fn path_get_link(&self, path: &CFString) -> Option<CFRetained<CFString>>
Available on crate feature SCPreferencesPath only.
pub fn path_get_link(&self, path: &CFString) -> Option<CFRetained<CFString>>
SCPreferencesPath only.Returns the link (if one exists) associated with the specified path.
Parameter prefs: The preferences session.
Parameter path: A string that represents the path to be returned.
Returns: Returns the dictionary associated with the specified path; NULL if the path is not a link or does not exist.
Sourcepub unsafe fn path_set_value(
&self,
path: &CFString,
value: &CFDictionary,
) -> bool
Available on crate feature SCPreferencesPath only.
pub unsafe fn path_set_value( &self, path: &CFString, value: &CFDictionary, ) -> bool
SCPreferencesPath only.Associates a dictionary with the specified path.
Parameter prefs: The preferences session.
Parameter path: A string that represents the path to be updated.
Parameter value: A dictionary that represents the data to be
stored at the specified path.
Returns: Returns TRUE if successful; FALSE otherwise.
§Safety
value generics must be of the correct type.
Sourcepub fn path_set_link(&self, path: &CFString, link: &CFString) -> bool
Available on crate feature SCPreferencesPath only.
pub fn path_set_link(&self, path: &CFString, link: &CFString) -> bool
SCPreferencesPath only.Associates a link to a second dictionary at the specified path.
Parameter prefs: The preferences session.
Parameter path: A string that represents the path to be updated.
Parameter link: A string that represents the link to be stored
at the specified path.
Returns: Returns TRUE if successful; FALSE otherwise.
Sourcepub fn path_remove_value(&self, path: &CFString) -> bool
Available on crate feature SCPreferencesPath only.
pub fn path_remove_value(&self, path: &CFString) -> bool
SCPreferencesPath only.Removes the data associated with the specified path.
Parameter prefs: The preferences session.
Parameter path: A string that represents the path to be returned.
Returns: Returns TRUE if successful; FALSE otherwise.
Source§impl SCPreferences
impl SCPreferences
Sourcepub fn set_computer_name(
&self,
name: Option<&CFString>,
name_encoding: CFStringEncoding,
) -> bool
Available on crate feature SCPreferencesSetSpecific only.
pub fn set_computer_name( &self, name: Option<&CFString>, name_encoding: CFStringEncoding, ) -> bool
SCPreferencesSetSpecific only.Updates the computer name preference.
Note: To commit these changes to permanent storage you must call the SCPreferencesCommitChanges function. In addition, you must call the SCPreferencesApplyChanges function for the new name to become active.
Parameter prefs: The preferences session.
Parameter name: The computer name to be set.
Parameter nameEncoding: The encoding associated with the computer name.
Returns: Returns TRUE if successful; FALSE otherwise.
Sourcepub fn set_local_host_name(&self, name: Option<&CFString>) -> bool
Available on crate feature SCPreferencesSetSpecific only.
pub fn set_local_host_name(&self, name: Option<&CFString>) -> bool
SCPreferencesSetSpecific only.Updates the local host name.
Note: To commit these changes to permanent storage you must call the SCPreferencesCommitChanges function. In addition, you must call the SCPreferencesApplyChanges function for the new name to become active.
Parameter prefs: The preferences session.
Parameter name: The local host name to be set.
Note: this string must conform to the naming conventions of a DNS host name as specified in RFC 1034 (section 3.5).
Returns: Returns TRUE if successful; FALSE otherwise.
Methods from Deref<Target = CFType>§
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: ConcreteType,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: ConcreteType,
Attempt to downcast the type to that of type T.
This is the reference-variant. Use CFRetained::downcast if you
want to convert a retained type. See also ConcreteType for more
details on which types support being converted to.
Sourcepub fn retain_count(&self) -> usize
pub fn retain_count(&self) -> usize
Get the reference count of the object.
This function may be useful for debugging. You normally do not use this function otherwise.
Beware that some things (like CFNumbers, small CFStrings etc.) may
not have a normal retain count for optimization purposes, and can
return usize::MAX in that case.
Trait Implementations§
Source§impl AsRef<AnyObject> for SCPreferences
impl AsRef<AnyObject> for SCPreferences
Source§impl AsRef<CFType> for SCPreferences
impl AsRef<CFType> for SCPreferences
Source§impl AsRef<SCPreferences> for SCPreferences
impl AsRef<SCPreferences> for SCPreferences
Source§impl Borrow<AnyObject> for SCPreferences
impl Borrow<AnyObject> for SCPreferences
Source§impl Borrow<CFType> for SCPreferences
impl Borrow<CFType> for SCPreferences
Source§impl ConcreteType for SCPreferences
impl ConcreteType for SCPreferences
Source§impl Debug for SCPreferences
impl Debug for SCPreferences
Source§impl Deref for SCPreferences
impl Deref for SCPreferences
Source§impl Hash for SCPreferences
impl Hash for SCPreferences
Source§impl Message for SCPreferences
impl Message for SCPreferences
Source§impl PartialEq for SCPreferences
impl PartialEq for SCPreferences
Source§impl RefEncode for SCPreferences
impl RefEncode for SCPreferences
Source§const ENCODING_REF: Encoding
const ENCODING_REF: Encoding
Source§impl Type for SCPreferences
impl Type for SCPreferences
Source§fn retain(&self) -> CFRetained<Self>where
Self: Sized,
fn retain(&self) -> CFRetained<Self>where
Self: Sized,
Source§fn as_concrete_TypeRef(&self) -> &Self
fn as_concrete_TypeRef(&self) -> &Self
core-foundation crate.Source§unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
core-foundation crate. Read moreSource§fn as_CFTypeRef(&self) -> &CFType
fn as_CFTypeRef(&self) -> &CFType
core-foundation crate.Source§unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
core-foundation crate. Read more