inline void unInhibit() { if (m_okDisp) { IOPMAssertionRelease(m_idDisp); m_okDisp = false; } if (m_okSys) { IOPMAssertionRelease(m_idSys); m_okSys = false; } }
/*********************************************************************** * SystemParametersInfo (MACDRV.@) */ BOOL CDECL macdrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param, UINT flags ) { switch (action) { case SPI_GETSCREENSAVEACTIVE: if (ptr_param) { CFDictionaryRef assertionStates; IOReturn status = IOPMCopyAssertionsStatus(&assertionStates); if (status == kIOReturnSuccess) { CFNumberRef count = CFDictionaryGetValue(assertionStates, kIOPMAssertionTypeNoDisplaySleep); CFNumberRef count2 = CFDictionaryGetValue(assertionStates, kIOPMAssertionTypePreventUserIdleDisplaySleep); long longCount = 0, longCount2 = 0; if (count) CFNumberGetValue(count, kCFNumberLongType, &longCount); if (count2) CFNumberGetValue(count2, kCFNumberLongType, &longCount2); *(BOOL *)ptr_param = !longCount && !longCount2; CFRelease(assertionStates); } else { WARN("Could not determine screen saver state, error code %d\n", status); *(BOOL *)ptr_param = TRUE; } return TRUE; } break; case SPI_SETSCREENSAVEACTIVE: { static IOPMAssertionID powerAssertion = kIOPMNullAssertionID; if (int_param) { if (powerAssertion != kIOPMNullAssertionID) { IOPMAssertionRelease(powerAssertion); powerAssertion = kIOPMNullAssertionID; } } else if (powerAssertion == kIOPMNullAssertionID) { CFStringRef assertName; /*Are we running Lion or later?*/ if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7) assertName = kIOPMAssertionTypePreventUserIdleDisplaySleep; else assertName = kIOPMAssertionTypeNoDisplaySleep; IOPMAssertionCreateWithName( assertName, kIOPMAssertionLevelOn, CFSTR("Wine Process requesting no screen saver"), &powerAssertion); } } break; } return FALSE; }
void setKeepAwake(bool awake) { if (awake){ #if defined(Q_OS_WIN) SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS); #elif defined(Q_OS_MAC) if(success == kIOReturnSuccess) { }else{ success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &assertionID); } #endif }else{ #if defined(Q_OS_WIN) SetThreadExecutionState(ES_CONTINUOUS); #elif defined(Q_OS_MAC) if(success == kIOReturnSuccess) { IOPMAssertionRelease(assertionID); success = kIOReturnError; }else{ } #endif } }
void PowerComponentMac::doEnableScreensaver() { if (m_assertion != 0) { IOPMAssertionRelease(m_assertion); m_assertion = 0; } }
void enable_screensaver() { #if __APPLE__ IOReturn success = IOPMAssertionRelease(assertionID); #elif _WIN32 SetThreadExecutionState(ES_CONTINUOUS); #endif }
void screenAllowSleep() { if (assertionID == kIOPMNullAssertionID) { return; } IOPMAssertionRelease(assertionID); assertionID = kIOPMNullAssertionID; }
int main() { IOReturn ret = 0; IOPMAssertionID _id = 0; CFDictionaryRef _props = 0; CFStringRef keys[10]; CFTypeRef vals[10]; int val = 0; ret = PMTestInitialize("PMAssertions", "com.apple.iokit.powertesting"); if(kIOReturnSuccess != ret) { fprintf(stderr,"PMTestInitialize failed with IOReturn error code 0x%08x\n", ret); exit(-1); } keys[0] = kIOPMAssertionTypeKey; vals[0] = kIOPMAssertionTypePreventUserIdleSystemSleep; keys[1] = kIOPMAssertionHumanReadableReasonKey; vals[1] = CFSTR("I did this because I had to."); val = 500; // seconds keys[2] = kIOPMAssertionTimeoutKey; vals[2] = CFNumberCreate(0, kCFNumberIntType, &val); keys[3] = kIOPMAssertionLocalizationBundlePathKey; vals[3] = CFSTR("/System/Library/CoreServices/powerd.bundle"); _props = CFDictionaryCreate(0, (const void **)keys, (const void **)vals, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); ret = IOPMAssertionCreateWithProperties(_props, &_id); CFRelease(_props); CFRelease(vals[0]); CFRelease(vals[2]); if (kIOReturnSuccess != ret) { PMTestFail("IOPMAssertionCreateWithProperties returns non-success 0x%08x\n", ret); exit(1); } ret = IOPMAssertionRelease(_id); if (kIOReturnSuccess != ret) { PMTestFail("IOPMAssertionRelease returns non-success 0x%08x\n", ret); exit(1); } PMTestPass("Successfully created and released via IOPMAssertionCrateWithProperties\n"); return 0; }
void EnableScreenSaver(bool enable) #endif { // Inhibit the screensaver. Depending on the operating system this may also // disable low-power states and/or screen dimming. #if defined(HAVE_X11) && HAVE_X11 if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER)) { X11Utils::InhibitScreensaver(win, !enable); } #endif #ifdef _WIN32 // Prevents Windows from sleeping, turning off the display, or idling if (enable) { SetThreadExecutionState(ES_CONTINUOUS); } else { EXECUTION_STATE should_screen_save = Config::Get(Config::MAIN_DISABLE_SCREENSAVER) ? ES_DISPLAY_REQUIRED : 0; SetThreadExecutionState(ES_CONTINUOUS | should_screen_save | ES_SYSTEM_REQUIRED); } #endif #ifdef __APPLE__ static IOPMAssertionID s_power_assertion = kIOPMNullAssertionID; if (Config::Get(Config::MAIN_DISABLE_SCREENSAVER)) { if (enable) { if (s_power_assertion != kIOPMNullAssertionID) { IOPMAssertionRelease(s_power_assertion); s_power_assertion = kIOPMNullAssertionID; } } else { CFStringRef reason_for_activity = CFSTR("Emulation Running"); if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, reason_for_activity, &s_power_assertion) != kIOReturnSuccess) { s_power_assertion = kIOPMNullAssertionID; } } } #endif }
void video_output_qt::resume_screensaver() { #if defined(Q_OS_WIN) /* TODO */ #elif defined(Q_OS_MAC) IOPMAssertionRelease(_disableDisplaySleepAssertion); #elif defined(Q_OS_UNIX) _widget->stop_rendering(); if (QProcess::execute(QString("xdg-screensaver resume ") + str::from(_container_widget->winId()).c_str()) != 0) msg::wrn(_("Cannot resume screensaver.")); _widget->start_rendering(); #endif }
void CPowerManagement::DoSetIdle() { if (!m_busy) return; m_busy = false; #ifdef __WXMSW__ SetThreadExecutionState(ES_CONTINUOUS); #elif defined(WITH_LIBDBUS) m_inhibitor->RequestIdle(); #elif defined(__WXMAC__) // >= 10.5 Required for Power Management #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 IOPMAssertionRelease(m_assertionID); #endif #endif }
IOReturn doRelease() { return IOPMAssertionRelease(assertionID); }
int main() { IOReturn ret = kIOReturnSuccess; IOPMAssertionID assertion_id[DO_ITERATIONS] = {kIOPMNullAssertionID}; int didIterations = 0; int didFork = 0; int i=0; int failureLine = 0; PMTestInitialize("AssertOneWithTimeout: Create an assertion, set a timeout, let it expire. Wait 10 seconds.", "com.apple.iokit.powermanagement"); PMTestLog("Performing %d assert, settimeout, release cycles.", DO_ITERATIONS); for (i=0; i<DO_ITERATIONS; i++) { ret = IOPMAssertionCreate( kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &assertion_id[i]); if(kIOReturnSuccess != ret) { PMTestFail("Error 0x%08x from IOPMAssertionCreate()\n", ret); failureLine = __LINE__; break; } ret = IOPMAssertionSetTimeout(assertion_id[i], 5.0); if(kIOReturnSuccess != ret) { PMTestFail("Error 0x%08x from IOPMAssertionSetTimeout()\n", ret); failureLine = __LINE__; break; } } sleep(10); /* * * WAIT FOR ASSERTIONS TO TIMEOUT * */ for (i=0; i<DO_ITERATIONS; i++) { IOPMAssertionRelease(assertion_id[i]); } didIterations = i; PMTestLog("IOPMAssertionSetTimeout stress test: Did %d iterations, %d of which were forked children.", didIterations, didFork); if (kIOReturnSuccess != ret) { PMTestFail("Failure - IOReturn value 0x%08x returned at %s:%d", ret, __FILE__, failureLine); } else { PMTestPass("settimeout stress test succeeded."); } // TODO: Test did configd crash? return 0; }
void cupsdSetBusyState(void) { int i; /* Looping var */ cupsd_job_t *job; /* Current job */ cupsd_printer_t *p; /* Current printer */ int newbusy; /* New busy state */ static int busy = 0; /* Current busy state */ static const char * const busy_text[] = { /* Text for busy states */ "Not busy", "Dirty files", "Printing jobs", "Printing jobs and dirty files", "Active clients", "Active clients and dirty files", "Active clients and printing jobs", "Active clients, printing jobs, and dirty files" }; #ifdef __APPLE__ static vproc_transaction_t vtran = 0; /* Current busy transaction */ static IOPMAssertionID keep_awake = 0;/* Keep the system awake while printing */ #endif /* __APPLE__ */ /* * Figure out how busy we are... */ newbusy = (DirtyCleanTime ? 1 : 0) | (cupsArrayCount(ActiveClients) ? 4 : 0); for (job = (cupsd_job_t *)cupsArrayFirst(PrintingJobs); job; job = (cupsd_job_t *)cupsArrayNext(PrintingJobs)) { if ((p = job->printer) != NULL) { for (i = 0; i < p->num_reasons; i ++) if (!strcmp(p->reasons[i], "connecting-to-device")) break; if (!p->num_reasons || i >= p->num_reasons) break; } } if (job) newbusy |= 2; cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdSetBusyState: newbusy=\"%s\", busy=\"%s\"", busy_text[newbusy], busy_text[busy]); /* * Manage state changes... */ if (newbusy != busy) { busy = newbusy; #ifdef __APPLE__ if (busy && !vtran) vtran = vproc_transaction_begin(NULL); else if (!busy && vtran) { vproc_transaction_end(NULL, vtran); vtran = 0; } #endif /* __APPLE__ */ } #ifdef __APPLE__ if (cupsArrayCount(PrintingJobs) > 0 && !keep_awake) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Asserting NetworkClientActive."); IOPMAssertionCreateWithName(kIOPMAssertNetworkClientActive, kIOPMAssertionLevelOn, CFSTR("org.cups.cupsd"), &keep_awake); } else if (cupsArrayCount(PrintingJobs) == 0 && keep_awake) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Releasing power assertion."); IOPMAssertionRelease(keep_awake); keep_awake = 0; } #endif /* __APPLE__ */ }
static void sysUpdate(void) { int i; /* Looping var */ cupsd_sysevent_t sysevent; /* The system event */ cupsd_printer_t *p; /* Printer information */ /* * Drain the event pipe... */ while (read((int)SysEventPipes[0], &sysevent, sizeof(sysevent)) == sizeof(sysevent)) { if (sysevent.event & SYSEVENT_CANSLEEP) { /* * If there are active printers that don't have the connecting-to-device * printer-state-reason then cancel the sleep request (i.e. this reason * indicates a job that is not yet connected to the printer)... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) { if (p->job) { for (i = 0; i < p->num_reasons; i ++) if (!strcmp(p->reasons[i], "connecting-to-device")) break; if (!p->num_reasons || i >= p->num_reasons) break; } } if (p) { cupsdLogMessage(CUPSD_LOG_INFO, "System sleep canceled because printer %s is active", p->name); IOCancelPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); } else { cupsdLogMessage(CUPSD_LOG_DEBUG, "System wants to sleep"); IOAllowPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); } } if (sysevent.event & SYSEVENT_WILLSLEEP) { cupsdLogMessage(CUPSD_LOG_DEBUG, "System going to sleep"); Sleeping = 1; for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Deregistering local printer \"%s\"", p->name); cupsdDeregisterPrinter(p, 0); } cupsdCleanDirty(); #ifdef kIOPMAssertionTypeDenySystemSleep /* * Remove our assertion as needed since the user wants the system to * sleep (different than idle sleep)... */ if (dark_wake) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Releasing dark wake assertion."); IOPMAssertionRelease(dark_wake); dark_wake = 0; } #endif /* kIOPMAssertionTypeDenySystemSleep */ /* * If we have no printing jobs, allow the power change immediately. * Otherwise set the SleepJobs time to 15 seconds in the future when * we'll take more drastic measures... */ if (cupsArrayCount(PrintingJobs) == 0) IOAllowPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); else { /* * If there are active printers that don't have the connecting-to-device * printer-state-reason then delay the sleep request (i.e. this reason * indicates a job that is not yet connected to the printer)... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) { if (p->job) { for (i = 0; i < p->num_reasons; i ++) if (!strcmp(p->reasons[i], "connecting-to-device")) break; if (!p->num_reasons || i >= p->num_reasons) break; } } if (p) { LastSysEvent = sysevent; SleepJobs = time(NULL) + 10; } else { IOAllowPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); } } } if (sysevent.event & SYSEVENT_WOKE) { cupsdLogMessage(CUPSD_LOG_DEBUG, "System woke from sleep"); IOAllowPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); Sleeping = 0; #ifdef kIOPMAssertionTypeDenySystemSleep if (cupsArrayCount(PrintingJobs) > 0 && !dark_wake) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Asserting dark wake."); IOPMAssertionCreateWithName(kIOPMAssertionTypeDenySystemSleep, kIOPMAssertionLevelOn, CFSTR("org.cups.cupsd"), &dark_wake); } #endif /* kIOPMAssertionTypeDenySystemSleep */ cupsdCheckJobs(); } if (sysevent.event & SYSEVENT_NETCHANGED) { if (!Sleeping) cupsdLogMessage(CUPSD_LOG_DEBUG, "System network configuration changed"); else cupsdLogMessage(CUPSD_LOG_DEBUG, "System network configuration changed; " "ignored while sleeping"); } if (sysevent.event & SYSEVENT_NAMECHANGED) { if (!Sleeping) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Computer name or BTMM domains changed"); /* * De-register the individual printers... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) cupsdDeregisterPrinter(p, 1); # if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /* * Update the computer name and BTMM domain list... */ cupsdUpdateDNSSDName(); # endif /* HAVE_DNSSD || HAVE_AVAHI */ /* * Now re-register them... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) cupsdRegisterPrinter(p); } else cupsdLogMessage(CUPSD_LOG_DEBUG, "Computer name or BTMM domains changed; ignored while " "sleeping"); } } }
DisplaySleepDisabler::~DisplaySleepDisabler() { IOPMAssertionRelease(m_disableDisplaySleepAssertion); }
void MacScreensaver::Uninhibit() { IOPMAssertionRelease(assertion_id_); }
static void __DAMountWithArgumentsCallbackStage1( int status, void * parameter ) { /* * Process the repair command's completion. */ __DAMountCallbackContext * context = parameter; DALogDebugHeader( "%s -> %s", gDAProcessNameID, gDAProcessNameID ); if ( context->assertionID != kIOPMNullAssertionID ) { IOPMAssertionRelease( context->assertionID ); context->assertionID = kIOPMNullAssertionID; } if ( status ) { /* * We were unable to repair the volume. */ if ( status == ECANCELED ) { status = 0; } else { DALogDebug( " repaired disk, id = %@, failure.", context->disk ); DALogError( "unable to repair %@ (status code 0x%08X).", context->disk, status ); if ( context->force ) { status = 0; } else { __DAMountWithArgumentsCallback( ___EDIRTY, context ); } } } else { /* * We were able to repair the volume. */ DADiskSetState( context->disk, kDADiskStateRequireRepair, FALSE ); DALogDebug( " repaired disk, id = %@, success.", context->disk ); } /* * Mount the volume. */ if ( status == 0 ) { /* * Create the mount point, in case one needs to be created. */ if ( context->mountpoint == NULL ) { context->mountpoint = DAMountCreateMountPointWithAction( context->disk, kDAMountPointActionMake ); } /* * Execute the mount command. */ if ( context->mountpoint ) { DALogDebug( " mounted disk, id = %@, ongoing.", context->disk ); DAFileSystemMountWithArguments( DADiskGetFileSystem( context->disk ), DADiskGetDevice( context->disk ), context->mountpoint, DADiskGetUserUID( context->disk ), DADiskGetUserGID( context->disk ), __DAMountWithArgumentsCallbackStage2, context, context->options, NULL ); } else { __DAMountWithArgumentsCallback( ENOSPC, context ); } } }