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

📄 rilhand.cpp

📁 windows mobile RIL软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        goto Error;
    }
    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::StartInit : VSP is opened successfully\r\n")));

    NKDbgPrintfW(TEXT("CRilHandle::StartInit : VSP is opened successfully\r\n"));
    // Initialize the serial port
    if (!m_pComDevice->InitComPortForRIL(NULL, NULL))
    {
        goto Error;
    }
    NKDbgPrintfW(TEXT("CRilHandle::StartInit : InitComPortForRIL successfully\r\n"));

    // Launch the auxiliary threads
    if (!LaunchThreads())
    {
        goto Error;
    }
    NKDbgPrintfW(TEXT("CRilHandle::StartInit : LaunchThreads successfully\r\n"));

#if defined(NO_INIT_ON_BOOT)
    GeneralInitDone(TRUE);
#else
    // Send the first init string to the COM port
    if (!SendComInitString(COM_INIT_INDEX))
    {
        goto Error;
    }



#ifdef RIL_WATSON_REPORT
    // Query for the equipment info so it is available in case of watson logging.
    QueueCmdIgnoreRsp(APIID_NONE, "AT+CGMI;+CGMM;+CGMR;+CGSN\r", CMDOPT_IGNORERADIOOFF, g_TimeoutCmdInit, ParseGetEquipmentInfo, NULL, 0, 0, 0);
#endif // RIL_WATSON_REPORT
#endif

    fRet = TRUE;

    Error:
    if (!fRet)
    {
        if (m_pComDevice)
        {
            COM_CloseInternal(m_pComDevice);
            m_pComDevice = NULL;
        }

        if (m_hInitEvent)
        {
            (void)CloseHandle(m_hInitEvent);
            m_hInitEvent = NULL;
        }

        if (m_hDataEvent)
        {
            (void)CloseHandle(m_hDataEvent);
            m_hDataEvent = NULL;
        }
    }

    return fRet;
}


void CRilHandle::GeneralInitDone(BOOL bSucceeded)
{
    if (m_fInited)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::FinishInit : Trying to reinit? Module reset itself?!, rebooting via CPM\r\n")));
#ifndef RIL_RADIO_RESILIENCE
        if(!CreateProcess(TEXT("rs.exe"), NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL))
        {
            SignalCriticalError(RILLOG_EVENT_GENERALREINIT, __LINE__, __FILE__);
        }
#endif // ! RIL_RADIO_RESILIENCE
    }

    if (bSucceeded)
    {
        m_fInited = TRUE;
    }
    else
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::FinishInit : Module failed initialization!\r\n")));
        m_fFailedInit = TRUE;
    }

    (void)SetEvent(m_hInitEvent);

    // Now we need to send a notification that we've intiailized properly
    SendReadyStateNotification(RIL_READYSTATE_INITIALIZED);
}

//
// Finish intialization
//
void CRilHandle::FinishInit(CCommand* pInitCmd, BOOL bSucceeded)
{
    // FUNCTION_TRACE(CRilHandle::FinishInit);

    DEBUGCHK(NULL != pInitCmd);

#if defined(OEM2_DRIVER) || defined(EMP_DRIVER)
    // One more thing, check if we are CFUN=1 so that we won't send it down again unnecesarily.

    QueueCmdIgnoreRsp(APIID_NONE, "AT+CFUN?\r", CMDOPT_IGNORERADIOOFF, g_TimeoutCmdInit, ParseGetEquipmentState, NULL, 0, 0, 0);
#endif
	NKDbgPrintfW(TEXT("enter CRilHandle::FinishInit!!!!\r\n"));
    if (pInitCmd->FGeneralInit())
    {
    	NKDbgPrintfW(TEXT("Process General Init done!!!!\r\n"));
        GeneralInitDone(bSucceeded);
    }

    if (pInitCmd->FSMSInit())
    {
        if (m_fInitedForSMS)
        {
	        NKDbgPrintfW(TEXT("CRilHandle::FinishInit : Trying to reinit SMS? Module reset itself?!!!!\r\n"));
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::FinishInit : Trying to reinit SMS? Module reset itself?!, rebooting via CPM\r\n")));
#ifndef RIL_RADIO_RESILIENCE
            if(!CreateProcess(TEXT("rs.exe"), NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL))
#endif // ! RIL_RADIO_RESILIENCE
            {
                SignalCriticalError(RILLOG_EVENT_GENERALREINIT, __LINE__, __FILE__);
            }
        }

        if (bSucceeded)
        {
            m_fInitedForSMS = TRUE;
        }
    }
}


