diff options
author | Rodeo <[email protected]> | 2013-03-18 18:07:48 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2013-03-18 18:07:48 +0000 |
commit | 30ddd53e26b3e2aa5930c6cf985f938e36985aed (patch) | |
tree | 3399efbb5727360437672b8918a32dab72420e22 /libhb/ports.c | |
parent | b0aa37a7ff20acafe7a28fe67c69699515d963c5 (diff) |
hb_system_sleep: refactoring.
Also:
- release power assertions before freeing them
- actually free the power assertions in hb_close() (previously unused)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5340 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/ports.c')
-rw-r--r-- | libhb/ports.c | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/libhb/ports.c b/libhb/ports.c index 7097f2ee9..98945fec0 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -792,63 +792,101 @@ char *strtok_r(char *s, const char *delim, char **save_ptr) #ifdef __APPLE__ // 128 chars limit for IOPMAssertionCreateWithName -static CFStringRef reasonForActivity= CFSTR("HandBrake is currently scanning and/or encoding"); +static CFStringRef reasonForActivity = + CFSTR("HandBrake is currently scanning and/or encoding"); #endif void* hb_system_sleep_opaque_init() { - void* opaque; + void *opaque = NULL; #ifdef __APPLE__ - opaque = calloc( sizeof( IOPMAssertionID ), 1); - IOPMAssertionID * assertionID = (IOPMAssertionID *)opaque; + opaque = calloc(sizeof(IOPMAssertionID), 1); + if (opaque == NULL) + { + hb_error("hb_system_sleep: failed to allocate opaque"); + return NULL; + } + + IOPMAssertionID *assertionID = (IOPMAssertionID*)opaque; *assertionID = -1; #endif - return opaque; } -void hb_system_sleep_opaque_close(void **_opaque) +void hb_system_sleep_opaque_close(void **opaque) { + if (*opaque != NULL) + { + hb_system_sleep_private_enable(*opaque); + } #ifdef __APPLE__ - IOPMAssertionID * assertionID = (IOPMAssertionID *) *_opaque; - free( assertionID ); + if (*opaque != NULL) + { + IOPMAssertionID *assertionID = (IOPMAssertionID*)*opaque; + free(assertionID); + } #endif - *_opaque = NULL; + *opaque = NULL; } -void hb_system_sleep_allow(void *opaque) +void hb_system_sleep_private_enable(void *opaque) { #ifdef __APPLE__ - IOPMAssertionID * assertionID = (IOPMAssertionID *)opaque; + if (opaque == NULL) + { + hb_error("hb_system_sleep: opaque is NULL"); + } + IOPMAssertionID *assertionID = (IOPMAssertionID*)opaque; if (*assertionID == -1) + { + // nothing to do return; + } IOReturn success = IOPMAssertionRelease(*assertionID); - - if (success == kIOReturnSuccess) { - hb_deep_log( 3, "osxsleep: IOPM assertion %d successfully released, sleep allowed", *assertionID ); + if (success == kIOReturnSuccess) + { + hb_deep_log(3, + "hb_system_sleep: assertion %d released, sleep allowed", + *assertionID); *assertionID = -1; - } else { - hb_log( "osxsleep: error while trying to unset power management assertion" ); + } + else + { + hb_log("hb_system_sleep: failed to allow system sleep"); } #endif } -void hb_system_sleep_prevent(void *opaque) +void hb_system_sleep_private_disable(void *opaque) { #ifdef __APPLE__ - IOPMAssertionID * assertionID = (IOPMAssertionID *)opaque; - + if (opaque == NULL) + { + hb_error("hb_system_sleep: opaque is NULL"); + } + + IOPMAssertionID *assertionID = (IOPMAssertionID*)opaque; if (*assertionID != -1) + { + // nothing to do return; + } IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, - kIOPMAssertionLevelOn, reasonForActivity, assertionID); - if (success == kIOReturnSuccess) { - hb_deep_log( 3, "IOPM assertion %d successfully created, prevent sleep", *assertionID); - } else { - hb_log( "osxsleep: error while trying to set power management assertion" ); + kIOPMAssertionLevelOn, + reasonForActivity, + assertionID); + if (success == kIOReturnSuccess) + { + hb_deep_log(3, + "hb_system_sleep: assertion %d created, sleep prevented", + *assertionID); + } + else + { + hb_log("hb_system_sleep: failed to prevent system sleep"); } #endif } |