| /****************************************************************************** |
| |
| *(C) Copyright 2011 Marvell International Ltd. |
| |
| * All Rights Reserved |
| |
| ******************************************************************************/ |
| /*******************************************/ |
| /* */ |
| /* Title: test xml parser wrapper */ |
| /* Filename: xmltest.c */ |
| /* */ |
| /* Author: Liming Xie */ |
| /* */ |
| /* Project, Target, subsystem: Tavor, PXA920, HAL */ |
| /* */ |
| /* */ |
| /* Created: Sep 2011 */ |
| /* */ |
| /********************************************/ |
| |
| #include <stdio.h> |
| #include "xmlparser.h" |
| #include "pthread.h" |
| #include "utlTrace.h" |
| |
| void *pRoot = NULL; |
| |
| void cfg_thread() |
| { |
| const char *pstr; |
| int val; |
| int ret; |
| char tmp[50]; |
| |
| DPRINTF(cfg_thread, "in child: pRoot:%x\n", pRoot); |
| |
| val = 10; |
| ret = get_int_value (pRoot, "//Mytest1", &val); |
| if (ret < 0) |
| { |
| DPRINTF(cfg_thread1, "In child failed reason:%d\n", ret); |
| } |
| else |
| { |
| DPRINTF(cfg_thread2, "In child get value:%d\n", val); |
| } |
| |
| val = 8; |
| ret = get_int_value (pRoot, "/DIAG/Mytest1_child", &val); |
| if (ret < 0) |
| { |
| DPRINTF(cfg_thread3, "in child: Fail to get /DIAG/Mytest1_child: reason:%d\n", ret); |
| ret = set_int_value (pRoot, "/DIAG/Mytest1_child", 12); |
| add_comment(pRoot, "/DIAG/Mytest1_child", "sss my comment for Mytest1"); |
| } |
| add_comment(pRoot, "/DIAG/Mytest1_child", "sss my comment for Mytest1"); |
| |
| sprintf(tmp, "%s", "OKOK"); |
| ret = get_char_array(pRoot, "/AGPS/Mytest5_child", tmp, 50); |
| if (ret < 0) |
| { |
| DPRINTF(cfg_thread4, "In child failed reason:%d\n", ret); |
| } |
| else |
| { |
| DPRINTF(cfg_thread5, "In child get value:%s\n", tmp); |
| } |
| |
| |
| add_comment(pRoot, "/AGPS/Mytest5_child", "my comment for Mytest5"); |
| set_char_array(pRoot, "/AGPS/Mytest5_child", "my content for Mytest5"); |
| |
| ret = get_char_array(pRoot, "/DIAG/SOCKET_PATH_MASTER", tmp, 50); |
| if (ret < 0) |
| { |
| DPRINTF(cfg_thread6, "In child: Fail to get /DIAG/SOCKET_PATH_MASTER\n"); |
| set_char_array(pRoot, "/DIAG/SOCKET_PATH_MASTER", "/dev/ttt_child"); |
| } |
| |
| } |
| void main() |
| { |
| const char *pstr; |
| int val; |
| int ret; |
| char tmp[50]; |
| pthread_t newthread; |
| void *myret; |
| |
| pRoot = open_tel_cfg("/data/mrvl_tel_cfg.xml"); |
| |
| if (pRoot == NULL) |
| { |
| DPRINTF(xmltest_main, "open_tel_cfg fail..\n"); |
| pRoot = create_tel_cfg("MRVL_TEL_CFG"); |
| if (pRoot == NULL) |
| DPRINTF(xmltest_main1, "pRoot == NULL\n"); |
| } |
| |
| if( pthread_create( &newthread, NULL, (void *)cfg_thread , NULL) != 0 ) |
| { |
| DPRINTF(xmltest_main2, "[%s]pthread_create failed!", __FUNCTION__); |
| } |
| |
| DPRINTF(xmltest_main3, "in parent thread: pRoot:%x\n", pRoot); |
| |
| val = 10; |
| ret = get_int_value (pRoot, "//Mytest1", &val); |
| DPRINTF(xmltest_main4, "ret == %d\n", ret); |
| DPRINTF(xmltest_main5, "val=%d\n", val); |
| |
| val = 8; |
| ret = get_int_value (pRoot, "/DIAG/Mytest1", &val); |
| if (ret < 0) |
| { |
| ret = set_int_value (pRoot, "/DIAG/Mytest1", 12); |
| DPRINTF(xmltest_main6, "ret == %d\n", ret); |
| add_comment(pRoot, "/DIAG/Mytest1", "sss my comment for Mytest1"); |
| } |
| add_comment(pRoot, "/DIAG/Mytest1", "sss my comment for Mytest1"); |
| |
| sprintf(tmp, "%s", "OKOK"); |
| ret = get_char_array(pRoot, "/AGPS/Mytest1", tmp, 50); |
| if (ret < 0) |
| { |
| DPRINTF(xmltest_main7, "failed reason:%d\n", ret); |
| } |
| else |
| { |
| DPRINTF(xmltest_main8, "get value:%s\n", tmp); |
| } |
| |
| add_comment(pRoot, "/AGPS/Mytest2", "my comment for Mytest2"); |
| |
| ret = get_char_array(pRoot, "/DIAG/SOCKET_PATH_MASTER", tmp, 50); |
| if (ret < 0) |
| { |
| DPRINTF(xmltest_main9, "Fail to get /DIAG/SOCKET_PATH_MASTER\n"); |
| set_char_array(pRoot, "/DIAG/SOCKET_PATH_MASTER", "/dev/ttt"); |
| } |
| |
| pthread_join(newthread, &myret); |
| close_tel_cfg("/data/mrvl_tel_cfg.xml", &pRoot); |
| } |