halapi: Add new hal_common_get_backend_module_name function 68/291368/3
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 28 Mar 2023 16:57:19 +0000 (01:57 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 17 Apr 2023 12:41:41 +0000 (21:41 +0900)
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 <cw00.choi@samsung.com>
include/hal-common.h
src/hal-api-common.c

index 6b632bb..f4dd4c4 100644 (file)
@@ -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
index babc61c..0984ef8 100644 (file)
@@ -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;