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

📄 util.cpp

📁 windows mobile RIL软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    // FUNCTION_TRACE(CBuffer::~CBuffer);
    delete[] m_szData;
}


//
// Append data to the response
//
BOOL CBuffer::Append(const LPCSTR szString, const UINT cbString)
{
    // FUNCTION_TRACE(CBuffer::Append);
    LPSTR szTemp = NULL;
    BOOL fRet = FALSE;

    if (!m_szData)
    {
        m_cbLength = 0;
        m_cbAlloc = ALLOC_SIZE;
        m_szData = new char[m_cbAlloc];
        if (!m_szData)
        {
            goto Error;
        }
    }

    if (m_cbLength + cbString + 1 > m_cbAlloc)
    {
        do
        {
            m_cbAlloc += ALLOC_SIZE;
        } while (m_cbLength + cbString + 1 > m_cbAlloc);

        szTemp = new char[m_cbAlloc];
        if (!szTemp)
        {
            goto Error;
        }

        memcpy(szTemp, m_szData, m_cbLength);
        delete[] m_szData;
        m_szData = szTemp;
    }

    memcpy(m_szData + m_cbLength, szString, cbString);
    m_cbLength += cbString;
    fRet = TRUE;

    Error:
    return fRet;
}


//
// Get the data out of the buffer
//    (the caller takes ownership of the m_szData storage)
//
LPSTR CBuffer::GiveUpData()
{
    // FUNCTION_TRACE(CBuffer::GiveUpData);
    LPSTR szTemp = m_szData;

    m_szData = NULL;
    m_cbLength = 0;
    m_cbAlloc = 0;

    return szTemp;
}


//
//
//
void CBuffer::InheritData(CBuffer* pSrcBuffer)
{
    // FUNCTION_TRACE(CBuffer::InheritData);
    delete[] m_szData;
    m_szData = NULL;
    m_cbLength = 0;
    m_cbAlloc = 0;

    m_cbAlloc = pSrcBuffer->m_cbAlloc;
    m_cbLength = pSrcBuffer->m_cbLength;
    m_szData = pSrcBuffer->GiveUpData();
}



//
// Shared resource ctor
//
CSharedResource::CSharedResource()
: m_fInited(FALSE),
m_dwSharedUsers(0),
m_hSharedUseSph(NULL),
m_hExclusiveUseSph(NULL),
m_hCancelEvent(NULL)
{
    FUNCTION_TRACE(CSharedResource::CSharedResource);
    InitializeCriticalSection(&m_cs);
}


//
// Shared resource dtor
//
CSharedResource::~CSharedResource()
{
    FUNCTION_TRACE(CSharedResource::~CSharedResource);
    if (m_hSharedUseSph)
    {
        (void)CloseHandle(m_hSharedUseSph);
        m_hSharedUseSph = NULL;
    }

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

    DeleteCriticalSection(&m_cs);
    m_fInited = FALSE;
}


//
// Shared resource intialization
//
BOOL CSharedResource::Init(const HANDLE hCancelEvent)
{
    FUNCTION_TRACE(CSharedResource::Init);
    if (m_fInited)
    {
        goto Error;
    }

    m_hSharedUseSph = CreateSemaphore(NULL, 1, 1, NULL);
    if (!m_hSharedUseSph)
    {
        goto Error;
    }

    m_hExclusiveUseSph = CreateSemaphore(NULL, 1, 1, NULL);
    if (!m_hExclusiveUseSph)
    {
        goto Error;
    }

    m_hCancelEvent = hCancelEvent;
    m_fInited = TRUE;

    Error:
    return m_fInited;
}


