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

📄 rilsimtkittext.cpp

📁 ril source code for Windows CE
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// 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:

RilSimTKitText.cpp

Abstract:


Notes:


--*/

#include "precomp.h"

#ifdef assert
#undef assert
#endif
#include "Safeint.hxx"


HRESULT CRilSimToolkitCommand::ParseTextFormatCommand(DWORD* pdwRetNotifyCode, BYTE* pbCmdQualifier, DWORD* pdwRetVal)
{
    HRESULT hr = S_OK;
    DWORD dwNotifyCode;

    *pbCmdQualifier = 0;
    *pdwRetVal = SIM_RESPONSE_OK;

    // First thing should be the Command ID.
    if (!ParseHexDWord((LPCSTR)m_lpbParse, SIMTKIT_TEXTPARSE_PARSE_LEADINGZERO, dwNotifyCode, (LPCSTR&)m_lpbParse))
    {
        *pdwRetVal = SIM_RESPONSE_ERR_COMMANDNUMBER;
        hr = E_FAIL;
        goto Exit;
    }

    // Set notify code return result
    *pdwRetNotifyCode = dwNotifyCode;

    DEBUGMSG(ZONE_INFO, (TEXT("RilDrv : SIMTKit: Parsing Command 0x%x\r\n"), dwNotifyCode));

    // Parse the rest of the information based on the command ID.
    switch(dwNotifyCode)
    {
        case SIM_NOTIFY_SETUPMENU:
        case SIM_NOTIFY_SELECTITEM:
            hr = ParseSetupMenu(dwNotifyCode, pbCmdQualifier);
            break;
        case SIM_NOTIFY_PLAYTONE:
            hr = ParsePlayTone();
            break;
        case SIM_NOTIFY_DISPLAYTEXT:
            hr = ParseDisplayText(pbCmdQualifier);
            break;
        case SIM_NOTIFY_GETINKEY:
            hr = ParseGetInKey(pbCmdQualifier);
            break;
        case SIM_NOTIFY_GETINPUT:
            hr = ParseGetInput(pbCmdQualifier);
            break;
        case SIM_NOTIFY_SETUPIDLEMODETEXT:
            hr = ParseSetupIdleModeText();
            break;
        case SIM_NOTIFY_SENDSMS:
        case SIM_NOTIFY_SENDSS:
        case SIM_NOTIFY_SENDUSSD:
        case SIM_NOTIFY_SETUPCALL:
        case SIM_NOTIFY_SENDDTMF:
        case SIM_NOTIFY_OPENCHANNEL:
        case SIM_NOTIFY_CLOSECHANNEL:
        case SIM_NOTIFY_RUNATCOMMAND:
            hr = ParseUnsolicitedData();
            break;
        case SIM_NOTIFY_REFRESH:
            hr = ParseRefresh(pbCmdQualifier);
            break;
        case SIM_NOTIFY_EVENTLIST:
            hr = ParseEventList();
            break;
        case SIM_NOTIFY_LAUNCHBROWSER:
            hr = ParseLaunchBrowser(pbCmdQualifier);
            break;
        case SIM_NOTIFY_RECEIVEDATA:
            hr = ParseReceiveData();
            break;
        case SIM_NOTIFY_SENDDATA:
            hr = ParseSendData();
            break;
        case SIM_NOTIFY_LANGUAGENOTIFICATION:
            hr = ParseLanguageNotification();
            break;
        case SIM_NOTIFY_CALLSETUP:
        case SIM_NOTIFY_MORETIME:
        case SIM_NOTIFY_POLLINTERVAL:
        case SIM_NOTIFY_POLLINGOFF:
        case SIM_NOTIFY_LOCALINFO:
        default:
            // We don't understand this command
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Don't understand command %x\r\n"), dwNotifyCode));
            *pdwRetVal = SIM_RESPONSE_ERR_COMMANDTYPE;
            hr = E_FAIL;
            goto Exit;
    } // switch(dwNotifyCode)

    // Set the return value if parsing of the command failed.
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Parsing of command %x failed.\r\n"), dwNotifyCode));
        *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
        goto Exit;
    }

Exit:

    return hr;
}