//
// Function passed to CQueue::Enum() below
//
BOOL GenerateCancelledRsp(void* pItem, DWORD dwData)
{
    FUNCTION_TRACE(GenerateCancelledRsp);
    DEBUGCHK(pItem != NULL);
    DEBUGCHK(dwData != NULL);

    CCommand* pCmd = (CCommand*)pItem;
    CRilHandle* pRilDevice = (CRilHandle*)dwData;
    HRESULT dwError = RIL_E_CANCELLED;

    // Send out cancelled response as a notification
    pCmd->SendResponse(RIL_RESULT_ERROR, &dwError, sizeof(HRESULT));

    // Continue enumeration
    return FALSE;
}


//
//
//
void CRilHandle::PrepareForReinit()
{
    // FUNCTION_TRACE(CRilHandle::PrepareForReinit);

    (void)ResetEvent(m_hInitEvent);
    m_fInited = FALSE;
    m_fFailedInit = FALSE;
    m_fInitedForSMS = FALSE;
    m_fInitedForSIMPB = FALSE;
    m_dwSIMPBLastSize = (DWORD)-1;

    // Reset g_dwReadyState
    SendReadyStateNotification(RIL_READYSTATE_NONE);

    // Clear the command queue, sending out "cancelled" responses to response callbacks
    // NOTE: The following line has been commented out to prevent commands
    // from being cancelled on start up when the shell turns the radio on.
    //g_pCmdQ->Enum(GenerateCancelledRsp, (DWORD)this, TRUE);
}

//
// Launch auxiliary threads
//
BOOL CRilHandle::LaunchThreads()
{
    // FUNCTION_TRACE(CRilHandle::LaunchThreads);

    BOOL fRet = FALSE;
    DWORD NumThreads = 2;

    if ( TRUE == CRilNdis.NdisSupported())
    {
        NumThreads++;
    }

    // Create a cancel event
    m_hCancelEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!m_hCancelEvent)
    {
        goto Error;
    }

    // Create command and response queues
    g_pCmdQ = new CPriorityQueue<CCommand, 40>;
    if (!g_pCmdQ || !g_pCmdQ->Init(m_hCancelEvent))
    {
        goto Error;
    }

    g_pRspQ = new CQueue<CResponse, 10>;
    if (!g_pRspQ || !g_pRspQ->Init(m_hCancelEvent))
    {
        goto Error;
    }

    g_pSimLockedQueue = new CQueue<CCommand, 10>;
    if (!g_pSimLockedQueue || !g_pSimLockedQueue->Init(m_hCancelEvent))
    {
        goto Error;
    }

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

    // Launch a auxiliary threads
    m_hCmdThread = CreateThread(NULL, 0, CmdThreadProc, (LPVOID)this, 0, &m_dwCmdThreadID);
    if (!m_hCmdThread)
    {
        goto Error;
    }

    m_hReadThread = CreateThread(NULL, 0, ReadThreadProc, (LPVOID)this, 0, &m_dwReadThreadID);
    if (!m_hReadThread)
    {
        goto Error;
    }

    // Launch NDIS notification thread.
    if ( !CRilNdis.NdisStart(m_hCancelEvent))
    {
      goto Error;
    }

    // Wait until all threads reach the checkpoint
    if (!m_pCheckPoint->Wait(10000))
    {
        goto Error;
    }

    NKDbgPrintfW(TEXT("CRilHandle::LaunchThreads : Launched threads reached ckeckpoint\r\n"));
    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::LaunchThreads : Launched threads reached ckeckpoint\r\n")));
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        NKDbgPrintfW(TEXT("CRilHandle::LaunchThreads : Launched threads goto Error\r\n"));
        if (m_hCmdThread)
        {
            (void)CloseHandle(m_hCmdThread);
            m_hCmdThread = NULL;
            m_dwCmdThreadID = 0;
        }

        if (m_hReadThread)
        {
            (void)CloseHandle(m_hReadThread);
            m_hReadThread = NULL;
            m_dwReadThreadID = 0;
        }

        delete m_pCheckPoint;
        m_pCheckPoint = NULL;

        delete g_pCmdQ;
        delete g_pRspQ;
        delete g_pSimLockedQueue;
        g_pCmdQ = NULL;
        g_pRspQ = NULL;
        g_pSimLockedQueue = NULL;

        if (m_hCancelEvent)
        {
            (void)CloseHandle(m_hCancelEvent);
            m_hCancelEvent = NULL;
        }
    }
    return fRet;
}


