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@
27 _SCDNotifierInformViaMachPort(SCDSessionRef session
, mach_msg_id_t identifier
, mach_port_t
*port
)
29 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
30 CFStringRef sessionKey
;
33 SCDLog(LOG_DEBUG
, CFSTR("_SCDNotifierInformViaMachPort:"));
35 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
36 return SCD_NOSESSION
; /* you must have an open session to play */
39 if (sessionPrivate
->notifyStatus
!= NotifierNotRegistered
) {
40 /* sorry, you can only have one notification registered at once */
41 return SCD_NOTIFIERACTIVE
;
44 if (*port
== MACH_PORT_NULL
) {
45 /* sorry, you must specify a valid mach port */
46 return SCD_INVALIDARGUMENT
;
49 /* push out a notification if any changes are pending */
50 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), sessionPrivate
->server
);
51 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
52 CFRelease(sessionKey
);
53 if (info
&& CFDictionaryContainsKey(info
, kSCDChangedKeys
)) {
54 CFNumberRef sessionNum
;
56 if (needsNotification
== NULL
)
57 needsNotification
= CFSetCreateMutable(NULL
,
59 &kCFTypeSetCallBacks
);
61 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &sessionPrivate
->server
);
62 CFSetAddValue(needsNotification
, sessionNum
);
63 CFRelease(sessionNum
);
71 _notifyviaport(mach_port_t server
,
73 mach_msg_id_t identifier
,
77 serverSessionRef mySession
= getSession(server
);
78 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)mySession
->session
;
80 SCDLog(LOG_DEBUG
, CFSTR("Send mach message when a notification key changes."));
81 SCDLog(LOG_DEBUG
, CFSTR(" server = %d"), server
);
82 SCDLog(LOG_DEBUG
, CFSTR(" port = %d"), port
);
83 SCDLog(LOG_DEBUG
, CFSTR(" message id = %d"), identifier
);
85 if (sessionPrivate
->notifyPort
!= MACH_PORT_NULL
) {
86 SCDLog(LOG_DEBUG
, CFSTR(" destroying old callback mach port %d"), sessionPrivate
->notifyPort
);
87 (void) mach_port_destroy(mach_task_self(), sessionPrivate
->notifyPort
);
90 *scd_status
= _SCDNotifierInformViaMachPort(mySession
->session
, identifier
, &port
);
92 if (*scd_status
== SCD_OK
) {
93 /* save notification port, requested identifier, and set notifier active */
94 sessionPrivate
->notifyStatus
= Using_NotifierInformViaMachPort
;
95 sessionPrivate
->notifyPort
= port
;
96 sessionPrivate
->notifyPortIdentifier
= identifier
;