HRESULT CRilSimToolkitCommand::ParseSetupMenu(DWORD dwCommandID, BYTE* pbCmdQualifier)
{
    BYTE* pbParse;
    DWORD dwLength;
    DWORD dwNumItems;
    DWORD dwSelection;
    DWORD dwHelpInfo;
    DWORD dwIconID = SIMTKIT_INVALID_VALUE;
    DWORD dwDispMode = SIMTKIT_INVALID_VALUE;
    DWORD dwRemoveMenu = 0;
    LPWSTR wszMenuTitle = NULL;
    size_t cbMenuTitleBufSize = 0;
    UINT uCurMenuItem;
    HRESULT hr = S_OK;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseSetupMenu\r\n")));

    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the notification should be in the form of:
    // Setup Menu:
    //,<numItems>,<selection>,<removemenu>,<helpInfo>,[<alphaId>][,<iconId>,<dispMode>]<CR><LF>
    // Select Item:
    // <numItems>,<selection>,<helpInfo>,<alphaId>[,<iconId>,<dispMode>]<CR><LF>
    //
    // +STGC: <itemId>,<itemText>[,<iconId>,<dispMode>,<nai><CR><LF>
    // [+STGC: <itemId>,<itemText>[,<iconId>,<dispMode>,<nai><CR><LF>
    // [...]]]]

    // ,<numItems>
    // integer: indicates the number of items accessible in the menu structure.
    // 0 is a special case, indicating the existing menu is to be removed
    // from the ME's menu structure.
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwNumItems, (LPCSTR&)pbParse))
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<selection>
    // integer: gives preferred user selection method
    // 0 no selection preference
    // 1 soft key selection preferred
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwSelection, (LPCSTR&)pbParse))
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Setup Menu only
    // ,<removemenu>
    if ((SIM_NOTIFY_SETUPMENU == dwCommandID) &&
        (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
         !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwRemoveMenu, (LPCSTR&)pbParse)))
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<helpInfo>
    // 0 no help information available
    // 1 help information available
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwHelpInfo, (LPCSTR&)pbParse))
    {
        hr = E_FAIL;
        goto Exit;
    }


    // [,<alphaId>] string format: using either SMS default alphabet
    // or UCS2 alpha field coding.

    // Setup Menu command with the RemoveMenu field set or 0 menu items treat the alpha ID as
    // optional.
    if ((SIM_NOTIFY_SETUPMENU == dwCommandID) &&
        ((0 != dwRemoveMenu) || (0 == dwNumItems)) )
    {
        if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            ParseEncodedText(pbParse, SIMTKIT_TEXT_ENCODING_ALPHAID, wszMenuTitle, cbMenuTitleBufSize, pbParse);
        }
    }
    else
    {
        // For all others, alpha ID is required.
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
            !ParseEncodedText(pbParse, SIMTKIT_TEXT_ENCODING_ALPHAID, wszMenuTitle, cbMenuTitleBufSize, pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }
    }

    // Optional: <iconId>,<dispMode>
    // Numeric tag for the icon to be displayed -
    // corresponds to the index in the Image file on the SIM
    // 0 No icon
    // 1..255 Icon tag
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        if (!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwIconID, (LPCSTR&)pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }

        // ,<dispMode>
        // integer: denotes use of associated icon
        // 0 display icon only (replaces any text string or alphaId)
        // 1 display with alpha Id or text string
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
            !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDispMode, (LPCSTR&)pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }
    }

    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Parse Menu items, if any are specified.
    if (0 < dwNumItems)
    {
        // Create space for a list of pointers to Menu items
        m_rgpsmi = new LPSIMMENUITEM[dwNumItems];
        if (!m_rgpsmi)
        {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
        memset( m_rgpsmi, 0, (sizeof(LPSIMMENUITEM) * dwNumItems) );

        // Parse through and add menu items.
        // ---------------------------------
        // The list of menu items we receive from the radio is indexed
        // starting at 1.
        for (uCurMenuItem = 1; uCurMenuItem <= dwNumItems ; uCurMenuItem++)
        {
            if ( FAILED(ParseMenuItem(pbParse)) )
            {
                hr = E_FAIL;
                goto Exit;
            }
        }
    }

    // Parsing successful, set proper values for build command functions

    // The radio should not send menu items if the remove menu setting
    // was set, but if any existed, remove them. This way an empty menu is
    // still sent to the simtkit layer to trigger the setup menu removal.
    // This is inefficient but suitable handling of this edge condition.
    if (0 != dwRemoveMenu)
    {
        if (NULL != m_rgpsmi)
        {
            // Free memory
            ASSERT( m_numpsmi == dwNumItems );
            for (DWORD i = 0; i < dwNumItems; i++)
            {
                delete [] (LPBYTE)(m_rgpsmi[i]);
                m_rgpsmi[i] = NULL;
            }
            delete [] m_rgpsmi;
            m_rgpsmi = NULL;
        }
        m_numpsmi = 0;
    }

    // Encode the HelpInfo setting into the command qualifier field to maintain
    // SIMTKIT compatibility between different notification types.
    if (dwHelpInfo)
    {
        *pbCmdQualifier |= SIMTKIT_TEXTPARSE_HELPINFO;
    }

    m_pwszAlphaId  = wszMenuTitle;
    m_dwAlphaIdLen = cbMenuTitleBufSize;

    if (SIMTKIT_INVALID_VALUE != dwIconID)
    {
        m_dwIconIdentifier = dwIconID;
    }

    if (SIMTKIT_INVALID_VALUE != dwDispMode)
    {
        m_dwIconQualifier = dwDispMode;
    }

    DEBUGMSG(ZONE_INFO, (TEXT("RilDrv : SIMTKit: ParseSetupMenu: NumItems: %d Menu Name: %s\r\n"), dwNumItems, wszMenuTitle));

Exit:

    if (FAILED(hr))
    {
        delete[] wszMenuTitle;

        if (NULL != m_rgpsmi)
        {
            // Free memory
            for (UINT i = 0; i < m_numpsmi; i++)
            {
                delete [] (LPBYTE)(m_rgpsmi[i]);
                m_rgpsmi[i] = NULL;
            }
            delete [] m_rgpsmi;
            m_rgpsmi = NULL;
        }
        m_numpsmi = 0;
    }

    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseSetupMenu\r\n")));

    return hr;
}

