]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDynamicStorePrivate.h
af5a5cc1fd83d49b04391ed30317a4fbf3743d63
[apple/configd.git] / SystemConfiguration.fproj / SCDynamicStorePrivate.h
1 /*
2 * Copyright (c) 2000, 2001, 2004, 2005, 2010, 2011 Apple 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
24 #ifndef _SCDYNAMICSTOREPRIVATE_H
25 #define _SCDYNAMICSTOREPRIVATE_H
26
27 #include <sys/cdefs.h>
28 #include <mach/message.h>
29 #include <CoreFoundation/CoreFoundation.h>
30 #include <SystemConfiguration/SCDynamicStore.h>
31
32 /*!
33 @header SCDynamicStorePrivate
34 @discussion The SCDynamicStore APIs provide access to a key-value
35 dictionary maintained by a server process. The dictionary is
36 accessible by all processes on the system. The APIs allow you
37 to list the current key-value pairs, add or remove key-value
38 pairs, add or change the values associated with a key, and
39 request change notifications.
40
41 The SCDynamicStore is not "persistent" (the store content
42 starts off empty and is not saved across boot).
43
44 All interaction with the SCDynamicStore [server] is via Mach
45 IPC (MiG) messages.
46
47 A client process, using the SCDynamicStoreSetNotificationKeys
48 API, specifies a list of specific keys of interest and/or a
49 list of regex(3) pattern strings that will be matched on
50 current (and future) keys in the store. Any matched keys that
51 are added, updated, or removed will trigger a notification.
52 The notification is delivered to the monitoring session via
53 a "something has changed" Mach IPC message. The callback
54 notification, as part of its implementation, issues a request
55 to the server to identify the specific list of changes and
56 this list is passed along as part of the callback. Any
57 subsequent changes to the SCDynamicStore will trigger a new
58 "something has changed" Mach IPC message and an additional
59 callback.
60
61 Note: the list (array) of changed keys passed to the
62 notification callback will be always be non-NULL
63 and non-empty with one exception. That exception
64 is when the SCDynamicStore server has been restarted.
65 In that case, if no reconnect callback was setup
66 with the SCDynamicStoreSetReconnectCallBack API
67 then a non-NULL but empty array will be passed.
68
69 Disconnect/reconnect considerations:
70
71 1. We don't expect the SCDynamicStore server to fail but one
72 should always be prepared for the unexpected.
73
74 2. Processes that write to the SCDynamicStore should be
75 prepared to repost any content when/if the server fails.
76 A callout, registered with the SCDynamicStoreSetReconnectCallBack
77 API, should be used to post any updates the SCDynamicStore
78 after a failure.
79
80 3. Processes that cache SCDynamicStore content (or otherwise
81 maintain state based on previous notifications) should be
82 aware that all store content is lost when/if the server
83 fails. After handling a SCDynamicStore notification with
84 no keys or a disconnect/reconnect callout, your code should
85 assume that any cached content is no longer valid.
86
87 Performance considerations:
88
89 1. We recommend that any code trying to capture a snapshot of
90 more than one SCDynamicStore key should use the SCDynamicStoreCopyMultiple
91 API (and not make multiple calls to SCDynamicStoreCopyValue).
92
93 2. We recommend that any code making multiple (and related)
94 changes to the SCDynamicStore should batch them into a
95 single call using the SCDynamicStoreSetMultiple API (and
96 not make multiple calls to SCDynamicStoreSetValue).
97 */
98
99 /*!
100 @typedef SCDynamicStoreDisconnectCallBack
101 @discussion Type of callback function used when notification of
102 the dynamic store session being disconnected is delivered.
103 @param store The dynamic store session.
104 @param info A C pointer to a user-specified block of data.
105 */
106 typedef void (*SCDynamicStoreDisconnectCallBack) (
107 SCDynamicStoreRef store,
108 void *info
109 );
110
111
112 __BEGIN_DECLS
113
114 /*!
115 @function SCDynamicStoreAddWatchedKey
116 @discussion Adds the specified key to the list of "dynamic store"
117 values that are being monitored for changes.
118 @param store The "dynamic store" session being watched.
119 @param key The key to be monitored.
120 @param isRegex A booolean indicating whether a specific key should
121 be monitored or if it consists of a regex(3) pattern string
122 of keys.
123 @result TRUE if the key was successfully added to the "watch"
124 list; FALSE if an error was encountered.
125 */
126 Boolean
127 SCDynamicStoreAddWatchedKey (SCDynamicStoreRef store,
128 CFStringRef key,
129 Boolean isRegex);
130
131 /*!
132 @function SCDynamicStoreRemoveWatchedKey
133 @discussion Removes the specified key from the list of "dynamic store"
134 values that are being monitored for changes.
135 @param store The "dynamic store" session being watched.
136 @param key The key that should no longer be monitored.
137 @param isRegex A booolean indicating whether a specific key should
138 be monitored or if it consists of a regex(3) pattern string
139 of keys.
140 @result TRUE if the key was successfully removed from the "watch"
141 list; FALSE if an error was encountered.
142 */
143 Boolean
144 SCDynamicStoreRemoveWatchedKey (SCDynamicStoreRef store,
145 CFStringRef key,
146 Boolean isRegex);
147
148 /*!
149 @function SCDynamicStoreNotifyFileDescriptor
150 @discussion Allocates a file descriptor that can be used to detect changes
151 to one of the system configuration data entries associated with the
152 current session's notifier keys. When a change is detected, the
153 specified identifier (4 bytes) will be delivered to the calling
154 application via the allocated file descriptor.
155
156 @param store An SCDynamicStoreRef that should be used for communication with the server.
157 @param identifier A (4 byte) integer that can be used to identify this
158 notification.
159 @param fd A pointer to a file descriptor. Upon return, fd will
160 contain the file descriptor that will be used for any notifications.
161 @result A boolean indicating the success (or failure) of the call.
162 */
163 Boolean
164 SCDynamicStoreNotifyFileDescriptor (SCDynamicStoreRef store,
165 int32_t identifier,
166 int *fd);
167
168 /*!
169 @function SCDynamicStoreNotifySignal
170 @discussion Requests that the specified BSD signal be sent to the process
171 with the indicated process id whenever a change has been detected
172 to one of the system configuration data entries associated with the
173 current session's notifier keys.
174
175 Note: this function is not valid for "configd" plug-ins.
176
177 @param store An SCDynamicStoreRef that should be used for communication with the server.
178 @param pid A UNIX process ID that should be signalled for any notifications.
179 @param sig A signal number to be used.
180 @result A boolean indicating the success (or failure) of the call.
181 */
182 Boolean
183 SCDynamicStoreNotifySignal (SCDynamicStoreRef store,
184 pid_t pid,
185 int sig);
186
187 /*!
188 @function SCDynamicStoreNotifyWait
189 @discussion Waits for a change to be made to a value in the
190 "dynamic store" that is being monitored.
191 @param store The "dynamic store" session.
192 @result TRUE if a change has been detected; FALSE if an error was encountered.
193 */
194 Boolean
195 SCDynamicStoreNotifyWait (SCDynamicStoreRef store);
196
197 /*!
198 @function SCDynamicStoreNotifyCancel
199 @discussion Cancels any outstanding notification requests for
200 this "dynamic store" session.
201
202 @param store The "dynamic store" session.
203 @result TRUE if all notifications have been cancelled; FALSE if an
204 error was encountered.
205 */
206 Boolean
207 SCDynamicStoreNotifyCancel (SCDynamicStoreRef store);
208
209 /*!
210 @function SCDynamicStoreSetDisconnectCallBack
211 @discussion Assigns a callback to a SCDynamicStore session. The function
212 is called when the session has been disconnected. The callback
213 should be established before a client writes any content to the
214 SCDynamicStore to ensure that the information can be re-posted
215 when/if a disconnect is detected.
216 @param store A reference to the dynamic store session.
217 @param callout The function to be called when the session was disconnected.
218 If NULL, the current callback is removed.
219 @result Returns TRUE on success, FALSE on failure.
220 */
221 Boolean
222 SCDynamicStoreSetDisconnectCallBack (
223 SCDynamicStoreRef store,
224 SCDynamicStoreDisconnectCallBack callout
225 ) __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_5_0/*SPI*/);
226
227 Boolean
228 SCDynamicStoreSnapshot (SCDynamicStoreRef store);
229
230 __END_DECLS
231
232 #endif /* _SCDYNAMICSTOREPRIVATE_H */