From: Chanwoo Choi Date: Mon, 26 Apr 2021 10:06:56 +0000 (+0900) Subject: halapi: Add new functions to get information of hal_backend structure X-Git-Tag: submit/tizen/20210428.073114^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc5a305b030bd67f8bbd1fbd49bc9eeb1c67985b;p=platform%2Fhal%2Fapi%2Fcommon.git halapi: Add new functions to get information of hal_backend structure The hal-api-common defines the common hal_backend structure for all hal backend driver. Add new functions to provide the information of hal_backend structure because of user request. Add the detailed function roles as following: [Newly added functions] - hal_common_get_backend_abi_version(enum hal_module module); : Get the backend HAL ABI version according to the type of HAL module - hal_common_get_backend_name(enum hal_module module, char *name, int size); : Get the backend name according to the type of HAL module - hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); : Get the backend vendor description according to the type of HAL module Change-Id: I2060e9047b60c029e161dc18f3981185a0f724a1 Signed-off-by: Chanwoo Choi --- diff --git a/include/hal-common.h b/include/hal-common.h index 67dc4b1..7ec6c1f 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -203,6 +203,31 @@ int hal_common_put_backend_with_library_name(enum hal_module module, int hal_common_check_backend_abi_version(enum hal_module module, enum hal_abi_version abi_version); +/** + * @brief Get the backend HAL ABI version according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @return @c positive integer value on success, otherwise a zero error value + */ +unsigned int hal_common_get_backend_abi_version(enum hal_module module); + +/** + * @brief Get the backend name according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend name of HAL module + * @param[in] Arrary size of name[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int hal_common_get_backend_name(enum hal_module module, char *name, int size); + +/** + * @brief Get the backend vendor description according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend vendor description of HAL module + * @param[in] Arrary size of vendor[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); + #ifdef __cplusplus } #endif diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 18eab76..7a98878 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -396,6 +396,82 @@ out: return ret; } +static int __get_backend_data(enum hal_module module, unsigned int *abi_version, + char *name, int name_size, char *vendor, int vendor_size) +{ + struct __hal_module_info *info = NULL; + int ret, len; + + if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { + _E("Invalid parameter of HAL module (%d)\n", module); + return 0; + } + + G_LOCK(hal_common_lock); + + if (_hal_api_conf_init()) { + ret = HAL_ABI_VERSION_UNKNOWN; + goto err_unlock; + } + + info = _hal_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); + ret = HAL_ABI_VERSION_UNKNOWN; + goto err_conf_exit; + } + + ret = __open_backend(info); + if (ret < 0) { + _E("%s: Failed to get the backend library by dlopen\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + /* Return abi_verion of hal_backend structure */ + if (!name_size && !vendor_size) { + *abi_version = info->backend->abi_version; + + /* Return name of hal_backend structure */ + } else if (info->backend->name && name_size && !vendor_size) { + len = strlen(info->backend->name); + + if (!info->backend->name || (len + 1 > name_size)) { + _E("%s: Invalid size of name[] array\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + strncpy(name, info->backend->name, len); + name[len] = '\0'; + + /* Return vendor of hal_backend structure */ + } else if (info->backend->vendor && !name_size && vendor_size) { + len = strlen(info->backend->vendor); + + if (!info->backend->vendor || (len + 1 > vendor_size)) { + _E("%s: Invalid size of vendor[] array\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + strncpy(vendor, info->backend->vendor, len); + vendor[len] = '\0'; + } else { + _E("%s: Failed to get backend data\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + ret = TIZEN_ERROR_NONE; + +err_conf_exit: + _hal_api_conf_exit(); +err_unlock: + G_UNLOCK(hal_common_lock); + return ret; +} + EXPORT int hal_common_get_backend(enum hal_module module, void **data) { @@ -505,3 +581,28 @@ out: _hal_api_conf_exit(); return ret; } + +EXPORT +unsigned int hal_common_get_backend_abi_version(enum hal_module module) +{ + unsigned int abi_version; + int ret; + + ret = __get_backend_data(module, &abi_version, NULL, 0, NULL, 0); + if (ret < 0) + return HAL_ABI_VERSION_UNKNOWN; + + return abi_version; +} + +EXPORT +int hal_common_get_backend_name(enum hal_module module, char *name, int size) +{ + return __get_backend_data(module, NULL, name, size, NULL, 0); +} + +EXPORT +int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size) +{ + return __get_backend_data(module, NULL, NULL, 0, vendor, size); +}