HRESULT CRilSimToolkitCommand::ParseMenuItem(LPBYTE& rpbParse)
{
    HRESULT hr = S_OK;
    DWORD dwItemID;
    DWORD dwIconID = SIMTKIT_INVALID_VALUE;
    DWORD dwDispMode = SIMTKIT_INVALID_VALUE;
    DWORD dwNAI;
    DWORD dwSize;
    LPWSTR wszItemText = NULL;
    size_t cbItemTextBufSize = 0;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseMenuItem\r\n")));

    // A menu item should look like this:
    // +STGC: <itemId>,<itemText>[,<iconId>,<dispMode>[,<nai>]<CR><LF>


    if ( !MatchStringBeginning((LPCSTR)rpbParse, "+STGC: ", (LPCSTR&)rpbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // <itemId>
    if ( !ParseDWord((LPCSTR)rpbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwItemID, (LPCSTR&)rpbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<itemText>
    if (!MatchStringBeginning((LPCSTR)rpbParse, ",", (LPCSTR&)rpbParse) ||
        !ParseEncodedText(rpbParse, SIMTKIT_TEXT_ENCODING_ALPHAID, wszItemText, cbItemTextBufSize, rpbParse))
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Optional: ,<iconId>,<dispMode>,<nai>
    if (MatchStringBeginning((LPCSTR)rpbParse, ",", (LPCSTR&)rpbParse))
    {
        //,<iconId>
        if (!ParseDWord((LPCSTR)rpbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwIconID, (LPCSTR&)rpbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }

        // ,<dispMode>
        if (!MatchStringBeginning((LPCSTR)rpbParse, ",", (LPCSTR&)rpbParse) ||
            !ParseDWord((LPCSTR)rpbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDispMode, (LPCSTR&)rpbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }

        // [,<nai>]
        if (MatchStringBeginning((LPCSTR)rpbParse, ",", (LPCSTR&)rpbParse))
        {
            if (!ParseDWord((LPCSTR)rpbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwNAI, (LPCSTR&)rpbParse))
            {
                hr = E_FAIL;
                goto Exit;
            }
        }
    }

    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)rpbParse, (LPCSTR&)rpbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    DEBUGMSG(ZONE_INFO, (TEXT("RilDrv : SIMTKit: ParseMenuItem: ItemID: %d Menu Name: %s\r\n"), dwItemID, wszItemText));

⌨️ 快捷键说明

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