objc2_system_configuration/generated/SCDynamicStore.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
11use crate::*;
12
13/// This is the handle to an open a dynamic store session
14/// with the system configuration daemon.
15///
16/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scdynamicstore?language=objc)
17#[repr(C)]
18pub struct SCDynamicStore {
19 inner: [u8; 0],
20 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
21}
22
23cf_type!(
24 #[encoding_name = "__SCDynamicStore"]
25 unsafe impl SCDynamicStore {}
26);
27
28/// Structure containing user-specified data and callbacks for an
29/// SCDynamicStore session.
30/// Field: version The version number of the structure type being passed
31/// in as a parameter to the SCDynamicStore creation function.
32/// This structure is version 0.
33/// Field: info A C pointer to a user-specified block of data.
34/// Field: retain The callback used to add a retain for the info field.
35/// If this parameter is not a pointer to a function of the correct
36/// prototype, the behavior is undefined. The value may be NULL.
37/// Field: release The calllback used to remove a retain previously added
38/// for the info field. If this parameter is not a pointer to a
39/// function of the correct prototype, the behavior is undefined.
40/// The value may be NULL.
41/// Field: copyDescription The callback used to provide a description of
42/// the info field.
43///
44/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scdynamicstorecontext?language=objc)
45#[repr(C)]
46#[derive(Clone, Copy, Debug, PartialEq)]
47pub struct SCDynamicStoreContext {
48 pub version: CFIndex,
49 pub info: *mut c_void,
50 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
51 pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
52 pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
53}
54
55#[cfg(feature = "objc2")]
56unsafe impl Encode for SCDynamicStoreContext {
57 const ENCODING: Encoding = Encoding::Struct(
58 "?",
59 &[
60 <CFIndex>::ENCODING,
61 <*mut c_void>::ENCODING,
62 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
63 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
64 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
65 ],
66 );
67}
68
69#[cfg(feature = "objc2")]
70unsafe impl RefEncode for SCDynamicStoreContext {
71 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
72}
73
74/// Type of callback function used when notification of
75/// changes to the dynamic store is delivered.
76///
77/// Parameter `store`: The dynamic store session.
78///
79/// Parameter `changedKeys`: The list of changed keys.
80///
81/// The list includes any specific SCDynamicStore keys that
82/// changed (add, update, remove, notify) since the last call
83/// to SCDynamicStoreSetNotificationKeys or since the last
84/// notification callback. The list also includes any specific
85/// keys matching one of the pattern string(s) that changed.
86///
87/// An empty list indicates that the SCDynamicStore server
88/// restarted and that any assumptions based on prior content
89/// of the SCDynamicStore should be discarded.
90///
91///
92/// Parameter `info`: A C pointer to a user-specified block of data.
93///
94/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scdynamicstorecallback?language=objc)
95pub type SCDynamicStoreCallBack =
96 Option<unsafe extern "C-unwind" fn(NonNull<SCDynamicStore>, NonNull<CFArray>, *mut c_void)>;
97
98unsafe impl ConcreteType for SCDynamicStore {
99 /// Returns the type identifier of all SCDynamicStore instances.
100 #[doc(alias = "SCDynamicStoreGetTypeID")]
101 #[inline]
102 fn type_id() -> CFTypeID {
103 extern "C-unwind" {
104 fn SCDynamicStoreGetTypeID() -> CFTypeID;
105 }
106 unsafe { SCDynamicStoreGetTypeID() }
107 }
108}
109
110/// Creates a new session used to interact with the dynamic
111/// store maintained by the System Configuration server.
112///
113/// Parameter `allocator`: The CFAllocator that should be used to allocate
114/// memory for the local dynamic store object.
115/// This parameter may be NULL in which case the current
116/// default CFAllocator is used. If this reference is not
117/// a valid CFAllocator, the behavior is undefined.
118///
119/// Parameter `name`: A string that describes the name of the calling
120/// process or plug-in of the caller.
121///
122/// Parameter `callout`: The function to be called when a watched value
123/// in the dynamic store is changed.
124/// A NULL value can be specified if no callouts are
125/// desired.
126///
127/// Parameter `context`: The SCDynamicStoreContext associated with the callout.
128///
129/// Returns: Returns a reference to the new SCDynamicStore session.
130/// You must release the returned value.
131#[inline]
132pub unsafe extern "C-unwind" fn SCDynamicStoreCreate(
133 allocator: Option<&CFAllocator>,
134 name: &CFString,
135 callout: SCDynamicStoreCallBack,
136 context: *mut SCDynamicStoreContext,
137) -> Option<CFRetained<SCDynamicStore>> {
138 extern "C-unwind" {
139 fn SCDynamicStoreCreate(
140 allocator: Option<&CFAllocator>,
141 name: &CFString,
142 callout: SCDynamicStoreCallBack,
143 context: *mut SCDynamicStoreContext,
144 ) -> Option<NonNull<SCDynamicStore>>;
145 }
146 let ret = unsafe { SCDynamicStoreCreate(allocator, name, callout, context) };
147 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
148}
149
150/// Creates a new session used to interact with the dynamic
151/// store maintained by the System Configuration server.
152///
153/// Parameter `allocator`: The CFAllocator that should be used to allocate
154/// memory for the local dynamic store object.
155/// This parameter may be NULL in which case the current
156/// default CFAllocator is used. If this reference is not
157/// a valid CFAllocator, the behavior is undefined.
158///
159/// Parameter `name`: A string that describes the name of the calling
160/// process or plug-in of the caller.
161///
162/// Parameter `storeOptions`: A CFDictionary containing options for the
163/// dynamic store session (such as whether all keys added or set
164/// into the dynamic store should be per-session keys).
165///
166/// Currently available options include:
167///
168/// <TABLE
169/// BORDER>
170/// <TR
171/// >
172/// <TH
173/// >key
174/// </TD
175/// >
176/// <TH
177/// >value
178/// </TD
179/// >
180/// </TR
181/// >
182/// <TR
183/// >
184/// <TD
185/// >kSCDynamicStoreUseSessionKeys
186/// </TD
187/// >
188/// <TD
189/// >CFBooleanRef
190/// </TD
191/// >
192/// </TR
193/// >
194/// </TABLE
195/// >
196///
197/// A NULL value can be specified if no options are desired.
198///
199/// Parameter `callout`: The function to be called when a watched value
200/// in the dynamic store is changed.
201/// A NULL value can be specified if no callouts are
202/// desired.
203///
204/// Parameter `context`: The SCDynamicStoreContext associated with the callout.
205///
206/// Returns: Returns a reference to the new SCDynamicStore session.
207/// You must release the returned value.
208#[inline]
209pub unsafe extern "C-unwind" fn SCDynamicStoreCreateWithOptions(
210 allocator: Option<&CFAllocator>,
211 name: &CFString,
212 store_options: Option<&CFDictionary>,
213 callout: SCDynamicStoreCallBack,
214 context: *mut SCDynamicStoreContext,
215) -> Option<CFRetained<SCDynamicStore>> {
216 extern "C-unwind" {
217 fn SCDynamicStoreCreateWithOptions(
218 allocator: Option<&CFAllocator>,
219 name: &CFString,
220 store_options: Option<&CFDictionary>,
221 callout: SCDynamicStoreCallBack,
222 context: *mut SCDynamicStoreContext,
223 ) -> Option<NonNull<SCDynamicStore>>;
224 }
225 let ret = unsafe {
226 SCDynamicStoreCreateWithOptions(allocator, name, store_options, callout, context)
227 };
228 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
229}
230
231extern "C" {
232 /// [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/kscdynamicstoreusesessionkeys?language=objc)
233 pub static kSCDynamicStoreUseSessionKeys: &'static CFString;
234}
235
236/// Creates a CFRunLoopSource object that can be added to the
237/// application's run loop. All dynamic store notifications are
238/// delivered using this run loop source.
239///
240/// Parameter `allocator`: The CFAllocator that should be used to allocate
241/// memory for this run loop source.
242/// This parameter may be NULL in which case the current
243/// default CFAllocator is used. If this reference is not
244/// a valid CFAllocator, the behavior is undefined.
245///
246/// Parameter `store`: A reference to the dynamic store session.
247///
248/// Parameter `order`: On platforms which support it, for source versions
249/// which support it, this parameter determines the order in
250/// which the sources which are ready to be processed are
251/// handled. A lower order number causes processing before
252/// higher order number sources. It is inadvisable to depend
253/// on the order number for any architectural or design aspect
254/// of code. In the absence of any reason to do otherwise,
255/// zero should be used.
256///
257/// Returns: A reference to the new CFRunLoopSource.
258/// You must release the returned value.
259#[inline]
260pub unsafe extern "C-unwind" fn SCDynamicStoreCreateRunLoopSource(
261 allocator: Option<&CFAllocator>,
262 store: &SCDynamicStore,
263 order: CFIndex,
264) -> Option<CFRetained<CFRunLoopSource>> {
265 extern "C-unwind" {
266 fn SCDynamicStoreCreateRunLoopSource(
267 allocator: Option<&CFAllocator>,
268 store: &SCDynamicStore,
269 order: CFIndex,
270 ) -> Option<NonNull<CFRunLoopSource>>;
271 }
272 let ret = unsafe { SCDynamicStoreCreateRunLoopSource(allocator, store, order) };
273 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
274}
275
276/// Returns an array of CFString keys representing the
277/// current dynamic store entries that match a specified pattern.
278///
279/// Parameter `store`: The dynamic store session.
280///
281/// Parameter `pattern`: A regex(3) regular expression pattern
282/// used to match the dynamic store keys.
283///
284/// Returns: Returns the list of matching keys; NULL if an error was
285/// encountered.
286/// You must release the returned value.
287#[inline]
288pub unsafe extern "C-unwind" fn SCDynamicStoreCopyKeyList(
289 store: Option<&SCDynamicStore>,
290 pattern: &CFString,
291) -> Option<CFRetained<CFArray>> {
292 extern "C-unwind" {
293 fn SCDynamicStoreCopyKeyList(
294 store: Option<&SCDynamicStore>,
295 pattern: &CFString,
296 ) -> Option<NonNull<CFArray>>;
297 }
298 let ret = unsafe { SCDynamicStoreCopyKeyList(store, pattern) };
299 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
300}
301
302/// Adds the key-value pair to the dynamic store if no
303/// such key already exists.
304///
305/// Parameter `store`: The dynamic store session.
306///
307/// Parameter `key`: The key of the value to add to the dynamic store.
308///
309/// Parameter `value`: The value to add to the dynamic store.
310///
311/// Returns: Returns TRUE if the key was added; FALSE if the key was already
312/// present in the dynamic store or if an error was encountered.
313#[inline]
314pub unsafe extern "C-unwind" fn SCDynamicStoreAddValue(
315 store: Option<&SCDynamicStore>,
316 key: &CFString,
317 value: &CFPropertyList,
318) -> bool {
319 extern "C-unwind" {
320 fn SCDynamicStoreAddValue(
321 store: Option<&SCDynamicStore>,
322 key: &CFString,
323 value: &CFPropertyList,
324 ) -> Boolean;
325 }
326 let ret = unsafe { SCDynamicStoreAddValue(store, key, value) };
327 ret != 0
328}
329
330/// Temporarily adds the key-value pair to the dynamic store
331/// if no such key already exists. Unless the key is updated by another
332/// session, the key-value pair will be removed automatically when the
333/// session is closed.
334///
335/// Parameter `store`: The dynamic store session.
336///
337/// Parameter `key`: The key of the value to add to the dynamic store.
338///
339/// Parameter `value`: The value to add to the dynamic store.
340///
341/// Returns: Returns TRUE if the key was added; FALSE if the key was already
342/// present in the dynamic store or if an error was encountered.
343#[inline]
344pub unsafe extern "C-unwind" fn SCDynamicStoreAddTemporaryValue(
345 store: &SCDynamicStore,
346 key: &CFString,
347 value: &CFPropertyList,
348) -> bool {
349 extern "C-unwind" {
350 fn SCDynamicStoreAddTemporaryValue(
351 store: &SCDynamicStore,
352 key: &CFString,
353 value: &CFPropertyList,
354 ) -> Boolean;
355 }
356 let ret = unsafe { SCDynamicStoreAddTemporaryValue(store, key, value) };
357 ret != 0
358}
359
360/// Gets the value of the specified key from the dynamic store.
361///
362/// Parameter `store`: The dynamic store session.
363///
364/// Parameter `key`: The key associated with the value you want to get.
365///
366/// Returns: Returns the value from the dynamic store that is associated with the given
367/// key; NULL if no value was located or an error was encountered.
368/// You must release the returned value.
369#[inline]
370pub unsafe extern "C-unwind" fn SCDynamicStoreCopyValue(
371 store: Option<&SCDynamicStore>,
372 key: &CFString,
373) -> Option<CFRetained<CFPropertyList>> {
374 extern "C-unwind" {
375 fn SCDynamicStoreCopyValue(
376 store: Option<&SCDynamicStore>,
377 key: &CFString,
378 ) -> Option<NonNull<CFPropertyList>>;
379 }
380 let ret = unsafe { SCDynamicStoreCopyValue(store, key) };
381 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
382}
383
384/// Gets the values of multiple keys in the dynamic store.
385///
386/// Parameter `store`: The dynamic store session.
387///
388/// Parameter `keys`: The keys associated with the values you want to get; NULL if no specific
389/// keys are requested.
390///
391/// Parameter `patterns`: An array of regex(3) pattern strings used to match the keys; NULL
392/// if no key patterns are requested.
393///
394/// Returns: Returns a dictionary containing the key-value pairs of specific keys and the
395/// key-value pairs of keys that matched the specified patterns;
396/// NULL if an error was encountered.
397/// You must release the returned value.
398#[inline]
399pub unsafe extern "C-unwind" fn SCDynamicStoreCopyMultiple(
400 store: Option<&SCDynamicStore>,
401 keys: Option<&CFArray>,
402 patterns: Option<&CFArray>,
403) -> Option<CFRetained<CFDictionary>> {
404 extern "C-unwind" {
405 fn SCDynamicStoreCopyMultiple(
406 store: Option<&SCDynamicStore>,
407 keys: Option<&CFArray>,
408 patterns: Option<&CFArray>,
409 ) -> Option<NonNull<CFDictionary>>;
410 }
411 let ret = unsafe { SCDynamicStoreCopyMultiple(store, keys, patterns) };
412 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
413}
414
415/// Adds or replaces a value in the dynamic store for
416/// the specified key.
417///
418/// Parameter `store`: The dynamic store session.
419///
420/// Parameter `key`: The key you want to set.
421///
422/// Parameter `value`: The value to add to or replace in the dynamic store.
423///
424/// Returns: Returns TRUE if the key was updated; FALSE if an error was encountered.
425#[inline]
426pub unsafe extern "C-unwind" fn SCDynamicStoreSetValue(
427 store: Option<&SCDynamicStore>,
428 key: &CFString,
429 value: &CFPropertyList,
430) -> bool {
431 extern "C-unwind" {
432 fn SCDynamicStoreSetValue(
433 store: Option<&SCDynamicStore>,
434 key: &CFString,
435 value: &CFPropertyList,
436 ) -> Boolean;
437 }
438 let ret = unsafe { SCDynamicStoreSetValue(store, key, value) };
439 ret != 0
440}
441
442/// Updates multiple values in the dynamic store.
443///
444/// Parameter `store`: The dynamic store session.
445///
446/// Parameter `keysToSet`: A dictionary of key-value pairs you want to set into the dynamic store.
447///
448/// Parameter `keysToRemove`: An array of keys you want to remove from the dynamic store.
449///
450/// Parameter `keysToNotify`: An array of keys to flag as changed (without changing their values).
451///
452/// Returns: Returns TRUE if the dynamic store updates were successful; FALSE if an error was encountered.
453#[inline]
454pub unsafe extern "C-unwind" fn SCDynamicStoreSetMultiple(
455 store: Option<&SCDynamicStore>,
456 keys_to_set: Option<&CFDictionary>,
457 keys_to_remove: Option<&CFArray>,
458 keys_to_notify: Option<&CFArray>,
459) -> bool {
460 extern "C-unwind" {
461 fn SCDynamicStoreSetMultiple(
462 store: Option<&SCDynamicStore>,
463 keys_to_set: Option<&CFDictionary>,
464 keys_to_remove: Option<&CFArray>,
465 keys_to_notify: Option<&CFArray>,
466 ) -> Boolean;
467 }
468 let ret =
469 unsafe { SCDynamicStoreSetMultiple(store, keys_to_set, keys_to_remove, keys_to_notify) };
470 ret != 0
471}
472
473/// Removes the value of the specified key from the
474/// dynamic store.
475///
476/// Parameter `store`: The dynamic store session.
477///
478/// Parameter `key`: The key of the value you want to remove.
479///
480/// Returns: Returns TRUE if the key was removed; FALSE if no value was
481/// located or an error was encountered.
482#[inline]
483pub unsafe extern "C-unwind" fn SCDynamicStoreRemoveValue(
484 store: Option<&SCDynamicStore>,
485 key: &CFString,
486) -> bool {
487 extern "C-unwind" {
488 fn SCDynamicStoreRemoveValue(store: Option<&SCDynamicStore>, key: &CFString) -> Boolean;
489 }
490 let ret = unsafe { SCDynamicStoreRemoveValue(store, key) };
491 ret != 0
492}
493
494/// Triggers a notification to be delivered for the
495/// specified key in the dynamic store.
496///
497/// Parameter `store`: The dynamic store session.
498///
499/// Parameter `key`: The key that should be flagged as changed. Any dynamic store sessions
500/// that are monitoring this key will received a notification. Note that the
501/// key's value is not updated.
502///
503/// Returns: Returns TRUE if the notification was processed; FALSE if an error was encountered.
504#[inline]
505pub unsafe extern "C-unwind" fn SCDynamicStoreNotifyValue(
506 store: Option<&SCDynamicStore>,
507 key: &CFString,
508) -> bool {
509 extern "C-unwind" {
510 fn SCDynamicStoreNotifyValue(store: Option<&SCDynamicStore>, key: &CFString) -> Boolean;
511 }
512 let ret = unsafe { SCDynamicStoreNotifyValue(store, key) };
513 ret != 0
514}
515
516/// Specifies a set of specific keys and key patterns
517/// that should be monitored for changes.
518///
519/// Parameter `store`: The dynamic store session being watched.
520///
521/// Parameter `keys`: An array of keys to be monitored; NULL if no specific keys
522/// are to be monitored.
523///
524/// Parameter `patterns`: An array of regex(3) pattern strings used to match keys to be monitored;
525/// NULL if no key patterns are to be monitored.
526///
527/// Returns: Returns TRUE if the set of notification keys and patterns was successfully
528/// updated; FALSE if an error was encountered.
529#[inline]
530pub unsafe extern "C-unwind" fn SCDynamicStoreSetNotificationKeys(
531 store: &SCDynamicStore,
532 keys: Option<&CFArray>,
533 patterns: Option<&CFArray>,
534) -> bool {
535 extern "C-unwind" {
536 fn SCDynamicStoreSetNotificationKeys(
537 store: &SCDynamicStore,
538 keys: Option<&CFArray>,
539 patterns: Option<&CFArray>,
540 ) -> Boolean;
541 }
542 let ret = unsafe { SCDynamicStoreSetNotificationKeys(store, keys, patterns) };
543 ret != 0
544}
545
546/// Returns an array of CFString keys representing the
547/// dynamic store entries that have changed since this
548/// function was last called. If possible, your application should
549/// use the notification functions instead of polling for the list
550/// of changed keys returned by this function.
551///
552/// Parameter `store`: The dynamic store session.
553///
554/// Returns: Returns the list of changed keys;
555/// NULL if an error was encountered.
556/// You must release the returned value.
557#[inline]
558pub unsafe extern "C-unwind" fn SCDynamicStoreCopyNotifiedKeys(
559 store: &SCDynamicStore,
560) -> Option<CFRetained<CFArray>> {
561 extern "C-unwind" {
562 fn SCDynamicStoreCopyNotifiedKeys(store: &SCDynamicStore) -> Option<NonNull<CFArray>>;
563 }
564 let ret = unsafe { SCDynamicStoreCopyNotifiedKeys(store) };
565 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
566}