]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDynamicStorePrivate.h
configd-699.30.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDynamicStorePrivate.h
1 /*
2 * Copyright (c) 2000, 2001, 2004, 2005, 2010, 2011, 2013 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
113 __BEGIN_DECLS
114
115 /*!
116 @function SCDynamicStoreAddWatchedKey
117 @discussion Adds the specified key to the list of "dynamic store"
118 values that are being monitored for changes.
119 @param store The "dynamic store" session being watched.
120 @param key The key to be monitored.
121 @param isRegex A booolean indicating whether a specific key should
122 be monitored or if it consists of a regex(3) pattern string
123 of keys.
124 @result TRUE if the key was successfully added to the "watch"
125 list; FALSE if an error was encountered.
126 */
127 Boolean
128 SCDynamicStoreAddWatchedKey (SCDynamicStoreRef store,
129 CFStringRef key,
130 Boolean isRegex);
131
132 /*!
133 @function SCDynamicStoreRemoveWatchedKey
134 @discussion Removes the specified key from the list of "dynamic store"
135 values that are being monitored for changes.
136 @param store The "dynamic store" session being watched.
137 @param key The key that should no longer be monitored.
138 @param isRegex A booolean indicating whether a specific key should
139 be monitored or if it consists of a regex(3) pattern string
140 of keys.
141 @result TRUE if the key was successfully removed from the "watch"
142 list; FALSE if an error was encountered.
143 */
144 Boolean
145 SCDynamicStoreRemoveWatchedKey (SCDynamicStoreRef store,
146 CFStringRef key,
147 Boolean isRegex);
148
149 /*!
150 @function SCDynamicStoreNotifyFileDescriptor
151 @discussion Allocates a file descriptor that can be used to detect changes
152 to one of the system configuration data entries associated with the
153 current session's notifier keys. When a change is detected, the
154 specified identifier (4 bytes) will be delivered to the calling
155 application via the allocated file descriptor.
156
157 @param store An SCDynamicStoreRef that should be used for communication with the server.
158 @param identifier A (4 byte) integer that can be used to identify this
159 notification.
160 @param fd A pointer to a file descriptor. Upon return, fd will
161 contain the file descriptor that will be used for any notifications.
162 @result A boolean indicating the success (or failure) of the call.
163 */
164 Boolean
165 SCDynamicStoreNotifyFileDescriptor (SCDynamicStoreRef store,
166 int32_t identifier,
167 int *fd);
168
169 /*!
170 @function SCDynamicStoreNotifySignal
171 @discussion Requests that the specified BSD signal be sent to the process
172 with the indicated process id whenever a change has been detected
173 to one of the system configuration data entries associated with the
174 current session's notifier keys.
175
176 Note: this function is not valid for "configd" plug-ins.
177
178 @param store An SCDynamicStoreRef that should be used for communication with the server.
179 @param pid A UNIX process ID that should be signalled for any notifications.
180 @param sig A signal number to be used.
181 @result A boolean indicating the success (or failure) of the call.
182 */
183 Boolean
184 SCDynamicStoreNotifySignal (SCDynamicStoreRef store,
185 pid_t pid,
186 int sig);
187
188 /*!
189 @function SCDynamicStoreNotifyWait
190 @discussion Waits for a change to be made to a value in the
191 "dynamic store" that is being monitored.
192 @param store The "dynamic store" session.
193 @result TRUE if a change has been detected; FALSE if an error was encountered.
194 */
195 Boolean
196 SCDynamicStoreNotifyWait (SCDynamicStoreRef store);
197
198 /*!
199 @function SCDynamicStoreNotifyCancel
200 @discussion Cancels any outstanding notification requests for
201 this "dynamic store" session.
202
203 @param store The "dynamic store" session.
204 @result TRUE if all notifications have been cancelled; FALSE if an
205 error was encountered.
206 */
207 Boolean
208 SCDynamicStoreNotifyCancel (SCDynamicStoreRef store);
209
210 /*!
211 @function SCDynamicStoreSetDisconnectCallBack
212 @discussion Assigns a callback to a SCDynamicStore session. The function
213 is called when the session has been disconnected. The callback
214 should be established before a client writes any content to the
215 SCDynamicStore to ensure that the information can be re-posted
216 when/if a disconnect is detected.
217 @param store A reference to the dynamic store session.
218 @param callout The function to be called when the session was disconnected.
219 If NULL, the current callback is removed.
220 @result Returns TRUE on success, FALSE on failure.
221 */
222 Boolean
223 SCDynamicStoreSetDisconnectCallBack (
224 SCDynamicStoreRef store,
225 SCDynamicStoreDisconnectCallBack callout
226 ) __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_5_0/*SPI*/);
227
228 Boolean
229 SCDynamicStoreSnapshot (SCDynamicStoreRef store);
230
231 __END_DECLS
232
233 #endif /* _SCDYNAMICSTOREPRIVATE_H */