Compartir a través de


Implement the WaitForEvent Method (Compact 2013)

3/26/2014

The WaitForEvent method determines how your system power state transitions to the next system power state. WaitForEvent examines timers and event types to decide the next system power state, sets an internal Power Manager variable to this next state, then returns the event type that was responsible for the system power state change. Typically, WaitForEvent waits for an event (such as the expiration of an activity timer) to determine which system power state to transition to next. When WaitForEvent determines the next system power state, it sets the member variable m_LastNewState to the enumeration type of the next state. For example, here is the EnterState implementation for the Unattended system power state:

PLATFORM_ACTIVITY_EVENTPowerStateUnattended::WaitForEvent (DWORD dwTimeouts, DWORD dwNumOfExternEvent,                                     HANDLE * pExternEventArray) {    TIMEOUT_ITEM TimeoutItem;     m_pPwrStateMgr->DisableResumingSuspendTimeout ();    m_pPwrStateMgr->DisableBacklightTimeout ();    m_pPwrStateMgr->DisableUserIdleTimeout ();    DWORD dwTimeout = m_pPwrStateMgr->GetSmallestTimeout (&TimeoutItem);     PLATFORM_ACTIVITY_EVENT activeEvent =        PowerState::WaitForEvent (dwTimeout, dwNumOfExternEvent, pExternEventArray);     switch (activeEvent) {      case PowerButtonPressed:           m_LastNewState = On;           break;       case Timeout:           {              switch (TimeoutItem)               {                case SuspendTimeout:                     m_LastNewState = Suspend;                     break;                 default:                     ASSERT (FALSE);               }              break;           }    }    return activeEvent; }

In the preceding example, if a PowerButtonPressed event is responsible for the next power state transition, WaitForEvent sets m_LastNewState to the system power state On. If a Timeout event is responsible for the state transition and the timeout is a suspend timeout, WaitForEvent sets m_LastNewState to the system power state Suspend. You can see more examples of state transition functionality by viewing the WaitForEvent methods of the other system power state classes in Pwstates.cpp.

In the system power state Off example, WaitForEvent simply returns the platform activity event value NoActivity, which means that no user activity or timeout event was responsible for the transition to the Off system power state.

PLATFORM_ACTIVITY_EVENTPowerStateOff::WaitForEvent (DWORD, DWORD dwNumOfExternEvent,                             HANDLE * pExternEventArray) {     return NoActivity; }

In this simplified example, the transition to system power state Off is initiated by an OEM application and there is no need to set the next system power state because the platform is being powered off.

See Also

Concepts

Implement System Power State Methods