Search in sources :

Example 6 with CFStringRef

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;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) CFStringRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef) KernReturnT(net.pms.util.jna.macos.kernreturn.KernReturnT) DefaultKernReturnT(net.pms.util.jna.macos.kernreturn.DefaultKernReturnT)

Aggregations

CFStringRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef)6 Test (org.junit.Test)4 IntByReference (com.sun.jna.ptr.IntByReference)2 CFDictionaryRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFDictionaryRef)2 CFNumberRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFNumberRef)2 DefaultKernReturnT (net.pms.util.jna.macos.kernreturn.DefaultKernReturnT)2 KernReturnT (net.pms.util.jna.macos.kernreturn.KernReturnT)2 NativeLong (com.sun.jna.NativeLong)1 PointerByReference (com.sun.jna.ptr.PointerByReference)1 StringByReference (net.pms.util.jna.StringByReference)1 CFArrayRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFArrayRef)1 CFMutableArrayRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableArrayRef)1 CFMutableDictionaryRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRef)1 CFMutableDictionaryRefByReference (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRefByReference)1 CFMutableStringRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableStringRef)1 CFTypeRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFTypeRef)1 IOIteratorT (net.pms.util.jna.macos.types.IOIteratorT)1 IOIteratorTRef (net.pms.util.jna.macos.types.IOIteratorTRef)1 IONameT (net.pms.util.jna.macos.types.IONameT)1 IOObjectT (net.pms.util.jna.macos.types.IOObjectT)1