• 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
IOKit: Unable to catch shutdown for power management(QA 1340)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

IOKit: Unable to catch shutdown for power management(QA 1340)


  • Subject: IOKit: Unable to catch shutdown for power management(QA 1340)
  • From: "parag vibhute" <email@hidden>
  • Date: Thu, 10 Jan 2008 21:21:08 +0530


Hi,

I am referring to Technical Note QA1340. URL: http://developer.apple.com/qa/qa2004/qa1340.html

Following is my code which is almost same as in technote, just added case for shutdown:

#include <Carbon/Carbon.h>

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>

#include <mach/mach_port.h>
#include <mach/mach_interface.h>
#include <mach/mach_init.h>

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

io_connect_t  root_port;    // a reference to the Root Power Domain IOService

void
MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, void * messageArgument )
{
//    printf( "messageType lx, arg lx\n",
//            (long unsigned int)messageType,
//            (long unsigned int)messageArgument );

    switch ( messageType )
    {

        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, &notifyPortRef, MySleepCallBack, &notifierObject );
    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:

This email sent to email@hidden

  • Prev by Date: Re: #define xxx #define yyy 123
  • Next by Date: Re: #define xxx #define yyy 123
  • Previous by thread: Re: #define xxx #define yyy 123
  • Next by thread: to read larger files using POSIX functions
  • Index(es):
    • Date
    • Thread