mirror of https://github.com/BOINC/boinc.git
client: Mac: continue replacing deprecated Mac APIs
This commit is contained in:
parent
18c6f7b9fc
commit
f7ae4c631b
|
@ -138,8 +138,6 @@ extern "C" {
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mach_port_t gEventHandle = NULL;
|
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
#ifdef _HPUX_SOURCE
|
#ifdef _HPUX_SOURCE
|
||||||
|
@ -2017,6 +2015,10 @@ int get_system_uptime() {
|
||||||
// CGEventSourceSecondsSinceLastEventType() API does work with ARD and VNC,
|
// CGEventSourceSecondsSinceLastEventType() API does work with ARD and VNC,
|
||||||
// except when BOINC is a pre-login launchd daemon running as user boinc_master.
|
// except when BOINC is a pre-login launchd daemon running as user boinc_master.
|
||||||
//
|
//
|
||||||
|
// IOHIDGetParameter() is deprecated in OS 10.12, but IORegistryEntryFromPath()
|
||||||
|
// and IORegistryEntryCreateCFProperty() do the same thing and have been
|
||||||
|
// available since OS 10.0.
|
||||||
|
//
|
||||||
// Also, CGEventSourceSecondsSinceLastEventType() does not detect user activity
|
// Also, CGEventSourceSecondsSinceLastEventType() does not detect user activity
|
||||||
// when the user who launched the client is switched out by fast user switching.
|
// when the user who launched the client is switched out by fast user switching.
|
||||||
//
|
//
|
||||||
|
@ -2030,72 +2032,23 @@ bool HOST_INFO::users_idle(
|
||||||
bool check_all_logins, double idle_time_to_run, double *actual_idle_time
|
bool check_all_logins, double idle_time_to_run, double *actual_idle_time
|
||||||
) {
|
) {
|
||||||
static bool error_posted = false;
|
static bool error_posted = false;
|
||||||
|
long idleNanoSeconds;
|
||||||
double idleTime = 0;
|
double idleTime = 0;
|
||||||
double idleTimeFromCG = 0;
|
double idleTimeFromCG = 0;
|
||||||
io_service_t service;
|
|
||||||
kern_return_t kernResult = kIOReturnError;
|
CFTypeRef idleTimeProperty;
|
||||||
UInt64 params;
|
io_registry_entry_t IOHIDSystemEntry;
|
||||||
IOByteCount rcnt = sizeof(UInt64);
|
|
||||||
void *IOKitlib = NULL;
|
|
||||||
static bool triedToLoadNXIdleTime = false;
|
|
||||||
static nxIdleTimeProc myNxIdleTimeProc = NULL;
|
|
||||||
|
|
||||||
if (error_posted) goto bail;
|
if (error_posted) goto bail;
|
||||||
|
|
||||||
if (!triedToLoadNXIdleTime) {
|
IOHIDSystemEntry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IOHIDSystem");
|
||||||
triedToLoadNXIdleTime = true;
|
if (IOHIDSystemEntry != MACH_PORT_NULL) {
|
||||||
|
idleTimeProperty = IORegistryEntryCreateCFProperty(IOHIDSystemEntry,CFSTR(EVSIOIDLE),kCFAllocatorDefault,kNilOptions);
|
||||||
IOKitlib = dlopen ("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_NOW );
|
idleNanoSeconds = (long)idleTimeProperty/256;
|
||||||
if (IOKitlib) {
|
idleTime = ((double)idleNanoSeconds) / 1000.0 / 1000.0 / 1000.0;
|
||||||
myNxIdleTimeProc = (nxIdleTimeProc)dlsym(IOKitlib, "NXIdleTime");
|
IOObjectRelease(IOHIDSystemEntry);
|
||||||
}
|
CFRelease(idleTimeProperty);
|
||||||
}
|
|
||||||
|
|
||||||
if (myNxIdleTimeProc) { // Use NXIdleTime API in OS 10.5 and earlier
|
|
||||||
if (gEventHandle) {
|
|
||||||
idleTime = myNxIdleTimeProc(gEventHandle);
|
|
||||||
} else {
|
} else {
|
||||||
// Initialize Mac OS X idle time measurement / idle detection
|
|
||||||
// Do this here because NXOpenEventStatus() may not be available
|
|
||||||
// immediately on system startup when running as a deaemon.
|
|
||||||
|
|
||||||
gEventHandle = NXOpenEventStatus();
|
|
||||||
if (!gEventHandle) {
|
|
||||||
if (get_system_uptime() > (120)) { // If system has been up for more than 2 minutes
|
|
||||||
msg_printf(NULL, MSG_INFO,
|
|
||||||
"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 ) {
|
|
||||||
msg_printf(NULL, MSG_INFO,
|
|
||||||
"User idle time measurement failed because IOHIDGetParameter failed."
|
|
||||||
);
|
|
||||||
error_posted = true;
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
idleTime = ((double)params) / 1000.0 / 1000.0 / 1000.0;
|
|
||||||
|
|
||||||
if (!gstate.executing_as_daemon) {
|
|
||||||
idleTimeFromCG = CGEventSourceSecondsSinceLastEventType
|
|
||||||
(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType);
|
|
||||||
|
|
||||||
if (idleTimeFromCG < idleTime) {
|
|
||||||
idleTime = idleTimeFromCG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
|
|
||||||
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
|
// When the system first starts up, allow time for HIDSystem to be available if needed
|
||||||
if (get_system_uptime() > (120)) { // If system has been up for more than 2 minutes
|
if (get_system_uptime() > (120)) { // If system has been up for more than 2 minutes
|
||||||
msg_printf(NULL, MSG_INFO,
|
msg_printf(NULL, MSG_INFO,
|
||||||
|
@ -2105,8 +2058,15 @@ bool HOST_INFO::users_idle(
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // End (gEventHandle == NULL)
|
|
||||||
} // End NXIdleTime API does not exist
|
if (!gstate.executing_as_daemon) {
|
||||||
|
idleTimeFromCG = CGEventSourceSecondsSinceLastEventType
|
||||||
|
(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType);
|
||||||
|
|
||||||
|
if (idleTimeFromCG < idleTime) {
|
||||||
|
idleTime = idleTimeFromCG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (actual_idle_time) {
|
if (actual_idle_time) {
|
||||||
|
|
Loading…
Reference in New Issue