2 * Copyright (c) 2012 David Kocher. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * Bug fixes, suggestions and comments should be sent to:
16 * dkocher@cyberduck.ch
19 #import "IOKitSleepPreventer.h"
20 #import <JavaNativeFoundation/JNFString.h>
21 #import <IOKit/pwr_mgt/IOPMLib.h>
23 JNIEXPORT jstring JNICALL Java_ch_cyberduck_core_IOKitSleepPreventer_createAssertion
24 (JNIEnv *env, jobject this, jstring reason)
26 IOPMAssertionID assertionID;
27 // Prevents the system from sleeping automatically due to a lack of user activity.
28 IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep,
29 kIOPMAssertionLevelOn, (CFStringRef)JNFJavaToNSString(env, reason), &assertionID);
30 if (success == kIOReturnSuccess) {
31 return JNFNSToJavaString(env, [NSString stringWithFormat: @"%u", assertionID]);
37 JNIEXPORT void JNICALL Java_ch_cyberduck_core_IOKitSleepPreventer_releaseAssertion
38 (JNIEnv *env, jobject this, jstring assertionID)
40 NSString* id = JNFJavaToNSString(env, assertionID);
41 IOPMAssertionRelease([id intValue]);