Partager via


Implement the EnterState Method (Compact 2013)

3/26/2014

Power Manager calls your EnterState method when it transitions the system into your new system power state. Your EnterState implementation can initialize timers or execute any other tasks that you need to perform when Power Manager transitions into your system power state; however, EnterState must always call the Power Manager function PmSetSystemPowerState_I before it exits. PmSetSystemPowerState_I, implemented in the Power Manager MDD, causes Power Manager to update all devices to the device power states associated with your system power state. When you call this function, you do not have to implement thread safety code to protect Power Manager’s device data structures — PmSetSystemPowerState_I serializes system power state changes using a critical section so that all system power state transitions occur atomically.

In this system power state Off example, EnterState simply calls the internal Power Manager function PmSetSystemPowerState_I to handle the state transition:

voidPowerStateOff::EnterState(){    PmSetSystemPowerState_I (GetStateString(), 0, 0, TRUE); }

The first PmSetSystemPowerState_I parameter specifies which system power state to transition to. In this example, EnterState calls the GetStateString method to return the string constant name of this system power state and then passes this name as the first argument to PmSetSystemPowerState_I. The second parameter allows the caller to pass power state hint flags should the first parameter be unspecified (for more information about hint flags, see Power Management Application Interface). In this example EnterState sets the hint flag to 0 (zero) because it is not used — the system power state is explicitly specified in the first parameter. The third parameter allows the caller to pass special flags to alter Power Manager behavior during power state transitions. EnterState sets this parameter to 0 (zero) so that the Power Manager transitions normally. Because Power Manager uses the PmSetSystemPowerState_I function to handle transition requests from both applications and internal Power Manager threads, you must specify the origin of the call in the last parameter. Set the last parameter to TRUE to indicate that this invocation is from within Power Manager.

The registry key for this Off system power state example associates the POWER_STATE_OFF flag with this state (see Define System Power State Registry Entries). As a result, PmSetSystemPowerState_I calls the function PlatformSetSystemPowerState (in Platform.cpp) and PlatformSetSystemPowerState calls, in turn, the OS function PowerOffSystem to power off the system.

See Also

Concepts

Implement System Power State Methods