add new API for model-config
authorNam KwanWoo <kw46.nam@samsung.com>
Wed, 5 Jun 2013 06:01:40 +0000 (15:01 +0900)
committerNam KwanWoo <kw46.nam@samsung.com>
Wed, 5 Jun 2013 06:01:40 +0000 (15:01 +0900)
Change-Id: I0b3fc69dd59e62dfa3c7f65cc8e5a8e7a7c449a8

CMakeLists.txt
include/system_info.h
include/system_info_private.h
packaging/capi-system-info.spec
src/system_info.c
src/system_info_parse.c [new file with mode: 0644]
src/system_info_platform.c

index 0f58f45..91bd0fd 100755 (executable)
@@ -10,7 +10,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
-SET(requires "dlog capi-base-common capi-media-sound-manager vconf x11 xi xrandr tapi haptic xproto openssl nfc location bluetooth-api mm-radio sensor libxml-2.0")
+SET(requires "dlog capi-base-common capi-media-sound-manager vconf x11 xi xrandr tapi haptic xproto openssl nfc location bluetooth-api mm-radio sensor iniparser libxml-2.0")
 SET(pc_requires "capi-base-common")
 
 INCLUDE(FindPkgConfig)
index b11e888..6b6f1a5 100644 (file)
@@ -158,6 +158,102 @@ int system_info_get_external_double(const char *key, double *value);
 int system_info_get_external_string(const char *key, char **value);
 
 /**
+ * @brief   Gets the boolean value of the platform feature
+ * @param[in] key The name of the platform feature to get
+ * @param[out] value The value of the given platform feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_platform_bool(const char *key, bool *value);
+
+/**
+ * @brief   Gets the integer value of the platform feature
+ * @param[in] key The name of the platform feature to get
+ * @param[out] value The value of the given platform feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_platform_int(const char *key, int *value);
+
+/**
+ * @brief   Gets the string value of the platform feature
+ * @remarks The @a value must be released with free() by you.
+ * @param[in] key The name of the platform feature to get
+ * @param[out] value The value of the given platform feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_platform_double(const char *key, double *value);
+
+/**
+ * @brief   Gets the string value of the platform feature
+ * @remarks The @a value must be released with free() by you.
+ * @param[in] key The name of the platform feature to get
+ * @param[out] value The value of the given platform feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_platform_string(const char *key, char **value);
+
+
+/**
+ * @brief   Gets the boolean value of the custom feature
+ * @param[in] key The name of the custom feature to get
+ * @param[out] value The value of the given custom feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_custom_bool(const char *key, bool *value);
+
+/**
+ * @brief   Gets the string value of the custom feature
+ * @remarks The @a value must be released with free() by you.
+ * @param[in] key The name of the custom feature to get
+ * @param[out] value The value of the given custom feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_custom_int(const char *key, int *value);
+
+/**
+ * @brief   Gets the string value of the custom feature
+ * @remarks The @a value must be released with free() by you.
+ * @param[in] key The name of the custom feature to get
+ * @param[out] value The value of the given custom feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_custom_double(const char *key, double *value);
+
+/**
+ * @brief   Gets the string value of the custom feature
+ * @remarks The @a value must be released with free() by you.
+ * @param[in] key The name of the custom feature to get
+ * @param[out] value The value of the given custom feature
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #SYSTEM_INFO_ERROR_NONE Successful
+ * @retval  #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval  #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file
+ * @retval  #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file
+ */
+int system_info_get_custom_string(const char *key, char **value);
+
+/**
  * @}
  */
 
index cb0e8fc..799e7b8 100644 (file)
@@ -29,10 +29,19 @@ extern "C"
 #define CPU_INFO_MAX_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
 #define CMDLINE_PATH "/proc/cmdline"
 #define XML_FILE_PATH "/etc/config/sys-info.xml"
+#define CONFIG_FILE_PATH "/etc/config/model-config.xml"
 #define MAXBUFSIZE 512
 
 #define EXTERNAL_VCONF_PREFIX "db/externals/"
 
+#define PLATFORM_TAG   "platform"
+#define CUSTOM_TAG     "custom"
+
+#define BOOL_TYPE      "bool"
+#define INT_TYPE       "int"
+#define DBL_TYPE       "double"
+#define STR_TYPE       "string"
+
 typedef enum {
        SYSTEM_INFO_DATA_TYPE_STRING,
        SYSTEM_INFO_DATA_TYPE_INT,
@@ -55,6 +64,10 @@ int system_info_get_system_info_initialized(void);
 void system_info_set_system_info_initialized(int value);
 system_info_mode_type_e system_info_get_system_info_model_type(void);
 
+int system_info_ini_get_string(char *ini_file, char *key, char **output);
+int system_info_get_value_from_xml(char *xml_file_path, char *model, char *id_field, char **value);
+int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value);
+
 int system_info_vconf_get_value_int(const char *vconf_key, int *value);
 int system_info_vconf_get_value_bool(const char *vconf_key, bool *value);
 int system_info_vconf_get_value_double(const char *vconf_key, double *value);
