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::*;
#[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 {}
);
#[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);
}
#[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);
}
pub type SCPreferencesCallBack = Option<
unsafe extern "C-unwind" fn(NonNull<SCPreferences>, SCPreferencesNotification, *mut c_void),
>;
unsafe impl ConcreteType for SCPreferences {
#[doc(alias = "SCPreferencesGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn SCPreferencesGetTypeID() -> CFTypeID;
}
unsafe { SCPreferencesGetTypeID() }
}
}
impl SCPreferences {
#[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) })
}
#[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) })
}
#[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
}
#[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
}
#[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
}
#[doc(alias = "SCPreferencesUnlock")]
#[inline]
pub fn unlock(&self) -> bool {
extern "C-unwind" {
fn SCPreferencesUnlock(prefs: &SCPreferences) -> Boolean;
}
let ret = unsafe { SCPreferencesUnlock(self) };
ret != 0
}
#[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) })
}
#[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) })
}
#[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) })
}
#[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
}
#[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
}
#[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
}
#[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
}
#[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
}
#[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
}
#[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
}
#[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) }
}