2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * March 24, 2000 Allan Nathanson <ajn@apple.com>
37 __SCDynamicStoreNotifyMachPort(SCDynamicStoreRef store
,
38 mach_msg_id_t identifier
,
41 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
42 CFStringRef sessionKey
;
45 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreNotifyMachPort:"));
47 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
48 return kSCStatusNoStoreSession
; /* you must have an open session to play */
51 if (storePrivate
->notifyStatus
!= NotifierNotRegistered
) {
52 /* sorry, you can only have one notification registered at once */
53 return kSCStatusNotifierActive
;
56 if (*port
== MACH_PORT_NULL
) {
57 /* sorry, you must specify a valid mach port */
58 return kSCStatusInvalidArgument
;
61 /* push out a notification if any changes are pending */
62 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
63 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
64 CFRelease(sessionKey
);
65 if (info
&& CFDictionaryContainsKey(info
, kSCDChangedKeys
)) {
66 CFNumberRef sessionNum
;
68 if (needsNotification
== NULL
)
69 needsNotification
= CFSetCreateMutable(NULL
,
71 &kCFTypeSetCallBacks
);
73 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
74 CFSetAddValue(needsNotification
, sessionNum
);
75 CFRelease(sessionNum
);
83 _notifyviaport(mach_port_t server
,
85 mach_msg_id_t identifier
,
89 serverSessionRef mySession
= getSession(server
);
90 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
92 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Send mach message when a notification key changes."));
93 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
94 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" port = %d"), port
);
95 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" message id = %d"), identifier
);
97 if (storePrivate
->notifyPort
!= MACH_PORT_NULL
) {
98 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" destroying old callback mach port %d"), storePrivate
->notifyPort
);
99 (void) mach_port_destroy(mach_task_self(), storePrivate
->notifyPort
);
102 *sc_status
= __SCDynamicStoreNotifyMachPort(mySession
->store
, identifier
, &port
);
104 if (*sc_status
== kSCStatusOK
) {
105 /* save notification port, requested identifier, and set notifier active */
106 storePrivate
->notifyStatus
= Using_NotifierInformViaMachPort
;
107 storePrivate
->notifyPort
= port
;
108 storePrivate
->notifyPortIdentifier
= identifier
;