use of net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef in project UniversalMediaServer by UniversalMediaServer.
the class IOKitUtils method resetIdleTimer.
/**
* Creates an assertion preventing sleep with a timeout value equal to the
* idle sleep time. This has the same effect as if a user activity occurred
* so that the idle timer was reset.
*
* @param assertionName the name of the assertion to create.
* @param assertionId the assertion id if you want to extend the time of an
* existing assertion or {@code 0} to create a new assertion.
* @return The assertionId of the created assertion. This may or may not be
* the same as {@code assertionId}.
* @throws IOKitException If an error occurs during the operation.
*/
public static int resetIdleTimer(String assertionName, int assertionId) throws IOKitException {
if (isMacOsVersionEqualOrGreater(7, 3)) {
IntByReference assertionIdRef = new IntByReference(assertionId > 0 ? assertionId : 0);
CFStringRef name = CFStringRef.toCFStringRef(assertionName);
KernReturnT ioReturn = ioKit.IOPMAssertionDeclareUserActivity(name, IOPMUserActiveType.kIOPMUserActiveLocal, assertionIdRef);
if (ioReturn == DefaultKernReturnT.KERN_SUCCESS) {
return assertionIdRef.getValue();
}
throw new IOKitException("IOPMAssertionDeclareUserActivity failed with error code: " + ioReturn.toStandardString());
}
LOGGER.warn("Unable to reset sleep timer; not supported by maxOS version {}", System.getProperty("os.version"));
return -1;
}
Aggregations