X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fhal-api-conf.c;h=791ed29f8c447822e7e2ce5f46ce639d7e789c0f;hb=28a766b1e13636421c19c601f85668d4505ce68a;hp=65e67f4ec88772f9842d5e36bea1b79566703428;hpb=0bde68b13a4809ae6772ce46677bfd1867b5f174;p=platform%2Fhal%2Fapi%2Fcommon.git diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 65e67f4..791ed29 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -19,9 +19,6 @@ #include #include -#include -#include - #include "hal-common.h" #include "hal-common-interface.h" @@ -29,12 +26,6 @@ #include "hal-api-conf.h" #include "hal-api-list.h" -#ifdef HAL_API_CONF_JSON -static enum hal_abi_version _platform_abi_version = HAL_ABI_VERSION_END; - -static json_object *_json_file_object = NULL; -#endif - static GHashTable *_module_hash = NULL; static int _usage_count = 0; @@ -54,208 +45,69 @@ do { \ if (info) { SAFE_FREE_AND_NULL(info->module_name); + SAFE_FREE_AND_NULL(info->backend_module_name); SAFE_FREE_AND_NULL(info->library_name); SAFE_FREE_AND_NULL(info->library_name_64bit); SAFE_FREE_AND_NULL(info->symbol_name); - SAFE_FREE_AND_NULL(info->abi_versions); SAFE_FREE_AND_NULL(info); } } -#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 static struct __hal_module_info* _get_module_info(enum hal_module module) { return &g_hal_module_info[module]; } -#endif static struct __hal_module_info* _get_module_info_with_library_name(enum hal_module module, const char *library_name) { - struct __hal_module_info *info = NULL, *new_info = NULL; - json_object *module_array_object = NULL; - const char *group_name = NULL; - const char *module_name = NULL; - int ret; + struct __hal_module_info *info = NULL, *new_info = NULL, *tmp_info = NULL; + char *library_name_prefix = NULL; -#ifdef HAL_API_CONF_JSON - if (!_json_file_object) + if (!_module_hash || !library_name) return NULL; -#endif - if (!_module_hash | !library_name) + tmp_info = _get_module_info(module); + if (tmp_info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); return NULL; + } - if (!g_str_has_prefix(library_name, "libhal-backend-")) { - _E("Invalid library name(%s) of HAL module(%d)\n", - library_name, module); + if (tmp_info->backend_module_name == NULL) { + _E("Don't support HAL backend of HAL module(%s)\n", + tmp_info->module_name); + return NULL; + } + library_name_prefix = g_strdup_printf("libhal-backend-%s", + tmp_info->backend_module_name); + if (!library_name_prefix) { + _E("Failed to allocate library_name_prefix of HAL module(%s)\n", + tmp_info->module_name); return NULL; } + if (!g_str_has_prefix(library_name, library_name_prefix)) { + _E("Invalid library name(%s) of HAL module(%s)\n", + library_name, tmp_info->module_name); + goto out; + } + /* Find module info with the passed library name */ info = (struct __hal_module_info*)g_hash_table_lookup(_module_hash, (gpointer)library_name); - if (info) + if (info) { + g_free(library_name_prefix); return info; + } /* Create new module info with the passed library name */ - info = _get_module_info(module); - if (info == NULL) { - _E("Failed to get HAL module(%d) information\n", module); - return NULL; - } + info = tmp_info; new_info = (struct __hal_module_info *)calloc(1, sizeof(struct __hal_module_info)); if (new_info == NULL) { _E("Failed to allocate the memory\n"); - return NULL; + goto out; } new_info->usage_count = 0; @@ -263,7 +115,7 @@ static struct __hal_module_info* _get_module_info_with_library_name(enum hal_mod new_info->module = info->module; new_info->license = info->license; new_info->module_name = g_strdup(info->module_name); -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__x86_64__) || defined(__riscv) new_info->library_name_64bit = g_strdup_printf("/hal/lib64/%s", library_name); #else new_info->library_name = g_strdup_printf("/hal/lib/%s", library_name); @@ -276,6 +128,9 @@ static struct __hal_module_info* _get_module_info_with_library_name(enum hal_mod g_hash_table_insert(_module_hash, (gpointer)library_name, new_info); +out: + g_free(library_name_prefix); + return new_info; } @@ -283,11 +138,6 @@ __attribute__ ((visibility("default"))) struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, const char *library_name) { -#ifdef HAL_API_CONF_JSON - if (!_json_file_object) - return NULL; -#endif - if (!_module_hash) return NULL; @@ -300,24 +150,7 @@ struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) { -#ifdef HAL_API_CONF_JSON - 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 (!_json_file_object || !_module_hash) - return HAL_ABI_VERSION_UNKNOWN; - - 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; -#else return g_platform_curr_abi_version; -#endif } __attribute__ ((visibility("default"))) @@ -326,29 +159,9 @@ int _hal_api_conf_init(void) if (_usage_count++ > 0) return 0; -#ifdef HAL_API_CONF_JSON - _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; - } -#endif - _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info); return 0; - -#ifdef HAL_API_CONF_JSON -err: - _usage_count--; - - if (_module_hash) { - g_hash_table_remove_all(_module_hash); - g_hash_table_unref(_module_hash); - } - - return -EINVAL; -#endif } __attribute__ ((visibility("default"))) @@ -358,13 +171,6 @@ void _hal_api_conf_exit(void) if (_usage_count != 0) return; -#ifdef HAL_API_CONF_JSON - if (_json_file_object) { - json_object_put(_json_file_object); - _json_file_object = NULL; - } -#endif - if (_module_hash) { g_hash_table_remove_all(_module_hash); g_hash_table_unref(_module_hash);