Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Cleaning up at sleep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cleaning up at sleep



Yes the Macintosh has Power Management and you can read about it at this URL. Actually download the .pdf at this URL.

http://developer.apple.com/techpubs/macosx/Kernel/kernel.html

Look for the document called IOKit fundamentals on that page and then read Chapter 10.

Here is a start. This small C program will register for Power events and wait for those events.

/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
cc test2.c -o pm_callback -Wall -Wno-four-char-constants -framework IOKit -framework CoreFoundation
*/

#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;


void callback(void * x,io_service_t y,natural_t messageType,void * messageArgument)
{
printf("messageType lx, arg lx\n",(long unsigned int)messageType, (long unsigned int)messageArgument);

switch ( messageType ) {
case kIOMessageSystemWillSleep:
IOAllowPowerChange(root_port,(long)messageArgument);
break;
case kIOMessageCanSystemSleep:
// IOCancelPowerChange(root_port,(long)messageArgument);
IOAllowPowerChange(root_port,(long)messageArgument);
break;
case kIOMessageSystemHasPoweredOn:
break;
}

}


int
main(int argc, char **argv)
{
IONotificationPortRef notify;
io_object_t anIterator;

root_port = IORegisterForSystemPower (0,&notify,callback,&anIterator);
if ( root_port == NULL ) {
printf("IORegisterForSystemPower failed\n");
return 1;
}


CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notify),
kCFRunLoopDefaultMode);

printf("wayne is waiting...\n\n");

CFRunLoopRun();

return 0;
}

On Thursday, February 14, 2002, at 06:28 PM, Andre John Mas wrote:

Is there any way to know when the computer is going to sleep so that
my driver can put the device in the right state. For example flushing
all data to a disk, so that no data is lost if it is unplugged after
sleep, but before being properly unmounted?

Andre

--
mailto:email@hidden
_______________________________________________
darwin-drivers mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-drivers
Do not post admin requests to the list. They will be ignored.

************************************
Wayne Flansburg, Worldwide Technical Support
Visit our PCI web page at:
http://developer.apple.com/hardware/pci/
************************************
_______________________________________________
darwin-drivers mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-drivers
Do not post admin requests to the list. They will be ignored.

References: 
 >Cleaning up at sleep (From: Andre John Mas <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.