2 * Copyright (c) 2000, 2001, 2004, 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _SCPREFERENCES_H
25 #define _SCPREFERENCES_H
27 #include <AvailabilityMacros.h>
28 #include <sys/cdefs.h>
29 #include <CoreFoundation/CoreFoundation.h>
30 #include <SystemConfiguration/SCDynamicStore.h>
35 @discussion The SCPreferences API allows an application to load and
36 store XML configuration data in a controlled manner and provide
37 the necessary notifications to other applications that need to
38 be aware of configuration changes.
40 To access configuration preferences, you must first establish a
41 preferences session using the SCPreferencesCreate function.
42 To identify a specific set of preferences to access, you pass a
43 value in the prefsID parameter.
44 A NULL value indicates that the default system preferences are
46 A string that starts with a leading "/" character specifies
47 the absolute path to the file containing the preferences to
49 A string that does not start with a leading "/" character
50 specifies a file relative to the default system preferences
53 When you are finished with the preferences session, use
54 CFRelease to close it.
59 @typedef SCPreferencesRef
60 @discussion This is the handle to an open preferences session for
61 accessing system configuration preferences.
63 typedef const struct __SCPreferences
* SCPreferencesRef
;
65 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
68 @enum SCPreferencesNotification
69 @discussion Used with the SCPreferencesCallBack callback
70 to describe the type of notification.
71 @constant kSCPreferencesNotificationCommit Indicates when new
72 preferences have been saved.
73 @constant kSCPreferencesNotificationApply Key Indicates when a
74 request has been made to apply the currently saved
75 preferences to the active system configuration.
78 kSCPreferencesNotificationCommit
= 1<<0,
79 kSCPreferencesNotificationApply
= 1<<1
81 typedef uint32_t SCPreferencesNotification
;
84 @typedef SCPreferencesContext
85 Structure containing user-specified data and callbacks for SCPreferences.
86 @field version The version number of the structure type being passed
87 in as a parameter to the SCPreferencesSetCallback function.
88 This structure is version 0.
89 @field info A C pointer to a user-specified block of data.
90 @field retain The callback used to add a retain for the info field.
91 If this parameter is not a pointer to a function of the correct
92 prototype, the behavior is undefined.
93 The value may be NULL.
94 @field release The calllback used to remove a retain previously added
96 If this parameter is not a pointer to a function of the
97 correct prototype, the behavior is undefined.
98 The value may be NULL.
99 @field copyDescription The callback used to provide a description of
105 const void *(*retain
)(const void *info
);
106 void (*release
)(const void *info
);
107 CFStringRef (*copyDescription
)(const void *info
);
108 } SCPreferencesContext
;
111 @typedef SCPreferencesCallBack
112 @discussion Type of the callback function used when the
113 preferences have been updated and/or applied.
114 @param prefs The preferences session.
115 @param notificationType The type of notification, such as changes
116 committed, changes applied, etc.
117 @param info A C pointer to a user-specified block of data.
119 typedef void (*SCPreferencesCallBack
) (
120 SCPreferencesRef prefs
,
121 SCPreferencesNotification notificationType
,
125 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 */
131 @function SCPreferencesGetTypeID
132 @discussion Returns the type identifier of all SCPreferences instances.
135 SCPreferencesGetTypeID (void);
138 @function SCPreferencesCreate
139 @discussion Initiates access to the per-system set of configuration
141 @param allocator The CFAllocator that should be used to allocate
142 memory for this preferences session.
143 This parameter may be NULL in which case the current
144 default CFAllocator is used.
145 If this reference is not a valid CFAllocator, the behavior
147 @param name A string that describes the name of the calling
149 @param prefsID A string that identifies the name of the
150 group of preferences to be accessed or updated.
151 @result Returns a reference to the new SCPreferences.
152 You must release the returned value.
155 SCPreferencesCreate (
156 CFAllocatorRef allocator
,
162 @function SCPreferencesLock
163 @discussion Locks access to the configuration preferences.
165 This function obtains exclusive access to the configuration
166 preferences. Clients attempting to obtain exclusive access
167 to the preferences will either receive a kSCStatusPrefsBusy
168 error or block waiting for the lock to be released.
169 @param prefs The preferences session.
170 @param wait A boolean flag indicating whether the calling process
171 should block waiting for another process to complete its update
172 operation and release its lock.
173 @result Returns TRUE if the lock was obtained;
174 FALSE if an error occurred.
178 SCPreferencesRef prefs
,
183 @function SCPreferencesCommitChanges
184 @discussion Commits changes made to the configuration preferences to
187 This function commits any changes to permanent storage.
188 Implicit calls to the SCPreferencesLock and SCPreferencesUnlock
189 functions will be made if exclusive access has not already been
192 Note: This routine commits changes to persistent storage.
193 Call the SCPreferencesApplyChanges function to apply the
194 changes to the running system.
195 @param prefs The preferences session.
196 @result Returns TRUE if the lock was obtained;
197 FALSE if an error occurred.
200 SCPreferencesCommitChanges (
201 SCPreferencesRef prefs
205 @function SCPreferencesApplyChanges
206 @discussion Requests that the currently stored configuration
207 preferences be applied to the active configuration.
208 @param prefs The preferences session.
209 @result Returns TRUE if the lock was obtained;
210 FALSE if an error occurred.
213 SCPreferencesApplyChanges (
214 SCPreferencesRef prefs
218 @function SCPreferencesUnlock
219 @discussion Releases exclusive access to the configuration preferences.
221 This function releases the exclusive access lock to the
222 preferences. Other clients will be now be able to establish
223 exclusive access to the preferences.
224 @param prefs The preferences session.
225 @result Returns TRUE if the lock was obtained;
226 FALSE if an error occurred.
229 SCPreferencesUnlock (
230 SCPreferencesRef prefs
234 @function SCPreferencesGetSignature
235 @discussion Returns a sequence of bytes that can be used to determine
236 if the saved configuration preferences have changed.
237 @param prefs The preferences session.
238 @result Returns a CFDataRef that reflects the signature of the configuration
239 preferences at the time of the call to the SCPreferencesCreate function.
242 SCPreferencesGetSignature (
243 SCPreferencesRef prefs
247 @function SCPreferencesCopyKeyList
248 @discussion Returns an array of currently defined preference keys.
249 @param prefs The preferences session.
250 @result Returns the list of keys.
251 You must release the returned value.
254 SCPreferencesCopyKeyList (
255 SCPreferencesRef prefs
259 @function SCPreferencesGetValue
260 @discussion Returns the data associated with a preference key.
262 This function retrieves data associated with the specified
265 Note: To avoid inadvertantly reading stale data, first call
266 the SCPreferencesLock function.
267 @param prefs The preferences session.
268 @param key The preference key to be returned.
269 @result Returns the value associated with the specified preference key;
270 NULL if no value was located.
273 SCPreferencesGetValue (
274 SCPreferencesRef prefs
,
279 @function SCPreferencesAddValue
280 @discussion Adds data for a preference key.
282 This function associates new data with the specified key.
283 To commit these changes to permanent storage, a call must
284 be made to the SCPreferencesCommitChanges function.
285 @param prefs The preferences session.
286 @param key The preference key to be updated.
287 @param value The CFPropertyListRef object containing the
288 value to be associated with the specified preference key.
289 @result Returns TRUE if the value was added;
290 FALSE if the key already exists or
291 if an error occurred.
294 SCPreferencesAddValue (
295 SCPreferencesRef prefs
,
297 CFPropertyListRef value
301 @function SCPreferencesSetValue
302 @discussion Updates the data associated with a preference key.
304 This function adds or replaces the value associated with the
305 specified key. To commit these changes to permanent storage
306 a call must be made to the SCPreferencesCommitChanges function.
307 @param prefs The preferences session.
308 @param key The preference key to be updated.
309 @param value The CFPropertyListRef object containing the
310 data to be associated with the specified preference key.
311 @result Returns TRUE if the value was set;
312 FALSE if an error occurred.
315 SCPreferencesSetValue (
316 SCPreferencesRef prefs
,
318 CFPropertyListRef value
322 @function SCPreferencesRemoveValue
323 @discussion Removes the data associated with a preference key.
325 This function removes the data associated with the specified
326 key. To commit these changes to permanent storage a call must
327 be made to the SCPreferencesCommitChanges function.
328 @param prefs The preferences session.
329 @param key The preference key to be removed.
330 @result Returns TRUE if the value was removed;
331 FALSE if the key did not exist or if an error occurred.
334 SCPreferencesRemoveValue (
335 SCPreferencesRef prefs
,
339 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
342 @function SCPreferencesSetCallback
343 @discussion Assigns a callback to a preferences session. The function
344 is called when the changes to the preferences have been
345 committed or applied.
346 @param prefs The preferences session.
347 @param callout The function to be called when the preferences have
348 been changed or applied.
349 If NULL, the current callback is removed.
350 @param context The SCPreferencesContext associated with
352 @result Returns TRUE if the notification client was successfully set.
355 SCPreferencesSetCallback (
356 SCPreferencesRef prefs
,
357 SCPreferencesCallBack callout
,
358 SCPreferencesContext
*context
359 ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
;
362 @function SCPreferencesScheduleWithRunLoop
363 @discussion Schedule commit and apply notifications for the specified
364 preferences session using the specified run loop and mode.
365 @param prefs The preferences session.
366 @param runLoop A reference to a run loop on which the notification
369 @param runLoopMode The mode on which to schedule the notification.
371 @result Returns TRUE if the notifications are successfully scheduled;
375 SCPreferencesScheduleWithRunLoop (
376 SCPreferencesRef prefs
,
377 CFRunLoopRef runLoop
,
378 CFStringRef runLoopMode
379 ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
;
382 @function SCPreferencesUnscheduleFromRunLoop
383 @discussion Unschedule commit and apply notifications for the specified
384 preferences session from the specified run loop and mode.
385 @param prefs The preferences session.
386 @param runLoop A reference to a run loop from which the notification
387 should be unscheduled.
389 @param runLoopMode The mode on which to unschedule the notification.
391 @result Returns TRUE if the notifications are successfully unscheduled;
395 SCPreferencesUnscheduleFromRunLoop (
396 SCPreferencesRef prefs
,
397 CFRunLoopRef runLoop
,
398 CFStringRef runLoopMode
399 ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
;
402 @function SCPreferencesSynchronize
403 @discussion Synchronizes accessed preferences with committed changes.
405 Any references to preference values returned by calls to the
406 SCPreferencesGetValue function are no longer valid unless they
407 were explicitly retained or copied. Any preference values
408 that were updated (add, set, remove) but not committed will
410 @param prefs The preferences session.
413 SCPreferencesSynchronize (
414 SCPreferencesRef prefs
415 ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
;
417 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 */
421 #endif /* _SCPREFERENCES_H */