Catching and preventing hard sleep
Catching and preventing hard sleep
- Subject: Catching and preventing hard sleep
- From: email@hidden
- Date: Wed, 30 Nov 2005 10:58:24 -0800 (PST)
Greetings,
I have been reading through documentation and mailing list archives for
sometime in search of a particular bit of functionality specific to apple
laptops. I need to catch and veto hard sleep caused by the closing of a
laptop lid on system running OS 10.4. From my research I understand that
this may be achieved through the Kernel, likely through a KEXT.
I have looked at the example RegisterForSleep, which shows how a program
can register to listen for and handle system sleep calls. This allows an
application to prevent idle sleep and gives them the oppourtunity to do
some housekeeping before an impending hard sleep, caused by closing the
laptop, or clicking sleep from the apple menu.
I have also looked at the KEXT called Insomnia* which when installed
prevents the system from going into hard sleep when the laptop lid is
closed. This is achieved by communicating with the root power domain:
// Include <IOKit/pwr_mgt/RootDomain.h>
// Prevents hard sleep when closing lid. found in Insomnia::init()
IOPMrootDomain *root = getPMRootDomain();
root->receivePowerNotification(kIOPMDisableClamshell);
// Allows hard sleep when closing lid. found in Insomnia::free()
IOPMrootDomain *root = getPMRootDomain();
root->receivePowerNotification(kIOPMEnableClamshell);
* http://binaervarianz.de/projekte/programmieren/meltmac/
Though preventing sleep is part of the solution I need to implement, more
importantly I must be able to catch it, prevent it. Attempting a
combination of RegisterForSleep and Insomnia did not do it. I loaded the
KEXT when the event kIOMessageSystemWillSleep was sent to my program but
to no avail. The system will sleep.
I have read a few brief snippets within the mailing list that said it is
possible to catch a hard sleep at the kernel level and veto it, but I
have yet to discover how to do this.
In an older version of <IOKIT/pwr_mgt/IOPM.h> I came across the following
enumeration definition:
// Power events
enum {
kClamshellClosedEventMask = (1<<0), // User closed lid
kDockingBarEventMask = (1<<1), // OBSOLETE
kACPlugEventMask = (1<<2), // User plugged or unplugged adapter
kFrontPanelButtonEventMask = (1<<3), // User hit the front panel button
kBatteryStatusEventMask = (1<<4) // Battery status has changed
};
kClamshellClosedEventMask looks very interesting. I don't have a sense of
how I could setup a event listener for this though. As well, the current
IOPM.h file on my system is actually without this definition.
I appreciate any and all commentary.
Most humble regards,
Eric Coffin
mobileneurons
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden