• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Benjamin

            靜以修身,儉以養德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 397, 文章 - 0, 評論 - 196, 引用 - 0
            數據加載中……

            BREW中的IWEB接口的基本用法

            BREW是無線二進制運行環境(Binary Runtime Environment for Wireless)的縮寫, 是高通公司2001年推出的基于CDMA網絡 "無線互聯網發射平臺" 上增值業務開發運行的基本平臺。它提供一個高效、低成本、可擴展和熟悉的應用程序執行環境(AEE), 著重開發可無縫植入任何實際手持設備的應用程序。BREW主要應用在移動通信領域,BREW類似一個開放免費的PC操作系統。
            在BREW平臺上的網絡應用主要是IScoket和IWeb接口,IWeb使用更簡單、方便些。在BREW下應用IWeb接口,主要過程如下:
            1.初始化接口:一般把這部分代碼放在了App_InitAppData函數中
            if (ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEB, (void **)&pMe->pIWeb) != SUCCESS)
             {
              pMe->pIWeb = NULL;
              return TRUE;
             }
             else
             { // 3a. Set up the callback function to receive response from server
              CALLBACK_Init(&pMe->WebCBStruct, IWebCB, pMe); // out, in, in
             }

             

             if (SUCCESS != ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pMe->pfm))
             {
              IAPPLET_Release((IApplet*)pMe);
              return TRUE;
             }

             if (SUCCESS != ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_WEBUTIL,(void **)&pMe->pIWebUtil))
             {
              pMe->pIWebUtil = NULL;
              return TRUE;
             }
            //初始化回調
            CALLBACK_Init(&pMe->WebCBStruct, IWebCB, pMe); // out, in, in


            //IWebCB函數定義
            void IWebCB (iweb* pMe) {
             // get info about the response
             pMe->pWebRespInfo = IWEBRESP_GetInfo(pMe->pIWebResp);
             // 5.a check error code
             if (!WEB_ERROR_SUCCEEDED(pMe->pWebRespInfo->nCode))
             { 
             return;
             }
             // 5.b get pointer to Source object
             pMe->pISource = pMe->pWebRespInfo->pisMessage;
             if (pMe->pISource == NULL)
             {
              return;
             }
             // 5.c register Isource Read callback
             CALLBACK_Init(&pMe->WebCBStruct, ReadFromWebCB, pMe); // out, in, in
             // 5.d post a read; data is processed by ISource callback
             ISOURCE_Readable(pMe->pISource, &pMe->WebCBStruct);
             return;
            }

            void ReadFromWebCB(iweb* pMe)
            {
             AECHAR szText[] = {'D','o','w','n','l','o','a','d', ' ','F', 'i', 'n', 'i','s','h','\0'};
             char buf[1024]; // allocate buffer
             int byteCount;
             // read data from stream; get number of bytes read
             byteCount = ISOURCE_Read(pMe->pISource, (char*)buf, sizeof(buf));
             switch (byteCount) {
              case ISOURCE_WAIT: // Buffer empty, but more data expected // post another read
               ISOURCE_Readable(pMe->pISource,&pMe->WebCBStruct);
               return;
              case ISOURCE_ERROR: // Error occurred ProcessError(…);
              case ISOURCE_END: // Buffer empty; all data received ProcessData(…);
               IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                                       AEE_FONT_BOLD,       // Use BOLD font
                                       szText,              // Text - Normally comes from resource
                                       -1,                  // -1 = Use full string length
                                       0,                   // Ignored - IDF_ALIGN_CENTER
                                       0,                   // Ignored - IDF_ALIGN_MIDDLE
                                       NULL,                // No clipping
                                       IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
               IDISPLAY_Update(pMe->a.m_pIDisplay);
               return;
              default: // data read; copy from chunk buffer 
                IFILE_Write(pMe->pIFile,buf,byteCount);
               // post another read
               ISOURCE_Readable(pMe->pISource,&pMe->WebCBStruct);
               return;
             }
            }

            //http請求頭的設置
            {
            int    i = 0;
                  WebOpt awo[10];

                  // set the IWeb connect timeout to 10 seconds.  this also sets the
                  // failover timeout, if unset, or set to 0, IWeb uses the system
                  // default (30 seconds unless an OEM changes it)
                  awo[i].nId  = WEBOPT_CONNECTTIMEOUT;
                  awo[i].pVal = (void *)100000;
                  i++;

                  // test user-agent, uncomment this section to ship your own user-agent
                  // string. if unset, IWeb will send a default.  If set to NULL, no
                  // user agent header will be sent */

                  // Set TEST_USER_AGENT in the NetDiagnostics project settings to all
                  // shipping of your own user agent.

            #ifdef TEST_USER_AGENT
                  awo[i].nId  = WEBOPT_USERAGENT;
                  awo[i].pVal = (void *)WEBBER_USERAGENT;
                  i++;
            #endif

                  // test nowaitconn, this only comes into effect if you build webber
                  // with multiple WebActions (see the definition of struct Webber)
                  awo[i].nId  = WEBOPT_FLAGS;
                  awo[i].pVal = (void *)WEBREQUEST_NOWAITCONN;
                  i++;
                 

                  // test forcenew, uncomment this section to try multiple simultaneous
                  // "forced" new connections. Forced new connections are not kept alive
                  // unless they are the first forced new connection to a host
            #ifdef TEST_FORCENEWCONN
                  awo[i].nId  = WEBOPT_FLAGS;
                  awo[i].pVal = (void *)WEBREQUEST_FORCENEWCONN;
                  i++;
            #endif


                  // turn off HTTP over HTTP proxying
                  awo[i].nId  = WEBOPT_PROXYSPEC;
                  awo[i].pVal = (void *)"http:///";
                  i++;

                  // turn on ALL proxying.  Proxyspecs are examined in WebOpt
                  // order, so in this list, with the above and below PROXYSPECs,
                  // everything except HTTP will be proxied through
                  // http://webproxy.yourdomain.com:8080, (which you'll have to
                  // set up to test, sorry
                  awo[i].nId  = WEBOPT_PROXYSPEC;
                  awo[i].pVal = (void *)"*:///http://192.168.1.46:80";
                  i++;

                  // Marks the end of the array of WebOpts
                  awo[i].nId  = WEBOPT_END;
                 
                  // Add Options
                  IWEB_AddOpt(pApp->m_pIWeb,awo);
               }

               // Initialize all my WebActions to point to  applet
                FOR_ALL_WEBACTIONS(pApp, p, p->pParent = pApp);


            //打開或建立接收響應數據的文件
            pMe->pIFile = IFILEMGR_OpenFile(pMe->pfm, "Rev.txt", _OFM_READWRITE);
             if (NULL == pMe->pIFile)
             {
              pMe->pIFile = IFILEMGR_OpenFile(pMe->pfm, "Rev.txt", _OFM_CREATE);
              if (NULL == pMe->pIFile)
              {
               int Result = GETLASTFPERROR();
               return FALSE;
              }
             }
            2.發送請求:其響應消息在回調函數ReadFromWebCB中接收,IWeb狀態、
            IWEB_GetResponse(pMe->pIWeb,
               (pMe->pIWeb,
               &pMe->pIWebResp,
               &pMe->WebCBStruct,
               m_gOutURL,
               //WEBOPT_HEADER,"GET /vt/v=w2.119&hl=zh-CN&gl=cn&x=53399&y=28435&z=16&s=Gali HTTP/1.0\r\nAccept:*/*\r\nX-Method:GET\r\nHost:203.208.37.99",
            WEBOPT_HEADERHANDLER, WebAction_Header,
               WEBOPT_STATUSHANDLER, WebAction_Status,
               WEBOPT_END))
            這里也可以直接設置這個請求頭(WEBOPT_HEADER)、請求消息(WEBOPT_BODY),如上所示。Method默認的就是GET,
            WEBOPT_STATUSHANDLER表示后面的WebAction_Status回調函數(功能是IWeb狀態)、WEBOPT_HEADERHANDLER的用法和
            上面的WEBOPT_STATUSHANDLER的用法一樣,后面跟的是服務端返回消息的回調函數,如下所示。

            //IWeb 狀態
            static void WebAction_Status(void *p, WebStatus ws, void *pVal)
            {
             char *pszStatus = NULL;

             switch (ws) {
               case WEBS_CANCELLED:
                //ISHELL_LoadResString(pApp->a.m_pIShell,"MessageBox",IDC_CANCEL,pApp->m_AnimalTitle,sizeof(pApp->m_AnimalTitle));
                pszStatus = "** cancelled...\n";
                break;
               case WEBS_GETHOSTBYNAME:
                //ISHELL_LoadResString(pApp->a.m_pIShell,"MessageBox",IDC_FIND_HOST,pApp->m_AnimalTitle,sizeof(pApp->m_AnimalTitle));
                pszStatus = "** finding host...\n";
                break;         
               case WEBS_CONNECT:
                pszStatus = "** connecting...\n";
                //ISHELL_LoadResString(pApp->a.m_pIShell,"MessageBox",IDC_CONNECTING,pApp->m_AnimalTitle,sizeof(pApp->m_AnimalTitle));
                break;
               case WEBS_SENDREQUEST:
                pszStatus = "** sending...\n";
                //ISHELL_LoadResString(pApp->a.m_pIShell,"MessageBox",IDC_SEND,pApp->m_AnimalTitle,sizeof(pApp->m_AnimalTitle));
                break;
               case WEBS_READRESPONSE:
                pszStatus = "** receiving...\n";
                //ISHELL_LoadResString(pApp->a.m_pIShell,"MessageBox",IDC_RECEIVE,pApp->m_AnimalTitle,sizeof(pApp->m_AnimalTitle));
                break;
               case WEBS_GOTREDIRECT:
                //pszStatus = "** redirect...\n";
                break;
               case WEBS_CACHEHIT:
                pszStatus = "** cache hit...\n";
                break;
             }
            }
            //返回信息頭
            static void WebAction_Header(void *p, const char *cpszName, GetLine *pglVal)
            {
               WebAction *pwa = (WebAction *)p;
               CDBApp * pApp = pwa->pParent;
             
                if ((char *)0 != cpszName) {
                // ND_Print(pApp, "%s:", cpszName);
              ;
                }
                //ND_Print(pApp, "%s\n", pglVal->psz);
            }

            3.釋放資源,關閉文件
            if (pMe->pIWeb)
             {
              IWEB_Release(pMe->pIWeb);
              pMe->pIWeb = NULL;
             }

             if (pMe->pIWebResp)
             {
              IWEBRESP_Release(pMe->pIWebResp);
              pMe->pIWebResp = NULL;
             }

             if (pMe->pIWebUtil)
             {
              IWEBUTIL_Release(pMe->pIWebUtil);
              pMe->pIWebUtil = NULL;
             }

             

             if (pMe->m_gOutURL)
             {
              FREE(pMe->m_gOutURL); 
              pMe->m_gOutURL = NULL;
             }

             if (pMe->pfm)
             {
              IFILEMGR_Release(pMe->pfm);
              pMe->pfm = NULL;
             }

             if (pMe->pIFile)
             {
              IFILE_Release(pMe->pIFile);
              pMe->pIFile = NULL;
             }
            BREW雖然支持C++,但是其原始的語法還是C語言,比較接近底層,在這里要注意回調函數定義的位置。

            posted on 2010-03-28 11:25 Benjamin 閱讀(1635) 評論(0)  編輯 收藏 引用 所屬分類: 其他手機平臺

            综合人妻久久一区二区精品| 国内精品久久久久久久影视麻豆| 国产99久久久国产精免费| 欧美日韩中文字幕久久伊人| 国产成人精品久久亚洲高清不卡| 国产精品免费看久久久香蕉| 久久国产AVJUST麻豆| 国产呻吟久久久久久久92| 一级女性全黄久久生活片免费| 91精品国产91热久久久久福利| 亚洲色欲久久久综合网| 热re99久久精品国产99热| 久久久久波多野结衣高潮| 久久成人小视频| 欧美精品一本久久男人的天堂| 久久天天躁狠狠躁夜夜2020一| 久久久久99精品成人片牛牛影视| 精品九九久久国内精品| 久久精品国产亚洲精品2020| 久久久久99这里有精品10| 女人香蕉久久**毛片精品| 久久精品九九亚洲精品| 伊人久久大香线焦AV综合影院| 久久亚洲av无码精品浪潮| 天天做夜夜做久久做狠狠| 国产精品亚洲美女久久久| www.久久热.com| 亚洲国产精品婷婷久久| 久久精品国产亚洲AV嫖农村妇女| 久久精品国产99国产精品导航| 亚洲欧美国产精品专区久久| 久久久91人妻无码精品蜜桃HD| 久久精品无码一区二区三区| 97久久精品无码一区二区| 奇米影视7777久久精品| 久久精品国产亚洲沈樵| 99久久99这里只有免费费精品| 亚洲综合精品香蕉久久网97 | 狠狠综合久久综合88亚洲 | 国产91久久综合| 91精品婷婷国产综合久久|