SCDynamicStore.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. {
  2. * Copyright (c) 2000 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 SCDynamicStore;
  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,CFArray,CFRunLoop,CFPropertyList,CFDictionary;
  105. {$ALIGN MAC68K}
  106. {!
  107. @header SCDynamicStore
  108. The SystemConfiguration framework provides access to the
  109. data used to configure a running system. The APIs provided
  110. by this framework communicate with the "configd" daemon.
  111. The "configd" daemon manages a "dynamic store" reflecting the
  112. desired configuration settings as well as the current state
  113. of the system. The daemon provides a notification mechanism
  114. for user-level processes that need to be aware of changes
  115. made to the data. Lastly, the daemon loads a number of
  116. bundles (or plug-ins) that monitor low-level kernel events
  117. and, via a set of policy modules, keep the state data up
  118. to date.
  119. }
  120. {!
  121. @typedef SCDynamicStoreRef
  122. @discussion This is the handle to an open "dynamic store" session
  123. with the system configuration daemon.
  124. }
  125. type
  126. SCDynamicStoreRef = ^SInt32; { an opaque 32-bit type }
  127. {!
  128. @typedef SCDynamicStoreContext
  129. }
  130. type
  131. SCDynamicStoreContext = record
  132. version: CFIndex;
  133. info: Ptr;
  134. retain: function( info: Ptr ): Ptr;
  135. release: procedure( info: Ptr );
  136. copyDescription: function( info: Ptr ): CFStringRef;
  137. end;
  138. SCDynamicStoreContextPtr = ^SCDynamicStoreContext;
  139. {!
  140. @typedef SCDynamicStoreCallBack
  141. @discussion Type of the callback function used when a
  142. dynamic store change is delivered.
  143. @param store The "dynamic store" session.
  144. @param changedKeys The list of changed keys.
  145. @param info ....
  146. }
  147. type SCDynamicStoreCallBack = procedure( store: SCDynamicStoreRef; changedKeys: CFArrayRef; info: Ptr );
  148. {!
  149. @function SCDynamicStoreGetTypeID
  150. Returns the type identifier of all SCDynamicStore instances.
  151. }
  152. function SCDynamicStoreGetTypeID: CFTypeID; external name '_SCDynamicStoreGetTypeID';
  153. {!
  154. @function SCDynamicStoreCreate
  155. @discussion Creates a new session used to interact with the dynamic
  156. store maintained by the SystemConfiguration server.
  157. @param allocator The CFAllocator which should be used to allocate
  158. memory for the local "dynamic store" and its storage for
  159. values.
  160. This parameter may be NULL in which case the current
  161. default CFAllocator is used. If this reference is not
  162. a valid CFAllocator, the behavior is undefined.
  163. @param name A string that describes the name of the calling
  164. process or plug-in of the caller.
  165. @param callout The function to be called when a watched value
  166. in the "dynamic store" is changed.
  167. A NULL value can be specified if no callouts are
  168. desired.
  169. @param context The SCDynamicStoreContext associated with the callout.
  170. @result A reference to the new SCDynamicStore.
  171. }
  172. function SCDynamicStoreCreate( allocator: CFAllocatorRef; name: CFStringRef; callout: SCDynamicStoreCallBack; var context: SCDynamicStoreContext ): SCDynamicStoreRef; external name '_SCDynamicStoreCreate';
  173. {!
  174. @function SCDynamicStoreCreateRunLoopSource
  175. @discussion Creates a new session used to interact with the dynamic
  176. store maintained by the SystemConfiguration server.
  177. @param allocator The CFAllocator which should be used to allocate
  178. memory for the local "dynamic store" and its storage for
  179. values.
  180. This parameter may be NULL in which case the current
  181. default CFAllocator is used. If this reference is not
  182. a valid CFAllocator, the behavior is undefined.
  183. @param store The "dynamic store" session.
  184. @param order On platforms which support it, this parameter
  185. determines the order in which the sources which are
  186. ready to be processed are handled. A lower order
  187. number causes processing before higher order number
  188. sources. It is inadvisable to depend on the order
  189. number for any architectural or design aspect of
  190. code. In the absence of any reason to do otherwise,
  191. zero should be used.
  192. @result A reference to the new CFRunLoopSource.
  193. You must release the returned value.
  194. }
  195. function SCDynamicStoreCreateRunLoopSource( allocator: CFAllocatorRef; store: SCDynamicStoreRef; order: CFIndex ): CFRunLoopSourceRef; external name '_SCDynamicStoreCreateRunLoopSource';
  196. {!
  197. @function SCDynamicStoreCopyKeyList
  198. @discussion Returns an array of CFString keys representing the
  199. configuration "dynamic store" entries that match a
  200. specified pattern.
  201. @param store The "dynamic store" session.
  202. @param pattern A regex(3) regular expression pattern that
  203. will be used to match the "dynamic store" keys.
  204. @result The list of matching keys.
  205. You must release the returned value.
  206. A NULL value will be returned if the list could not be obtained.
  207. }
  208. function SCDynamicStoreCopyKeyList( store: SCDynamicStoreRef; pattern: CFStringRef ): CFArrayRef; external name '_SCDynamicStoreCopyKeyList';
  209. {!
  210. @function SCDynamicStoreAddValue
  211. @discussion Adds the key-value pair to the "dynamic store" if no
  212. such key already exists.
  213. @param store The "dynamic store" session.
  214. @param key The key of the value to add to the "dynamic store".
  215. @param value The value to add to the "dynamic store".
  216. @result TRUE if the key was added; FALSE if the key was already
  217. present in the "dynamic store" or if an error was encountered.
  218. }
  219. function SCDynamicStoreAddValue( store: SCDynamicStoreRef; key: CFStringRef; value: CFPropertyListRef ): Boolean; external name '_SCDynamicStoreAddValue';
  220. {!
  221. @function SCDynamicStoreAddTemporaryValue
  222. @discussion Adds the key-value pair on a temporary basis to the
  223. "dynamic store" if no such key already exists. This entry
  224. will, unless updated by another session, automatically be
  225. removed when the session is closed.
  226. @param store The "dynamic store" session.
  227. @param key The key of the value to add to the "dynamic store".
  228. @param value The value to add to the "dynamic store".
  229. @result TRUE if the key was added; FALSE if the key was already
  230. present in the "dynamic store" or if an error was encountered.
  231. }
  232. function SCDynamicStoreAddTemporaryValue( store: SCDynamicStoreRef; key: CFStringRef; value: CFPropertyListRef ): Boolean; external name '_SCDynamicStoreAddTemporaryValue';
  233. {!
  234. @function SCDynamicStoreCopyValue
  235. @discussion Obtains a value from the "dynamic store" for the
  236. specified key.
  237. @param store The "dynamic store" session.
  238. @param key The key you wish to obtain.
  239. @result The value from the store that is associated with the
  240. given key. The value is returned as a Core Foundation
  241. Property List data type.
  242. You must release the returned value.
  243. If no value was located, NULL is returned.
  244. }
  245. function SCDynamicStoreCopyValue( store: SCDynamicStoreRef; key: CFStringRef ): CFPropertyListRef; external name '_SCDynamicStoreCopyValue';
  246. {!
  247. @function SCDynamicStoreCopyMultiple
  248. @discussion Fetches multiple values in the "dynamic store".
  249. @param store The "dynamic store" session.
  250. @param keys The keys to be fetched; NULL if no specific keys
  251. are requested.
  252. @param patterns The regex(3) pattern strings to be fetched; NULL
  253. if no key patterns are requested.
  254. @result A dictionary containing the specific keys which were found
  255. in the "dynamic store" and any keys which matched the specified
  256. patterns; NULL is returned if an error was encountered.
  257. You must release the returned value.
  258. }
  259. function SCDynamicStoreCopyMultiple( store: SCDynamicStoreRef; keys: CFArrayRef; patterns: CFArrayRef ): CFDictionaryRef; external name '_SCDynamicStoreCopyMultiple';
  260. {!
  261. @function SCDynamicStoreSetValue
  262. @discussion Adds or replaces a value in the "dynamic store" for
  263. the specified key.
  264. @param store The "dynamic store" session.
  265. @param key The key you wish to set.
  266. @param value The value to add to or replace in the "dynamic store".
  267. @result TRUE if the key was updated; FALSE if an error was encountered.
  268. }
  269. function SCDynamicStoreSetValue( store: SCDynamicStoreRef; key: CFStringRef; value: CFPropertyListRef ): Boolean; external name '_SCDynamicStoreSetValue';
  270. {!
  271. @function SCDynamicStoreSetMultiple
  272. @discussion Updates multiple values in the "dynamic store".
  273. @param store The "dynamic store" session.
  274. @param keysToSet Key/value pairs you wish to set into the "dynamic store".
  275. @param keysToRemove A list of keys you wish to remove from the "dynamic store".
  276. @param keysToNotify A list of keys to flag as changed (without actually changing the data).
  277. @result TRUE if the dynamic store updates were successful; FALSE if an error was encountered.
  278. }
  279. function SCDynamicStoreSetMultiple( store: SCDynamicStoreRef; keysToSet: CFDictionaryRef; keysToRemove: CFArrayRef; keysToNotify: CFArrayRef ): Boolean; external name '_SCDynamicStoreSetMultiple';
  280. {!
  281. @function SCDynamicStoreRemoveValue
  282. @discussion Removes the value of the specified key from the
  283. "dynamic store".
  284. @param store The "dynamic store" session.
  285. @param key The key of the value you wish to remove.
  286. @result TRUE if the key was removed; FALSE if no value was
  287. located or an error was encountered.
  288. }
  289. function SCDynamicStoreRemoveValue( store: SCDynamicStoreRef; key: CFStringRef ): Boolean; external name '_SCDynamicStoreRemoveValue';
  290. {!
  291. @function SCDynamicStoreNotifyValue
  292. @discussion Triggers a notification to be delivered for the
  293. specified key in the dynamic store.
  294. @param store The "dynamic store" session.
  295. @param key The key which should be flagged as changed (without actually changing the data).
  296. @result TRUE if the value was updated; FALSE if an error was encountered.
  297. }
  298. function SCDynamicStoreNotifyValue( store: SCDynamicStoreRef; key: CFStringRef ): Boolean; external name '_SCDynamicStoreNotifyValue';
  299. {!
  300. @function SCDynamicStoreSetNotificationKeys
  301. @discussion Specifies a set of specific keys and key patterns
  302. which should be monitored for changes.
  303. @param store The "dynamic store" session being watched.
  304. @param keys The keys to be monitored; NULL if no specific keys
  305. are to be monitored.
  306. @param patterns The regex(3) pattern strings to be monitored; NULL
  307. if no key patterns are to be monitored.
  308. @result TRUE if the monitored keys were set; FALSE if an error
  309. was encountered.
  310. }
  311. function SCDynamicStoreSetNotificationKeys( store: SCDynamicStoreRef; keys: CFArrayRef; patterns: CFArrayRef ): Boolean; external name '_SCDynamicStoreSetNotificationKeys';
  312. {!
  313. @function SCDynamicStoreCopyNotifiedKeys
  314. @discussion Returns an array of CFString keys representing the
  315. "dynamic store" entries that have changed since this
  316. function was last called.
  317. @param store The "dynamic store" session.
  318. @result The list of changed keys.
  319. You must release the returned value.
  320. A NULL value will be returned if the list could not be obtained.
  321. }
  322. function SCDynamicStoreCopyNotifiedKeys( store: SCDynamicStoreRef ): CFArrayRef; external name '_SCDynamicStoreCopyNotifiedKeys';
  323. end.