halapi: Remove circular dependency between packages 20/254120/4 accepted/tizen/unified/20210225.130533 submit/tizen/20210224.090756 submit/tizen/20210225.073439
authorSeungha Son <seungha.son@samsung.com>
Tue, 23 Feb 2021 14:58:19 +0000 (23:58 +0900)
committerSeungha Son <seungha.son@samsung.com>
Wed, 24 Feb 2021 03:30:11 +0000 (12:30 +0900)
 Change json parsing library from json-glib to json-c
 because when using json-glib, the circular dependency
 problem between dependent rpm is occured.

 By changing the json-parser-lib from json-glib to json-c,
 the circular dependency was removed and the problem was solved.

Change-Id: I694e05649a875ea8a3af8128efc5be7c88282830
Signed-off-by: Seungha Son <seungha.son@samsung.com>
CMakeLists.txt
packaging/hal-api-common.spec
src/hal-api-conf.c

index ae9fd01..df8d137 100644 (file)
@@ -16,7 +16,7 @@ SET(PKG_MODULES
        dlog
        gio-2.0
        glib-2.0
-       json-glib-1.0
+       json-c
        libtzplatform-config
 )
 
index b381841..223887f 100644 (file)
@@ -21,7 +21,7 @@ BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(json-glib-1.0)
+BuildRequires: pkgconfig(json-c)
 BuildRequires: pkgconfig(gmock)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(systemd)
index 9b8480b..46d1be6 100644 (file)
@@ -18,7 +18,9 @@
 
 #include <gio/gio.h>
 #include <glib-object.h>
-#include <json-glib/json-glib.h>
+
+#include <json-c/json.h>
+#include <json-c/arraylist.h>
 
 #include "hal-common.h"
 #include "hal-common-interface.h"
@@ -29,8 +31,7 @@
 
 static enum hal_abi_version _platform_abi_version = HAL_ABI_VERSION_END;
 
-static JsonParser *_parser = NULL;
-static JsonObject *_root_object = NULL;
+static json_object *_json_file_object = NULL;
 
 static GHashTable *_module_hash = NULL;
 
@@ -105,13 +106,22 @@ do { \
        }
 }
 
-static struct __hal_module_info *__create_hal_module_info(enum hal_module module, JsonObject *object)
+static const char * __get_json_object_string(json_object *object, const char *key)
+{
+       json_object *temp_object = NULL;
+
+       json_object_object_get_ex(object, key, &temp_object);
+       return json_object_get_string(temp_object);
+}
+
+static struct __hal_module_info *__create_hal_module_info(enum hal_module module, json_object *object)
 {
        struct __hal_module_info *info;
-       JsonArray *abi_versions_array = NULL;
        GList *abi_list = NULL;
        GList *iter_list = NULL;
        int list_index = 0;
+       json_object *abi_versions_array;
+       json_object *tmp_object;
        const char *tmp;
 
        info = (struct __hal_module_info *)calloc(1, sizeof(struct __hal_module_info));
@@ -123,52 +133,47 @@ static struct __hal_module_info *__create_hal_module_info(enum hal_module module
        info->module = module;
        info->module_name = g_strdup(__convert_module_to_string(module));
 
-       tmp = json_object_get_string_member(object, "group");
+       tmp = __get_json_object_string(object, "group");
        info->group = __convert_group_str_to_enum(tmp);
 
-       tmp = json_object_get_string_member(object, "license");
+       tmp = __get_json_object_string(object, "license");
        info->license = __convert_license_str_to_enum(tmp);
 
-       info->library_name = g_strdup(json_object_get_string_member(object, "library_name"));
-       info->library_name_64bit = g_strdup(json_object_get_string_member(object, "library_name_64bit"));
-       info->symbol_name = g_strdup(json_object_get_string_member(object, "symbol_name"));
+       info->library_name = g_strdup(__get_json_object_string(object, "library_name"));
+       info->library_name_64bit = g_strdup(__get_json_object_string(object, "library_name_64bit"));
+       info->symbol_name = g_strdup(__get_json_object_string(object, "symbol_name"));
 
        if (info->library_name && info->library_name_64bit && info->symbol_name)
                info->hal_api = true;
 
-       abi_versions_array = json_object_get_array_member(object, "abi_versions");
-       if (abi_versions_array == NULL)
+       json_object_object_get_ex(object, "abi_versions", &abi_versions_array);
+       if (json_object_get_type(abi_versions_array) != json_type_array)
                return info;
 
-       abi_list = json_array_get_elements(abi_versions_array);
-       info->num_abi_versions = g_list_length(abi_list);
+       info->num_abi_versions = json_object_array_length(abi_versions_array);
        if (info->num_abi_versions > 0) {
                info->abi_versions = (struct hal_abi_version_match*)calloc(info->num_abi_versions,
                                sizeof(struct hal_abi_version_match));
                if (info->abi_versions == NULL) {
                        _E("Out of Memory\n");
                        _destroy_module_info(info);
-                       g_list_free(abi_list);
                        return NULL;
                }
 
-               for (iter_list = abi_list; iter_list != NULL; iter_list = iter_list->next) {
-                       JsonObject *tmp_object = json_node_get_object(iter_list->data);
+               for (int i = 0; i < info->num_abi_versions; i++) {
+                       json_object *abi_object = json_object_array_get_idx(abi_versions_array, i);
 
-                       tmp = json_object_get_string_member(tmp_object, "platform_abi_version");
+                       tmp = __get_json_object_string(abi_object, "platform_abi_version");
                        info->abi_versions[list_index].platform_abi_version =
                                __convert_abi_version_str_to_enum(tmp);
 
-                       tmp = json_object_get_string_member(tmp_object, "backend_min_abi_version");
+                       tmp = __get_json_object_string(abi_object, "backend_min_abi_version");
                        info->abi_versions[list_index].backend_min_abi_version =
                                __convert_abi_version_str_to_enum(tmp);
                        list_index++;
                }
        }
 
-       if (abi_list)
-               g_list_free(abi_list);
-
        return info;
 }
 
@@ -176,28 +181,26 @@ __attribute__ ((visibility("default")))
 struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module)
 {
        struct __hal_module_info *info = NULL;
-       JsonArray *module_array = NULL;
-       GList *module_list = NULL;
-       GList *iter_list;
+       json_object *module_array_object = NULL;
        const char *group_name = NULL;
        const char *module_name = NULL;
+       int i;
 
-       if (!_root_object || !_module_hash)
+       if (!_json_file_object || !_module_hash)
                return NULL;
 
        info = (struct __hal_module_info*)g_hash_table_lookup(_module_hash, GINT_TO_POINTER(module));
        if (info != NULL)
                return info;
 
-       module_array = json_object_get_array_member(_root_object, "MODULE_INFO");
-       module_list = json_array_get_elements(module_array);
+       json_object_object_get_ex(_json_file_object, "MODULE_INFO", &module_array_object);
        module_name = __convert_module_to_string(module);
 
-       for (iter_list = module_list; iter_list != NULL; iter_list = iter_list->next) {
-               JsonObject *tmp_object = json_node_get_object(iter_list->data);
-               const char *value = json_object_get_string_member(tmp_object, "module");
+       for (i = 0; i < json_object_array_length(module_array_object); i++) {
+               json_object *temp_object = json_object_array_get_idx(module_array_object, i);
+               const char *value = __get_json_object_string(temp_object, "module");
                if (g_strcmp0(value, module_name) == 0) {
-                       info = __create_hal_module_info(module, tmp_object);
+                       info = __create_hal_module_info(module, temp_object);
                        if (info == NULL)
                                _E("Failed to create hal module info\n");
                        else
@@ -206,10 +209,6 @@ struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module)
                }
        }
 
-ret:
-       if (module_list)
-               g_list_free(module_list);
-
        return info;
 }
 
@@ -217,14 +216,15 @@ enum hal_abi_version _hal_api_conf_get_platform_abi_version(void)
 {
        const char *abi_version = NULL;
        bool ret_initialized;
+       json_object *platform_obj = NULL;
 
        if (_platform_abi_version != HAL_ABI_VERSION_END)
                return _platform_abi_version;
 
-       if (!_root_object || !_module_hash)
+       if (!_json_file_object || !_module_hash)
                return HAL_ABI_VERSION_UNKNOWN;
 
-       abi_version = json_object_get_string_member(_root_object, "PLATFORM_ABI_VERSION");
+       abi_version = __get_json_object_string(_json_file_object, "PLATFORM_ABI_VERSION");
        _platform_abi_version = __convert_abi_version_str_to_enum(abi_version);
 
        return _platform_abi_version;
@@ -233,27 +233,15 @@ enum hal_abi_version _hal_api_conf_get_platform_abi_version(void)
 __attribute__ ((visibility("default")))
 int _hal_api_conf_init(void)
 {
-       JsonNode *root_node = NULL;
-       GError *error = NULL;
-       gboolean result;
-
        if (_usage_count++ > 0)
                return 0;
 
-       _parser = json_parser_new();
-       result = json_parser_load_from_file(_parser, HAL_CONFIGURATION_PATH, &error);
-       if (result == FALSE) {
-               _E("Failed to parsing json configuration file : %s\n", error->message);
-               goto err;
-       }
-
-       root_node = json_parser_get_root(_parser);
-       if (JSON_NODE_HOLDS_OBJECT(root_node) == FALSE) {
-               _E("There is no object in root node\n");
+       _json_file_object = json_object_from_file(HAL_CONFIGURATION_PATH);
+       if (_json_file_object == NULL) {
+               _E("Failed to parsing json configuration file : %s\n", json_util_get_last_err());
                goto err;
        }
 
-       _root_object = json_node_get_object(root_node);
        _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info);
 
        return 0;
@@ -261,11 +249,6 @@ int _hal_api_conf_init(void)
 err:
        _usage_count--;
 
-       if (error)
-               g_error_free(error);
-       if (_parser)
-               g_object_unref(_parser);
-
        if (_module_hash) {
                g_hash_table_remove_all(_module_hash);
                g_hash_table_unref(_module_hash);
@@ -281,8 +264,10 @@ void _hal_api_conf_exit(void)
        if (_usage_count != 0)
                return;
 
-       if (_parser)
-               g_object_unref(_parser);
+       if (_json_file_object) {
+               json_object_put(_json_file_object);
+               _json_file_object = NULL;
+       }
 
        if (_module_hash) {
                g_hash_table_remove_all(_module_hash);