//
// Called to acquire shared use permission
//
BOOL CSharedResource::EnterSharedUse()
{
    FUNCTION_TRACE(CSharedResource::EnterSharedUse);
    HANDLE rghObjects[2] = { m_hSharedUseSph, m_hCancelEvent};
    DWORD dwWait;
    BOOL fRet = FALSE;

    if (!m_fInited)
    {
        goto Error;
    }

    // Wait until shared use is granted
    dwWait = WaitForMultipleObjects(2, rghObjects, FALSE, INFINITE);
    if (WAIT_OBJECT_0 + 1 == dwWait)
    {
        // We hit the terminate event -- quit
        goto Error;
    }
    else if (WAIT_OBJECT_0 != dwWait)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : WaitForMultipleObjects : Failed, RetVal=0x%x, GetLastError=0x%x\r\n"),dwWait,GetLastError()));
        DEBUGCHK(WAIT_FAILED == dwWait);
        goto Error;
    }

    {
        SYNCBLOCK(m_cs);

        // Grant shared use for anyone who's waiting
        if (!ReleaseSemaphore(m_hSharedUseSph, 1, NULL))
        {
            goto Error;
        }

        // Increment the number of shared users
        m_dwSharedUsers++;

        // If this is the first shared user, we need to make sure there are no exclusive users at the moment
        if (1 == m_dwSharedUsers)
        {
            // Wait until the exclusive user is done
            rghObjects[0] = m_hExclusiveUseSph;
            dwWait = WaitForMultipleObjects(2, rghObjects, FALSE, INFINITE);
            if (WAIT_OBJECT_0 + 1 == dwWait)
            {
                // We hit the terminate event -- quit
                goto Error;
            }
            else if (WAIT_OBJECT_0 != dwWait)
            {
                DEBUGCHK(FALSE);
                goto Error;
            }
        }
    }
    fRet = TRUE;

    Error:
    return fRet;
}


//
// Called to relinquish shared use permission
//
BOOL CSharedResource::ExitSharedUse()
{
    FUNCTION_TRACE(CSharedResource::ExitSharedUse);
    SYNCBLOCK(m_cs);

    BOOL fRet = FALSE;

    if (!m_fInited)
    {
        goto Error;
    }

    // Decrement the number of shared users
    m_dwSharedUsers--;

    // If this is the last shared user, allow exclusive use
    if (!m_dwSharedUsers)
    {
        if (!ReleaseSemaphore(m_hExclusiveUseSph, 1, NULL))
        {
            goto Error;
        }
    }

    fRet = TRUE;

    Error:
    return fRet;
}


//
// Called to acquire exclusive use permission
//
BOOL CSharedResource::EnterExclusiveUse(PFN_SHRDUSE_ACTION pfnAction, const DWORD dwParam) const
{
    FUNCTION_TRACE(CSharedResource::EnterExclusiveUse);
    HANDLE rghObjects[2] = { m_hSharedUseSph, m_hCancelEvent};
    DWORD dwWait;
    BOOL fRet = FALSE;
    int RetryCount = 10;

    if (!m_fInited)
    {
        goto Error;
    }

    // Lock shared users out until this exclusive user can finish its operation
    dwWait = WaitForMultipleObjects(2, rghObjects, FALSE, INFINITE);
    if (WAIT_OBJECT_0 + 1 == dwWait)
    {
        // We hit the terminate event -- quit
        goto Error;
    }
    else if (WAIT_OBJECT_0 != dwWait)
    {
        DEBUGCHK(FALSE);
        goto Error;
    }

    for (;;)
    {
        // Call the custom action routine, passing it the specified parameter
        pfnAction(dwParam);

        // Wait until there are no other exclusive users
        rghObjects[0] = m_hExclusiveUseSph;
        dwWait = WaitForMultipleObjects(2, rghObjects, FALSE, 500);
        if (WAIT_OBJECT_0 == dwWait)
        {
            // We own it now.
            break;
        }
        if (WAIT_OBJECT_0 + 1 == dwWait)
        {
            // We hit the terminate event -- quit
            goto Error;
        }
        else if (WAIT_TIMEOUT == dwWait)
        {
            // We timed out.
            // Have we exceeded our retry count?
            if (--RetryCount<=0)
            {
                goto Error;
            }
            // Try to signal and wait again.
        }
        else
        {
            // Some other error
            DEBUGCHK(FALSE);
            goto Error;
        }
    }

    // Allow shared users to proceed (they will be locked out until there're no more exclusive users)
    if (!ReleaseSemaphore(m_hSharedUseSph, 1, NULL))
    {
        goto Error;
    }
    fRet = TRUE;

    Error:
    return fRet;
}


