X-Git-Url: https://git.saurik.com/apple/cf.git/blobdiff_plain/b0e0750aaee7a1a2cd8e3aa918bd9fc756e9dfcf..cf7d2af96685aba74e84652f9ed1098e9253902e:/CFUserNotification.c?ds=sidebyside diff --git a/CFUserNotification.c b/CFUserNotification.c index 68f86c3..ee63e85 100644 --- a/CFUserNotification.c +++ b/CFUserNotification.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Apple Inc. All rights reserved. + * Copyright (c) 2009 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -21,7 +21,7 @@ * @APPLE_LICENSE_HEADER_END@ */ /* CFUserNotification.c - Copyright (c) 2000-2007 Apple Inc. All rights reserved. + Copyright (c) 2000-2009, Apple Inc. All rights reserved. Responsibility: Doug Davidson */ @@ -74,6 +74,8 @@ CONST_STRING_DECL(kCFUserNotificationCheckBoxTitlesKey, "CheckBoxTitles") CONST_STRING_DECL(kCFUserNotificationTextFieldValuesKey, "TextFieldValues") CONST_STRING_DECL(kCFUserNotificationPopUpSelectionKey, "PopUpSelection") CONST_STRING_DECL(kCFUserNotificationKeyboardTypesKey, "KeyboardTypes") +CONST_STRING_DECL(kCFUserNotificationAlertTopMostKey, "AlertTopMost") // boolean value + static CFTypeID __kCFUserNotificationTypeID = _kCFRuntimeNotATypeID; @@ -104,7 +106,7 @@ static CFStringRef __CFUserNotificationCopyDescription(CFTypeRef cf) { #define MESSAGE_TIMEOUT 100 #if DEPLOYMENT_TARGET_MACOSX #define NOTIFICATION_PORT_NAME "com.apple.UNCUserNotification" -#elif 0 +#elif DEPLOYMENT_TARGET_EMBEDDED #define NOTIFICATION_PORT_NAME "com.apple.SBUserNotification" #else #error Unknown or unspecified DEPLOYMENT_TARGET @@ -206,14 +208,15 @@ static SInt32 _CFUserNotificationSendRequest(CFAllocatorRef allocator, CFStringR mach_port_t bootstrapPort = MACH_PORT_NULL, serverPort = MACH_PORT_NULL; CFIndex size; char namebuffer[MAX_PORT_NAME_LENGTH + 1]; + strlcpy(namebuffer, NOTIFICATION_PORT_NAME, sizeof(namebuffer)); if (sessionID) { - char sessionid[MAX_PORT_NAME_LENGTH + 1]; - CFIndex len = MAX_PORT_NAME_LENGTH - sizeof(NOTIFICATION_PORT_NAME) - sizeof(NOTIFICATION_PORT_NAME_SUFFIX); + char sessionid[MAX_PORT_NAME_LENGTH + 1]; + CFIndex len = MAX_PORT_NAME_LENGTH - sizeof(NOTIFICATION_PORT_NAME) - sizeof(NOTIFICATION_PORT_NAME_SUFFIX); CFStringGetBytes(sessionID, CFRangeMake(0, CFStringGetLength(sessionID)), kCFStringEncodingUTF8, 0, false, (uint8_t *)sessionid, len, &size); - sessionid[len - 1] = '\0'; - strlcat(namebuffer, NOTIFICATION_PORT_NAME_SUFFIX, sizeof(namebuffer)); - strlcat(namebuffer, sessionid, sizeof(namebuffer)); + sessionid[len - 1] = '\0'; + strlcat(namebuffer, NOTIFICATION_PORT_NAME_SUFFIX, sizeof(namebuffer)); + strlcat(namebuffer, sessionid, sizeof(namebuffer)); } retval = task_get_bootstrap_port(mach_task_self(), &bootstrapPort); @@ -258,12 +261,11 @@ CFUserNotificationRef CFUserNotificationCreate(CFAllocatorRef allocator, CFTimeI CFUserNotificationRef userNotification = NULL; SInt32 retval = ERR_SUCCESS; static uint16_t tokenCounter = 0; - SInt32 token = ((getpid()<<16) | (tokenCounter++)); + SInt32 token = ((getpid() << 16) | (tokenCounter++)); CFStringRef sessionID = (dictionary ? CFDictionaryGetValue(dictionary, kCFUserNotificationSessionIDKey) : NULL); mach_port_t replyPort = MACH_PORT_NULL; if (!allocator) allocator = __CFGetDefaultAllocator(); - retval = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &replyPort); if (ERR_SUCCESS == retval && MACH_PORT_NULL != replyPort) retval = _CFUserNotificationSendRequest(allocator, sessionID, replyPort, token, timeout, flags, dictionary); if (ERR_SUCCESS == retval) { @@ -319,7 +321,7 @@ SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification, if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) { msg = (mach_msg_base_t *)CFAllocatorAllocate(CFGetAllocator(userNotification), size, 0); - if (__CFOASafe) __CFSetLastAllocationEventName(msg, "CFUserNotification (temp)"); + if (__CFOASafe) __CFSetLastAllocationEventName(msg, "CFUserNotification (temp)"); if (msg) { memset(msg, 0, size); msg->header.msgh_size = size; @@ -360,13 +362,9 @@ CFStringRef CFUserNotificationGetResponseValue(CFUserNotificationRef userNotific if (userNotification && userNotification->_responseDictionary) { value = CFDictionaryGetValue(userNotification->_responseDictionary, key); if (CFGetTypeID(value) == CFStringGetTypeID()) { - if (0 == idx) { - retval = (CFStringRef)value; - } + if (0 == idx) retval = (CFStringRef)value; } else if (CFGetTypeID(value) == CFArrayGetTypeID()) { - if (0 <= idx && idx < CFArrayGetCount((CFArrayRef)value)) { - retval = (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)value, idx); - } + if (0 <= idx && idx < CFArrayGetCount((CFArrayRef)value)) retval = (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)value, idx); } } return retval; @@ -380,18 +378,14 @@ CFDictionaryRef CFUserNotificationGetResponseDictionary(CFUserNotificationRef us SInt32 CFUserNotificationUpdate(CFUserNotificationRef userNotification, CFTimeInterval timeout, CFOptionFlags flags, CFDictionaryRef dictionary) { CHECK_FOR_FORK(); SInt32 retval = ERR_SUCCESS; - if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) { - retval = _CFUserNotificationSendRequest(CFGetAllocator(userNotification), userNotification->_sessionID, userNotification->_replyPort, userNotification->_token, timeout, flags|kCFUserNotificationUpdateFlag, dictionary); - } + if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) retval = _CFUserNotificationSendRequest(CFGetAllocator(userNotification), userNotification->_sessionID, userNotification->_replyPort, userNotification->_token, timeout, flags|kCFUserNotificationUpdateFlag, dictionary); return retval; } SInt32 CFUserNotificationCancel(CFUserNotificationRef userNotification) { CHECK_FOR_FORK(); SInt32 retval = ERR_SUCCESS; - if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) { - retval = _CFUserNotificationSendRequest(CFGetAllocator(userNotification), userNotification->_sessionID, userNotification->_replyPort, userNotification->_token, 0, kCFUserNotificationCancelFlag, NULL); - } + if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) retval = _CFUserNotificationSendRequest(CFGetAllocator(userNotification), userNotification->_sessionID, userNotification->_replyPort, userNotification->_token, 0, kCFUserNotificationCancelFlag, NULL); return retval; } @@ -400,7 +394,7 @@ CFRunLoopSourceRef CFUserNotificationCreateRunLoopSource(CFAllocatorRef allocato CFRunLoopSourceRef source = NULL; if (userNotification && callout && !userNotification->_machPort && MACH_PORT_NULL != userNotification->_replyPort) { CFMachPortContext context = {0, userNotification, NULL, NULL, NULL}; - userNotification->_machPort = CFMachPortCreateWithPort(CFGetAllocator(userNotification), (mach_port_t)userNotification->_replyPort, _CFUserNotificationMachPortCallBack, &context, false); + userNotification->_machPort = CFMachPortCreateWithPort(CFGetAllocator(userNotification), (mach_port_t)userNotification->_replyPort, _CFUserNotificationMachPortCallBack, &context, NULL); } if (userNotification && userNotification->_machPort) { source = CFMachPortCreateRunLoopSource(allocator, userNotification->_machPort, order);