@@ -122,7 +135,6 @@ int system_info_get_graphics_hwaccel_supported(system_info_key_e key, system_inf
 int system_info_get_feature_auto_rotation_supported(system_info_key_e key, system_info_data_type_e data_type, void **value);
 int system_info_get_feature_pinch_zoom_supported(system_info_key_e key, system_info_data_type_e data_type, void **value);
 
-int system_info_get_value_from_xml(char *xml_file_path, char *model, char *id_field, char **value);
 #ifdef __cplusplus
 }
 #endif
index d395ce5..d7c879f 100644 (file)
@@ -1,20 +1,20 @@
 #sbs-git:slp/api/system-info capi-system-info 0.1.0 63d15bafa590ee9de869c8a8ade712e06828e5c3
-Name:       capi-system-info
-Summary:    A System Information library in SLP C API
-Version: 0.1.14
-Release:    0
-Group:      System/Libraries
-License:    Apache License, Version 2.0 and IEFT RFC Collection
-Source0:    %{name}-%{version}.tar.gz
-BuildRequires:  cmake
-BuildRequires:  pkgconfig(dlog)
-BuildRequires:  pkgconfig(vconf)
-BuildRequires:  pkgconfig(capi-base-common)
+Name:          capi-system-info
+Summary:       A System Information library in SLP C API
+Version:       0.2.0
+Release:       0
+Group:         System/Libraries
+License:       Apache License, Version 2.0 and IEFT RFC Collection
+Source0:       %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(capi-media-sound-manager)
-BuildRequires:  pkgconfig(x11)
-BuildRequires:  pkgconfig(xi)
+BuildRequires: pkgconfig(x11)
+BuildRequires: pkgconfig(xi)
 BuildRequires: pkgconfig(xrandr)
-BuildRequires:  pkgconfig(tapi)
+BuildRequires: pkgconfig(tapi)
 BuildRequires: pkgconfig(haptic)
 BuildRequires: pkgconfig(xproto)
 BuildRequires: pkgconfig(openssl)
@@ -24,7 +24,8 @@ BuildRequires:        pkgconfig(bluetooth-api)
 BuildRequires: pkgconfig(mm-radio)
 BuildRequires: pkgconfig(sensor)
 BuildRequires: pkgconfig(gles11)
-BuildRequires:  pkgconfig(libxml-2.0)
+BuildRequires: pkgconfig(iniparser)
+BuildRequires:         pkgconfig(libxml-2.0)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index 2abcaaf..24776e8 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <vconf.h>
 #include <dlog.h>
@@ -640,3 +641,218 @@ int system_info_get_external_string(const char *key, char **value)
 
        return SYSTEM_INFO_ERROR_NONE;
 }