//
// Called to relinquish exclusive use permission
//
BOOL CSharedResource::ExitExclusiveUse() const
{
    FUNCTION_TRACE(CSharedResource::ExitExclusiveUse);
    // Allow other exclusive users and shared users to proceed
    return ReleaseSemaphore(m_hExclusiveUseSph, 1, NULL);
}

extern BOOL g_bRadioOff;
extern RILCALLINFO g_rgfCallStates[RIL_MAX_TRACKED_CALL_ID];
void IndicateCallActivityToAudioSubsystem ( BOOL fActive, BOOL fCheckCallList  )
{
#if defined (PHILIP_DRIVER)
	if(RILDrv_OpenMyWav() == FALSE)
    {
	    NKDbgPrintfW(TEXT("RILDrv : i : RILDrv_OpenMyWav : FAILED\r\n"));
    	return;
    }
#endif
				
#if defined (OEM1_DRIVER_WAVEXT) || defined (PHILIP_DRIVER)
    DWORD dwRet;
    static BOOL g_dwIoctlCallActive = FALSE;

    if ( FALSE == fCheckCallList )
    {
        if ( TRUE == fActive )
        {
            //signal audio driver that at least one call is active
            if( (FALSE == g_bRadioOff) && (g_hWavDev != NULL) && (g_hWavDev != INVALID_HANDLE_VALUE) )
            {
                if (DeviceIoControl (g_hWavDev, IOCTL_GSM_CALL_ACTIVE, 0, 0, NULL, 0, &dwRet, NULL))
                {
                    //DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : RILSetAudioPath : IOCTL_GSM_CALL_ACTIVE\r\n")));
					NKDbgPrintfW(TEXT("RILDrv : i : RILSetAudioPath : IOCTL_GSM_CALL_ACTIVE\r\n"));
                    g_dwIoctlCallActive = TRUE;
                }
            }
        }
        else
        {
            if ( TRUE == g_dwIoctlCallActive )
            {
                if( (g_hWavDev != NULL) && (g_hWavDev != INVALID_HANDLE_VALUE) )
                {
                    DeviceIoControl (g_hWavDev, IOCTL_GSM_CALL_INACTIVE, 0, 0, NULL, 0, &dwRet, NULL);
                    g_dwIoctlCallActive = FALSE;
                    //DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : RILSetAudioPath : IOCTL_GSM_CALL_INACTIVE\r\n")));
					NKDbgPrintfW(TEXT("RILDrv : i : RILSetAudioPath : IOCTL_GSM_CALL_INACTIVE\r\n"));
                }
            }
        }
    }
    else // If fChecklist is TRUE, an INACTIVE is implied
    {
        DWORD dwIndexCount;
        BOOL  fFoundActiveCall = FALSE;
        // Look for an active call
        for ( dwIndexCount = 0; dwIndexCount < RIL_MAX_TRACKED_CALL_ID; dwIndexCount++ )
        {
            // Valid entries set the cbSize
            if ( g_rgfCallStates[dwIndexCount].cbSize == sizeof(RILCALLINFO))
            {
                // If ci_cpistatus is set the call could be connected or disconnected
                // If ci_cpistatus is not set, the call is active by default (clcc processing)
                if ( g_rgfCallStates[dwIndexCount].dwParams & RIL_PARAM_CI_CPISTATUS )
                {
                    // If dwStatus is not disconnected, the call is considered active.
                    if ( g_rgfCallStates[dwIndexCount].dwStatus != RIL_CPISTAT_DISCONNECTED )
                    {
                        fFoundActiveCall = TRUE;
                        break;
                    }
                } 
                else
                {
                     fFoundActiveCall = TRUE;
                     break;
                } 
            }
        }
        if( (g_hWavDev != NULL) && (g_hWavDev != INVALID_HANDLE_VALUE) && (FALSE == fFoundActiveCall))
        {
            DWORD dwRet;
            DeviceIoControl (g_hWavDev, IOCTL_GSM_CALL_INACTIVE, 0, 0, NULL, 0, &dwRet, NULL);
            //DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : RILSetAudioPath : IOCTL_GSM_CALL_INACTIVE\r\n")));
			NKDbgPrintfW(TEXT("RILDrv : i : RILSetAudioPath : IOCTL_GSM_CALL_INACTIVE\r\n"));
        }
    }
#endif
}

⌨️ 快捷键说明

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