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

📄 monitor.cpp

📁 ril source code for Windows CE
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:

monitor.cpp

Abstract:


Notes:


--*/

#ifndef RIL_RADIO_RESILIENCE

#include "precomp.h"

void Reboot() 
{
    // Flush the flash database volumes
    CeFlushDBVol(NULL);
    
    // Flush the registry to flash.
    RegFlushKey(HKEY_CURRENT_USER);

    KernelIoControl(IOCTL_HAL_REBOOT, NULL, NULL, NULL, 0, NULL);

    return;
}


//
// Thread responsible for monitoring RIL
//
DWORD WINAPI MonitorThreadProc(LPVOID lpParameter)
{
    FUNCTION_TRACE(MonitorThreadProc);
#ifdef UNDER_CE
    DWORD dwWait;
    CMonitor* pMonitor = (CMonitor*)lpParameter;
    int nEventCnt = 2;
    
    DEBUGCHK(NULL != pMonitor);

    // Let the main thead know that the thread has started up
    pMonitor->m_pCheckPoint->Reached();

    HANDLE rghEvents[] = { g_hCriticalErrorEvent, pMonitor->m_hCancelEvent };

    // Switch the thread into higher priority (to guarantee that CPM doesn't reboot the device just because this
    //    thread didn't get scheduled)
    if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)) {
        goto Error;
    }

    while (1) {
        dwWait = WaitForMultipleObjects(nEventCnt, rghEvents, FALSE, INFINITE);
        if (WAIT_OBJECT_0 == dwWait) {
                // For platforms that do not use CPM, just reboot thank you
                DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL: Critical error has occurred, rebooting system...\r\n")));
                Reboot();
        } else if (WAIT_OBJECT_0 + 1 == dwWait) {
            // RIL is exiting -- terminate this thread
            goto Error;
        }
    }

Error:
#endif // UNDER_CE

    return 0;
}


//
// Ctor
//
CMonitor::CMonitor()
: m_hCancelEvent(NULL),
  m_pCheckPoint(NULL),
  m_hMonitorThread(NULL)
{
    FUNCTION_TRACE(CMonitor::CMonitor);
}


//
// Dtor
//
CMonitor::~CMonitor()
{
    FUNCTION_TRACE(CMonitor::~CMonitor);

    // Destroy the monitor thread
    if (m_hMonitorThread)
    {
        // Wait for the monitor thread to terminate
        DWORD dwRes = WaitForSingleObject(m_hMonitorThread, 10000);
        if (WAIT_OBJECT_0 != dwRes)
        {
            // If the thread did not terminate, then maybe
            // the timeout is too short. Alert someone.
            ASSERT(0);

            // We could try to force the thread to terminate,
            // but it's probably not worth the risk. The monitor
            // thread does two things: notify CPM, and quit.
            // If the thread is stuck in CPM, then let's not
            // exacerbate the problem by killing a thread that
            // is executing CPM code.
        }

        // Close thread object
        (void)CloseHandle(m_hMonitorThread);
        m_hMonitorThread = NULL;
    }

    delete m_pCheckPoint;
    m_pCheckPoint = NULL;
}


//
// Initialisation
//
BOOL CMonitor::Init(const HANDLE hCancelEvent, const DWORD dwCmdThreadID, const DWORD dwReadThreadID)
{
    FUNCTION_TRACE(CMonitor::Init);
    DEBUGCHK(NULL != hCancelEvent);
    DEBUGCHK(0 != dwCmdThreadID);
    DEBUGCHK(0 != dwReadThreadID);
    DEBUGCHK(NULL != g_hCriticalErrorEvent);

    BOOL fRet = FALSE;

#ifdef UNDER_CE
    m_hCancelEvent = hCancelEvent;

    // Create the thread checkpoint
    m_pCheckPoint = new CCheckPoint;
    if (!m_pCheckPoint || !m_pCheckPoint->Init(1)) {
        goto Error;
    }

    // Launch the monitor thread
    m_hMonitorThread = CreateThread(NULL, 0, MonitorThreadProc, (LPVOID)this, 0, NULL);
    if (!m_hMonitorThread) {
        goto Error;
    }

    // Wait until the thread starts up
    if (!m_pCheckPoint->Wait(30000)) {
        goto Error;
    }
    fRet = TRUE;

Error:
    delete m_pCheckPoint;
    m_pCheckPoint = NULL;

    if (!fRet) {
        if (m_hMonitorThread) {
            (void)CloseHandle(m_hMonitorThread);
            m_hMonitorThread = NULL;
        }
    }
#endif // UNDER_CE

    return fRet;
}

#endif // !RIL_RADIO_RESILIENCE

⌨️ 快捷键说明

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