From d3ea592d1851e7114a1e0cfc8c88b654907e5acb Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 20 Aug 2021 12:40:40 +0900 Subject: [PATCH] halapi: Add ENABLE_DLOG build option Add ENABLE_DLOG build option to support the case of when DLOG should be disabled. Also, if don't require dlog, hal-api-common is not able to use tizen error value. So that change the error value to make it minimum package dependency. Change-Id: I52766750c3b8b547dbc9e2576e0e9a8b3d2b1232 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 12 ++++- packaging/hal-api-common.spec | 4 +- src/common.h | 10 +++- src/hal-api-common.c | 115 +++++++++++++++++++++--------------------- 4 files changed, 79 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 260849c..9a318e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,12 +12,22 @@ SET(LIBDIR ${CMAKE_LIBDIR_PREFIX}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) +if (${ENABLE_DLOG}) +ADD_DEFINITIONS("-DENABLE_DLOG=1") +ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_COMMON\"") SET(PKG_MODULES dlog gio-2.0 glib-2.0 json-c ) +else() +SET(PKG_MODULES + gio-2.0 + glib-2.0 + json-c +) +endif() INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) @@ -31,8 +41,6 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functi SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") -ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_COMMON\"") - SET(SRCS src/hal-api-common.c src/hal-api-conf.c) diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index c699c35..4aeeb86 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -56,7 +56,9 @@ Haltests for hal-api-common %define hal_rpmdb_checker_path /opt/etc/hal -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DCMAKE_LIBDIR_PREFIX=%{_libdir} \ + -DENABLE_DLOG=1 %build cp %{SOURCE1} . diff --git a/src/common.h b/src/common.h index b567f8b..4a89747 100644 --- a/src/common.h +++ b/src/common.h @@ -18,7 +18,6 @@ #define __COMMON_H__ #include -#include #include "hal-common.h" @@ -26,10 +25,19 @@ extern "C" { #endif +#ifdef ENABLE_DLOG +#include + #define _D(fmt, args...) SLOGD(fmt, ##args) #define _I(fmt, args...) SLOGI(fmt, ##args) #define _W(fmt, args...) SLOGW(fmt, ##args) #define _E(fmt, args...) SLOGE(fmt, ##args) +#else +#define _D(fmt, args...) do { } while(0) +#define _I(fmt, args...) do { } while(0) +#define _W(fmt, args...) do { } while(0) +#define _E(fmt, args...) do { } while(0) +#endif #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index c825c3f..22c50e8 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #define _GNU_SOURCE @@ -51,36 +50,36 @@ int hal_common_get_backend_library_name(enum hal_module module, char *name, int /* 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; + return -EINVAL; } if (_hal_api_conf_init()) - return TIZEN_ERROR_UNKNOWN; + return -EINVAL; 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_UNKNOWN; + ret = -EINVAL; goto out; } library_name = get_backend_library_name(info); if (!library_name) { _E("%s backend library name is NULL\n", info->module_name); - ret = TIZEN_ERROR_NONE; + ret = 0; goto out; } len_library_name = strlen(library_name); if (!name || (len_library_name + 1 > size)) { - ret = TIZEN_ERROR_UNKNOWN; + ret = -EINVAL; name = NULL; goto out; } strncpy(name, library_name, len_library_name); name[len_library_name] = '\0'; - ret = TIZEN_ERROR_NONE; + ret = 0; out: _hal_api_conf_exit(); @@ -98,35 +97,35 @@ int hal_common_get_backend_symbol_name(enum hal_module module, char *name, int s /* Check parameter whether is valid or not */ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { _E("Invalid paramer of HAL module (%d)\n", module); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } if (_hal_api_conf_init()) - return TIZEN_ERROR_UNKNOWN; + return -EINVAL; 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_UNKNOWN; + ret = -EINVAL; goto out; } symbol_name = info->symbol_name; if (!symbol_name) { _E("%s backend symbol name is NULL\n", info->module_name); - ret = TIZEN_ERROR_NONE; + ret = 0; goto out; } len_symbol_name = strlen(symbol_name); if (!name || (len_symbol_name + 1 > size)) { - ret = TIZEN_ERROR_UNKNOWN; + ret = -EINVAL; name = NULL; goto out; } strncpy(name, symbol_name, len_symbol_name); name[len_symbol_name] = '\0'; - ret = TIZEN_ERROR_NONE; + ret = 0; out: _hal_api_conf_exit(); @@ -145,14 +144,14 @@ static int __open_backend(struct __hal_module_info *info) if (!backend_library_name) { _E("%s: Failed to get backend library name\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err; } if (!info->symbol_name) { _E("%s: Failed to get backend symbol name\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err; } @@ -160,7 +159,7 @@ static int __open_backend(struct __hal_module_info *info) if (!info->handle) { _E("%s: Failed to load backend library (%s)\n", info->module_name, dlerror()); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err; } @@ -168,7 +167,7 @@ static int __open_backend(struct __hal_module_info *info) if (!info->backend) { _E("%s: Failed to find backend data (%s)\n", info->module_name, dlerror()); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_dlclose; } @@ -212,12 +211,12 @@ static int __init_backend(struct __hal_module_info *info, void **data, if (!info->handle || !info->backend) { _I("%s: Has not yet dlopend backend\n", info->module_name); - return TIZEN_ERROR_NONE; + return 0; } if (!info->backend->init) { _E("%s: hal_backend->init() is NULL\n", info->module_name); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } /* Check HAL ABI Version */ @@ -225,7 +224,7 @@ static int __init_backend(struct __hal_module_info *info, void **data, info->backend->abi_version); if (ret < 0) { _E("%s: Failed to check ABI version\n", info->module_name); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } /* Initialize backend */ @@ -234,10 +233,10 @@ static int __init_backend(struct __hal_module_info *info, void **data, _E("%s: Failed to initialize backend: name(%s)/vendor(%s)\n", info->module_name, info->backend->name, info->backend->vendor); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } - return TIZEN_ERROR_NONE; + return 0; } static int __exit_backend(struct __hal_module_info *info, void *data, @@ -247,7 +246,7 @@ static int __exit_backend(struct __hal_module_info *info, void *data, if (!info->handle || !info->backend) { _I("%s: Has not yet dlopend backend\n", info->module_name); - return TIZEN_ERROR_NONE; + return 0; } /* Exit backend */ @@ -257,7 +256,7 @@ static int __exit_backend(struct __hal_module_info *info, void *data, _E("%s: Failed to exit backend: name(%s)/vendor(%s)\n", info->module_name, info->backend->name, info->backend->vendor); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } } @@ -272,12 +271,12 @@ static int __get_backend(enum hal_module module, void **data, if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { _E("Invalid parameter of HAL module (%d)\n", module); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } G_LOCK(hal_common_lock); if (_hal_api_conf_init()) { - ret = TIZEN_ERROR_UNKNOWN; + ret = -EINVAL; goto err; } @@ -288,7 +287,7 @@ static int __get_backend(enum hal_module module, void **data, else _E("Failed to get HAL module(%d) information (%s)\n", module, library_name); - ret = TIZEN_ERROR_UNKNOWN; + ret = -EINVAL; goto err; } @@ -296,7 +295,7 @@ static int __get_backend(enum hal_module module, void **data, if (ret < 0) { _E("%s: Failed to get the backend library by dlopen\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err; } @@ -304,7 +303,7 @@ static int __get_backend(enum hal_module module, void **data, if (ret < 0) { _E("%s: Failed to initialize the backend library\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_dlclose; } @@ -316,7 +315,7 @@ static int __get_backend(enum hal_module module, void **data, program_invocation_name); G_UNLOCK(hal_common_lock); - return TIZEN_ERROR_NONE; + return 0; err_dlclose: _hal_api_conf_exit(); @@ -335,7 +334,7 @@ static int __put_backend(enum hal_module module, void *data, /* 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; + return -EINVAL; } G_LOCK(hal_common_lock); @@ -343,19 +342,19 @@ static int __put_backend(enum hal_module module, void *data, info = _hal_api_conf_get_module_info(module, library_name); if (info == NULL) { _E("Failed to get HAL module(%d) information\n", module); - ret = TIZEN_ERROR_UNKNOWN; + ret = -EINVAL; goto out; } if (!info->handle || !info->backend) { _I("%s: Has not yet dlopend backend\n", info->module_name); - ret = TIZEN_ERROR_NONE; + ret = 0; goto out; } if (!info->usage_count) { _I("%s: Already fully put for HAL module\n", info->module_name); - ret = TIZEN_ERROR_NONE; + ret = 0; goto out; } @@ -363,7 +362,7 @@ static int __put_backend(enum hal_module module, void *data, if (ret < 0) { _E("%s: Failed to exit the backend library\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto out; } @@ -375,14 +374,14 @@ static int __put_backend(enum hal_module module, void *data, program_invocation_name); if (info->usage_count > 0) { - ret = TIZEN_ERROR_NONE; + ret = 0; goto out; } __close_backend(info); _hal_api_conf_exit(); - ret = TIZEN_ERROR_NONE; + ret = 0; out: G_UNLOCK(hal_common_lock); @@ -418,7 +417,7 @@ static int __get_backend_data(enum hal_module module, unsigned int *abi_version, if (ret < 0) { _E("%s: Failed to get the backend library by dlopen\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_conf_exit; } @@ -432,7 +431,7 @@ static int __get_backend_data(enum hal_module module, unsigned int *abi_version, if (!info->backend->name || (len + 1 > name_size)) { _E("%s: Invalid size of name[] array\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_conf_exit; } @@ -445,7 +444,7 @@ static int __get_backend_data(enum hal_module module, unsigned int *abi_version, if (!info->backend->vendor || (len + 1 > vendor_size)) { _E("%s: Invalid size of vendor[] array\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_conf_exit; } @@ -453,10 +452,10 @@ static int __get_backend_data(enum hal_module module, unsigned int *abi_version, vendor[len] = '\0'; } else { _E("%s: Failed to get backend data\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_conf_exit; } - ret = TIZEN_ERROR_NONE; + ret = 0; err_conf_exit: _hal_api_conf_exit(); @@ -502,30 +501,30 @@ int hal_common_check_backend_abi_version(enum hal_module module, /* Check parameter whether is valid or not */ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { _E("Invalid paramer of HAL module(%d)\n", module); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } if (abi_version <= HAL_ABI_VERSION_UNKNOWN || abi_version >= HAL_ABI_VERSION_END) { _E("Invalid paramer of HAL ABI version(%d) for HAL module(%d)\n", abi_version, module); - return TIZEN_ERROR_INVALID_PARAMETER; + return -EINVAL; } if (_hal_api_conf_init()) - return TIZEN_ERROR_UNKNOWN; + return -EINVAL; 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_UNKNOWN; + ret = -EINVAL; goto out; } /* Check abi_version whether is supported or not */ if (!info->hal_api) { _E("%s: Doesn't support HAL API\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto out; } @@ -533,7 +532,7 @@ int hal_common_check_backend_abi_version(enum hal_module module, || !info->abi_versions) { _E("%s: Doesn't have the ABI version information\n", info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto out; } @@ -549,13 +548,13 @@ int hal_common_check_backend_abi_version(enum hal_module module, data->backend_min_abi_version >= HAL_ABI_VERSION_END) { _E("%s: abi_versions[%d].backend_min_abi_version(%d) is invalid\n", info->module_name, i, data->backend_min_abi_version); - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto out; } if (abi_version <= data->platform_abi_version && abi_version >= data->backend_min_abi_version) { - ret = TIZEN_ERROR_NONE; + ret = 0; goto out; } @@ -568,7 +567,7 @@ int hal_common_check_backend_abi_version(enum hal_module module, hal_abi_version_str[data->backend_min_abi_version], hal_abi_version_str[data->platform_abi_version]); } - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; out: _hal_api_conf_exit(); @@ -620,23 +619,23 @@ static int __get_backend_library_data(enum hal_module module, /* 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; + return -EINVAL; } if (_hal_api_conf_init()) - return TIZEN_ERROR_UNKNOWN; + return -EINVAL; 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; + ret = -EINVAL; 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; + ret = -EINVAL; goto err; } backend_module_name = g_strdup_printf("libhal-backend-%s", @@ -644,7 +643,7 @@ static int __get_backend_library_data(enum hal_module module, if (!backend_module_name) { _E("Failed to allocate the backend_module_name of HAL module(%s)\n", info->module_name); - ret = TIZEN_ERROR_UNKNOWN; + ret = -EINVAL; goto err; } @@ -653,7 +652,7 @@ static int __get_backend_library_data(enum hal_module module, 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; + ret = -EINVAL; goto err_free_backend_module_name; } @@ -675,7 +674,7 @@ static int __get_backend_library_data(enum hal_module module, } if (lib_count > 0 && count != lib_count) { - ret = TIZEN_ERROR_INVALID_PARAMETER; + ret = -EINVAL; goto err_mismatch_count; } -- 2.7.4