SCPreferences.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. {
  2. * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  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
  11. * file.
  12. *
  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.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. }
  23. { Pascal Translation: Peter N Lewis, <[email protected]>, 2004 }
  24. {
  25. Modified for use with Free Pascal
  26. Version 200
  27. Please report any bugs to <[email protected]>
  28. }
  29. {$mode macpas}
  30. {$packenum 1}
  31. {$macro on}
  32. {$inline on}
  33. {$CALLING MWPASCAL}
  34. unit SCPreferences;
  35. interface
  36. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  37. {$setc GAP_INTERFACES_VERSION := $0200}
  38. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  39. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  40. {$endc}
  41. {$ifc defined CPUPOWERPC and defined CPUI386}
  42. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  43. {$endc}
  44. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  45. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  46. {$endc}
  47. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  48. {$setc __ppc__ := 1}
  49. {$elsec}
  50. {$setc __ppc__ := 0}
  51. {$endc}
  52. {$ifc not defined __i386__ and defined CPUI386}
  53. {$setc __i386__ := 1}
  54. {$elsec}
  55. {$setc __i386__ := 0}
  56. {$endc}
  57. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  58. {$error Conflicting definitions for __ppc__ and __i386__}
  59. {$endc}
  60. {$ifc defined __ppc__ and __ppc__}
  61. {$setc TARGET_CPU_PPC := TRUE}
  62. {$setc TARGET_CPU_X86 := FALSE}
  63. {$elifc defined __i386__ and __i386__}
  64. {$setc TARGET_CPU_PPC := FALSE}
  65. {$setc TARGET_CPU_X86 := TRUE}
  66. {$elsec}
  67. {$error Neither __ppc__ nor __i386__ is defined.}
  68. {$endc}
  69. {$setc TARGET_CPU_PPC_64 := FALSE}
  70. {$ifc defined FPC_BIG_ENDIAN}
  71. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  72. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  73. {$elifc defined FPC_LITTLE_ENDIAN}
  74. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  75. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  76. {$elsec}
  77. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  78. {$endc}
  79. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  80. {$setc CALL_NOT_IN_CARBON := FALSE}
  81. {$setc OLDROUTINENAMES := FALSE}
  82. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  83. {$setc OPAQUE_UPP_TYPES := TRUE}
  84. {$setc OTCARBONAPPLICATION := TRUE}
  85. {$setc OTKERNEL := FALSE}
  86. {$setc PM_USE_SESSION_APIS := TRUE}
  87. {$setc TARGET_API_MAC_CARBON := TRUE}
  88. {$setc TARGET_API_MAC_OS8 := FALSE}
  89. {$setc TARGET_API_MAC_OSX := TRUE}
  90. {$setc TARGET_CARBON := TRUE}
  91. {$setc TARGET_CPU_68K := FALSE}
  92. {$setc TARGET_CPU_MIPS := FALSE}
  93. {$setc TARGET_CPU_SPARC := FALSE}
  94. {$setc TARGET_OS_MAC := TRUE}
  95. {$setc TARGET_OS_UNIX := FALSE}
  96. {$setc TARGET_OS_WIN32 := FALSE}
  97. {$setc TARGET_RT_MAC_68881 := FALSE}
  98. {$setc TARGET_RT_MAC_CFM := FALSE}
  99. {$setc TARGET_RT_MAC_MACHO := TRUE}
  100. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  101. {$setc TYPE_BOOL := FALSE}
  102. {$setc TYPE_EXTENDED := FALSE}
  103. {$setc TYPE_LONGLONG := TRUE}
  104. uses MacTypes,CFBase,SCDynamicStore,CFDate,CFPropertyList,CFArray,CFData;
  105. {$ALIGN MAC68K}
  106. {!
  107. @header SCPreferences
  108. The SCPreferencesXXX() APIs allow an application to load and
  109. store XML configuration data in a controlled manner and provide
  110. the necessary notifications to other applications that need to
  111. be aware of configuration changes.
  112. The stored XML configuration data is accessed using a prefsID. A
  113. NULL value indicates that the default system preferences are to
  114. be accessed.
  115. A string which starts with a leading "/" character specifies the
  116. path to the file containing te preferences to be accessed.
  117. A string which does not start with a leading "/" character
  118. specifies a file relative to the default system preferences
  119. directory.
  120. }
  121. {!
  122. @typedef SCPreferencesRef
  123. @discussion This is the handle to an open "session" for
  124. accessing system configuration preferences.
  125. }
  126. type
  127. SCPreferencesRef = ^SInt32; { an opaque 32-bit type }
  128. {!
  129. @function SCPreferencesGetTypeID
  130. Returns the type identifier of all SCPreferences instances.
  131. }
  132. function SCPreferencesGetTypeID: CFTypeID; external name '_SCPreferencesGetTypeID';
  133. {!
  134. @function SCPreferencesCreate
  135. @discussion Initiates access to the per-system set of configuration
  136. preferences.
  137. @param allocator ...
  138. @param name A string that describes the name of the calling
  139. process.
  140. @param prefsID A string that identifies the name of the
  141. group of preferences to be accessed/updated.
  142. @result prefs A pointer to memory that will be filled with an
  143. SCPreferencesRef handle to be used for all subsequent requests.
  144. If a session cannot be established, the contents of
  145. memory pointed to by this parameter are undefined.
  146. }
  147. function SCPreferencesCreate( allocator: CFAllocatorRef; name: CFStringRef; prefsID: CFStringRef ): SCPreferencesRef; external name '_SCPreferencesCreate';
  148. {!
  149. @function SCPreferencesLock
  150. @discussion Locks access to the configuration preferences.
  151. This function obtains exclusive access to the configuration
  152. preferences associated with this prefsID. Clients attempting
  153. to obtain exclusive access to the preferences will either receive
  154. an kSCStatusPrefsBusy error or block waiting for the lock to be
  155. released.
  156. @param session An SCPreferencesRef handle that should be used for
  157. all API calls.
  158. @param wait A boolean flag indicating whether the calling process
  159. should block waiting for another process to complete its update
  160. operation and release its lock.
  161. @result TRUE if the lock was obtained; FALSE if an error occurred.
  162. }
  163. function SCPreferencesLock( session: SCPreferencesRef; wait: Boolean ): Boolean; external name '_SCPreferencesLock';
  164. {!
  165. @function SCPreferencesCommitChanges
  166. @discussion Commits changes made to the configuration preferences to
  167. persitent storage.
  168. This function commits any changes to permanent storage. An
  169. implicit call to SCPreferencesLock/SCPreferencesUnlock will
  170. be made if exclusive access has not already been established.
  171. Note: This routine commits changes to persistent storage.
  172. Call SCPreferencesApplyChanges() to apply the changes
  173. to the running system.
  174. @param session An SCPreferencesRef handle that should be used for
  175. all API calls.
  176. @result TRUE if the lock was obtained; FALSE if an error occurred.
  177. }
  178. function SCPreferencesCommitChanges( session: SCPreferencesRef ): Boolean; external name '_SCPreferencesCommitChanges';
  179. {!
  180. @function SCPreferencesApplyChanges
  181. @discussion Requests that the currently stored configuration
  182. preferences be applied to the active configuration.
  183. @param session An SCPreferencesRef handle that should be used for
  184. all API calls.
  185. @result TRUE if the lock was obtained; FALSE if an error occurred.
  186. }
  187. function SCPreferencesApplyChanges( session: SCPreferencesRef ): Boolean; external name '_SCPreferencesApplyChanges';
  188. {!
  189. @function SCPreferencesUnlock
  190. @discussion Releases exclusive access to the configuration preferences.
  191. This function releases the exclusive access "lock" for this prefsID.
  192. Other clients will be now be able to establish exclusive access to
  193. the preferences.
  194. @param session An SCPreferencesRef handle that should be used for
  195. all API calls.
  196. @result TRUE if the lock was obtained; FALSE if an error occurred.
  197. }
  198. function SCPreferencesUnlock( session: SCPreferencesRef ): Boolean; external name '_SCPreferencesUnlock';
  199. {!
  200. @function SCPreferencesGetSignature
  201. @discussion Returns a sequence of bytes that can be used to determine
  202. if the saved configuration preferences have changed.
  203. @param session An SCPreferencesRef handle that should be used for
  204. all API calls.
  205. @param signature A pointer to a CFDataRef that will reflect
  206. the signature of the configuration preferences at the time
  207. of the call to SCPreferencesCreate().
  208. @result A CFDataRef that reflects the signature of the configuration
  209. preferences at the time of the call to SCPreferencesCreate().
  210. }
  211. function SCPreferencesGetSignature( session: SCPreferencesRef ): CFDataRef; external name '_SCPreferencesGetSignature';
  212. {!
  213. @function SCPreferencesCopyKeyList
  214. @discussion Returns an array of currently defined preference keys.
  215. @param session An SCPreferencesRef handle that should be used for
  216. all API calls.
  217. @result The list of keys. You must release the returned value.
  218. }
  219. function SCPreferencesCopyKeyList( session: SCPreferencesRef ): CFArrayRef; external name '_SCPreferencesCopyKeyList';
  220. {!
  221. @function SCPreferencesGetValue
  222. @discussion Returns the data associated with a preference key.
  223. This function retrieves data associated with a key for the prefsID.
  224. Note: You could read stale data and not know it, unless you
  225. first call SCPreferencesLock().
  226. @param session An SCPreferencesRef handle that should be used for
  227. all API calls.
  228. @param key The preference key to be returned.
  229. @result The value associated with the specified preference key; If no
  230. value was located, NULL is returned.
  231. }
  232. function SCPreferencesGetValue( session: SCPreferencesRef; key: CFStringRef ): CFPropertyListRef; external name '_SCPreferencesGetValue';
  233. {!
  234. @function SCPreferencesAddValue
  235. @discussion Adds data for a preference key.
  236. This function associates new data with the specified key. In order
  237. to commit these changes to permanent storage a call must be made to
  238. SCPreferencesCommitChanges().
  239. @param session The SCPreferencesRef handle that should be used to
  240. communicate with the APIs.
  241. @param key The preference key to be updated.
  242. @param value The CFPropertyListRef object containing the
  243. value to be associated with the specified preference key.
  244. @result TRUE if the value was added; FALSE if the key already exists or
  245. if an error occurred.
  246. }
  247. function SCPreferencesAddValue( session: SCPreferencesRef; key: CFStringRef; value: CFPropertyListRef ): Boolean; external name '_SCPreferencesAddValue';
  248. {!
  249. @function SCPreferencesSetValue
  250. @discussion Updates the data associated with a preference key.
  251. This function adds or replaces the value associated with the
  252. specified key. In order to commit these changes to permanent
  253. storage a call must be made to SCPreferencesCommitChanges().
  254. @param session The SCPreferencesRef handle that should be used to
  255. communicate with the APIs.
  256. @param key The preference key to be updated.
  257. @param value The CFPropertyListRef object containing the
  258. data to be associated with the specified preference key.
  259. @result TRUE if the value was set; FALSE if an error occurred.
  260. }
  261. function SCPreferencesSetValue( session: SCPreferencesRef; key: CFStringRef; value: CFPropertyListRef ): Boolean; external name '_SCPreferencesSetValue';
  262. {!
  263. @function SCPreferencesRemoveValue
  264. @discussion Removes the data associated with a preference key.
  265. This function removes the data associated with the specified
  266. key. In order to commit these changes to permanent storage a
  267. call must be made to SCPreferencesCommitChanges().
  268. @param session The SCPreferencesRef handle that should be used to
  269. communicate with the APIs.
  270. @param key The preference key to be removed.
  271. @result TRUE if the value was removed; FALSE if the key did not exist or
  272. if an error occurred.
  273. }
  274. function SCPreferencesRemoveValue( session: SCPreferencesRef; key: CFStringRef ): Boolean; external name '_SCPreferencesRemoveValue';
  275. end.