2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
21 * @APPLE_LICENSE_HEADER_END@
23 /* CFUserNotification.c
24 Copyright 2000-2002, Apple, Inc. All rights reserved.
25 Responsibility: Doug Davidson
28 #include <CoreFoundation/CFUserNotification.h>
29 #include <CoreFoundation/CFPropertyList.h>
30 #include <CoreFoundation/CFNumber.h>
31 #include <CoreFoundation/CFMachPort.h>
32 #include <CoreFoundation/CFRunLoop.h>
33 #include "CFInternal.h"
35 #define __kCFLogUserNotification 20
36 #define CFUserNotificationLog(alertHeader, alertMessage) CFLog(__kCFLogUserNotification, CFSTR("%@: %@"), alertHeader, alertMessage);
39 kCFUserNotificationCancelFlag
= (1 << 3),
40 kCFUserNotificationUpdateFlag
= (1 << 4)
43 CONST_STRING_DECL(kCFUserNotificationTokenKey
, "Token")
44 CONST_STRING_DECL(kCFUserNotificationTimeoutKey
, "Timeout")
45 CONST_STRING_DECL(kCFUserNotificationFlagsKey
, "Flags")
46 CONST_STRING_DECL(kCFUserNotificationIconPathKey
, "IconPath")
47 CONST_STRING_DECL(kCFUserNotificationSoundPathKey
, "SoundPath")
48 CONST_STRING_DECL(kCFUserNotificationLocalizationPathKey
, "LocalizationPath")
49 CONST_STRING_DECL(kCFUserNotificationAlertSourceKey
, "AlertSource")
50 CONST_STRING_DECL(kCFUserNotificationTextFieldLabelsKey
, "TextFieldTitles")
51 CONST_STRING_DECL(kCFUserNotificationCheckBoxLabelsKey
, "CheckBoxTitles")
52 CONST_STRING_DECL(kCFUserNotificationIconURLKey
, "IconURL")
53 CONST_STRING_DECL(kCFUserNotificationSoundURLKey
, "SoundURL")
54 CONST_STRING_DECL(kCFUserNotificationLocalizationURLKey
, "LocalizationURL")
55 CONST_STRING_DECL(kCFUserNotificationAlertHeaderKey
, "AlertHeader")
56 CONST_STRING_DECL(kCFUserNotificationAlertMessageKey
, "AlertMessage")
57 CONST_STRING_DECL(kCFUserNotificationDefaultButtonTitleKey
, "DefaultButtonTitle")
58 CONST_STRING_DECL(kCFUserNotificationAlternateButtonTitleKey
, "AlternateButtonTitle")
59 CONST_STRING_DECL(kCFUserNotificationOtherButtonTitleKey
, "OtherButtonTitle")
60 CONST_STRING_DECL(kCFUserNotificationProgressIndicatorValueKey
, "ProgressIndicatorValue")
61 CONST_STRING_DECL(kCFUserNotificationSessionIDKey
, "SessionID")
62 CONST_STRING_DECL(kCFUserNotificationPopUpTitlesKey
, "PopUpTitles")
63 CONST_STRING_DECL(kCFUserNotificationTextFieldTitlesKey
, "TextFieldTitles")
64 CONST_STRING_DECL(kCFUserNotificationCheckBoxTitlesKey
, "CheckBoxTitles")
65 CONST_STRING_DECL(kCFUserNotificationTextFieldValuesKey
, "TextFieldValues")
66 CONST_STRING_DECL(kCFUserNotificationPopUpSelectionKey
, "PopUpSelection")
68 static CFTypeID __kCFUserNotificationTypeID
= _kCFRuntimeNotATypeID
;
70 struct __CFUserNotification
{
74 CFTimeInterval _timeout
;
75 CFOptionFlags _requestFlags
;
76 CFOptionFlags _responseFlags
;
77 CFStringRef _sessionID
;
78 CFDictionaryRef _responseDictionary
;
80 CFMachPortRef _machPort
;
82 CFUserNotificationCallBack _callout
;
85 static CFStringRef
__CFUserNotificationCopyDescription(CFTypeRef cf
) {
86 CFMutableStringRef result
;
87 result
= CFStringCreateMutable(CFGetAllocator(cf
), 0);
88 CFStringAppendFormat(result
, NULL
, CFSTR("<CFUserNotification 0x%x>"), (UInt32
)cf
);
97 #include <mach/mach.h>
98 #include <mach/error.h>
99 #include <servers/bootstrap.h>
103 #define MAX_STRING_LENGTH PATH_MAX
104 #define MAX_STRING_COUNT 16
105 #define MAX_PORT_NAME_LENGTH 63
106 #define NOTIFICATION_PORT_NAME "com.apple.UNCUserNotification"
107 #define NOTIFICATION_PORT_NAME_OLD "UNCUserNotification"
108 #define NOTIFICATION_PORT_NAME_SUFFIX ".session."
109 #define MESSAGE_TIMEOUT 100
111 #endif /* __MACH__ */
113 static void __CFUserNotificationDeallocate(CFTypeRef cf
);
115 static const CFRuntimeClass __CFUserNotificationClass
= {
117 "CFUserNotification",
120 __CFUserNotificationDeallocate
,
124 __CFUserNotificationCopyDescription
127 __private_extern__
void __CFUserNotificationInitialize(void) {
128 __kCFUserNotificationTypeID
= _CFRuntimeRegisterClass(&__CFUserNotificationClass
);
131 CFTypeID
CFUserNotificationGetTypeID(void) {
132 return __kCFUserNotificationTypeID
;
135 #if defined(__MACH__)
137 static void __CFUserNotificationDeallocate(CFTypeRef cf
) {
138 CFUserNotificationRef userNotification
= (CFUserNotificationRef
)cf
;
139 if (userNotification
->_machPort
) {
140 CFMachPortInvalidate(userNotification
->_machPort
);
141 CFRelease(userNotification
->_machPort
);
142 } else if (MACH_PORT_NULL
!= userNotification
->_replyPort
) {
143 mach_port_destroy(mach_task_self(), userNotification
->_replyPort
);
145 if (userNotification
->_sessionID
) CFRelease(userNotification
->_sessionID
);
146 if (userNotification
->_responseDictionary
) CFRelease(userNotification
->_responseDictionary
);
149 static void _CFUserNotificationAddToDictionary(const void *key
, const void *value
, void *context
) {
150 if (CFGetTypeID(key
) == CFStringGetTypeID()) CFDictionarySetValue((CFMutableDictionaryRef
)context
, key
, value
);
153 static CFDictionaryRef
_CFUserNotificationModifiedDictionary(CFAllocatorRef allocator
, CFDictionaryRef dictionary
, SInt32 token
, SInt32 timeout
, CFStringRef source
) {
154 CFMutableDictionaryRef md
= CFDictionaryCreateMutable(allocator
, 0, &kCFCopyStringDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
155 CFNumberRef tokenNumber
= CFNumberCreate(allocator
, kCFNumberSInt32Type
, &token
);
156 CFNumberRef timeoutNumber
= CFNumberCreate(allocator
, kCFNumberSInt32Type
, &timeout
);
158 CFStringRef path
= NULL
;
160 if (dictionary
) CFDictionaryApplyFunction(dictionary
, _CFUserNotificationAddToDictionary
, md
);
161 if (source
) CFDictionaryAddValue(md
, kCFUserNotificationAlertSourceKey
, source
);
163 CFDictionaryAddValue(md
, kCFUserNotificationTokenKey
, tokenNumber
);
164 CFRelease(tokenNumber
);
167 CFDictionaryAddValue(md
, kCFUserNotificationTimeoutKey
, timeoutNumber
);
168 CFRelease(timeoutNumber
);
171 url
= CFDictionaryGetValue(md
, kCFUserNotificationIconURLKey
);
172 if (url
&& CFGetTypeID((CFTypeRef
)url
) == CFURLGetTypeID()) {
173 url
= CFURLCopyAbsoluteURL(url
);
174 CFDictionaryRemoveValue(md
, kCFUserNotificationIconURLKey
);
175 path
= CFURLCopyFileSystemPath(url
, kCFURLPOSIXPathStyle
);
176 CFDictionaryAddValue(md
, kCFUserNotificationIconPathKey
, path
);
180 url
= CFDictionaryGetValue(md
, kCFUserNotificationSoundURLKey
);
181 if (url
&& CFGetTypeID((CFTypeRef
)url
) == CFURLGetTypeID()) {
182 url
= CFURLCopyAbsoluteURL(url
);
183 CFDictionaryRemoveValue(md
, kCFUserNotificationSoundURLKey
);
184 path
= CFURLCopyFileSystemPath(url
, kCFURLPOSIXPathStyle
);
185 CFDictionaryAddValue(md
, kCFUserNotificationSoundPathKey
, path
);
189 url
= CFDictionaryGetValue(md
, kCFUserNotificationLocalizationURLKey
);
190 if (url
&& CFGetTypeID((CFTypeRef
)url
) == CFURLGetTypeID()) {
191 url
= CFURLCopyAbsoluteURL(url
);
192 CFDictionaryRemoveValue(md
, kCFUserNotificationLocalizationURLKey
);
193 path
= CFURLCopyFileSystemPath(url
, kCFURLPOSIXPathStyle
);
194 CFDictionaryAddValue(md
, kCFUserNotificationLocalizationPathKey
, path
);
201 static SInt32
_CFUserNotificationSendRequest(CFAllocatorRef allocator
, CFStringRef sessionID
, mach_port_t replyPort
, SInt32 token
, CFTimeInterval timeout
, CFOptionFlags flags
, CFDictionaryRef dictionary
) {
202 CFDictionaryRef modifiedDictionary
= NULL
;
203 SInt32 retval
= ERR_SUCCESS
, itimeout
= (timeout
> 0.0 && timeout
< INT_MAX
) ? (SInt32
)timeout
: 0;
205 mach_msg_base_t
*msg
= NULL
;
206 mach_port_t bootstrapPort
= MACH_PORT_NULL
, serverPort
= MACH_PORT_NULL
;
208 char namebuffer
[MAX_PORT_NAME_LENGTH
+ 1], oldnamebuffer
[MAX_PORT_NAME_LENGTH
+ 1];
211 strcpy(namebuffer
, NOTIFICATION_PORT_NAME
);
212 strcpy(oldnamebuffer
, NOTIFICATION_PORT_NAME_OLD
);
214 strcat(namebuffer
, NOTIFICATION_PORT_NAME_SUFFIX
);
215 namelen
= strlen(namebuffer
);
216 CFStringGetBytes(sessionID
, CFRangeMake(0, CFStringGetLength(sessionID
)), kCFStringEncodingUTF8
, 0, false, namebuffer
+ namelen
, MAX_PORT_NAME_LENGTH
- namelen
, &size
);
217 namebuffer
[namelen
+ size
] = '\0';
219 strcat(oldnamebuffer
, NOTIFICATION_PORT_NAME_SUFFIX
);
220 namelen
= strlen(oldnamebuffer
);
221 CFStringGetBytes(sessionID
, CFRangeMake(0, CFStringGetLength(sessionID
)), kCFStringEncodingUTF8
, 0, false, oldnamebuffer
+ namelen
, MAX_PORT_NAME_LENGTH
- namelen
, &size
);
222 oldnamebuffer
[namelen
+ size
] = '\0';
225 retval
= task_get_bootstrap_port(mach_task_self(), &bootstrapPort
);
226 if (ERR_SUCCESS
== retval
&& MACH_PORT_NULL
!= bootstrapPort
) retval
= bootstrap_look_up(bootstrapPort
, namebuffer
, &serverPort
);
227 if (ERR_SUCCESS
!= retval
|| MACH_PORT_NULL
== serverPort
) retval
= bootstrap_look_up(bootstrapPort
, oldnamebuffer
, &serverPort
);
228 if (ERR_SUCCESS
== retval
&& MACH_PORT_NULL
!= serverPort
) {
229 modifiedDictionary
= _CFUserNotificationModifiedDictionary(allocator
, dictionary
, token
, itimeout
, _CFProcessNameString());
230 if (modifiedDictionary
) {
231 data
= CFPropertyListCreateXMLData(allocator
, modifiedDictionary
);
233 size
= sizeof(mach_msg_base_t
) + ((CFDataGetLength(data
) + 3) & (~0x3));
234 msg
= (mach_msg_base_t
*)CFAllocatorAllocate(allocator
, size
, 0);
235 if (__CFOASafe
) __CFSetLastAllocationEventName(msg
, "CFUserNotification (temp)");
237 memset(msg
, 0, size
);
238 msg
->header
.msgh_bits
= MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND
, MACH_MSG_TYPE_MAKE_SEND_ONCE
);
239 msg
->header
.msgh_size
= size
;
240 msg
->header
.msgh_remote_port
= serverPort
;
241 msg
->header
.msgh_local_port
= replyPort
;
242 msg
->header
.msgh_id
= flags
;
243 msg
->body
.msgh_descriptor_count
= 0;
244 CFDataGetBytes(data
, CFRangeMake(0, CFDataGetLength(data
)), (uint8_t *)msg
+ sizeof(mach_msg_base_t
));
245 //CFShow(CFStringCreateWithBytes(NULL, (UInt8 *)msg + sizeof(mach_msg_base_t), CFDataGetLength(data), kCFStringEncodingUTF8, false));
246 retval
= mach_msg((mach_msg_header_t
*)msg
, MACH_SEND_MSG
|MACH_SEND_TIMEOUT
, size
, 0, MACH_PORT_NULL
, MESSAGE_TIMEOUT
, MACH_PORT_NULL
);
247 CFAllocatorDeallocate(allocator
, msg
);
249 retval
= unix_err(ENOMEM
);
253 retval
= unix_err(ENOMEM
);
255 CFRelease(modifiedDictionary
);
257 retval
= unix_err(ENOMEM
);
263 CFUserNotificationRef
CFUserNotificationCreate(CFAllocatorRef allocator
, CFTimeInterval timeout
, CFOptionFlags flags
, SInt32
*error
, CFDictionaryRef dictionary
) {
264 CFUserNotificationRef userNotification
= NULL
;
265 SInt32 retval
= ERR_SUCCESS
;
266 static uint16_t tokenCounter
= 0;
267 SInt32 token
= ((getpid()<<16) | (tokenCounter
++));
268 CFStringRef sessionID
= (dictionary
? CFDictionaryGetValue(dictionary
, kCFUserNotificationSessionIDKey
) : NULL
);
269 mach_port_t replyPort
= MACH_PORT_NULL
;
271 if (!allocator
) allocator
= __CFGetDefaultAllocator();
273 retval
= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE
, &replyPort
);
274 if (ERR_SUCCESS
== retval
&& MACH_PORT_NULL
!= replyPort
) retval
= _CFUserNotificationSendRequest(allocator
, sessionID
, replyPort
, token
, timeout
, flags
, dictionary
);
275 if (ERR_SUCCESS
== retval
) {
276 userNotification
= (CFUserNotificationRef
)_CFRuntimeCreateInstance(allocator
, __kCFUserNotificationTypeID
, sizeof(struct __CFUserNotification
) - sizeof(CFRuntimeBase
), NULL
);
277 if (userNotification
) {
278 userNotification
->_replyPort
= replyPort
;
279 userNotification
->_token
= token
;
280 userNotification
->_timeout
= timeout
;
281 userNotification
->_requestFlags
= flags
;
282 userNotification
->_responseFlags
= 0;
283 userNotification
->_sessionID
= NULL
;
284 userNotification
->_responseDictionary
= NULL
;
285 userNotification
->_machPort
= NULL
;
286 userNotification
->_callout
= NULL
;
287 if (sessionID
) userNotification
->_sessionID
= CFStringCreateCopy(allocator
, sessionID
);
289 retval
= unix_err(ENOMEM
);
292 if (dictionary
) CFUserNotificationLog(CFDictionaryGetValue(dictionary
, kCFUserNotificationAlertHeaderKey
), CFDictionaryGetValue(dictionary
, kCFUserNotificationAlertMessageKey
));
294 if (ERR_SUCCESS
!= retval
&& MACH_PORT_NULL
!= replyPort
) mach_port_destroy(mach_task_self(), replyPort
);
295 if (error
) *error
= retval
;
296 return userNotification
;
299 static void _CFUserNotificationMachPortCallBack(CFMachPortRef port
, void *m
, CFIndex size
, void *info
) {
300 CFUserNotificationRef userNotification
= (CFUserNotificationRef
)info
;
301 mach_msg_base_t
*msg
= (mach_msg_base_t
*)m
;
302 CFOptionFlags responseFlags
= msg
->header
.msgh_id
;
303 if (msg
->header
.msgh_size
> sizeof(mach_msg_base_t
)) {
304 CFDataRef responseData
= CFDataCreate(NULL
, (uint8_t *)msg
+ sizeof(mach_msg_base_t
), msg
->header
.msgh_size
- sizeof(mach_msg_base_t
));
306 userNotification
->_responseDictionary
= CFPropertyListCreateFromXMLData(NULL
, responseData
, kCFPropertyListImmutable
, NULL
);
307 CFRelease(responseData
);
310 CFMachPortInvalidate(userNotification
->_machPort
);
311 CFRelease(userNotification
->_machPort
);
312 userNotification
->_machPort
= NULL
;
313 mach_port_destroy(mach_task_self(), userNotification
->_replyPort
);
314 userNotification
->_replyPort
= MACH_PORT_NULL
;
315 userNotification
->_callout(userNotification
, responseFlags
);
318 SInt32
CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification
, CFTimeInterval timeout
, CFOptionFlags
*responseFlags
) {
319 SInt32 retval
= ERR_SUCCESS
;
320 mach_msg_timeout_t msgtime
= (timeout
> 0.0 && 1000.0 * timeout
< INT_MAX
) ? (mach_msg_timeout_t
)(1000.0 * timeout
) : 0;
321 mach_msg_base_t
*msg
= NULL
;
322 CFIndex size
= MAX_STRING_COUNT
* MAX_STRING_LENGTH
;
323 CFDataRef responseData
;
325 if (userNotification
&& MACH_PORT_NULL
!= userNotification
->_replyPort
) {
326 msg
= (mach_msg_base_t
*)CFAllocatorAllocate(CFGetAllocator(userNotification
), size
, 0);
327 if (__CFOASafe
) __CFSetLastAllocationEventName(msg
, "CFUserNotification (temp)");
329 memset(msg
, 0, size
);
330 msg
->header
.msgh_size
= size
;
332 retval
= mach_msg((mach_msg_header_t
*)msg
, MACH_RCV_MSG
|MACH_RCV_TIMEOUT
, 0, size
, userNotification
->_replyPort
, msgtime
, MACH_PORT_NULL
);
334 retval
= mach_msg((mach_msg_header_t
*)msg
, MACH_RCV_MSG
, 0, size
, userNotification
->_replyPort
, 0, MACH_PORT_NULL
);
336 if (ERR_SUCCESS
== retval
) {
337 if (responseFlags
) *responseFlags
= msg
->header
.msgh_id
;
338 if (msg
->header
.msgh_size
> sizeof(mach_msg_base_t
)) {
339 responseData
= CFDataCreate(NULL
, (uint8_t *)msg
+ sizeof(mach_msg_base_t
), msg
->header
.msgh_size
- sizeof(mach_msg_base_t
));
341 userNotification
->_responseDictionary
= CFPropertyListCreateFromXMLData(NULL
, responseData
, kCFPropertyListImmutable
, NULL
);
342 CFRelease(responseData
);
345 if (userNotification
->_machPort
) {
346 CFMachPortInvalidate(userNotification
->_machPort
);
347 CFRelease(userNotification
->_machPort
);
348 userNotification
->_machPort
= NULL
;
350 mach_port_destroy(mach_task_self(), userNotification
->_replyPort
);
351 userNotification
->_replyPort
= MACH_PORT_NULL
;
353 CFAllocatorDeallocate(CFGetAllocator(userNotification
), msg
);
355 retval
= unix_err(ENOMEM
);
361 CFStringRef
CFUserNotificationGetResponseValue(CFUserNotificationRef userNotification
, CFStringRef key
, CFIndex idx
) {
362 CFStringRef retval
= NULL
;
363 CFTypeRef value
= NULL
;
364 if (userNotification
&& userNotification
->_responseDictionary
) {
365 value
= CFDictionaryGetValue(userNotification
->_responseDictionary
, key
);
366 if (CFGetTypeID(value
) == CFStringGetTypeID()) {
368 retval
= (CFStringRef
)value
;
370 } else if (CFGetTypeID(value
) == CFArrayGetTypeID()) {
371 if (0 <= idx
&& idx
< CFArrayGetCount((CFArrayRef
)value
)) {
372 retval
= (CFStringRef
)CFArrayGetValueAtIndex((CFArrayRef
)value
, idx
);
379 CFDictionaryRef
CFUserNotificationGetResponseDictionary(CFUserNotificationRef userNotification
) {
380 return userNotification
? userNotification
->_responseDictionary
: NULL
;
383 SInt32
CFUserNotificationUpdate(CFUserNotificationRef userNotification
, CFTimeInterval timeout
, CFOptionFlags flags
, CFDictionaryRef dictionary
) {
384 SInt32 retval
= ERR_SUCCESS
;
385 if (userNotification
&& MACH_PORT_NULL
!= userNotification
->_replyPort
) {
386 retval
= _CFUserNotificationSendRequest(CFGetAllocator(userNotification
), userNotification
->_sessionID
, userNotification
->_replyPort
, userNotification
->_token
, timeout
, flags
|kCFUserNotificationUpdateFlag
, dictionary
);
391 SInt32
CFUserNotificationCancel(CFUserNotificationRef userNotification
) {
392 SInt32 retval
= ERR_SUCCESS
;
393 if (userNotification
&& MACH_PORT_NULL
!= userNotification
->_replyPort
) {
394 retval
= _CFUserNotificationSendRequest(CFGetAllocator(userNotification
), userNotification
->_sessionID
, userNotification
->_replyPort
, userNotification
->_token
, 0, kCFUserNotificationCancelFlag
, NULL
);
399 CFRunLoopSourceRef
CFUserNotificationCreateRunLoopSource(CFAllocatorRef allocator
, CFUserNotificationRef userNotification
, CFUserNotificationCallBack callout
, CFIndex order
) {
400 CFRunLoopSourceRef source
= NULL
;
401 if (userNotification
&& callout
&& !userNotification
->_machPort
&& MACH_PORT_NULL
!= userNotification
->_replyPort
) {
402 CFMachPortContext context
= {0, userNotification
, NULL
, NULL
, NULL
};
403 userNotification
->_machPort
= CFMachPortCreateWithPort(CFGetAllocator(userNotification
), (mach_port_t
)userNotification
->_replyPort
, _CFUserNotificationMachPortCallBack
, &context
, false);
405 if (userNotification
&& userNotification
->_machPort
) {
406 source
= CFMachPortCreateRunLoopSource(allocator
, userNotification
->_machPort
, order
);
407 userNotification
->_callout
= callout
;
412 SInt32
CFUserNotificationDisplayNotice(CFTimeInterval timeout
, CFOptionFlags flags
, CFURLRef iconURL
, CFURLRef soundURL
, CFURLRef localizationURL
, CFStringRef alertHeader
, CFStringRef alertMessage
, CFStringRef defaultButtonTitle
) {
413 CFUserNotificationRef userNotification
;
414 SInt32 retval
= ERR_SUCCESS
;
415 CFMutableDictionaryRef dict
= CFDictionaryCreateMutable(NULL
, 0, &kCFCopyStringDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
416 if (iconURL
) CFDictionaryAddValue(dict
, kCFUserNotificationIconURLKey
, iconURL
);
417 if (soundURL
) CFDictionaryAddValue(dict
, kCFUserNotificationSoundURLKey
, soundURL
);
418 if (localizationURL
) CFDictionaryAddValue(dict
, kCFUserNotificationLocalizationURLKey
, localizationURL
);
419 if (alertHeader
) CFDictionaryAddValue(dict
, kCFUserNotificationAlertHeaderKey
, alertHeader
);
420 if (alertMessage
) CFDictionaryAddValue(dict
, kCFUserNotificationAlertMessageKey
, alertMessage
);
421 if (defaultButtonTitle
) CFDictionaryAddValue(dict
, kCFUserNotificationDefaultButtonTitleKey
, defaultButtonTitle
);
422 userNotification
= CFUserNotificationCreate(NULL
, timeout
, flags
, &retval
, dict
);
423 if (userNotification
) CFRelease(userNotification
);
428 CF_EXPORT SInt32
CFUserNotificationDisplayAlert(CFTimeInterval timeout
, CFOptionFlags flags
, CFURLRef iconURL
, CFURLRef soundURL
, CFURLRef localizationURL
, CFStringRef alertHeader
, CFStringRef alertMessage
, CFStringRef defaultButtonTitle
, CFStringRef alternateButtonTitle
, CFStringRef otherButtonTitle
, CFOptionFlags
*responseFlags
) {
429 CFUserNotificationRef userNotification
;
430 SInt32 retval
= ERR_SUCCESS
;
431 CFMutableDictionaryRef dict
= CFDictionaryCreateMutable(NULL
, 0, &kCFCopyStringDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
432 if (iconURL
) CFDictionaryAddValue(dict
, kCFUserNotificationIconURLKey
, iconURL
);
433 if (soundURL
) CFDictionaryAddValue(dict
, kCFUserNotificationSoundURLKey
, soundURL
);
434 if (localizationURL
) CFDictionaryAddValue(dict
, kCFUserNotificationLocalizationURLKey
, localizationURL
);
435 if (alertHeader
) CFDictionaryAddValue(dict
, kCFUserNotificationAlertHeaderKey
, alertHeader
);
436 if (alertMessage
) CFDictionaryAddValue(dict
, kCFUserNotificationAlertMessageKey
, alertMessage
);
437 if (defaultButtonTitle
) CFDictionaryAddValue(dict
, kCFUserNotificationDefaultButtonTitleKey
, defaultButtonTitle
);
438 if (alternateButtonTitle
) CFDictionaryAddValue(dict
, kCFUserNotificationAlternateButtonTitleKey
, alternateButtonTitle
);
439 if (otherButtonTitle
) CFDictionaryAddValue(dict
, kCFUserNotificationOtherButtonTitleKey
, otherButtonTitle
);
440 userNotification
= CFUserNotificationCreate(NULL
, timeout
, flags
, &retval
, dict
);
441 if (userNotification
) {
442 retval
= CFUserNotificationReceiveResponse(userNotification
, timeout
, responseFlags
);
443 if (MACH_RCV_TIMED_OUT
== retval
) {
444 retval
= CFUserNotificationCancel(userNotification
);
445 if (responseFlags
) *responseFlags
= kCFUserNotificationCancelResponse
;
447 CFRelease(userNotification
);
455 #warning CFUserNotification functions not fully implemented
457 void __CFUserNotificationDeallocate(CFTypeRef cf
) {
460 CFUserNotificationRef
CFUserNotificationCreate(CFAllocatorRef allocator
, CFTimeInterval timeout
, CFOptionFlags flags
, SInt32
*error
, CFDictionaryRef dictionary
) {
461 CFUserNotificationLog(CFDictionaryGetValue(dictionary
, kCFUserNotificationAlertHeaderKey
), CFDictionaryGetValue(dictionary
, kCFUserNotificationAlertMessageKey
));
465 SInt32
CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification
, CFTimeInterval timeout
, CFOptionFlags
*responseFlags
) {
469 CFDictionaryRef
CFUserNotificationCopyResponseDictionary(CFUserNotificationRef userNotification
) {
473 SInt32
CFUserNotificationUpdate(CFUserNotificationRef userNotification
, CFTimeInterval timeout
, CFOptionFlags flags
, CFDictionaryRef dictionary
) {
477 SInt32
CFUserNotificationCancel(CFUserNotificationRef userNotification
) {
481 CFRunLoopSourceRef
CFUserNotificationCreateRunLoopSource(CFAllocatorRef allocator
, CFUserNotificationRef userNotification
, CFUserNotificationCallBack callout
, CFIndex order
) {
485 SInt32
CFUserNotificationDisplayNotice(CFTimeInterval timeout
, CFOptionFlags flags
, CFURLRef iconURL
, CFURLRef soundURL
, CFURLRef localizationURL
, CFStringRef alertHeader
, CFStringRef alertMessage
, CFStringRef defaultButtonTitle
) {
486 CFUserNotificationLog(alertHeader
, alertMessage
);
490 SInt32
CFUserNotificationDisplayAlert(CFTimeInterval timeout
, CFOptionFlags flags
, CFURLRef iconURL
, CFURLRef soundURL
, CFURLRef localizationURL
, CFStringRef alertHeader
, CFStringRef alertMessage
, CFStringRef defaultButtonTitle
, CFStringRef alternateButtonTitle
, CFStringRef otherButtonTitle
, CFOptionFlags
*responseFlags
) {
491 CFUserNotificationLog(alertHeader
, alertMessage
);
495 #endif /* __MACH__ */
497 #undef __kCFLogUserNotification
498 #undef CFUserNotificationLog
499 #undef MAX_STRING_LENGTH
500 #undef MAX_STRING_COUNT
501 #undef NOTIFICATION_PORT_NAME
502 #undef NOTIFICATION_PORT_NAME_OLD
503 #undef MESSAGE_TIMEOUT