+//*********************************************************************************
+
+void IOPMrootDomain::setQuickSpinDownTimeout ( void )
+{
+ //IOLog("setQuickSpinDownTimeout\n");
+ super::setAggressiveness((unsigned long)kPMMinutesToSpinDown,(unsigned long)1);
+}
+
+//*********************************************************************************
+// restoreUserSpinDownTimeout
+//
+//*********************************************************************************
+
+void IOPMrootDomain::restoreUserSpinDownTimeout ( void )
+{
+ if(systemBooting) {
+ IOLog("!!!!! WARNING !!!!! restoreUserSpinDownTimeout called too early\n");
+ }
+ //IOLog("restoreUserSpinDownTimeout, user_spindown = %u\n", user_spindown);
+
+ super::setAggressiveness((unsigned long)kPMMinutesToSpinDown,(unsigned long)user_spindown);
+}
+
+
+//*********************************************************************************
+// sysPowerDownHandler
+//
+// Receives a notification when the RootDomain changes state.
+//
+// Allows us to take action on system sleep, power down, and restart after
+// applications have received their power change notifications and replied,
+// but before drivers have powered down. We perform a vfs sync on power down.
+//*********************************************************************************
+
+IOReturn IOPMrootDomain::sysPowerDownHandler( void * target, void * refCon,
+ UInt32 messageType, IOService * service,
+ void * messageArgument, vm_size_t argSize )
+{
+ IOReturn ret;
+ IOPowerStateChangeNotification * params = (IOPowerStateChangeNotification *) messageArgument;
+ IOPMrootDomain * rootDomain = OSDynamicCast(IOPMrootDomain, service);
+
+ if(!rootDomain)
+ return kIOReturnUnsupported;
+
+ switch (messageType) {
+ case kIOMessageSystemWillSleep:
+ rootDomain->powerOverrideOnPriv(); // start ignoring children's requests
+ // (fall through to other cases)
+ case kIOMessageSystemWillPowerOff:
+ case kIOMessageSystemWillRestart:
+
+ // Interested applications have been notified of an impending power
+ // change and have acked (when applicable).
+ // This is our chance to save whatever state we can before powering
+ // down.
+ // We call sync_internal defined in xnu/bsd/vfs/vfs_syscalls.c,
+ // via callout
+
+ // We will ack within 20 seconds
+ params->returnValue = 20 * 1000 * 1000;
+
+ if ( ! OSCompareAndSwap( 0, 1, &gSleepOrShutdownPending ) )
+ {
+ // Purposely delay the ack and hope that shutdown occurs quickly.
+ // Another option is not to schedule the thread and wait for
+ // ack timeout...
+ AbsoluteTime deadline;
+ clock_interval_to_deadline( 15, kSecondScale, &deadline );
+ thread_call_enter1_delayed( rootDomain->diskSyncCalloutEntry,
+ (thread_call_param_t)params->powerRef,
+ deadline );
+ }
+ else
+ thread_call_enter1(rootDomain->diskSyncCalloutEntry, (thread_call_param_t)params->powerRef);
+ ret = kIOReturnSuccess;
+ break;
+ default:
+ ret = kIOReturnUnsupported;
+ break;
+ }
+ return ret;
+}
+
+//*********************************************************************************
+// displayWranglerNotification
+//
+// Receives a notification when the IODisplayWrangler changes state.
+//
+// Allows us to take action on display dim/undim.
+//
+// When the display goes dim we:
+// - Start the idle sleep timer
+// - set the quick spin down timeout
+//
+// On wake from display dim:
+// - Cancel the idle sleep timer
+// - restore the user's chosen spindown timer from the "quick" spin down value
+//*********************************************************************************