-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeepalive.mm
36 lines (30 loc) · 1.3 KB
/
keepalive.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
--------------------------------------------------------------------------------
- Module : keepalive.mm
- Description : A wrapper to keep an app alive, written
- in C++ and Objective-C so made for the OSX platform.
- Author : Tim Zaman, 18-FEB-2016
--------------------------------------------------------------------------------
*/
#include "keepalive.h"
#import <IOKit/pwr_mgt/IOPMLib.h>
// kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
// kIOPMAssertionTypeNoIdleSleep prevents idle sleep
//reasonForActivity is a descriptive string used by the system whenever it needs
// to tell the user why the system is not sleeping. For example,
// "Mail Compacting Mailboxes" would be a useful string.
IOPMAssertionID assertionID;
void KeepAlive::KeepAliveMM(){
// NOTE: IOPMAssertionCreateWithName limits the string to 128 characters.
CFStringRef reasonForActivity = CFSTR("Program Running.");
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
if (success == kIOReturnSuccess){
// @TODO?
} else {
// @TODO?
}
}
void KeepAlive::KeepAliveDestructorMM(){
IOReturn success = IOPMAssertionRelease(assertionID);
}