From 4af2c41657c4ed0a522309a9432180459c2e8cd5 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Tue, 3 Mar 2009 03:50:02 +0000 Subject: [PATCH] client: Revise Apple idle time detection for compatibility with OS 10.6. svn path=/trunk/boinc/; revision=17436 --- client/hostinfo_unix.cpp | 53 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index 9d0d3d8f1e..8cb0f9d039 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -1115,44 +1115,43 @@ bool HOST_INFO::users_idle( // Do this here because NXOpenEventStatus() may not be available // immediately on system startup when running as a deaemon. - if (TickCount() > (120*60)) { // If system has been up for more than 2 minutes - msg_printf(NULL, MSG_USER_ERROR, - "User idle detection is disabled: initialization failed." - ); - error_posted = true; - goto bail; - } - gEventHandle = NXOpenEventStatus(); + if (!gEventHandle) { + if (TickCount() > (120*60)) { // If system has been up for more than 2 minutes + msg_printf(NULL, MSG_USER_ERROR, + "User idle detection is disabled: initialization failed." + ); + error_posted = true; + goto bail; + } + } } } else { // NXIdleTime API does not exist in OS 10.6 and later if (gEventHandle) { kernResult = IOHIDGetParameter( gEventHandle, CFSTR(EVSIOIDLE), sizeof(UInt64), ¶ms, &rcnt ); if ( kernResult != kIOReturnSuccess ) { - if (!error_posted) { - msg_printf(NULL, MSG_USER_ERROR, - "User idle time measurement failed because IOHIDGetParameter failed." - ); - error_posted = true; - } + msg_printf(NULL, MSG_USER_ERROR, + "User idle time measurement failed because IOHIDGetParameter failed." + ); + error_posted = true; goto bail; } idleTime = ((double)params) / 1000.0 / 1000.0 / 1000.0; } else { - // When the system first starts up, allow time for HIDSystem to be available if needed - if (TickCount() > (120*60)) { // If system has been up for more than 2 minutes - msg_printf(NULL, MSG_USER_ERROR, - "Could not connect to HIDSystem: user idle detection is disabled." - ); - goto bail; - } - service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass)); - if (service == 0) goto bail; - - kernResult = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &gEventHandle); - if (kernResult != KERN_SUCCESS) goto bail; - + if (service) { + kernResult = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &gEventHandle); + } + if ( (!service) || (kernResult != KERN_SUCCESS) ) { + // When the system first starts up, allow time for HIDSystem to be available if needed + if (TickCount() > (120*60)) { // If system has been up for more than 2 minutes + msg_printf(NULL, MSG_USER_ERROR, + "Could not connect to HIDSystem: user idle detection is disabled." + ); + error_posted = true; + goto bail; + } + } } // End gEventHandle == NULL } // End NXIdleTime API does not exist