From 7ee8e54bb80d9e24c14b73e1cf181dcf3eafe2d3 Mon Sep 17 00:00:00 2001 From: Nam KwanWoo Date: Tue, 26 Mar 2013 17:40:10 +0900 Subject: [PATCH] change xml file and way to read xml file Change-Id: I8efe8fb4f4afa6f99eed5b8b7a8f2a181c95466a --- configuration/sys-info.xml | 13 ++ configuration/sys-info_.xml | 11 -- include/system_info_private.h | 2 +- packaging/capi-system-info.spec | 8 +- src/system_info_device.c | 363 +++++++--------------------------------- 5 files changed, 77 insertions(+), 320 deletions(-) create mode 100644 configuration/sys-info.xml delete mode 100644 configuration/sys-info_.xml diff --git a/configuration/sys-info.xml b/configuration/sys-info.xml new file mode 100644 index 0000000..d0dc96b --- /dev/null +++ b/configuration/sys-info.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/configuration/sys-info_.xml b/configuration/sys-info_.xml deleted file mode 100644 index b796dc6..0000000 --- a/configuration/sys-info_.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/include/system_info_private.h b/include/system_info_private.h index 641cfbf..5332bce 100644 --- a/include/system_info_private.h +++ b/include/system_info_private.h @@ -28,7 +28,7 @@ extern "C" #define CPU_INFO_FILE_PATH "/proc/cpuinfo" #define CPU_INFO_MAX_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" #define CMDLINE_PATH "/proc/cmdline" -#define XML_FILE_PATH "/usr/etc/sys-info.xml" +#define XML_FILE_PATH "/etc/config/sys-info.xml" #define MAXBUFSIZE 512 typedef enum { diff --git a/packaging/capi-system-info.spec b/packaging/capi-system-info.spec index e9cad3b..d8ba454 100644 --- a/packaging/capi-system-info.spec +++ b/packaging/capi-system-info.spec @@ -2,7 +2,7 @@ Name: capi-system-info Summary: A System Information library in SLP C API Version: 0.1.9 -Release: 0 +Release: 1 Group: System/Libraries License: Apache License, Version 2.0 and IEFT RFC Collection Source0: %{name}-%{version}.tar.gz @@ -59,8 +59,8 @@ cat LICENSE.RFC4122 >> %{buildroot}/usr/share/license/%{name} mkdir -p %{buildroot}/etc cp -f script/make_info_file.sh %{buildroot}/etc/make_info_file.sh -mkdir -p %{buildroot}/usr/etc -cp -f configuration/sys-info_.xml %{buildroot}/usr/etc/sys-info.xml +mkdir -p %{buildroot}/etc/config +cp -f configuration/sys-info.xml %{buildroot}/etc/config/sys-info.xml %make_install @@ -73,7 +73,7 @@ cp -f configuration/sys-info_.xml %{buildroot}/usr/etc/sys-info.xml %{_libdir}/libcapi-system-info.so.* /usr/share/license/%{name} %attr(0744,root,-) /etc/make_info_file.sh -/usr/etc/sys-info.xml +/etc/config/sys-info.xml %manifest system-info.manifest %files devel diff --git a/src/system_info_device.c b/src/system_info_device.c index 2c6ab79..300e667 100644 --- a/src/system_info_device.c +++ b/src/system_info_device.c @@ -74,10 +74,6 @@ #include #include -#include -#include -#include - #define PROP_MULTITOUCH "EvdevMultitouch MultiTouch" #define DEVICE_UUID_STRING_SIZE 37 @@ -443,50 +439,16 @@ int system_info_get_wps_supported(system_info_key_e key, system_info_data_type_e int system_info_get_keyboard_type(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; - - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } + char *string = NULL; + char *model = "default"; - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "Keyboad_type", &string)) { + LOGE("cannot get Keyboad_type info from %s!!!", XML_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - cur = cur->xmlChildrenNode; + *value = string; - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); - - if (!strncmp(id, "Keyboad_type", strlen("Keyboad_type"))) { - if (!strncmp(string, "NULL", strlen("NULL"))) - *value = NULL; - else - *value = string; - break; - } - } - } - - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } @@ -526,64 +488,32 @@ int system_info_get_nfc_supported(system_info_key_e key, system_info_data_type_e int system_info_get_tvout_supported(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; bool *supported; + char *string = NULL; + char *model = "default"; supported = (bool *)value; - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "tv_out_support", &string)) { + LOGE("cannot get tv_out_support info from %s!!!", NFC_INFO_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); + if (!strcmp(string, "true") || !strcmp(string, "TRUE")) + *supported = true; + else + *supported = false; - if (!strncmp(id, "tv_out_support", strlen("tv_out_support"))) { - if (!strncmp(string, "TRUE", strlen("TRUE"))) - *supported = true; - else - *supported = false; - break; - } - } - } + free(string); - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } int system_info_get_wifi_supported(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; bool *supported; + char *string = NULL; + char *model = "default"; supported = (bool *)value; @@ -592,55 +522,26 @@ int system_info_get_wifi_supported(system_info_key_e key, system_info_data_type_ return SYSTEM_INFO_ERROR_NONE; } - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "wifi_support", &string)) { + LOGE("cannot get wifi_support info from %s!!!", NFC_INFO_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); + if (!strcmp(string, "true") || !strcmp(string, "TRUE")) + *supported = true; + else + *supported = false; - if (!strncmp(id, "wifi_support", strlen("wifi_support"))) { - if (!strncmp(string, "TRUE", strlen("TRUE"))) - *supported = true; - else - *supported = false; - break; - } - } - } + free(string); - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } int system_info_get_wifi_direct_supported(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; bool *supported; + char *string = NULL; + char *model = "default"; supported = (bool *)value; @@ -649,44 +550,18 @@ int system_info_get_wifi_direct_supported(system_info_key_e key, system_info_dat return SYSTEM_INFO_ERROR_NONE; } - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "wifi_direct_support", &string)) { + LOGE("cannot get wifi_direct_support info from %s!!!", NFC_INFO_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); + if (!strcmp(string, "true") || !strcmp(string, "TRUE")) + *supported = true; + else + *supported = false; - if (!strncmp(id, "wifi_direct_support", strlen("wifi_direct_support"))) { - if (!strncmp(string, "TRUE", strlen("TRUE"))) - *supported = true; - else - *supported = false; - break; - } - } - } + free(string); - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } @@ -717,7 +592,7 @@ int system_info_get_csc_sales_code(system_info_key_e key, system_info_data_type_ CSC_SALES_CODE = (char *)value; if (system_info_vconf_get_value_string(VCONFKEY_CSC_SALESCODE, &CSC_SALES_CODE)) - return SYSTEM_INFO_ERROR_IO_ERROR; + return SYSTEM_INFO_ERROR_IO_ERROR; return SYSTEM_INFO_ERROR_NONE; } @@ -1013,53 +888,24 @@ int system_info_get_back_camera_flash_supported(system_info_key_e key, system_in int system_info_get_sip_voip_supported(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; bool *supported; + char *string = NULL; + char *model = "default"; supported = (bool *)value; - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "sip_voip_support", &string)) { + LOGE("cannot get sip_voip_support info from %s!!!", NFC_INFO_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); + if (!strcmp(string, "true") || !strcmp(string, "TRUE")) + *supported = true; + else + *supported = false; - if (!strncmp(id, "sip_voip_support", strlen("sip_voip_support"))) { - if (!strncmp(string, "TRUE", strlen("TRUE"))) - *supported = true; - else - *supported = false; - break; - } - } - } + free(string); - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } @@ -1084,53 +930,24 @@ int system_info_get_microphone_supported(system_info_key_e key, system_info_data int system_info_get_speech_recognition_supported(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; bool *supported; + char *string = NULL; + char *model = "default"; supported = (bool *)value; - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "speech_recognition_support", &string)) { + LOGE("cannot get speech_recognition_support info from %s!!!", NFC_INFO_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); + if (!strcmp(string, "true") || !strcmp(string, "TRUE")) + *supported = true; + else + *supported = false; - if (!strncmp(id, "speech_recognition_support", strlen("speech_recognition_support"))) { - if (!strncmp(string, "TRUE", strlen("TRUE"))) - *supported = true; - else - *supported = false; - break; - } - } - } + free(string); - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } @@ -1150,93 +967,31 @@ int system_info_get_barometer_sensor_supported(system_info_key_e key, system_inf int system_info_get_manufacturer(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; - - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } + char *string = NULL; + char *model = "default"; - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "MANUFACTURER", &string)) { + LOGE("cannot get MANUFACTURER info from %s!!!", XML_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); - - if (!strncmp(id, "MANUFACTURER", strlen("MANUFACTURER"))) { *value = string; - break; - } - } - } - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } int system_info_get_cp_interface(system_info_key_e key, system_info_data_type_e data_type, void **value) { - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlNode *cur_node = NULL; - char *id; - char *string; - - doc = xmlParseFile(XML_FILE_PATH); - - if (doc == NULL) { - LOGE("cannot file open %s file!!!", XML_FILE_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - LOGE("empty document %s file!!!", XML_FILE_PATH); - xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; - } + char *string = NULL; + char *model = "default"; - if (xmlStrcmp(cur->name, (const xmlChar*)"sysinfo")) { - LOGE("document of the wrong type, root node != sysinfo"); - xmlFreeDoc(doc); + if (system_info_get_value_from_xml(XML_FILE_PATH, model, "CP_Interface", &string)) { + LOGE("cannot get CP_Interface info from %s!!!", XML_FILE_PATH); return SYSTEM_INFO_ERROR_IO_ERROR; } - cur = cur->xmlChildrenNode; - - for (cur_node = cur; cur_node; cur_node = cur_node->next) { - if (cur_node->type == XML_ELEMENT_NODE) { - id = (char *)g_strdup((char*)xmlGetProp(cur_node, (const xmlChar*)"id")); - string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar*)"string")); - - if (!strncmp(id, "CP_Interface", strlen("CP_Interface"))) { *value = string; - break; - } - } - } - xmlFreeDoc(doc); return SYSTEM_INFO_ERROR_NONE; } -- 2.7.4