#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"
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;
}
}
-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));
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;
}
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
}
}
-ret:
- if (module_list)
- g_list_free(module_list);
-
return info;
}
{
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;
__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;
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);
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);