*/
int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size);
+/**
+ * @brief Get the number of the backend libraries according to the type of HAL module
+ * @param[in] HAL module id among enum hal_moudle
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int hal_common_get_backend_count(enum hal_module module);
+
+/**
+ * @brief Get the backend library names according to the type of HAL module
+ * @param[in] HAL module id among enum hal_moudle
+ * @param[out] Data pointer should be filled by backend library names
+ * @param[in] Number of backend library of specific HAL module
+ * @param[in] Maximum length of the library name
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int hal_common_get_backend_library_names(enum hal_module module,
+ char **library_names,
+ int library_count,
+ int library_name_size);
+
#ifdef __cplusplus
}
#endif
#include <stdbool.h>
#include <dlfcn.h>
#include <dlog.h>
+#include <dirent.h>
#define _GNU_SOURCE
#include <errno.h>
{
return __get_backend_data(module, NULL, NULL, 0, vendor, size);
}
+
+
+static int __get_backend_library_data(enum hal_module module,
+ char **lib_names,
+ int lib_count,
+ int lib_name_size)
+{
+ struct __hal_module_info *info = NULL;
+ struct dirent *de;
+ DIR *dir;
+ const char *backend_module_name = NULL;
+ int count, i, ret, len;
+#if defined(__aarch64__)
+ const char hal_backend_path[] = "/hal/lib64";
+#else
+ const char hal_backend_path[] = "/hal/lib";
+#endif
+
+ /* Check parameter whether is valid or not */
+ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) {
+ _E("Invalid parameter of HAL module (%d)\n", module);
+ return TIZEN_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_hal_api_conf_init())
+ return TIZEN_ERROR_UNKNOWN;
+
+ info = _hal_api_conf_get_module_info(module, NULL);
+ if (info == NULL) {
+ _E("Failed to get HAL module(%d) information\n", module);
+ ret = TIZEN_ERROR_INVALID_PARAMETER;
+ goto err;
+ }
+
+ if (info->backend_module_name == NULL) {
+ _E("Don't support HAL backend of HAL module(%s)\n",
+ info->module_name);
+ ret = TIZEN_ERROR_INVALID_PARAMETER;
+ goto err;
+ }
+ backend_module_name = g_strdup_printf("libhal-backend-%s",
+ info->backend_module_name);
+ if (!backend_module_name) {
+ _E("Failed to allocate the backend_module_name of HAL module(%s)\n",
+ info->module_name);
+ ret = TIZEN_ERROR_UNKNOWN;
+ goto err;
+ }
+
+ /* Find HAL backend libraries */
+ dir = opendir(hal_backend_path);
+ if (!dir) {
+ _E("Failed to find HAL backend path(%s) for HAL module(%s)\n",
+ hal_backend_path, info->module_name);
+ ret = TIZEN_ERROR_UNKNOWN;
+ goto err_free_backend_module_name;
+ }
+
+ count = 0;
+ while ((de = readdir(dir)) != NULL) {
+ if (!g_str_has_prefix(de->d_name, backend_module_name))
+ continue;
+
+ if (lib_count == 0)
+ count++;
+ else if (lib_count > 0) {
+ len = strlen(de->d_name) + 1;
+
+ if (len > lib_name_size)
+ len = lib_name_size;
+
+ strncpy(lib_names[count++], de->d_name, len);
+ }
+ }
+
+ if (lib_count > 0 && count != lib_count) {
+ ret = TIZEN_ERROR_INVALID_PARAMETER;
+ goto err_mismatch_count;
+ }
+
+ closedir(dir);
+ _hal_api_conf_exit();
+ g_free(backend_module_name);
+
+ return count;
+
+err_mismatch_count:
+ for (i = count - 1; i >= 0; i--)
+ memset(lib_names[i], 0, strlen(lib_names[i]));
+
+ closedir(dir);
+err_free_backend_module_name:
+ g_free(backend_module_name);
+err:
+ _hal_api_conf_exit();
+ return ret;
+}
+
+EXPORT
+int hal_common_get_backend_count(enum hal_module module)
+{
+ return __get_backend_library_data(module, NULL, 0, 0);
+}
+
+EXPORT
+int hal_common_get_backend_library_names(enum hal_module module,
+ char **library_names,
+ int library_count,
+ int library_name_size)
+{
+ int ret = __get_backend_library_data(module, library_names,
+ library_count, library_name_size);
+ return (ret < 0) ? ret : 0;
+}