sockettest.c
上传用户:wdy0515
上传日期:2015-09-05
资源大小:5k
文件大小:27k
源码类别:

手机WAP编程

开发平台:

C/C++

  1. #include "MMI_features.h"
  2. /* MTK End */
  3. #if !defined(__MTK_TARGET__)
  4. #include <windows.h>
  5. #endif 
  6. /**********************/
  7. /*****  Header Files *****/
  8. /**********************/
  9. #ifdef FIRST_PASS
  10. #include "BuildCfg.h"
  11. #endif 
  12. #include "CustDataRes.h"
  13. #include "EventsGprot.h"
  14. #include "historyGprot.h"
  15. #include "ProtocolEvents.h"
  16. #include "CustMenuRes.h"
  17. #include "wgui_categories.h"
  18. #include "HardwareEvents.h"
  19. #include "Thrdosinterface.h"
  20. #include "OSThreadInterfaceGprot.h"
  21. #include "TimerEvents.h"
  22. #include "MainMenuDef.h"
  23. #include "EngineerModeDef.h"
  24. #include "EngineerModeType.h"
  25. #include "EngineerModeProt.h"
  26. #include "PixtelDataTypes.h"
  27. #include "CustomCfg.h"
  28. #include "Unicodexdcl.h"
  29. #include "audioInc.h"
  30. #include "IdleAppDef.h"
  31. #include "BootUp.h"
  32. #include "GlobalDefs.h"
  33. #include "soc_api.h"
  34. #include "app2soc_struct.h"
  35. #include "EngineerModeSocketApp.h"
  36. #include "EngineerModeSocketAppPing.h"
  37. #include "OrganizerDef.h"
  38. soc_demo_app_transaction_struct *test_soc_demo_transaction = NULL;
  39. void mmi_test_socket();
  40. int test_mmi_soc_demo_app_request(
  41. mmi_soc_demo_app_enum app_id,
  42. int account_id,
  43. char server_ip_address[4],
  44. char *url,
  45. int url_len,
  46. char *echo_text,
  47. int echo_text_len,
  48. mmi_soc_demo_app_rsp_t callback);
  49. void tst_EmSocketRsp(mmi_soc_demo_app_enum app_id_enum, int result, char *response, int response_len);
  50. kal_bool test_en_soc_demo_app_create_socket();
  51. int test_en_soc_demo_http_send_request(void);
  52. void test_em_soc_demo_app_socket_notify(void *inMsg);
  53. void tst_em_soc_demo_app_start_timer(void);
  54. void tst_em_soc_demo_app_timer_handler(void);
  55. void tst_en_soc_demo_tcp_app_recv_response(void);
  56. void tst_en_soc_output_result(int ret, char *out_str, int len);
  57. int tst_mmi_soc_demo_app_request_abort(void);
  58. void tst_em_soc_demo_app_stop_timer(void);
  59. extern void StartTimer(U16 timerid, U32 delay, FuncPtr funcPtr);
  60. extern void StopTimer(U16 timerid);
  61. void tst_EmSocketRsp(mmi_soc_demo_app_enum app_id_enum, int result, char *response, int response_len)
  62. {
  63. /*----------------------------------------------------------------*/
  64. /* Local Variables   */
  65. /*----------------------------------------------------------------*/
  66. U16 i,j,k;
  67. U16 databgin, namebgin,preClsbgin,curpricebgin;
  68. U16 pack_byte;
  69. U8 socknum;
  70. /*----------------------------------------------------------------*/
  71. /* Object   */
  72. /*----------------------------------------------------------------*/
  73. for(i = 0; i < response_len; i++)
  74. {
  75. if(response[i] == 0x20 && response[i+1] == 0x20 )
  76. {
  77. pack_byte = response[i-2];
  78. pack_byte = ((pack_byte & 0x00ff)<<8) + response[i -1];
  79. kal_prompt_trace(MOD_WAP,"##########pack_byte[%d]",pack_byte);
  80. break;
  81. }
  82. }
  83. databgin = i + 2;
  84. namebgin = databgin + 6;
  85. //curpricebgin = namebgin + 52;
  86. pack_byte -=2;
  87. socknum = pack_byte / 258;
  88. kal_prompt_trace(MOD_WAP,"##########socknum[%d]",socknum);
  89. for(j = 0; j < socknum; j++)
  90. {
  91.   U8 cur[10][4];
  92.   U8 preCls[10][4];
  93.   U8 stockname[10][24];
  94.   U16 index = 0;
  95.   float preprice[10];
  96.   float currentprice[10];
  97.   float updown[10];
  98.   ////////////////////////////////////name/////////////////////////////
  99.   for(k = namebgin + j*258; k <namebgin+ j*258 + 24; k++)
  100.   {
  101. stockname[j][index++] = response[k];
  102.   }
  103.   ////////////////////////////////////preprice////////////////////////////
  104.   {  
  105.   index = 0;
  106.   k = k;
  107.   preClsbgin =k;
  108.   }
  109.   for(;k <preClsbgin + 4;k++ )
  110.   {
  111.   preCls[j][index++] = response[k];
  112.   kal_prompt_trace(MOD_WAP,"#############preprice = %x",response[k]);
  113.   }
  114.   {
  115. U32 prevalue;
  116. prevalue = (preCls[j][0]<<24) + (preCls[j][1]<<16) +(preCls[j][2]<<8) + (preCls[j][3]);
  117. preprice[j] = ((float)prevalue) /10000;
  118.  kal_prompt_trace(MOD_WAP,"---------------------prevalue = %d",prevalue);
  119.   }
  120.   
  121.   ////////////////////////////////////current price/////////////////////////
  122.   {  
  123.   index = 0;
  124.   k = k + 24;
  125.   curpricebgin =k;
  126.   }
  127.   
  128.    for(; k < curpricebgin + 4; k++)
  129.   {
  130. cur[j][index++] = response[k];
  131.   }
  132.    
  133.  {
  134. U32 value;
  135. value = ( cur[j][0]<<24) + (cur[j][1]<<16) + (cur[j][2]<<8) + (cur[j][3]);
  136. currentprice[j] = ((float)value) /10000;
  137.  }
  138.   /////////////////////////////////////end///////////////////////////////
  139. }
  140.    
  141. }
  142. void mmi_test_socket(void)
  143. {
  144. /*----------------------------------------------------------------*/
  145. /* Local Variables   */
  146. /*----------------------------------------------------------------*/
  147. #ifdef MMI_ON_HARDWARE_P
  148. U8 emSocketAccountId = custom_get_csd_profile_num();
  149. #else 
  150. U8 emSocketAccountId = 5;
  151. #endif 
  152. mmi_soc_demo_app_result emSocketTmpResult = EN_SOC_SUCCESS;
  153. S8 AscTmp[16];
  154. kal_prompt_trace(MOD_WAP," mmi_test_socket __________________ emSocketAccountId=%d",emSocketAccountId);
  155. emSocketTmpResult = test_mmi_soc_demo_app_request(
  156. HTTP,
  157. 10,
  158. NULL,
  159. NULL,//emSocketInputdata,
  160. 0,//strlen(emSocketInputdata),
  161. NULL,
  162. 0,
  163.   tst_EmSocketRsp);
  164. }
  165. int test_mmi_soc_demo_app_request(
  166. mmi_soc_demo_app_enum app_id,
  167. int account_id,
  168. char server_ip_address[4],
  169. char *url,
  170. int url_len,
  171. char *echo_text,
  172. int echo_text_len,
  173. mmi_soc_demo_app_rsp_t callback)
  174. {
  175. /*----------------------------------------------------------------*/
  176. /* Local Variables   */
  177. /*----------------------------------------------------------------*/
  178. /*----------------------------------------------------------------*/
  179. /* Code Body   */
  180. /*----------------------------------------------------------------*/
  181. if (test_soc_demo_transaction)
  182. {
  183. kal_prompt_trace(MOD_WAP,"###########################Transaction existed");
  184. #ifdef MMI_ON_HARDWARE_P
  185. kal_print("Transaction existed!!");
  186. #endif 
  187. return EN_SOC_BUSY;
  188. }
  189. else
  190. {
  191. if ((test_soc_demo_transaction = OslMalloc(sizeof(soc_demo_app_transaction_struct))) == NULL)
  192. {
  193.     #ifdef MMI_ON_HARDWARE_P
  194. kal_print("No memory");
  195.     #endif 
  196. en_soc_output_result(EN_SOC_NO_MEMORY, NULL, 0);
  197. return EN_SOC_NO_MEMORY;
  198. }
  199. else
  200. {
  201. memset(test_soc_demo_transaction, 0, sizeof(soc_demo_app_transaction_struct));
  202. if ((test_soc_demo_transaction->rcvd_buffer = OslMalloc(MAX_RCV_BUFFER_SIZE)) == NULL)
  203. {
  204.         #ifdef MMI_ON_HARDWARE_P
  205. kal_print("No memory");
  206.         #endif 
  207. en_soc_output_result(EN_SOC_NO_MEMORY, NULL, 0);
  208. return EN_SOC_NO_MEMORY;
  209. }
  210. else
  211. {
  212. if ((test_soc_demo_transaction->snd_buffer = OslMalloc(MAX_SND_BUFFER_SIZE)) == NULL)
  213. {
  214.             #ifdef MMI_ON_HARDWARE_P
  215. kal_print("No memory");
  216.             #endif 
  217. en_soc_output_result(EN_SOC_NO_MEMORY, NULL, 0);
  218. return EN_SOC_NO_MEMORY;
  219. }
  220. else
  221. {
  222. /* Set initial values to test_soc_demo_transaction */
  223. memset((kal_int8*) test_soc_demo_transaction->rcvd_buffer, 0, MAX_RCV_BUFFER_SIZE);
  224. memset((kal_int8*) test_soc_demo_transaction->snd_buffer, 0, MAX_SND_BUFFER_SIZE);
  225. test_soc_demo_transaction->soc_demo_app_id = app_id;
  226. test_soc_demo_transaction->nwt_acount_id = account_id;
  227. if (server_ip_address)
  228. {
  229. memcpy(test_soc_demo_transaction->server_ip_addr.addr, server_ip_address, 4);
  230. test_soc_demo_transaction->server_ip_addr.addr_len = 4;
  231. }
  232. test_soc_demo_transaction->url = (kal_int8*) url;
  233. test_soc_demo_transaction->url_len = url_len;
  234. test_soc_demo_transaction->snd_counter = 0;
  235. test_soc_demo_transaction->rcvd_counter = 0;
  236. test_soc_demo_transaction->callback = callback;
  237. if (echo_text)
  238. {
  239. if (echo_text_len > MAX_SND_BUFFER_SIZE)
  240. {
  241. memcpy(test_soc_demo_transaction->snd_buffer, echo_text, MAX_SND_BUFFER_SIZE);
  242. test_soc_demo_transaction->snd_data_len = MAX_SND_BUFFER_SIZE;
  243. }
  244. else
  245. {
  246. memcpy(test_soc_demo_transaction->snd_buffer, echo_text, echo_text_len);
  247. test_soc_demo_transaction->snd_data_len = echo_text_len;
  248. }
  249. OslMfree(echo_text);
  250. }
  251. if (test_en_soc_demo_app_create_socket() == KAL_FALSE)
  252. {
  253. return EN_SOC_NO_MEMORY;
  254. }
  255. else
  256. kal_prompt_trace(MOD_WAP,"_________________________ CREATE SOCKET OK");
  257. switch (app_id)
  258. {
  259. case HTTP:
  260. {
  261. test_soc_demo_transaction->state = HTTP_DNS_QUERY;
  262. return test_en_soc_demo_http_send_request();
  263. }
  264. default:
  265. {
  266. return EN_SOC_UNKNOWN_APP;
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. kal_bool test_en_soc_demo_app_create_socket()
  275. {
  276. /*----------------------------------------------------------------*/
  277. /* Local Variables   */
  278. /*----------------------------------------------------------------*/
  279. kal_uint8 val = 1;
  280. /*----------------------------------------------------------------*/
  281. /* Code Body   */
  282. /*----------------------------------------------------------------*/
  283. if (test_soc_demo_transaction)
  284. {
  285. test_soc_demo_transaction->state = SOC_CREATING;
  286. switch (test_soc_demo_transaction->soc_demo_app_id)
  287. {
  288. case HTTP:
  289. {
  290. test_soc_demo_transaction->socket_id = soc_create(PF_INET, SOCK_STREAM, 0, MOD_MMI, test_soc_demo_transaction->nwt_acount_id);
  291. if (test_soc_demo_transaction->socket_id >= 0)
  292. {
  293. if (soc_setsockopt(test_soc_demo_transaction->socket_id, SOC_NBIO, &val, sizeof(val)) < 0)
  294. {
  295.                 #ifdef MMI_ON_HARDWARE_P
  296. kal_print("Set socket to nonblock mode error !!");
  297.                 #endif 
  298. return KAL_FALSE;
  299. }
  300. val = SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT;
  301. if (soc_setsockopt(test_soc_demo_transaction->socket_id, SOC_ASYNC, &val, sizeof(val)) < 0)
  302. {
  303.                 #ifdef MMI_ON_HARDWARE_P
  304. kal_print("Set socket to nonblock mode error !!");
  305.                 #endif 
  306. return KAL_FALSE;
  307. }
  308. test_soc_demo_transaction->state = SOC_CREATED;
  309. return KAL_TRUE;
  310. }
  311. else
  312. {
  313. return KAL_FALSE;
  314. }
  315. break;
  316. }
  317. default:
  318. return KAL_FALSE;
  319. }
  320. }
  321. else
  322. {
  323. return KAL_FALSE;
  324. }
  325. }
  326. int test_en_soc_demo_http_send_request(void)
  327. {
  328. /*----------------------------------------------------------------*/
  329. /* Local Variables   */
  330. /*----------------------------------------------------------------*/
  331. /*----------------------------------------------------------------*/
  332. /* Code Body   */
  333. /*----------------------------------------------------------------*/
  334. if (test_soc_demo_transaction)
  335. {
  336. if (test_soc_demo_transaction->state == HTTP_DNS_QUERY &&
  337. (soc_demo_app_http_url_struct*) test_soc_demo_transaction->url_parsed_info == NULL)
  338. {
  339. kal_prompt_trace(MOD_WAP," test_en_soc_demo_http_send_request __________________________________");
  340. test_soc_demo_transaction->server_ip_addr.addr[0] = 10;
  341. test_soc_demo_transaction->server_ip_addr.addr[1] = 0;
  342. test_soc_demo_transaction->server_ip_addr.addr[2] = 0;
  343. test_soc_demo_transaction->server_ip_addr.addr[3] = 172;
  344. test_soc_demo_transaction->server_ip_addr.port = 80;
  345. test_soc_demo_transaction->rcvd_counter = 0;
  346. test_soc_demo_transaction->server_ip_addr.addr_len = 4;
  347. test_soc_demo_transaction->state = HTTP_TCP_CON_CREATING;
  348. test_en_soc_demo_http_send_request();
  349. }
  350. else if (test_soc_demo_transaction->state == HTTP_TCP_CON_CREATING)
  351. {
  352. kal_int8 ret;
  353. char CRLF[3] = {0x0d, 0x0a, 0x00};
  354. test_soc_demo_transaction->state = HTTP_TCP_CON_CREATED;
  355. test_soc_demo_transaction->snd_data_len=0;
  356. strcat(test_soc_demo_transaction->snd_buffer,"GET ");
  357. test_soc_demo_transaction->snd_data_len+=4;
  358. strcat((char*)test_soc_demo_transaction->snd_buffer,"http://61.135.159.21/cgi-bin/weather?024 ");
  359. test_soc_demo_transaction->snd_data_len+=41; 
  360. strcat((char*)test_soc_demo_transaction->snd_buffer,"HTTP/1.1");
  361. test_soc_demo_transaction->snd_data_len+=8; 
  362. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  363. test_soc_demo_transaction->snd_data_len+=2;
  364. strcat((char*)test_soc_demo_transaction->snd_buffer,"Host: 10.0.0.172:80");
  365. test_soc_demo_transaction->snd_data_len+=19;
  366. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  367. test_soc_demo_transaction->snd_data_len+=2; 
  368. strcat((char*)test_soc_demo_transaction->snd_buffer,"User-Agent: */*");
  369. test_soc_demo_transaction->snd_data_len+=15;
  370. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  371. test_soc_demo_transaction->snd_data_len+=2;
  372. strcat((char*)test_soc_demo_transaction->snd_buffer,"Accept: */*");
  373. test_soc_demo_transaction->snd_data_len+=11;
  374. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  375. test_soc_demo_transaction->snd_data_len+=2;
  376. strcat((char*)test_soc_demo_transaction->snd_buffer,"X-Online-Host: 61.135.159.21");
  377. test_soc_demo_transaction->snd_data_len+=28;
  378. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  379. test_soc_demo_transaction->snd_data_len+=2; 
  380. strcat((char*)test_soc_demo_transaction->snd_buffer,"Connection: Keep-Alive");
  381. test_soc_demo_transaction->snd_data_len+=22;
  382. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  383. test_soc_demo_transaction->snd_data_len+=2;
  384. strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
  385. test_soc_demo_transaction->snd_data_len+=2; 
  386. kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:n %s", test_soc_demo_transaction->snd_buffer);
  387. kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:n %s", &test_soc_demo_transaction->snd_buffer[60]);
  388. kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:n %s", &test_soc_demo_transaction->snd_buffer[120]);
  389. #ifdef MMI_ON_HARDWARE_P
  390. kal_prompt_trace(MOD_WAP, "___________________ Http connect to %d.%d,%d,%d and port: %d",
  391. test_soc_demo_transaction->server_ip_addr.addr[0],
  392. test_soc_demo_transaction->server_ip_addr.addr[1],
  393. test_soc_demo_transaction->server_ip_addr.addr[2],
  394. test_soc_demo_transaction->server_ip_addr.addr[3],
  395. test_soc_demo_transaction->server_ip_addr.port);
  396.    
  397. ret = soc_connect(test_soc_demo_transaction->socket_id, &test_soc_demo_transaction->server_ip_addr);
  398.  
  399. kal_prompt_trace(MOD_WAP, "___________________ Http connect result is %d", ret);
  400. #endif 
  401. if (ret == SOC_SUCCESS)
  402. {
  403. test_en_soc_demo_http_send_request();
  404. return EN_SOC_SUCCESS;
  405. }
  406. else if (ret == SOC_WOULDBLOCK)
  407. {
  408. SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
  409. return EN_SOC_SUCCESS;
  410. }
  411. else
  412. {
  413. if (ret == SOC_ERROR)
  414. {
  415. return EN_SOC_PEER_NOT_REACHABLE;
  416. }
  417. else
  418. {
  419. return EN_SOC_ERROR;
  420. }
  421. }
  422. }
  423. else if (test_soc_demo_transaction->state == HTTP_TCP_CON_CREATED || test_soc_demo_transaction->state == REQ_SEND_RETRY ||
  424.  test_soc_demo_transaction->state == REQ_SENDING)
  425. {
  426. kal_int32 ret;
  427. if (test_soc_demo_transaction->state != REQ_SENDING)
  428. {
  429. test_soc_demo_transaction->snd_counter = 0;
  430. }
  431. test_soc_demo_transaction->state = REQ_SENDING;
  432. #ifdef MMI_ON_HARDWARE_P
  433. kal_prompt_trace(MOD_WAP, "___________________ Http send request to %d.%d,%d,%d and port: %d",
  434. test_soc_demo_transaction->server_ip_addr.addr[0],
  435. test_soc_demo_transaction->server_ip_addr.addr[1],
  436. test_soc_demo_transaction->server_ip_addr.addr[2],
  437. test_soc_demo_transaction->server_ip_addr.addr[3],
  438. test_soc_demo_transaction->server_ip_addr.port);
  439. #endif /* MMI_ON_HARDWARE_P */ 
  440. ret = soc_send(
  441. test_soc_demo_transaction->socket_id,
  442. (kal_uint8*) (test_soc_demo_transaction->snd_buffer + test_soc_demo_transaction->snd_counter),
  443. (test_soc_demo_transaction->snd_data_len - test_soc_demo_transaction->snd_counter),
  444. 0);
  445. #ifdef MMI_ON_HARDWARE_P
  446. kal_prompt_trace(MOD_WAP, "___________________ Http send request result, sent_bytes:%d", ret);
  447. #endif 
  448. if (ret > 0)
  449. {
  450. if (ret == (kal_int32) test_soc_demo_transaction->snd_data_len)
  451. {
  452. test_soc_demo_transaction->state = REQ_SENT;
  453. test_soc_demo_transaction->post_retry_counter++;
  454. tst_em_soc_demo_app_start_timer(); /* wait for servwer's response */
  455. tst_en_soc_demo_tcp_app_recv_response();
  456. return EN_SOC_SUCCESS;
  457. }
  458. else
  459. {
  460. test_soc_demo_transaction->snd_counter += ret;
  461. return EN_SOC_SUCCESS;
  462. }
  463. }
  464. else
  465. {
  466. if (ret == SOC_WOULDBLOCK)
  467. {
  468. /* waits for socket notify */
  469. SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
  470. return EN_SOC_SUCCESS;
  471. }
  472. else
  473. {
  474. if (ret == SOC_ERROR)
  475. {
  476. return EN_SOC_PEER_NOT_REACHABLE;
  477. }
  478. else
  479. {
  480. return EN_SOC_ERROR;
  481. }
  482. }
  483. }
  484. }
  485. else
  486. {
  487. return EN_SOC_ERROR;
  488. }
  489. }
  490. else
  491. {
  492. return EN_SOC_ERROR;
  493. }
  494. }
  495. void test_em_soc_demo_app_socket_notify(void *inMsg)
  496. {
  497. /*----------------------------------------------------------------*/
  498. /* Local Variables   */
  499. /*----------------------------------------------------------------*/
  500. app_soc_notify_ind_struct *soc_notify = (app_soc_notify_ind_struct*) inMsg;
  501. /*----------------------------------------------------------------*/
  502. /* Code Body   */
  503. /*----------------------------------------------------------------*/
  504. kal_prompt_trace(MOD_WAP," entry the function test_em_soc_demo_app_socket_notify");
  505. if (!test_soc_demo_transaction)
  506. {
  507. return;
  508. }
  509. #ifdef MMI_ON_HARDWARE_P
  510. kal_prompt_trace(MOD_WAP, "___________________ Got socket notify, event_type:%d", soc_notify->event_type);
  511. #endif 
  512. switch (soc_notify->event_type)
  513. {
  514. case SOC_WRITE:
  515. {
  516. switch (test_soc_demo_transaction->soc_demo_app_id)
  517. {
  518. case HTTP:
  519. test_en_soc_demo_http_send_request();
  520. break;
  521. case DAYTIME:
  522. case ECHO:
  523. break;
  524. case TRACERT:
  525. break;
  526. }
  527. break;
  528. }
  529. case SOC_READ:
  530. {
  531. switch (test_soc_demo_transaction->soc_demo_app_id)
  532. {
  533. case HTTP:
  534. tst_en_soc_demo_tcp_app_recv_response();
  535. break;
  536. case DAYTIME:
  537. case ECHO:
  538. break;
  539. case TRACERT:
  540. if ( test_soc_demo_transaction->state != REQ_SENT)
  541. {
  542. }
  543. else
  544. {
  545. }
  546. break;
  547. }
  548. break;
  549. }
  550. case SOC_CONNECT:
  551. {
  552. if (test_soc_demo_transaction->soc_demo_app_id == HTTP)
  553. {
  554. if (soc_notify->result == KAL_TRUE)
  555. {
  556. test_soc_demo_transaction->state = HTTP_TCP_CON_CREATED;
  557. test_en_soc_demo_http_send_request();
  558. }
  559. else
  560. {
  561. kal_prompt_trace(MOD_WAP," SOC_CONNECT ____________________ ERROR");
  562. }
  563. }
  564. break;
  565. }
  566. case SOC_CLOSE:
  567. {
  568. kal_prompt_trace(MOD_WAP,"soc_demo_transaction->rcvd_counter:%d",test_soc_demo_transaction->rcvd_counter);
  569. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction->rcvd_buffer:n%s",test_soc_demo_transaction->rcvd_buffer);
  570. }
  571. default:
  572. break;
  573. }
  574. }
  575. void tst_em_soc_demo_app_start_timer(void)
  576. {
  577. /*----------------------------------------------------------------*/
  578. /* Local Variables   */
  579. /*----------------------------------------------------------------*/
  580. /*----------------------------------------------------------------*/
  581. /* Code Body   */
  582. /*----------------------------------------------------------------*/
  583. StartTimer(EM_GPRS_SOC_DEMO_APP_TIMER, SOC_DEMO_APP_POST_TIMEOUT, tst_em_soc_demo_app_timer_handler);
  584. }
  585. void tst_em_soc_demo_app_timer_handler(void)
  586. {
  587. /*----------------------------------------------------------------*/
  588. /* Local Variables   */
  589. /*----------------------------------------------------------------*/
  590. /*----------------------------------------------------------------*/
  591. /* Code Body   */
  592. /*----------------------------------------------------------------*/
  593. if (test_soc_demo_transaction->post_retry_counter < MAX_POST_RETRY_NUM)
  594. {
  595. test_soc_demo_transaction->state = REQ_SEND_RETRY;
  596. switch (test_soc_demo_transaction->soc_demo_app_id)
  597. {
  598. case HTTP:
  599. test_en_soc_demo_http_send_request();
  600. break;
  601. case DAYTIME:
  602. case ECHO:
  603. break;
  604. default:
  605. break;
  606. }
  607. }
  608. else
  609. {
  610. }
  611. }
  612. void tst_en_soc_demo_tcp_app_recv_response(void)
  613. {
  614. /*----------------------------------------------------------------*/
  615. /* Local Variables   */
  616. /*----------------------------------------------------------------*/
  617.    int i = 0;
  618. /*----------------------------------------------------------------*/
  619. /* Code Body   */
  620. /*----------------------------------------------------------------*/
  621. if (test_soc_demo_transaction && test_soc_demo_transaction->state < RSP_RCVD)
  622. {
  623.         int ret_val = 0;
  624.         test_soc_demo_transaction->state = RSP_RCVING;
  625. do{
  626.   ret_val = soc_recv(
  627.                     test_soc_demo_transaction->socket_id,
  628.                     (kal_uint8*) (test_soc_demo_transaction->rcvd_buffer + test_soc_demo_transaction->rcvd_counter),
  629.                     (MAX_RCV_BUFFER_SIZE - test_soc_demo_transaction->rcvd_counter),
  630.                     0);
  631.    test_soc_demo_transaction->rcvd_counter += ret_val;
  632.    
  633.  kal_prompt_trace(MOD_WAP,"tst_en_soc_demo_tcp_app_recv_response--ret_val[%d]",ret_val);
  634.  kal_prompt_trace(MOD_WAP," test_soc_demo_transaction->rcvd_counter [%d]", test_soc_demo_transaction->rcvd_counter );
  635. }while(ret_val>0);
  636. if (ret_val == SOC_WOULDBLOCK)
  637.    {
  638.   SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
  639.   test_soc_demo_transaction->rcvd_counter += 2;
  640.   return;
  641.   }
  642. else
  643. tst_en_soc_output_result(
  644.                 EN_SOC_SUCCESS,
  645.                 (char*)test_soc_demo_transaction->rcvd_buffer,
  646.                 test_soc_demo_transaction->rcvd_counter);
  647.     }
  648. }
  649. void tst_en_soc_show_output_string()
  650. {
  651.     U8 *guiBuffer, *info;
  652.     U8 showbuff[1000];
  653.     memset(showbuff,0,sizeof(showbuff));
  654.     /*----------------------------------------------------------------*/
  655.     /* Code Body                                                      */
  656.     /*----------------------------------------------------------------*/
  657.     guiBuffer = GetCurrGuiBuffer(ORGANIZER_SOCKET_SHOW);
  658.     EntryNewScreen(ORGANIZER_SOCKET_SHOW, NULL,  tst_en_soc_show_output_string, NULL);
  659.      AnsiiToUnicodeString((S8 *)showbuff,(S8 *)test_soc_demo_transaction->rcvd_buffer);
  660.      kal_prompt_trace(MOD_WAP,"entry tst_en_soc_show_output_string");
  661.      kal_prompt_trace(MOD_WAP,"the vaule of showbuff is %s",test_soc_demo_transaction->rcvd_buffer);
  662.      kal_prompt_trace(MOD_WAP,"the length of showbuff is %d",test_soc_demo_transaction->rcvd_counter);
  663.     ShowCategory74Screen(
  664.         0,
  665.         0,
  666.         0,
  667.         0,
  668.         STR_GLOBAL_BACK,
  669.         IMG_GLOBAL_BACK,
  670.         (PU8) showbuff,
  671.         test_soc_demo_transaction->rcvd_counter * 2,
  672.         guiBuffer);
  673.     
  674.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  675.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  676. }
  677. void tst_en_soc_output_result(int ret, char *out_str, int len)
  678. {
  679. /*----------------------------------------------------------------*/
  680. /* Local Variables   */
  681. /*----------------------------------------------------------------*/
  682. /*----------------------------------------------------------------*/
  683. /* Code Body   */
  684. /*----------------------------------------------------------------*/
  685. if (test_soc_demo_transaction)
  686. {
  687. #ifdef MMI_ON_HARDWARE_P
  688. kal_prompt_trace(MOD_WAP, "soc demp app result: %d", ret);
  689. kal_prompt_trace(MOD_WAP, "the value of out_str is %sn",out_str);
  690. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 1 is %sn",(test_soc_demo_transaction->rcvd_buffer + 100));
  691. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 2 is %sn",(test_soc_demo_transaction->rcvd_buffer + 200));
  692. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 3 is %sn",(test_soc_demo_transaction->rcvd_buffer + 300));
  693. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 4 is %sn",(test_soc_demo_transaction->rcvd_buffer + 400));
  694. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 5 is %sn",(test_soc_demo_transaction->rcvd_buffer + 500));
  695. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 6 is %sn",(test_soc_demo_transaction->rcvd_buffer + 600));
  696. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 7 is %sn",(test_soc_demo_transaction->rcvd_buffer + 700));
  697. kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 8 is %sn",(test_soc_demo_transaction->rcvd_buffer + 800));
  698. // tst_en_soc_show_output_string();
  699. #endif 
  700. if(test_soc_demo_transaction->callback != NULL)//wangdecheng add
  701. {
  702. test_soc_demo_transaction->callback(test_soc_demo_transaction->soc_demo_app_id, ret, out_str, len);
  703. }
  704. if (ret != EN_SOC_SUCCESS)
  705. {
  706. test_soc_demo_transaction->state = SOC_CLOSING;
  707. }
  708. tst_mmi_soc_demo_app_request_abort();
  709. }
  710. }
  711. int tst_mmi_soc_demo_app_request_abort(void)
  712. {
  713. /*----------------------------------------------------------------*/
  714. /* Local Variables   */
  715. /*----------------------------------------------------------------*/
  716. /*----------------------------------------------------------------*/
  717. /* Code Body   */
  718. /*----------------------------------------------------------------*/
  719. if (test_soc_demo_transaction)
  720. {
  721. if (test_soc_demo_transaction->socket_id >= 0)
  722. {
  723.     #ifdef MMI_ON_HARDWARE_P
  724. ilm_struct *ilm_send = NULL;
  725.     #endif 
  726.     #ifndef MMI_ON_WIN32
  727. soc_close(test_soc_demo_transaction->socket_id);
  728. soc_close_nwk_account_by_id(MOD_MMI,test_soc_demo_transaction->nwt_acount_id);
  729.     #endif
  730.     #ifdef MMI_ON_HARDWARE_P
  731. /* close socket and disconnect bearer here */
  732. ilm_send = allocate_ilm(MOD_MMI);
  733. ilm_send->msg_id = MSG_ID_APP_SOC_DEACTIVATE_REQ;
  734. ilm_send->peer_buff_ptr = NULL;
  735. ilm_send->local_para_ptr = NULL;
  736. SEND_ILM(MOD_MMI, MOD_SOC, SOC_APP_SAP, ilm_send);
  737.     #endif /* MMI_ON_HARDWARE_P */ 
  738. }
  739. test_soc_demo_transaction->post_retry_counter = 0;
  740. if (test_soc_demo_transaction->url)
  741. {
  742. OslMfree(test_soc_demo_transaction->url);
  743. }
  744. /* We have to free recv_buffer. */
  745. if (test_soc_demo_transaction->rcvd_buffer)
  746. {
  747. OslMfree(test_soc_demo_transaction->rcvd_buffer);
  748. }
  749. if (test_soc_demo_transaction->snd_buffer)
  750. {
  751. OslMfree(test_soc_demo_transaction->snd_buffer);
  752. }
  753. if (test_soc_demo_transaction->url_parsed_info)
  754. {
  755. if (test_soc_demo_transaction->url_parsed_info->host_name)
  756. {
  757. OslMfree(test_soc_demo_transaction->url_parsed_info->host_name);
  758. }
  759. if (test_soc_demo_transaction->url_parsed_info->url_link)
  760. {
  761. OslMfree(test_soc_demo_transaction->url_parsed_info->url_link);
  762. }
  763. OslMfree(test_soc_demo_transaction->url_parsed_info);
  764. }
  765. tst_em_soc_demo_app_stop_timer();
  766. OslMfree(test_soc_demo_transaction);
  767. test_soc_demo_transaction = NULL;
  768.  kal_prompt_trace(MOD_WAP,"###########################Transaction have been destroy!!");
  769.  
  770. }
  771. return 0;
  772. }
  773. void tst_em_soc_demo_app_stop_timer(void)
  774. {
  775. /*----------------------------------------------------------------*/
  776. /* Local Variables   */
  777. /*----------------------------------------------------------------*/
  778. /*----------------------------------------------------------------*/
  779. /* Code Body   */
  780. /*----------------------------------------------------------------*/
  781. StopTimer(EM_GPRS_SOC_DEMO_APP_TIMER);
  782. }