macOS system sleep prevention using IOKit power assertions
More...
Go to the source code of this file.
macOS system sleep prevention using IOKit power assertions
Definition in file macos/keepawake.c.
◆ platform_disable_keepawake()
| void platform_disable_keepawake |
( |
void |
| ) |
|
Definition at line 33 of file macos/keepawake.c.
33 {
34 if (g_power_assertion != kIOPMNullAssertionID) {
35 IOPMAssertionRelease(g_power_assertion);
36 log_debug("Keepawake disabled (released assertion ID: %u)", g_power_assertion);
37 g_power_assertion = kIOPMNullAssertionID;
38 }
39}
◆ platform_enable_keepawake()
| asciichat_error_t platform_enable_keepawake |
( |
void |
| ) |
|
Definition at line 14 of file macos/keepawake.c.
14 {
15
16 if (g_power_assertion != kIOPMNullAssertionID) {
17 log_debug("Keepawake already enabled");
18 return ASCIICHAT_OK;
19 }
20
21 CFStringRef reason = CFSTR("ascii-chat is running");
22 IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventSystemSleep, kIOPMAssertionLevelOn, reason,
23 &g_power_assertion);
24
25 if (result != kIOReturnSuccess) {
26 return SET_ERRNO(ERROR_PLATFORM_INIT, "Failed to create power assertion (error %d)", result);
27 }
28
29 log_debug("Keepawake enabled via IOKit (assertion ID: %u)", g_power_assertion);
30 return ASCIICHAT_OK;
31}