2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * March 24, 2000 Allan Nathanson <ajn@apple.com>
41 __SCDynamicStoreNotifyMachPort(SCDynamicStoreRef store
,
42 mach_msg_id_t identifier
,
45 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
46 CFStringRef sessionKey
;
49 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreNotifyMachPort:"));
51 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
52 return kSCStatusNoStoreSession
; /* you must have an open session to play */
55 if (storePrivate
->notifyStatus
!= NotifierNotRegistered
) {
56 /* sorry, you can only have one notification registered at once */
57 return kSCStatusNotifierActive
;
60 if (*port
== MACH_PORT_NULL
) {
61 /* sorry, you must specify a valid mach port */
62 return kSCStatusInvalidArgument
;
65 /* push out a notification if any changes are pending */
66 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
67 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
68 CFRelease(sessionKey
);
69 if (info
&& CFDictionaryContainsKey(info
, kSCDChangedKeys
)) {
70 CFNumberRef sessionNum
;
72 if (needsNotification
== NULL
)
73 needsNotification
= CFSetCreateMutable(NULL
,
75 &kCFTypeSetCallBacks
);
77 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
78 CFSetAddValue(needsNotification
, sessionNum
);
79 CFRelease(sessionNum
);
88 _notifyviaport(mach_port_t server
,
90 mach_msg_id_t identifier
,
94 serverSessionRef mySession
= getSession(server
);
95 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
97 if (_configd_verbose
) {
98 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Send mach message when a notification key changes."));
99 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
100 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" port = %d"), port
);
101 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" message id = %d"), identifier
);
105 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
109 if (storePrivate
->notifyPort
!= MACH_PORT_NULL
) {
110 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" destroying old callback mach port %d"), storePrivate
->notifyPort
);
111 (void) mach_port_destroy(mach_task_self(), storePrivate
->notifyPort
);
114 *sc_status
= __SCDynamicStoreNotifyMachPort(mySession
->store
, identifier
, &port
);
116 if (*sc_status
== kSCStatusOK
) {
117 /* save notification port, requested identifier, and set notifier active */
118 storePrivate
->notifyStatus
= Using_NotifierInformViaMachPort
;
119 storePrivate
->notifyPort
= port
;
120 storePrivate
->notifyPortIdentifier
= identifier
;