//
// Test the cancel event
//
BOOL CRilHandle::FCancelSet() const
{
    // // FUNCTION_TRACE(CRilHandle::FCancelSet);
    return (WAIT_OBJECT_0 == WaitForSingleObject(m_hCancelEvent, 0));
}


//
//
//
BOOL CRilHandle::WaitForInit(DWORD dwTimeout) const
{
    // FUNCTION_TRACE(CRilHandle::WaitForInit);
    HANDLE rghEvents[] = { m_hInitEvent, m_hCancelEvent };
    switch (WaitForMultipleObjects(2, rghEvents, FALSE, dwTimeout))
    {
    case WAIT_OBJECT_0:
    case WAIT_OBJECT_0 + 1:
        return TRUE;
    default:
        return FALSE;
    }
}


//
// Returns true if there is a command on the command queue that can
// be executed now.
// Returns false if the command thread should quit.
//
BOOL CRilHandle::WaitForCommandOrCancel() const
{
    BOOL fRet = FALSE;
    CCommand* pCmd = NULL;
    HANDLE rghEvents[] = { g_pCmdQ->GetPutEvent(), m_hCancelEvent, m_hInitEvent };

    if (WAIT_OBJECT_0 == WaitForSingleObject(m_hInitEvent, 0))
    {
        // If the init event is signaled now, then it doesn't
        // matter what the next command is. Set return to true.
        // The subsequent call to Get will block if the queue
        // happens to be empty.
        fRet = TRUE;
    }

    while (!fRet)
    {
        // Look for a command on the queue.
        if (g_pCmdQ->Peek(pCmd))
        {
            if (pCmd->FInit())
            {
                // The next command is for init. Send it.
                fRet = TRUE;
                break;
            }
        }

        switch (WaitForMultipleObjects(3, rghEvents, FALSE, INFINITE))
        {
        case WAIT_OBJECT_0:
            // Put signaled. Loop to see if it is an init command.
            break;

        case WAIT_OBJECT_0 + 1:
            // Cancel signaled, so return FALSE now.
            return FALSE;

        case WAIT_OBJECT_0 + 2:
            // Init command signaled, so ok to send next command.
            fRet = TRUE;
            break;

        default:
            return FALSE;
        }
    }

    DEBUGCHK(TRUE == fRet);

    // Check the cancel event before returning
    // in case some other event (like init)
    // preempted this event.
    return (!FCancelSet());
}


//
//
//
BOOL CRilHandle::AddToList(CRilInstanceHandle* const pInstance)
{
    // FUNCTION_TRACE(CRilHandle::AddToList);
    return m_pInstances->Add(pInstance);
}


//
//
//
BOOL CRilHandle::RemoveFromList(CRilInstanceHandle* const pInstance)
{
    // FUNCTION_TRACE(CRilHandle::RemoveFromList);
    return m_pInstances->Remove(pInstance);
}


//
//
//
HRESULT CRilHandle::GetNextCmdID()
{
    // FUNCTION_TRACE(CRilHandle::GetNextCmdID);
    SYNCBLOCK(m_csCmdID);

    // Make sure not to wrap into error values
    if (FAILED(m_hrNextCmdID))
    {
        m_hrNextCmdID = INITIAL_COMMAND_ID;
    }

    return m_hrNextCmdID++;
}


//
// Function passed to CDlbList::Enum() below
//
BOOL NotifyHandle(void* pItem, DWORD dwData)
{
    FUNCTION_TRACE(NotifyHandle);
    DEBUGCHK(pItem != NULL);
    DEBUGCHK(dwData != NULL);

    CRilInstanceHandle* pHandle = (CRilInstanceHandle*)pItem;
    CNotificationData* pnd = (CNotificationData*)dwData;

    if (pHandle->FReadyForNotifications())

⌨️ 快捷键说明

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