From 5d2ce093a0c4d6c97a4dabf9ab67d5eff5450d9c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 29 Mar 2023 01:57:19 +0900 Subject: [PATCH] halapi: Add new hal_common_get_backend_module_name function Add new hal_common_get_backend_module_name function in order to provide the HAL module name [Detailed function prototype] - int hal_common_get_backend_module_name(enum hal_module module, char *name, int size); Change-Id: I521846db3917571ea7cfa00dd701dd9e8c7c97a2 Signed-off-by: Chanwoo Choi --- include/hal-common.h | 9 +++++++++ src/hal-api-common.c | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index 6b632bb..f4dd4c4 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -104,6 +104,15 @@ int hal_common_get_backend_library_name(enum hal_module module, char *name, int int hal_common_get_backend_symbol_name(enum hal_module module, char *name, int size); /** + * @brief Get the backend module name according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend module name of HAL module + * @param[in] Arrary size of name[] + * @return @c 0 on success, otherwise a negative error value + */ +int hal_common_get_backend_module_name(enum hal_module module, char *name, int size); + +/** * @brief Get the backend data according to the type of HAL module * @param[in] HAL module id among enum hal_moudle * @param[out] Data pointer where 'hal_backend_[module]_funcs' instance diff --git a/src/hal-api-common.c b/src/hal-api-common.c index babc61c..0984ef8 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -37,6 +37,9 @@ extern char *program_invocation_name; #define EXPORT __attribute__ ((visibility("default"))) #endif +#define HAL_BACKEND_SYMBOL_NAME 1 +#define HAL_BACKEND_MODULE_NAME 2 + static enum hal_abi_version g_platform_curr_abi_version; G_LOCK_DEFINE_STATIC(hal_common_lock); @@ -87,13 +90,12 @@ out: return ret; } -EXPORT -int hal_common_get_backend_symbol_name(enum hal_module module, char *name, int size) +static int __hal_common_get_backend_name(enum hal_module module, char *name, int size, int name_type) { struct __hal_module_info *info = NULL; - char *symbol_name = NULL; + char *str = NULL; int ret; - int len_symbol_name; + int len_str; /* Check parameter whether is valid or not */ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { @@ -110,21 +112,32 @@ int hal_common_get_backend_symbol_name(enum hal_module module, char *name, int s ret = -EINVAL; goto out; } - symbol_name = info->symbol_name; - if (!symbol_name) { - _E("%s backend symbol name is NULL\n", info->module_name); + + switch (name_type) { + case HAL_BACKEND_SYMBOL_NAME: + str = info->symbol_name; + break; + case HAL_BACKEND_MODULE_NAME: + str = info->module_name; + break; + default: + break; + } + + if (!str) { + _I("%s backend name is NULL\n", info->module_name); ret = 0; goto out; } - len_symbol_name = strlen(symbol_name); - if (!name || (len_symbol_name + 1 > size)) { + len_str = strlen(str); + if (!str || (len_str + 1 > size) || len_str == 0) { ret = -EINVAL; - name = NULL; + str = NULL; goto out; } - strncpy(name, symbol_name, len_symbol_name); - name[len_symbol_name] = '\0'; + strncpy(name, str, len_str); + name[len_str] = '\0'; ret = 0; out: @@ -133,6 +146,18 @@ out: return ret; } +EXPORT +int hal_common_get_backend_symbol_name(enum hal_module module, char *name, int size) +{ + return __hal_common_get_backend_name(module, name, size, HAL_BACKEND_SYMBOL_NAME); +} + +EXPORT +int hal_common_get_backend_module_name(enum hal_module module, char *name, int size) +{ + return __hal_common_get_backend_name(module, name, size, HAL_BACKEND_MODULE_NAME); +} + static int __open_backend(struct __hal_module_info *info) { const char *backend_library_name = NULL; -- 2.7.4