configd-802.20.7.tar.gz
[apple/configd.git] / scutil.tproj / session.c
CommitLineData
5958d7c0 1/*
17d3ee29 2 * Copyright (c) 2000-2004, 2010, 2011 Apple Inc. All rights reserved.
5958d7c0
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
009ee3c6 5 *
009ee3c6
A
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
5958d7c0
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
009ee3c6
A
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 *
5958d7c0
A
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
0fae82ee
A
24/*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * November 9, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
5958d7c0 34#include "scutil.h"
17d3ee29 35#include "cache.h"
009ee3c6 36#include "session.h"
dbf6a266 37#include "notifications.h"
5958d7c0 38
6bb65964
A
39
40static void
41reconnected(SCDynamicStoreRef store, void *info)
42{
43 SCPrint(TRUE, stdout, CFSTR("SCDynamicStore server restarted, session reconnected\n"));
44 return;
45}
46
47
dbf6a266 48__private_extern__
5958d7c0
A
49void
50do_open(int argc, char **argv)
51{
009ee3c6
A
52 if (store) {
53 CFRelease(store);
54 CFRelease(watchedKeys);
55 CFRelease(watchedPatterns);
56 }
5958d7c0 57
dbf6a266
A
58 if (argc < 1) {
59 store = SCDynamicStoreCreate(NULL, CFSTR("scutil"), storeCallback, NULL);
60 } else {
61 CFMutableDictionaryRef options;
62
63 options = CFDictionaryCreateMutable(NULL,
64 0,
65 &kCFTypeDictionaryKeyCallBacks,
66 &kCFTypeDictionaryValueCallBacks);
67 CFDictionarySetValue(options, kSCDynamicStoreUseSessionKeys, kCFBooleanTrue);
68 store = SCDynamicStoreCreateWithOptions(NULL,
69 CFSTR("scutil"),
70 options,
71 storeCallback,
72 NULL);
73 CFRelease(options);
74 }
75 if (store == NULL) {
0fae82ee 76 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
5958d7c0
A
77 return;
78 }
79
6bb65964
A
80 (void) SCDynamicStoreSetDisconnectCallBack(store, reconnected);
81
009ee3c6
A
82 watchedKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
83 watchedPatterns = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
84
17d3ee29
A
85 cache_close();
86
5958d7c0
A
87 return;
88}
89
90
dbf6a266 91__private_extern__
5958d7c0
A
92void
93do_close(int argc, char **argv)
94{
6bb65964
A
95 if (notifyRls != NULL) {
96 if (doDispatch) {
97 (void) SCDynamicStoreSetDispatchQueue(store, NULL);
98 } else {
99 CFRunLoopSourceInvalidate(notifyRls);
100 CFRelease(notifyRls);
101 }
0fae82ee
A
102 notifyRls = NULL;
103 }
5958d7c0 104
6bb65964 105 if (notifyRl != NULL) {
009ee3c6
A
106 CFRunLoopStop(notifyRl);
107 notifyRl = NULL;
108 }
109
6bb65964 110 if (store != NULL) {
0fae82ee
A
111 CFRelease(store);
112 store = NULL;
009ee3c6
A
113 CFRelease(watchedKeys);
114 watchedKeys = NULL;
115 CFRelease(watchedPatterns);
116 watchedPatterns = NULL;
5958d7c0 117 }
5958d7c0 118
17d3ee29 119 cache_close();
5958d7c0 120
5958d7c0
A
121 return;
122}