halapi: Add new functions to get information of hal_backend structure 16/257516/4 accepted/tizen/unified/20210429.011907 submit/tizen/20210428.073114
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 26 Apr 2021 10:06:56 +0000 (19:06 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 28 Apr 2021 06:19:42 +0000 (15:19 +0900)
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 <cw00.choi@samsung.com>
include/hal-common.h
src/hal-api-common.c

index 67dc4b174ebedd185634ddf5a8dcc309489703a1..7ec6c1f14adfe2ae2bba09e3d0f35158cd08e5f5 100644 (file)
@@ -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
index 18eab7673c2aa7db2cb89288122e266739a644b6..7a988783742760e898cc2d6df4fe91d5debf47f4 100644 (file)
@@ -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);
+}