-#ifdef HAL_API_CONF_JSON
-static enum hal_abi_version __convert_abi_version_str_to_enum(const char *abi_version) {
- int version;
- for (version = HAL_ABI_VERSION_UNKNOWN + 1; version < HAL_ABI_VERSION_END; version++){
- if (g_strcmp0(abi_version, hal_abi_version_str[version]) == 0)
- return (enum hal_abi_version)version;
- }
-
- return HAL_ABI_VERSION_UNKNOWN;
-}
-
-static const char *__convert_module_to_string(enum hal_module module)
-{
- return hal_module_string[module];
-}
-
-static enum hal_group __convert_group_str_to_enum(const char * group)
-{
- enum hal_group group_idx;
-
- for (group_idx = HAL_GROUP_UNKNOWN + 1; group_idx < HAL_GROUP_END; group_idx++) {
- if (g_strcmp0(group, hal_group_string[group_idx]) == 0)
- return group_idx;
- }
-
- return HAL_GROUP_UNKNOWN;
-}
-
-static enum hal_license __convert_license_str_to_enum(const char *license)
-{
- if (g_strcmp0(license, "APACHE_2_0") == 0)
- return HAL_LICENSE_APACHE_2_0;
-
- if (g_strcmp0(license, "FLORA") == 0)
- return HAL_LICENSE_FLORA;
-
- if (g_strcmp0(license, "MIT") == 0)
- return HAL_LICENSE_MIT;
-
- return HAL_LICENSE_UNKNOWN;
-}
-
-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;
- 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));
- if (info == NULL) {
- _E("Out of Memory\n");
- return NULL;
- }
-
- info->module = module;
- info->module_name = g_strdup(__convert_module_to_string(module));
-
- tmp = __get_json_object_string(object, "group");
- info->group = __convert_group_str_to_enum(tmp);
-
- tmp = __get_json_object_string(object, "license");
- info->license = __convert_license_str_to_enum(tmp);
-
- 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;
-
- json_object_object_get_ex(object, "abi_versions", &abi_versions_array);
- if (json_object_get_type(abi_versions_array) != json_type_array)
- return info;
-
- 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);
- return NULL;
- }
-
- for (int i = 0; i < info->num_abi_versions; i++) {
- json_object *abi_object = json_object_array_get_idx(abi_versions_array, i);
-
- 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 = __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++;
- }
- }
-
- return info;
-}
-
-static struct __hal_module_info* _get_module_info(enum hal_module module)
-{
- struct __hal_module_info *info = NULL;
- json_object *module_array_object = NULL;
- const char *group_name = NULL;
- const char *module_name = NULL;
- int i;
-
- 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;
-
- json_object_object_get_ex(_json_file_object, "MODULE_INFO", &module_array_object);
- module_name = __convert_module_to_string(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, temp_object);
- if (info == NULL)
- _E("Failed to create hal module info\n");
- else
- g_hash_table_insert(_module_hash, GINT_TO_POINTER(module), info);
- break;
- }
- }
-
- return info;
-}
-#else