]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifyviaport.c
configd-24.tar.gz
[apple/configd.git] / configd.tproj / _notifyviaport.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include "configd.h"
24 #include "session.h"
25
26 SCDStatus
27 _SCDNotifierInformViaMachPort(SCDSessionRef session, mach_msg_id_t identifier, mach_port_t *port)
28 {
29 SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)session;
30 CFStringRef sessionKey;
31 CFDictionaryRef info;
32
33 SCDLog(LOG_DEBUG, CFSTR("_SCDNotifierInformViaMachPort:"));
34
35 if ((session == NULL) || (sessionPrivate->server == MACH_PORT_NULL)) {
36 return SCD_NOSESSION; /* you must have an open session to play */
37 }
38
39 if (sessionPrivate->notifyStatus != NotifierNotRegistered) {
40 /* sorry, you can only have one notification registered at once */
41 return SCD_NOTIFIERACTIVE;
42 }
43
44 if (*port == MACH_PORT_NULL) {
45 /* sorry, you must specify a valid mach port */
46 return SCD_INVALIDARGUMENT;
47 }
48
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;
55
56 if (needsNotification == NULL)
57 needsNotification = CFSetCreateMutable(NULL,
58 0,
59 &kCFTypeSetCallBacks);
60
61 sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &sessionPrivate->server);
62 CFSetAddValue(needsNotification, sessionNum);
63 CFRelease(sessionNum);
64 }
65
66 return SCD_OK;
67 }
68
69
70 kern_return_t
71 _notifyviaport(mach_port_t server,
72 mach_port_t port,
73 mach_msg_id_t identifier,
74 int *scd_status
75 )
76 {
77 serverSessionRef mySession = getSession(server);
78 SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)mySession->session;
79
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);
84
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);
88 }
89
90 *scd_status = _SCDNotifierInformViaMachPort(mySession->session, identifier, &port);
91
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;
97 }
98
99 return KERN_SUCCESS;
100 }