• <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

            靜以修身,儉以養德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 398, 文章 - 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 閱讀(1641) 評論(0)  編輯 收藏 引用 所屬分類: 其他手機平臺

            国产Av激情久久无码天堂| 蜜桃麻豆www久久国产精品| 无码人妻精品一区二区三区久久| 久久精品国产99国产精品导航| 国产精品一区二区久久不卡| 精品欧美一区二区三区久久久| 综合人妻久久一区二区精品| 久久国产精品无码HDAV| 久久亚洲精品无码AV红樱桃| 久久综合九色综合网站| 久久久精品免费国产四虎| 久久亚洲日韩看片无码| 久久91亚洲人成电影网站| 中文字幕无码久久精品青草| 99久久精品免费看国产免费| 久久精品人人槡人妻人人玩AV| 久久久久久无码国产精品中文字幕| 日日噜噜夜夜狠狠久久丁香五月| 日韩久久久久中文字幕人妻 | 久久夜色精品国产噜噜亚洲AV| 久久精品亚洲乱码伦伦中文| 久久久久久九九99精品| 亚洲午夜久久久久久久久电影网| 久久久久国产| 国产精品成人99久久久久| 久久99精品国产| 精品久久久久久国产| AV狠狠色丁香婷婷综合久久| 欧美亚洲色综久久精品国产| 亚洲中文字幕无码久久2017 | 看久久久久久a级毛片| 午夜精品久久久久| 久久亚洲精品国产精品婷婷 | 久久AV高清无码| 亚洲成色WWW久久网站| 一本一本久久A久久综合精品 | 国产激情久久久久影院小草| 99热成人精品免费久久| 久久精品无码免费不卡| 一本大道久久a久久精品综合| 99热精品久久只有精品|