• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cancel Sleep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cancel Sleep


  • Subject: Re: Cancel Sleep
  • From: Brian Bergstrand <email@hidden>
  • Date: Sat, 29 Dec 2007 16:14:14 +0200


On Dec 29, 2007, at 1:35 PM, Andrew James wrote:

Hi,

How do i cancel a sleep event from happening, along with things like the lid closing and causing a sleep.
_______________________________________________



You can only cancel idle sleep, not user initiated sleep (via the power button, the Sleep menu, or closing the lid.



#import <IOKit/IOMessage.h> #import <IOKit/pwr_mgt/IOPMLib.h>

static io_connect_t powerPort = (io_connect_t)0;
static void iokpm_callback (void *, io_service_t, natural_t, void*);

int main(int argc, char* argv[]) {
IONotificationPortRef portRef;
io_object_t notifier;
CFRunLoopSourceRef source;
powerPort = IORegisterForSystemPower (NULL, &portRef, iokpm_callback, &notifier);
if (powerPort) {
source = IONotificationPortGetRunLoopSource(portRef);
CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop], source, kCFRunLoopCommonModes);
}

[[NSRunLoop currentRunLoop] run];
}


static void iokpm_callback (void *myData, io_service_t service, natural_t message, void *arg)
{
switch(message) {
// must always respond to the power state change messages
case kIOMessageSystemWillSleep:
case kIOMessageCanSystemSleep:
// we can't prevent user initiated power off, only idle power off
case kIOMessageSystemWillPowerOff:
case kIOMessageSystemWillRestart:
IOAllowPowerChange(powerPort, (long)arg);
break;


        case kIOMessageCanSystemPowerOff:
            if (dontIdleSleep) {
                IOCancelPowerChange(powerPort, (long)arg);
            } else
                IOAllowPowerChange(powerPort, (long)arg);
        break;

        default:
        break;
    }
}


Brian Bergstrand <http://www.bergstrand.org/brian/> PGP Key ID: 0xB6C7B6A2

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Cancel Sleep
      • From: Andrew James <email@hidden>
References: 
 >Cancel Sleep (From: Andrew James <email@hidden>)

  • Prev by Date: Re: pipes, scripts, and launchd
  • Next by Date: Re: Cancel Sleep
  • Previous by thread: Cancel Sleep
  • Next by thread: Re: Cancel Sleep
  • Index(es):
    • Date
    • Thread