+
+int system_info_get_platform_bool(const char *key, bool *value)
+{
+       int ret;
+       bool *supported;
+       char *string = NULL;
+
+       supported = (bool *)value;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, BOOL_TYPE, &
+string);
+       if (ret) {
+               LOGE("cannot get %s", key);
+               return ret;
+       }
+
+       if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
+               *supported = true;
+       else
+               *supported = false;
+
+       free(string);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_platform_int(const char *key, int *value)
+{
+       int ret;
+       int *ret_val;
+       char *string = NULL;
+
+       ret_val = (int *)value;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, INT_TYPE, &
+string);
+       if (ret) {
+               LOGE("cannot get %s", key);
+               return ret;
+       }
+
+       *ret_val = atoi(string);
+
+       free(string);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_platform_double(const char *key, double *value)
+{
+       int ret;
+       double *ret_val;
+       char *string = NULL;
+
+       ret_val = (double *)value;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, DBL_TYPE, &
+string);
+       if (ret) {
+               LOGE("cannot get %s", key);
+               return ret;
+       }
+
+       *ret_val = atof(string);
+
+       free(string);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_platform_string(const char *key, char **value)
+{
+       int ret;
+       char *string = NULL;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, STR_TYPE, &
+string);
+       if (ret) {
+               LOGE("cannot get %s", key);
+               return ret;
+       }
+
+       *value = string;
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_custom_bool(const char *key, bool *value)
+{
+       int ret;
+       bool *supported;
+       char *string = NULL;
+
+       supported = (bool *)value;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, BOOL_TYPE, &
+string);
+       if (ret) {
+               LOGI("cannot get %s", key);
+               *supported = false;
+               return SYSTEM_INFO_ERROR_NONE;
+       }
+
+       if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
+               *supported = true;
+       else
+               *supported = false;
+
+       free(string);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_custom_int(const char *key, int *value)
+{
+       int ret;
+       int *ret_val;
+       char *string = NULL;
+
+       ret_val = (int *)value;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, INT_TYPE, &
+string);
+       if (ret) {
+               LOGI("cannot get %s", key);
+               *ret_val = 0;
+               return SYSTEM_INFO_ERROR_NONE;
+       }
+
+       *ret_val = atoi(string);
+
+       free(string);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_custom_double(const char *key, double *value)
+{
+       int ret;
+       double *ret_val;
+       char *string = NULL;
+
+       ret_val = (double *)value;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, DBL_TYPE, &
+string);
+       if (ret) {
+               LOGI("cannot get %s", key);
+               *ret_val = 0;
+               return SYSTEM_INFO_ERROR_NONE;
+       }
+
+       *ret_val = atof(string);
+
+       free(string);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_custom_string(const char *key, char **value)
+{
+       int ret;
+       char *string = NULL;
+
+       if (access(CONFIG_FILE_PATH, R_OK)) {
+               LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, STR_TYPE, &
+string);
+       if (ret) {
+               LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
+               return ret;
+       }
+
+       *value = string;
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
diff --git a/src/system_info_parse.c b/src/system_info_parse.c
new file mode 100644 (file)
index 0000000..e8e66c1
--- /dev/null
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dlog.h>
+
+#include <system_info.h>
+#include <system_info_private.h>
+
+#include <iniparser.h>
+
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_SYSTEM_INFO"
+
+#define MODEL_CONFIG_TAG "model-config"
+
+int system_info_ini_get_string(char *ini_file, char *key, char **output)
+{
+       dictionary      *ini;
+       char *str;
+       char *tmp;
+
+       ini = iniparser_load(ini_file);
+
+       if (ini == NULL) {
+               LOGE("cannot file open %s file!!!", ini_file);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       str = iniparser_getstr(ini, key);
+
+       if (str == NULL) {
+               LOGE("NOT found %s(0x%08x)", key, SYSTEM_INFO_ERROR_IO_ERROR);
+               iniparser_freedict(ini);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       tmp = strdup(str);
+
+       if (tmp == NULL) {
+               LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
+               iniparser_freedict(ini);
+               return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+       }
+
+       *output = tmp;
+       iniparser_freedict(ini);
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_value_from_xml(char *xml_file_path, char *model, char *id_field, char **value)
+{
+       xmlDocPtr doc = NULL;
+       xmlNodePtr cur = NULL;
+       xmlNodePtr default_node = NULL;
+       xmlNodePtr model_node = NULL;
+       xmlNode *cur_node = NULL;
+       char *id = NULL;
+       char *string = NULL;
+
+       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;
+       }
+
+       for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+               if (!xmlStrcmp(cur->name, (const xmlChar*)"sys-info"))
+                       break;
+       }
+
+       if (cur == NULL) {
+               LOGE("cannot find %s root element file!!!", "sys-info");
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       cur = cur->xmlChildrenNode;
+
+       for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+               if (!xmlStrcmp(cur_node->name, (const xmlChar*)"default"))
+                       default_node = cur_node;
+               if (strcmp(model, "default") && !xmlStrcmp(cur_node->name, (const xmlChar*)model))
+                       model_node = cur_node;
+       }
+
+       if (model_node) {
+               cur = model_node->xmlChildrenNode;
+
+               for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+                       if (cur_node->type == XML_ELEMENT_NODE) {
+                               id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
+                               string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
+
+                               if (!strncmp(id, id_field, strlen(id_field))) {
+                                       if (string) {
+                                               *value = strdup(string);
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (*value == NULL && default_node) {
+               cur = default_node->xmlChildrenNode;
+
+               for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+                       if (cur_node->type == XML_ELEMENT_NODE) {
+                               id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
+                               string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
+
+                               if (!strncmp(id, id_field, strlen(id_field))) {
+                                       if (string) {
+                                               *value = strdup(string);
+                                               free(id);
+                                               free(string);
+                                               break;
+                                       }
+                               }
+                               free(id);
+                               free(string);
+                       }
+               }
+       }
+
+       if (!cur_node) {
+               LOGE("cannot find %s field from %s file!!!", id_field, xml_file_path);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       if (*value == NULL) {
+               LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+       }
+
+       xmlFreeDoc(doc);
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value)
+{
+       xmlDocPtr doc = NULL;
+       xmlNodePtr cur = NULL;
+       xmlNodePtr model_node = NULL;
+       xmlNode *cur_node = NULL;
+       char *name = NULL;
+       char *type = NULL;
+       char *string = NULL;
+
+       doc = xmlParseFile(CONFIG_FILE_PATH);
+
+       if (doc == NULL) {
+               LOGE("cannot file open %s file!!!", CONFIG_FILE_PATH);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       cur = xmlDocGetRootElement(doc);
+       if (cur == NULL) {
+               LOGE("empty document %s file!!!", CONFIG_FILE_PATH);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+               if (!xmlStrcmp(cur->name, (const xmlChar*)MODEL_CONFIG_TAG))
+                       break;
+       }
+
+       if (cur == NULL) {
+               LOGE("cannot find %s root element file!!!", MODEL_CONFIG_TAG);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       cur = cur->xmlChildrenNode;
+
+       for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+               if (!xmlStrcmp(cur_node->name, (const xmlChar*)feature_tag))
+                       model_node = cur_node;
+       }
+
+       if (model_node == NULL) {
+               LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       if (model_node) {
+               cur = model_node->xmlChildrenNode;
+
+               for (cur_node = cur; cur_node; cur_node = cur_node->next) {
+                       if (cur_node->type == XML_ELEMENT_NODE) {
+                               name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
+                               type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type");
+
+                               if (!strncmp(name, name_field, strlen(name_field))) {
+                                       if (strncmp(type, type_field, strlen(type_field))) {
+                                               LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
+                                               free(name);
+                                               free(type);
+                                               xmlFreeDoc(doc);
+                                               return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+                                       }
+                                       string = (char *)xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
+                                       if (string) {
+                                               *value = strdup(string);
+                                               free(name);
+                                               free(type);
+                                               break;
+                                       }
+                               }
+                               free(name);
+                               free(type);
+                       }
+               }
+       }
+
+       if (!cur_node) {
+               LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       if (*value == NULL) {
+               LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
+               xmlFreeDoc(doc);
+               return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+       }
+
+       xmlFreeDoc(doc);
+       return SYSTEM_INFO_ERROR_NONE;
+}
index 25dbe2d..30e5fcc 100644 (file)
 #include <GLES/gl.h>
 #include <GLES/glext.h>
 
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 #define SCREEN_INFO_FILE_PATH "/etc/config/screen/sysinfo-screen.xml"
 #define TOUCH_INFO_FILE_PATH   "/etc/config/touch/sysinfo-touch.xml"
 
-int system_info_get_value_from_xml(char *xml_file_path, char *model, char *id_field, char **value)
-{
-       xmlDocPtr doc = NULL;
-       xmlNodePtr cur = NULL;
-       xmlNodePtr default_node = NULL;
-       xmlNodePtr model_node = NULL;
-       xmlNode *cur_node = NULL;
-       char *id = NULL;
-       char *string = NULL;
-
-       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;
-       }
-
-       for (cur_node = cur; cur_node; cur_node = cur_node->next) {
-               if (!xmlStrcmp(cur->name, (const xmlChar*)"sys-info"))
-                       break;
-       }
-
-       if (cur == NULL) {
-               LOGE("cannot find %s root element file!!!", "sys-info");
-               xmlFreeDoc(doc);
-               return SYSTEM_INFO_ERROR_IO_ERROR;
-       }
-
-       cur = cur->xmlChildrenNode;
-
-       for (cur_node = cur; cur_node; cur_node = cur_node->next) {
-               if (!xmlStrcmp(cur_node->name, (const xmlChar*)"default"))
-                       default_node = cur_node;
-               if (strcmp(model, "default") && !xmlStrcmp(cur_node->name, (const xmlChar*)model))
-                       model_node = cur_node;
-       }
-
-       if (model_node) {
-               cur = model_node->xmlChildrenNode;
-
-               for (cur_node = cur; cur_node; cur_node = cur_node->next) {
-                       if (cur_node->type == XML_ELEMENT_NODE) {
-                               id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
-                               string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
-
-                               if (!strncmp(id, id_field, strlen(id_field))) {
-                                       if (string) {
-                                               *value = strdup(string);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       if (*value == NULL && default_node) {
-               cur = default_node->xmlChildrenNode;
-
-               for (cur_node = cur; cur_node; cur_node = cur_node->next) {
-                       if (cur_node->type == XML_ELEMENT_NODE) {
-                               id = (char *)xmlGetProp(cur_node, (const xmlChar*)"id");
-                               string = (char *) xmlGetProp(cur_node, (const xmlChar*)"string");
-
-                               if (!strncmp(id, id_field, strlen(id_field))) {
-                                       if (string) {
-                                               *value = strdup(string);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       if (!cur_node) {
-               LOGE("cannot find %s field from %s file!!!", id_field, xml_file_path);
-               xmlFreeDoc(doc);
-               return SYSTEM_INFO_ERROR_IO_ERROR;
-       }
-
-       if (*value == NULL) {
-               LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
-               xmlFreeDoc(doc);
-               return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
-       }
-
-       xmlFreeDoc(doc);
-       return SYSTEM_INFO_ERROR_NONE;
-}
-
 int system_info_get_model(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
        char *MODEL = NULL;