OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #if defined(FLETCH_TARGET_OS_MACOS) | 5 #if defined(DARTINO_TARGET_OS_MACOS) |
6 | 6 |
7 #include <IOKit/pwr_mgt/IOPMLib.h> | 7 #include <IOKit/pwr_mgt/IOPMLib.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_native_api.h" | 10 #include "include/dart_native_api.h" |
11 | 11 |
12 #include "power_management_extension.h" | 12 #include "power_management_extension.h" |
13 | 13 |
14 int64_t HandleDisableSleep(const char* reason) { | 14 int64_t HandleDisableSleep(const char* reason) { |
15 CFStringRef reasonForActivity = | 15 CFStringRef reasonForActivity = |
16 CFStringCreateWithCString(NULL, reason, kCFStringEncodingUTF8); | 16 CFStringCreateWithCString(NULL, reason, kCFStringEncodingUTF8); |
17 | 17 |
18 IOPMAssertionID assertionID; | 18 IOPMAssertionID assertionID; |
19 IOReturn success = IOPMAssertionCreateWithName( | 19 IOReturn success = IOPMAssertionCreateWithName( |
20 kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, | 20 kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, |
21 reasonForActivity, &assertionID); | 21 reasonForActivity, &assertionID); |
22 if (success == kIOReturnSuccess) { | 22 if (success == kIOReturnSuccess) { |
23 return assertionID; | 23 return assertionID; |
24 } else { | 24 } else { |
25 return -1; | 25 return -1; |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 void HandleEnableSleep(int64_t disable_id) { | 29 void HandleEnableSleep(int64_t disable_id) { |
30 IOPMAssertionRelease(disable_id); | 30 IOPMAssertionRelease(disable_id); |
31 } | 31 } |
32 | 32 |
33 #endif // FLETCH_TARGET_OS_MACOS | 33 #endif // DARTINO_TARGET_OS_MACOS |
OLD | NEW |