case kIOMessageSystemWillRestart: printf("system will restart\n"); system("ls / > /par1"); break;
case kIOMessageSystemWillPowerOff:
printf("system will poweroff\n"); system("ls / > /par4"); break;
case kIOMessageCanSystemSleep: /*
Idle sleep is about to kick in. Applications have a chance to prevent sleep by calling IOCancelPowerChange. Most applications should not prevent idle sleep.
Power Management waits up to 30 seconds for you to either allow or deny idle sleep.
If you don't acknowledge this power change by calling either IOAllowPowerChange or IOCancelPowerChange, the system will wait 30 seconds then go to sleep. */
// we will allow idle sleep
printf("system can sleep\n"); IOAllowPowerChange( root_port, (long)messageArgument ); system("ls / > /par2"); break;
case kIOMessageSystemWillSleep:
/* The system WILL go to sleep. If you do not call IOAllowPowerChange or IOCancelPowerChange to acknowledge this message, sleep will be delayed by 30 seconds.
NOTE: If you call IOCancelPowerChange to deny sleep it returns kIOReturnSuccess,
however the system WILL still go to sleep. */
// we cannot deny forced sleep printf("system will sleep"); IOAllowPowerChange( root_port, (long)messageArgument );
system("ls / > /par3"); break;
default: break;
} }
int main( int argc, char **argv ) { IONotificationPortRef notifyPortRef; // notification port allocated by IORegisterForSystemPower
io_object_t notifierObject; // notifier object, used to deregister later void* refCon; // this parameter is passed to the callback
// register to receive system sleep notifications
root_port = IORegisterForSystemPower( refCon, ¬ifyPortRef, MySleepCallBack, ¬ifierObject ); if ( root_port == NULL ) { printf("IORegisterForSystemPowe
r failed\n");
return 1; }
// add the notification port to the application runloop CFRunLoopAddSource( CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef),
kCFRunLoopCommonModes );
printf( "waiting...\n\n" );
/* Start the run loop to receive sleep notifications. You don't need to call this if you already have a Carbon or Cocoa EventLoop running.
*/ CFRunLoopRun();
return (0); }
I have written above code in corefoundation project but since it is related to power management so posted question in this mailing list. I am able to get sleep notifications in above code but not able get
system shutdown & restart notification. Where am I wrong?
Thanks, Palav
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden
This email sent to email@hidden