sockettest.c
上传用户:wdy0515
上传日期:2015-09-05
资源大小:5k
文件大小:27k
- #include "MMI_features.h"
- /* MTK End */
- #if !defined(__MTK_TARGET__)
- #include <windows.h>
- #endif
- /**********************/
- /***** Header Files *****/
- /**********************/
- #ifdef FIRST_PASS
- #include "BuildCfg.h"
- #endif
- #include "CustDataRes.h"
- #include "EventsGprot.h"
- #include "historyGprot.h"
- #include "ProtocolEvents.h"
- #include "CustMenuRes.h"
- #include "wgui_categories.h"
- #include "HardwareEvents.h"
- #include "Thrdosinterface.h"
- #include "OSThreadInterfaceGprot.h"
- #include "TimerEvents.h"
- #include "MainMenuDef.h"
- #include "EngineerModeDef.h"
- #include "EngineerModeType.h"
- #include "EngineerModeProt.h"
- #include "PixtelDataTypes.h"
- #include "CustomCfg.h"
- #include "Unicodexdcl.h"
- #include "audioInc.h"
- #include "IdleAppDef.h"
- #include "BootUp.h"
- #include "GlobalDefs.h"
- #include "soc_api.h"
- #include "app2soc_struct.h"
- #include "EngineerModeSocketApp.h"
- #include "EngineerModeSocketAppPing.h"
- #include "OrganizerDef.h"
- soc_demo_app_transaction_struct *test_soc_demo_transaction = NULL;
- void mmi_test_socket();
- int test_mmi_soc_demo_app_request(
- mmi_soc_demo_app_enum app_id,
- int account_id,
- char server_ip_address[4],
- char *url,
- int url_len,
- char *echo_text,
- int echo_text_len,
- mmi_soc_demo_app_rsp_t callback);
- void tst_EmSocketRsp(mmi_soc_demo_app_enum app_id_enum, int result, char *response, int response_len);
- kal_bool test_en_soc_demo_app_create_socket();
- int test_en_soc_demo_http_send_request(void);
- void test_em_soc_demo_app_socket_notify(void *inMsg);
- void tst_em_soc_demo_app_start_timer(void);
- void tst_em_soc_demo_app_timer_handler(void);
- void tst_en_soc_demo_tcp_app_recv_response(void);
- void tst_en_soc_output_result(int ret, char *out_str, int len);
- int tst_mmi_soc_demo_app_request_abort(void);
- void tst_em_soc_demo_app_stop_timer(void);
- extern void StartTimer(U16 timerid, U32 delay, FuncPtr funcPtr);
- extern void StopTimer(U16 timerid);
- void tst_EmSocketRsp(mmi_soc_demo_app_enum app_id_enum, int result, char *response, int response_len)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i,j,k;
- U16 databgin, namebgin,preClsbgin,curpricebgin;
- U16 pack_byte;
- U8 socknum;
- /*----------------------------------------------------------------*/
- /* Object */
- /*----------------------------------------------------------------*/
- for(i = 0; i < response_len; i++)
- {
- if(response[i] == 0x20 && response[i+1] == 0x20 )
- {
- pack_byte = response[i-2];
- pack_byte = ((pack_byte & 0x00ff)<<8) + response[i -1];
- kal_prompt_trace(MOD_WAP,"##########pack_byte[%d]",pack_byte);
- break;
- }
- }
-
- databgin = i + 2;
- namebgin = databgin + 6;
- //curpricebgin = namebgin + 52;
- pack_byte -=2;
- socknum = pack_byte / 258;
- kal_prompt_trace(MOD_WAP,"##########socknum[%d]",socknum);
-
- for(j = 0; j < socknum; j++)
- {
- U8 cur[10][4];
- U8 preCls[10][4];
- U8 stockname[10][24];
- U16 index = 0;
- float preprice[10];
- float currentprice[10];
- float updown[10];
- ////////////////////////////////////name/////////////////////////////
- for(k = namebgin + j*258; k <namebgin+ j*258 + 24; k++)
- {
- stockname[j][index++] = response[k];
- }
- ////////////////////////////////////preprice////////////////////////////
- {
- index = 0;
- k = k;
- preClsbgin =k;
- }
- for(;k <preClsbgin + 4;k++ )
- {
- preCls[j][index++] = response[k];
- kal_prompt_trace(MOD_WAP,"#############preprice = %x",response[k]);
-
- }
- {
- U32 prevalue;
- prevalue = (preCls[j][0]<<24) + (preCls[j][1]<<16) +(preCls[j][2]<<8) + (preCls[j][3]);
- preprice[j] = ((float)prevalue) /10000;
-
- kal_prompt_trace(MOD_WAP,"---------------------prevalue = %d",prevalue);
-
- }
-
- ////////////////////////////////////current price/////////////////////////
- {
- index = 0;
- k = k + 24;
- curpricebgin =k;
- }
-
- for(; k < curpricebgin + 4; k++)
- {
- cur[j][index++] = response[k];
- }
-
- {
- U32 value;
- value = ( cur[j][0]<<24) + (cur[j][1]<<16) + (cur[j][2]<<8) + (cur[j][3]);
- currentprice[j] = ((float)value) /10000;
- }
- /////////////////////////////////////end///////////////////////////////
- }
-
- }
- void mmi_test_socket(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- #ifdef MMI_ON_HARDWARE_P
- U8 emSocketAccountId = custom_get_csd_profile_num();
- #else
- U8 emSocketAccountId = 5;
- #endif
- mmi_soc_demo_app_result emSocketTmpResult = EN_SOC_SUCCESS;
- S8 AscTmp[16];
- kal_prompt_trace(MOD_WAP," mmi_test_socket __________________ emSocketAccountId=%d",emSocketAccountId);
- emSocketTmpResult = test_mmi_soc_demo_app_request(
- HTTP,
- 10,
- NULL,
- NULL,//emSocketInputdata,
- 0,//strlen(emSocketInputdata),
- NULL,
- 0,
- tst_EmSocketRsp);
- }
- int test_mmi_soc_demo_app_request(
- mmi_soc_demo_app_enum app_id,
- int account_id,
- char server_ip_address[4],
- char *url,
- int url_len,
- char *echo_text,
- int echo_text_len,
- mmi_soc_demo_app_rsp_t callback)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (test_soc_demo_transaction)
- {
- kal_prompt_trace(MOD_WAP,"###########################Transaction existed");
- #ifdef MMI_ON_HARDWARE_P
- kal_print("Transaction existed!!");
- #endif
- return EN_SOC_BUSY;
- }
- else
- {
- if ((test_soc_demo_transaction = OslMalloc(sizeof(soc_demo_app_transaction_struct))) == NULL)
- {
- #ifdef MMI_ON_HARDWARE_P
- kal_print("No memory");
- #endif
- en_soc_output_result(EN_SOC_NO_MEMORY, NULL, 0);
- return EN_SOC_NO_MEMORY;
- }
- else
- {
- memset(test_soc_demo_transaction, 0, sizeof(soc_demo_app_transaction_struct));
- if ((test_soc_demo_transaction->rcvd_buffer = OslMalloc(MAX_RCV_BUFFER_SIZE)) == NULL)
- {
- #ifdef MMI_ON_HARDWARE_P
- kal_print("No memory");
- #endif
- en_soc_output_result(EN_SOC_NO_MEMORY, NULL, 0);
- return EN_SOC_NO_MEMORY;
- }
- else
- {
- if ((test_soc_demo_transaction->snd_buffer = OslMalloc(MAX_SND_BUFFER_SIZE)) == NULL)
- {
- #ifdef MMI_ON_HARDWARE_P
- kal_print("No memory");
- #endif
- en_soc_output_result(EN_SOC_NO_MEMORY, NULL, 0);
- return EN_SOC_NO_MEMORY;
- }
- else
- {
- /* Set initial values to test_soc_demo_transaction */
- memset((kal_int8*) test_soc_demo_transaction->rcvd_buffer, 0, MAX_RCV_BUFFER_SIZE);
- memset((kal_int8*) test_soc_demo_transaction->snd_buffer, 0, MAX_SND_BUFFER_SIZE);
- test_soc_demo_transaction->soc_demo_app_id = app_id;
- test_soc_demo_transaction->nwt_acount_id = account_id;
- if (server_ip_address)
- {
- memcpy(test_soc_demo_transaction->server_ip_addr.addr, server_ip_address, 4);
- test_soc_demo_transaction->server_ip_addr.addr_len = 4;
- }
- test_soc_demo_transaction->url = (kal_int8*) url;
- test_soc_demo_transaction->url_len = url_len;
- test_soc_demo_transaction->snd_counter = 0;
- test_soc_demo_transaction->rcvd_counter = 0;
- test_soc_demo_transaction->callback = callback;
- if (echo_text)
- {
- if (echo_text_len > MAX_SND_BUFFER_SIZE)
- {
- memcpy(test_soc_demo_transaction->snd_buffer, echo_text, MAX_SND_BUFFER_SIZE);
- test_soc_demo_transaction->snd_data_len = MAX_SND_BUFFER_SIZE;
- }
- else
- {
- memcpy(test_soc_demo_transaction->snd_buffer, echo_text, echo_text_len);
- test_soc_demo_transaction->snd_data_len = echo_text_len;
- }
- OslMfree(echo_text);
- }
- if (test_en_soc_demo_app_create_socket() == KAL_FALSE)
- {
- return EN_SOC_NO_MEMORY;
- }
- else
- kal_prompt_trace(MOD_WAP,"_________________________ CREATE SOCKET OK");
- switch (app_id)
- {
- case HTTP:
- {
- test_soc_demo_transaction->state = HTTP_DNS_QUERY;
- return test_en_soc_demo_http_send_request();
- }
- default:
- {
- return EN_SOC_UNKNOWN_APP;
- }
- }
- }
- }
- }
- }
- }
- kal_bool test_en_soc_demo_app_create_socket()
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- kal_uint8 val = 1;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (test_soc_demo_transaction)
- {
- test_soc_demo_transaction->state = SOC_CREATING;
- switch (test_soc_demo_transaction->soc_demo_app_id)
- {
- case HTTP:
- {
- test_soc_demo_transaction->socket_id = soc_create(PF_INET, SOCK_STREAM, 0, MOD_MMI, test_soc_demo_transaction->nwt_acount_id);
- if (test_soc_demo_transaction->socket_id >= 0)
- {
- if (soc_setsockopt(test_soc_demo_transaction->socket_id, SOC_NBIO, &val, sizeof(val)) < 0)
- {
- #ifdef MMI_ON_HARDWARE_P
- kal_print("Set socket to nonblock mode error !!");
- #endif
- return KAL_FALSE;
- }
- val = SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT;
- if (soc_setsockopt(test_soc_demo_transaction->socket_id, SOC_ASYNC, &val, sizeof(val)) < 0)
- {
- #ifdef MMI_ON_HARDWARE_P
- kal_print("Set socket to nonblock mode error !!");
- #endif
- return KAL_FALSE;
- }
- test_soc_demo_transaction->state = SOC_CREATED;
- return KAL_TRUE;
- }
- else
- {
- return KAL_FALSE;
- }
- break;
- }
- default:
- return KAL_FALSE;
- }
- }
- else
- {
- return KAL_FALSE;
- }
- }
- int test_en_soc_demo_http_send_request(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (test_soc_demo_transaction)
- {
- if (test_soc_demo_transaction->state == HTTP_DNS_QUERY &&
- (soc_demo_app_http_url_struct*) test_soc_demo_transaction->url_parsed_info == NULL)
- {
- kal_prompt_trace(MOD_WAP," test_en_soc_demo_http_send_request __________________________________");
- test_soc_demo_transaction->server_ip_addr.addr[0] = 10;
- test_soc_demo_transaction->server_ip_addr.addr[1] = 0;
- test_soc_demo_transaction->server_ip_addr.addr[2] = 0;
- test_soc_demo_transaction->server_ip_addr.addr[3] = 172;
- test_soc_demo_transaction->server_ip_addr.port = 80;
-
- test_soc_demo_transaction->rcvd_counter = 0;
- test_soc_demo_transaction->server_ip_addr.addr_len = 4;
- test_soc_demo_transaction->state = HTTP_TCP_CON_CREATING;
- test_en_soc_demo_http_send_request();
-
- }
- else if (test_soc_demo_transaction->state == HTTP_TCP_CON_CREATING)
- {
- kal_int8 ret;
- char CRLF[3] = {0x0d, 0x0a, 0x00};
-
- test_soc_demo_transaction->state = HTTP_TCP_CON_CREATED;
- test_soc_demo_transaction->snd_data_len=0;
- strcat(test_soc_demo_transaction->snd_buffer,"GET ");
- test_soc_demo_transaction->snd_data_len+=4;
- strcat((char*)test_soc_demo_transaction->snd_buffer,"http://61.135.159.21/cgi-bin/weather?024 ");
- test_soc_demo_transaction->snd_data_len+=41;
- strcat((char*)test_soc_demo_transaction->snd_buffer,"HTTP/1.1");
- test_soc_demo_transaction->snd_data_len+=8;
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
- strcat((char*)test_soc_demo_transaction->snd_buffer,"Host: 10.0.0.172:80");
- test_soc_demo_transaction->snd_data_len+=19;
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
-
- strcat((char*)test_soc_demo_transaction->snd_buffer,"User-Agent: */*");
- test_soc_demo_transaction->snd_data_len+=15;
-
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
- strcat((char*)test_soc_demo_transaction->snd_buffer,"Accept: */*");
- test_soc_demo_transaction->snd_data_len+=11;
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
-
- strcat((char*)test_soc_demo_transaction->snd_buffer,"X-Online-Host: 61.135.159.21");
- test_soc_demo_transaction->snd_data_len+=28;
-
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
- strcat((char*)test_soc_demo_transaction->snd_buffer,"Connection: Keep-Alive");
- test_soc_demo_transaction->snd_data_len+=22;
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
-
- strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
- test_soc_demo_transaction->snd_data_len+=2;
-
- kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:n %s", test_soc_demo_transaction->snd_buffer);
- kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:n %s", &test_soc_demo_transaction->snd_buffer[60]);
- kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:n %s", &test_soc_demo_transaction->snd_buffer[120]);
- #ifdef MMI_ON_HARDWARE_P
- kal_prompt_trace(MOD_WAP, "___________________ Http connect to %d.%d,%d,%d and port: %d",
- test_soc_demo_transaction->server_ip_addr.addr[0],
- test_soc_demo_transaction->server_ip_addr.addr[1],
- test_soc_demo_transaction->server_ip_addr.addr[2],
- test_soc_demo_transaction->server_ip_addr.addr[3],
- test_soc_demo_transaction->server_ip_addr.port);
-
- ret = soc_connect(test_soc_demo_transaction->socket_id, &test_soc_demo_transaction->server_ip_addr);
-
- kal_prompt_trace(MOD_WAP, "___________________ Http connect result is %d", ret);
- #endif
- if (ret == SOC_SUCCESS)
- {
- test_en_soc_demo_http_send_request();
- return EN_SOC_SUCCESS;
- }
- else if (ret == SOC_WOULDBLOCK)
- {
- SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
- return EN_SOC_SUCCESS;
- }
- else
- {
- if (ret == SOC_ERROR)
- {
- return EN_SOC_PEER_NOT_REACHABLE;
- }
- else
- {
- return EN_SOC_ERROR;
- }
- }
- }
- else if (test_soc_demo_transaction->state == HTTP_TCP_CON_CREATED || test_soc_demo_transaction->state == REQ_SEND_RETRY ||
- test_soc_demo_transaction->state == REQ_SENDING)
- {
- kal_int32 ret;
- if (test_soc_demo_transaction->state != REQ_SENDING)
- {
- test_soc_demo_transaction->snd_counter = 0;
- }
- test_soc_demo_transaction->state = REQ_SENDING;
- #ifdef MMI_ON_HARDWARE_P
- kal_prompt_trace(MOD_WAP, "___________________ Http send request to %d.%d,%d,%d and port: %d",
- test_soc_demo_transaction->server_ip_addr.addr[0],
- test_soc_demo_transaction->server_ip_addr.addr[1],
- test_soc_demo_transaction->server_ip_addr.addr[2],
- test_soc_demo_transaction->server_ip_addr.addr[3],
- test_soc_demo_transaction->server_ip_addr.port);
- #endif /* MMI_ON_HARDWARE_P */
- ret = soc_send(
- test_soc_demo_transaction->socket_id,
- (kal_uint8*) (test_soc_demo_transaction->snd_buffer + test_soc_demo_transaction->snd_counter),
- (test_soc_demo_transaction->snd_data_len - test_soc_demo_transaction->snd_counter),
- 0);
- #ifdef MMI_ON_HARDWARE_P
- kal_prompt_trace(MOD_WAP, "___________________ Http send request result, sent_bytes:%d", ret);
- #endif
- if (ret > 0)
- {
- if (ret == (kal_int32) test_soc_demo_transaction->snd_data_len)
- {
- test_soc_demo_transaction->state = REQ_SENT;
- test_soc_demo_transaction->post_retry_counter++;
- tst_em_soc_demo_app_start_timer(); /* wait for servwer's response */
- tst_en_soc_demo_tcp_app_recv_response();
- return EN_SOC_SUCCESS;
- }
- else
- {
- test_soc_demo_transaction->snd_counter += ret;
- return EN_SOC_SUCCESS;
- }
- }
- else
- {
- if (ret == SOC_WOULDBLOCK)
- {
- /* waits for socket notify */
- SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
- return EN_SOC_SUCCESS;
- }
- else
- {
- if (ret == SOC_ERROR)
- {
- return EN_SOC_PEER_NOT_REACHABLE;
- }
- else
- {
- return EN_SOC_ERROR;
- }
- }
- }
- }
- else
- {
- return EN_SOC_ERROR;
- }
- }
- else
- {
- return EN_SOC_ERROR;
- }
- }
- void test_em_soc_demo_app_socket_notify(void *inMsg)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- app_soc_notify_ind_struct *soc_notify = (app_soc_notify_ind_struct*) inMsg;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- kal_prompt_trace(MOD_WAP," entry the function test_em_soc_demo_app_socket_notify");
-
- if (!test_soc_demo_transaction)
- {
- return;
- }
- #ifdef MMI_ON_HARDWARE_P
- kal_prompt_trace(MOD_WAP, "___________________ Got socket notify, event_type:%d", soc_notify->event_type);
- #endif
- switch (soc_notify->event_type)
- {
- case SOC_WRITE:
- {
- switch (test_soc_demo_transaction->soc_demo_app_id)
- {
- case HTTP:
- test_en_soc_demo_http_send_request();
- break;
- case DAYTIME:
- case ECHO:
- break;
- case TRACERT:
- break;
- }
- break;
- }
- case SOC_READ:
- {
- switch (test_soc_demo_transaction->soc_demo_app_id)
- {
- case HTTP:
- tst_en_soc_demo_tcp_app_recv_response();
- break;
- case DAYTIME:
- case ECHO:
- break;
- case TRACERT:
- if ( test_soc_demo_transaction->state != REQ_SENT)
- {
- }
- else
- {
- }
- break;
- }
- break;
- }
- case SOC_CONNECT:
- {
- if (test_soc_demo_transaction->soc_demo_app_id == HTTP)
- {
- if (soc_notify->result == KAL_TRUE)
- {
- test_soc_demo_transaction->state = HTTP_TCP_CON_CREATED;
- test_en_soc_demo_http_send_request();
- }
- else
- {
- kal_prompt_trace(MOD_WAP," SOC_CONNECT ____________________ ERROR");
- }
- }
- break;
- }
- case SOC_CLOSE:
- {
- kal_prompt_trace(MOD_WAP,"soc_demo_transaction->rcvd_counter:%d",test_soc_demo_transaction->rcvd_counter);
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction->rcvd_buffer:n%s",test_soc_demo_transaction->rcvd_buffer);
- }
- default:
- break;
- }
- }
- void tst_em_soc_demo_app_start_timer(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- StartTimer(EM_GPRS_SOC_DEMO_APP_TIMER, SOC_DEMO_APP_POST_TIMEOUT, tst_em_soc_demo_app_timer_handler);
-
- }
- void tst_em_soc_demo_app_timer_handler(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (test_soc_demo_transaction->post_retry_counter < MAX_POST_RETRY_NUM)
- {
- test_soc_demo_transaction->state = REQ_SEND_RETRY;
- switch (test_soc_demo_transaction->soc_demo_app_id)
- {
- case HTTP:
- test_en_soc_demo_http_send_request();
- break;
- case DAYTIME:
- case ECHO:
- break;
- default:
- break;
- }
- }
- else
- {
- }
- }
- void tst_en_soc_demo_tcp_app_recv_response(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- int i = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (test_soc_demo_transaction && test_soc_demo_transaction->state < RSP_RCVD)
- {
- int ret_val = 0;
- test_soc_demo_transaction->state = RSP_RCVING;
- do{
-
- ret_val = soc_recv(
- test_soc_demo_transaction->socket_id,
- (kal_uint8*) (test_soc_demo_transaction->rcvd_buffer + test_soc_demo_transaction->rcvd_counter),
- (MAX_RCV_BUFFER_SIZE - test_soc_demo_transaction->rcvd_counter),
- 0);
- test_soc_demo_transaction->rcvd_counter += ret_val;
-
- kal_prompt_trace(MOD_WAP,"tst_en_soc_demo_tcp_app_recv_response--ret_val[%d]",ret_val);
- kal_prompt_trace(MOD_WAP," test_soc_demo_transaction->rcvd_counter [%d]", test_soc_demo_transaction->rcvd_counter );
- }while(ret_val>0);
-
- if (ret_val == SOC_WOULDBLOCK)
- {
- SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
- test_soc_demo_transaction->rcvd_counter += 2;
- return;
- }
- else
- tst_en_soc_output_result(
- EN_SOC_SUCCESS,
- (char*)test_soc_demo_transaction->rcvd_buffer,
- test_soc_demo_transaction->rcvd_counter);
- }
- }
- void tst_en_soc_show_output_string()
- {
- U8 *guiBuffer, *info;
- U8 showbuff[1000];
- memset(showbuff,0,sizeof(showbuff));
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- guiBuffer = GetCurrGuiBuffer(ORGANIZER_SOCKET_SHOW);
- EntryNewScreen(ORGANIZER_SOCKET_SHOW, NULL, tst_en_soc_show_output_string, NULL);
- AnsiiToUnicodeString((S8 *)showbuff,(S8 *)test_soc_demo_transaction->rcvd_buffer);
- kal_prompt_trace(MOD_WAP,"entry tst_en_soc_show_output_string");
- kal_prompt_trace(MOD_WAP,"the vaule of showbuff is %s",test_soc_demo_transaction->rcvd_buffer);
- kal_prompt_trace(MOD_WAP,"the length of showbuff is %d",test_soc_demo_transaction->rcvd_counter);
- ShowCategory74Screen(
- 0,
- 0,
- 0,
- 0,
- STR_GLOBAL_BACK,
- IMG_GLOBAL_BACK,
- (PU8) showbuff,
- test_soc_demo_transaction->rcvd_counter * 2,
- guiBuffer);
-
- SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
- SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
- }
- void tst_en_soc_output_result(int ret, char *out_str, int len)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
-
- if (test_soc_demo_transaction)
- {
- #ifdef MMI_ON_HARDWARE_P
- kal_prompt_trace(MOD_WAP, "soc demp app result: %d", ret);
- kal_prompt_trace(MOD_WAP, "the value of out_str is %sn",out_str);
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 1 is %sn",(test_soc_demo_transaction->rcvd_buffer + 100));
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 2 is %sn",(test_soc_demo_transaction->rcvd_buffer + 200));
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 3 is %sn",(test_soc_demo_transaction->rcvd_buffer + 300));
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 4 is %sn",(test_soc_demo_transaction->rcvd_buffer + 400));
-
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 5 is %sn",(test_soc_demo_transaction->rcvd_buffer + 500));
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 6 is %sn",(test_soc_demo_transaction->rcvd_buffer + 600));
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 7 is %sn",(test_soc_demo_transaction->rcvd_buffer + 700));
- kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 8 is %sn",(test_soc_demo_transaction->rcvd_buffer + 800));
- // tst_en_soc_show_output_string();
-
- #endif
- if(test_soc_demo_transaction->callback != NULL)//wangdecheng add
- {
- test_soc_demo_transaction->callback(test_soc_demo_transaction->soc_demo_app_id, ret, out_str, len);
- }
- if (ret != EN_SOC_SUCCESS)
- {
- test_soc_demo_transaction->state = SOC_CLOSING;
- }
- tst_mmi_soc_demo_app_request_abort();
- }
- }
- int tst_mmi_soc_demo_app_request_abort(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (test_soc_demo_transaction)
- {
- if (test_soc_demo_transaction->socket_id >= 0)
- {
- #ifdef MMI_ON_HARDWARE_P
- ilm_struct *ilm_send = NULL;
- #endif
- #ifndef MMI_ON_WIN32
- soc_close(test_soc_demo_transaction->socket_id);
- soc_close_nwk_account_by_id(MOD_MMI,test_soc_demo_transaction->nwt_acount_id);
- #endif
- #ifdef MMI_ON_HARDWARE_P
- /* close socket and disconnect bearer here */
- ilm_send = allocate_ilm(MOD_MMI);
- ilm_send->msg_id = MSG_ID_APP_SOC_DEACTIVATE_REQ;
- ilm_send->peer_buff_ptr = NULL;
- ilm_send->local_para_ptr = NULL;
- SEND_ILM(MOD_MMI, MOD_SOC, SOC_APP_SAP, ilm_send);
- #endif /* MMI_ON_HARDWARE_P */
- }
- test_soc_demo_transaction->post_retry_counter = 0;
- if (test_soc_demo_transaction->url)
- {
- OslMfree(test_soc_demo_transaction->url);
- }
- /* We have to free recv_buffer. */
- if (test_soc_demo_transaction->rcvd_buffer)
- {
- OslMfree(test_soc_demo_transaction->rcvd_buffer);
- }
- if (test_soc_demo_transaction->snd_buffer)
- {
- OslMfree(test_soc_demo_transaction->snd_buffer);
- }
- if (test_soc_demo_transaction->url_parsed_info)
- {
- if (test_soc_demo_transaction->url_parsed_info->host_name)
- {
- OslMfree(test_soc_demo_transaction->url_parsed_info->host_name);
- }
- if (test_soc_demo_transaction->url_parsed_info->url_link)
- {
- OslMfree(test_soc_demo_transaction->url_parsed_info->url_link);
- }
- OslMfree(test_soc_demo_transaction->url_parsed_info);
- }
- tst_em_soc_demo_app_stop_timer();
- OslMfree(test_soc_demo_transaction);
- test_soc_demo_transaction = NULL;
- kal_prompt_trace(MOD_WAP,"###########################Transaction have been destroy!!");
-
- }
- return 0;
- }
- void tst_em_soc_demo_app_stop_timer(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- StopTimer(EM_GPRS_SOC_DEMO_APP_TIMER);
- }