ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
macos/keepawake.c
Go to the documentation of this file.
1
10#include <IOKit/pwr_mgt/IOPMLib.h>
11
12static IOPMAssertionID g_power_assertion = kIOPMNullAssertionID;
13
15 // macOS: Use IOKit power assertions
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}
32
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}
⚠️‼️ Comprehensive thread-local error context system for ascii-chat
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it, returning the error code.
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
@ ERROR_PLATFORM_INIT
Definition error_codes.h:60
@ ASCIICHAT_OK
Definition error_codes.h:51
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:548
void platform_disable_keepawake(void)
Disable system sleep prevention (allow OS to sleep)
asciichat_error_t platform_enable_keepawake(void)
Enable system sleep prevention (keepawake mode)
📝 Logging API with multiple log levels and terminal output control
Cross-platform system functions interface for ascii-chat.