⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stubbattery.cpp

📁 此代码为WCE5.0下电源管理的源代码
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

//
// This module contains a power monitoring thread that generates the appropriate
// PM notifications when power status or other variables changes.  OEMs may choose to
// customize this routine for their own platforms.
//

#include <pmimpl.h>
#include <pmpolicy.h>

// This thread monitors battery notification and generates update messages as appropriate.
EXTERN_C DWORD WINAPI 
PowerMonitorThreadProc(LPVOID lpvParam)
{
    BOOL fDone = FALSE;
    DWORD dwStatus;
    INT iPriority;
    HANDLE hev[2];
    SETFNAME(_T("PowerMonitorThreadProc"));

    UnusedParameter(lpvParam);

    DEBUGMSG(ZONE_INIT, (_T("+%s: thread 0x%08x\r\n"), pszFname, GetCurrentThreadId()));

    // create our notification queue
    hev[0] = PmPolicyCreateNotificationQueue();
    if(hev[0] == NULL) {
        DEBUGMSG(ZONE_WARN, (_T("%s: PmPolicyCreateNotificationQueue() failed\r\n"), pszFname));
        goto done;
    }
    
    // set the thread priority
    if(!GetPMThreadPriority(_T("SystemPriority256"), &iPriority)) {
        iPriority = DEF_SYSTEM_THREAD_PRIORITY;
    }
    CeSetThreadPriority(GetCurrentThread(), iPriority);

    // set up the events we're interested in
    hev[1] = ghevPmShutdown;

    // wait for battery status updates
    while(!fDone) {
        dwStatus = WaitForMultipleObjects(dim(hev), hev, FALSE, INFINITE);
        switch(dwStatus) {
        case (WAIT_OBJECT_0 + 0):
            {
                POWERPOLICYMESSAGE ppm;
                dwStatus = PmPolicyReadNotificationQueue(hev[0], &ppm, sizeof(ppm));
                if(dwStatus == ERROR_SUCCESS) {
                    DEBUGMSG(ZONE_PLATFORM, (_T("%s: got request 0x%04x (data 0x%08x) from process 0x%08x\r\n"),
                        pszFname, ppm.dwMessage, ppm.dwData, ppm.hOwnerProcess));
                    switch(ppm.dwMessage) {
                    case PPN_POWERCHANGE:
                        PmUpdatePowerStatus();      // ignore return value
                        break;
                    default:
                        // unhandled notification type, ignore it
                        DEBUGMSG(ZONE_WARN, (_T("%s: unhandled policy notification 0x%04x (data 0x%08x)\r\n"), 
                            pszFname, ppm.dwMessage, ppm.dwData));
                        break;
                    }
                }
            }
            break;
        case (WAIT_OBJECT_0 + 1):
            DEBUGMSG(ZONE_WARN, (_T("%s: shutdown event signaled, exiting\r\n"), 
                pszFname));
            fDone = TRUE;
            break;
        default:
            DEBUGMSG(ZONE_WARN, 
                (_T("%s: WaitForSingleObject() returned %d (last error %d), exiting\r\n"),
                pszFname, dwStatus, GetLastError()));
            fDone = TRUE;
        }
    }

done:
    // release resources
    if(hev[0] != NULL) PmPolicyCloseNotificationQueue(hev[0]);

    DEBUGMSG(ZONE_INIT | ZONE_WARN, (_T("-%s: exiting\r\n"), pszFname));

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -