I’m developing a kernel driver for a USB device on OS X. After adding the setPowerState handler, I’m noticing that it’s called for a wake event immediately after the start method is called. This happens on OS X 10.6 when I load the driver, and when I plug the USB device in.
The kernel.log shows the iolog entries I’m making on each method call:
...(attach device)
MyDriver: Initializing
MyDriver: Probing
MyDriver: Starting
MyDriver: Waking
...(detach device)
MyDriver: Stopping
MyDriver: Freeing
Can I expect wakeup to occur after start every time?
If so is it reasonable to put most of my initialization code into the setPowerState handler, knowing it will be called after start?
Is this true for OS X 10.4 and 10.5 as well?
Yes you can, provide your have your driver is correctly connected to the Power Plane and has correctly initialised Power Managment (see the link below under the Implementing Basic Power Management heading.
It is not only reasonable but it is expected. Note that the only initialization code that make not be in
setPowerStateand that is instartor elsewhere is stuff that is only loaded the once and has power state handling code for sleep and wake events instart.For more information see here.
The only difference between setPowerState in Mac OS X versions is that in Mac OS X 10.5 and newer, setPowerState is called in its own thread, whilst 10.4 it is called as part of the existing thread.