/*
- * Copyright (c) 2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2009 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* @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
*/
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;
#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
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);
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) {
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;
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;
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;
}
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);