From 6c39b97c886d317b624d6f7d6d386cb48aae30dd Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 8 Jan 2021 12:46:15 +0900 Subject: [PATCH 01/16] halapi: common: Change the parameter name of helper functions for readability hal-api-common's helper functions have the 'enum hal_module' as first parameter. In order to improve the readability, replace parameter name from 'handle' to 'module'. Change-Id: I3baa384885d9e5225987f143d4b1951c4b6aedd6 Signed-off-by: Chanwoo Choi --- include/hal-common.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index e25503b..9df3d31 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -105,7 +105,7 @@ enum hal_module { * @return @c backend library name on success and don't need to be freed * due to the global variable, otherwise NULL. */ -const char *hal_common_get_backend_library_name(enum hal_module handle); +const char *hal_common_get_backend_library_name(enum hal_module module); /** * @brief Get the backend symbol name according to the type of HAL module @@ -113,7 +113,7 @@ const char *hal_common_get_backend_library_name(enum hal_module handle); * @return @c backend library name on success and don't need to be freed * due to the global variable, otherwise NULL. */ -const char *hal_common_get_backend_symbol_name(enum hal_module handle); +const char *hal_common_get_backend_symbol_name(enum hal_module module); /** * @brief Get the backend data according to the type of HAL module @@ -122,7 +122,7 @@ const char *hal_common_get_backend_symbol_name(enum hal_module handle); * should be stored from HAL backend binary. * @return @c 0 on success, otherwise a negative error value */ -int hal_common_get_backend(enum hal_module handle, void **data); +int hal_common_get_backend(enum hal_module module, void **data); /** * @brief Put the backend data according to the type of HAL module @@ -130,7 +130,7 @@ int hal_common_get_backend(enum hal_module handle, void **data); * @param[in] Data pointer where 'hal_backend_[module]_funcs' instance * @return @c 0 on success, otherwise a negative error value */ -int hal_common_put_backend(enum hal_module handle, void *data); +int hal_common_put_backend(enum hal_module module, void *data); /** * @brief Check HAL ABI version whehter is suppored or not on current platform @@ -138,7 +138,7 @@ int hal_common_put_backend(enum hal_module handle, void *data); * @param[in] HAL ABI version of backend module among enum hal_abi_version * @return @c 0 on success, otherwise a negative error value */ -int hal_common_check_backend_abi_version(enum hal_module handle, +int hal_common_check_backend_abi_version(enum hal_module module, enum hal_abi_version abi_version); #ifdef __cplusplus -- 2.7.4 From 415c591303fca1ea627f277b620b7f71914973b6 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Mon, 11 Jan 2021 08:03:47 +0900 Subject: [PATCH 02/16] halapi: common: Add hal_api_version_str array and an error message Add hal_api_version_str array to display as string after converting each enum value. It's easier to understand than using enum value. If abi version doesn't support about current version and compatible version, then it needs to notice about not supporting abi_version. Change-Id: I67f31423a4b9d911b269d8c7560c9907a6bafc8b Signed-off-by: Jaehoon Chung --- include/hal-common-interface.h | 5 +++++ src/hal-api-common.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/hal-common-interface.h b/include/hal-common-interface.h index 39831b9..dab26cb 100644 --- a/include/hal-common-interface.h +++ b/include/hal-common-interface.h @@ -29,6 +29,11 @@ enum hal_abi_version { HAL_ABI_VERSION_END, }; +static const char *const hal_abi_version_str[] = { + [HAL_ABI_VERSION_UNKNOWN] = "Unknown HAL ABI Version", + [HAL_ABI_VERSION_TIZEN_6_5] = "HAL_ABI_VERSION_TIZEN_6_5", +}; + typedef struct __hal_backend { const char *name; const char *vendor; diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 9f47636..61ef60c 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -222,6 +222,12 @@ int hal_common_check_backend_abi_version(enum hal_module module, if (abi_version <= data->curr_version && abi_version >= data->compat_version) return TIZEN_ERROR_NONE; + + _E("%s doesn't support %s of HAL Backend\n", hal_abi_version_str[g_curr_hal_abi_version], + hal_abi_version_str[abi_version]); + _E("Must use the following ABI versions from %s to %s\n", + hal_abi_version_str[data->compat_version], + hal_abi_version_str[data->curr_version]); } return TIZEN_ERROR_INVALID_PARAMETER; -- 2.7.4 From b615b27655bbaae210b76483f3760cd1791a2a8c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 11 Jan 2021 15:00:55 +0900 Subject: [PATCH 03/16] halapi: common: Change variable name for improving the readability Change the variable name for improving the readability because prior defined variable name is vague to pass the correct meaning of version. So that change the name as following in order to improve the readability and understanding. [Chagned variable names] - g_curr_hal_abi_version -> g_platform_curr_abi_version - current_version -> platform_abi_version - compat_version -> backend_min_abi_version Change-Id: I733b203a6c0fe058dedb6e9e26f832a0629ccc15 Signed-off-by: Chanwoo Choi --- src/common.h | 122 +++++++++++++++++++++++++-------------------------- src/hal-api-common.c | 12 ++--- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/common.h b/src/common.h index 39ab920..7f9dadf 100644 --- a/src/common.h +++ b/src/common.h @@ -36,35 +36,35 @@ * and HAL backend package like hal-backend-audio-*.rpm which is included * in hal.img. In order to compare ABI version between two binary, * Tizen core platform always must maintain the current HAL ABI version. - * So that, define the below global variable (g_curr_hal_abi_version). + * So that, define the below global variable (g_platform_curr_abi_version). * - * 'g_curr_hal_abi_version' will be used for all HAL API modules, + * 'g_platform_curr_abi_version' will be used for all HAL API modules, * to check whether HAL backend ABI version of each module in hal.img * is supported or not with current Tizen core HAL ABI version. * - * 'g_curr_hal_abi_version' must be updated when Tizen platform will be released - * officially. + * 'g_platform_curr_abi_version' must be updated when Tizen platform + * will be released officially. */ /* FIXME: Need to be initialized by configuration file like xml */ -enum hal_abi_version g_curr_hal_abi_version = HAL_ABI_VERSION_TIZEN_6_5; +enum hal_abi_version g_platform_curr_abi_version = HAL_ABI_VERSION_TIZEN_6_5; struct hal_abi_version_match { - enum hal_abi_version curr_version; - enum hal_abi_version compat_version; + enum hal_abi_version platform_abi_version; + enum hal_abi_version backend_min_abi_version; } abi_version_match_data[HAL_MODULE_END][HAL_ABI_VERSION_MAX] = { /* HAL_GROUP_GRAPHICS */ [HAL_MODULE_TBM] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_TDM] = { /* FIXME: Need to be filled from configuration file. */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_COREGL] = { @@ -84,22 +84,22 @@ struct hal_abi_version_match { [HAL_MODULE_AUDIO] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_CAMERA] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_RADIO] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_CODEC] = { @@ -125,15 +125,15 @@ struct hal_abi_version_match { [HAL_MODULE_BLUETOOTH] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_WIFI] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_NAN] = { @@ -141,22 +141,22 @@ struct hal_abi_version_match { [HAL_MODULE_NFC] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_ZIGBEE] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_UWB] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_MTP] = { @@ -170,8 +170,8 @@ struct hal_abi_version_match { [HAL_MODULE_TELPEPHONY] = { /* FIXME: Need to be determined whehter support HAL API or not. */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, @@ -179,8 +179,8 @@ struct hal_abi_version_match { [HAL_MODULE_LOCATION] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, @@ -190,100 +190,100 @@ struct hal_abi_version_match { [HAL_MODULE_POWER] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_SENSOR] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_PERIPHERAL] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_BATTERY] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_BEZEL] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_DISPLAY] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_IR] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_TOUCHSCREEN] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_LED] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_BOARD] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_THERMAL] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_USB_GADGET] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, [HAL_MODULE_DEVICE_HAPTIC] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, @@ -292,8 +292,8 @@ struct hal_abi_version_match { [HAL_MODULE_FOO] = { /* FIXME: Need to be initialized by configuration file like xml */ [0] = { - .curr_version = HAL_ABI_VERSION_TIZEN_6_5, - .compat_version = HAL_ABI_VERSION_TIZEN_6_5, + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, }; diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 61ef60c..896691c 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -216,18 +216,18 @@ int hal_common_check_backend_abi_version(enum hal_module module, struct hal_abi_version_match *data = &hal_module_info[module].abi_versions[i]; - if (g_curr_hal_abi_version != data->curr_version) + if (g_platform_curr_abi_version != data->platform_abi_version) continue; - if (abi_version <= data->curr_version - && abi_version >= data->compat_version) + if (abi_version <= data->platform_abi_version + && abi_version >= data->backend_min_abi_version) return TIZEN_ERROR_NONE; - _E("%s doesn't support %s of HAL Backend\n", hal_abi_version_str[g_curr_hal_abi_version], + _E("%s doesn't support %s of HAL Backend\n", hal_abi_version_str[g_platform_curr_abi_version], hal_abi_version_str[abi_version]); _E("Must use the following ABI versions from %s to %s\n", - hal_abi_version_str[data->compat_version], - hal_abi_version_str[data->curr_version]); + hal_abi_version_str[data->backend_min_abi_version], + hal_abi_version_str[data->platform_abi_version]); } return TIZEN_ERROR_INVALID_PARAMETER; -- 2.7.4 From b7115a417e172637844acb3e2229161d915bd989 Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Tue, 12 Jan 2021 17:52:23 +0900 Subject: [PATCH 04/16] Fix wrong spelling HAL_MODULE_TELPEPHONY -> HAL_MODULE_TELEPHONY Change-Id: Ie3b77e9b3839de8306e2c49e10bdeb4b3fe91744 Signed-off-by: Seungha Son --- include/hal-common.h | 2 +- src/common.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index 9df3d31..09df968 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -72,7 +72,7 @@ enum hal_module { HAL_MODULE_MTP, /* HAL_GROUP_TELEPHONY */ - HAL_MODULE_TELPEPHONY = 45, + HAL_MODULE_TELEPHONY = 45, /* HAL_GROUP_LOCATION */ HAL_MODULE_LOCATION = 50, diff --git a/src/common.h b/src/common.h index 7f9dadf..c8b263b 100644 --- a/src/common.h +++ b/src/common.h @@ -167,7 +167,7 @@ struct hal_abi_version_match { }, /* HAL_GROUP_TELEPHONY */ - [HAL_MODULE_TELPEPHONY] = { + [HAL_MODULE_TELEPHONY] = { /* FIXME: Need to be determined whehter support HAL API or not. */ [0] = { .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, @@ -526,9 +526,9 @@ static struct __hal_module_info { }, /* HAL_GROUP_TELEPHONY */ - [HAL_MODULE_TELPEPHONY] = { + [HAL_MODULE_TELEPHONY] = { .group = HAL_GROUP_TELEPHONY, - .module = HAL_MODULE_TELPEPHONY, + .module = HAL_MODULE_TELEPHONY, .license = HAL_LICENSE_APACHE_2_0, .module_name = "TELEPHONY", .library_name = NULL, -- 2.7.4 From 9b018a5842c4c37d479e2e820ea03b63b1455c69 Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Fri, 8 Jan 2021 16:52:23 +0900 Subject: [PATCH 05/16] Add hal-api-common uniitest skeleton This test will run automatically when building gbs. The result can be checked by the developer and the side effect of the edited content can be checked. it is a test for the currently implemented operation, and a test for applying TDD in the future. Change-Id: I5af141dbb601524ff517b78e7cc970323ed138fc Signed-off-by: Seungha Son --- CMakeLists.txt | 4 +++- haltests/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ haltests/src/test_hal.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ haltests/src/test_main.cc | 37 +++++++++++++++++++++++++++++++++++++ packaging/hal-api-common.spec | 4 ++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 haltests/CMakeLists.txt create mode 100644 haltests/src/test_hal.cc create mode 100644 haltests/src/test_main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index fc2b438..060a688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(hal-api-common C) +PROJECT(hal-api-common C CXX) SET(VERSION_MAJOR 0) SET(VERSION "${VERSION_MAJOR}.1.0") @@ -46,3 +46,5 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h") INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) + +ADD_SUBDIRECTORY(haltests) diff --git a/haltests/CMakeLists.txt b/haltests/CMakeLists.txt new file mode 100644 index 0000000..30a7992 --- /dev/null +++ b/haltests/CMakeLists.txt @@ -0,0 +1,30 @@ +ENABLE_TESTING() +SET(HAL_COMMON_UNITTEST "common-unittest") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g -Wall -Werror") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -g -Wall -Werror") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed,--gc-sections -pie") + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNITTEST_SRCS) +ADD_EXECUTABLE(${HAL_COMMON_UNITTEST} ${UNITTEST_SRCS}) + +TARGET_INCLUDE_DIRECTORIES(${HAL_COMMON_UNITTEST} PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/../include" + "${CMAKE_CURRENT_SOURCE_DIR}/../src" +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(hal_common_unittest_pkgs REQUIRED gmock) + +FOREACH(flag ${hal_common_unittest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +TARGET_LINK_LIBRARIES(${HAL_COMMON_UNITTEST} ${hal_common_unittest_pkgs_LDFLAGS} hal-api-common) +SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES LINK_FLAGS "-pie") + +ADD_TEST( + NAME ${HAL_COMMON_UNITTEST} + COMMAND ${HAL_COMMON_UNITTEST} +) diff --git a/haltests/src/test_hal.cc b/haltests/src/test_hal.cc new file mode 100644 index 0000000..cb51371 --- /dev/null +++ b/haltests/src/test_hal.cc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "hal-common.h" +#include "hal-common-interface.h" + +using namespace std; + +class CommonHaltest : public testing::Test { + public: + CommonHaltest() {} + + virtual ~CommonHaltest() {} + + virtual void SetUp() {} + + virtual void TearDown() {} +}; + +TEST(CommonHaltest, get_backend_library_name_unknown) { + const char *ret = hal_common_get_backend_library_name(HAL_MODULE_UNKNOWN); + EXPECT_TRUE(ret == nullptr); +} diff --git a/haltests/src/test_main.cc b/haltests/src/test_main.cc new file mode 100644 index 0000000..c2eb730 --- /dev/null +++ b/haltests/src/test_main.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +int main(int argc, char** argv) { + int ret = -1; + + try { + testing::InitGoogleTest(&argc, argv); + } catch(...) { + std::cout << "Exception occurred" << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& e) { + ret = -1; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + } + + return ret; +} diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 9704ee6..b6e21ee 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -17,6 +17,7 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmock) %description %{name} interface @@ -40,6 +41,9 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir}/ cp %{SOURCE1} . make %{?jobs:-j%jobs} +%check +(cd haltests && LD_LIBRARY_PATH=../ ctest -V) + %install rm -rf %{buildroot} %make_install -- 2.7.4 From 6735d5d11651e59b3b5d749b7af28fcec19302dd Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Thu, 14 Jan 2021 18:57:06 +0900 Subject: [PATCH 06/16] halapi: Include stdbool header for common.h The stdbool.h file is required to use the bool data type. Change-Id: I0cc08f2a0229bfb64ddbcf46c1cd69da1a183c82 Signed-off-by: Seungha Son --- src/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common.h b/src/common.h index c8b263b..4121c1b 100644 --- a/src/common.h +++ b/src/common.h @@ -17,6 +17,7 @@ #ifndef __COMMON_H__ #define __COMMON_H__ +#include #include #include "hal-common.h" -- 2.7.4 From 586e27a77f64145dcb5878c97b2fea211e26c846 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 18 Jan 2021 19:48:06 +0900 Subject: [PATCH 07/16] halapi: Fix fault by using backend instance before dlclose backend library When try to use backend->name, backend->vendor variables after dlclose(handle) of HAL backend shared library, segmentation fault happen. So that move dlclose(hanlde) at the end of hal_common_put_backend() to fix the segmentation fault. Change-Id: Icc89e26b0ff11706657f1bfdeff16eba17f255d9 Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 896691c..b07765d 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -172,11 +172,14 @@ int hal_common_put_backend(enum hal_module module, void *data) } } + _I("Put HAL backend: name(%s)/vendor(%s)\n", + backend->name, backend->vendor); + if (handle) dlclose(handle); - _I("Put HAL backend: name(%s)/vendor(%s)\n", - backend->name, backend->vendor); + hal_module_info[module].library_backend = NULL; + hal_module_info[module].library_handle = NULL; return TIZEN_ERROR_NONE; } -- 2.7.4 From 3403d9e6b8ba05af3cf54f551797946fae4b2934 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 19 Jan 2021 09:35:10 +0900 Subject: [PATCH 08/16] halapi: Add /etc/ld.so.conf.d/libhal-api.conf A ldd and ldconfig commands do not work. Example1) "ldd /usr/bin/deviced | grep libhal-api-common" Example2) "ldconfig -p | grep libhal-api-common" Change-Id: I42d0ece00df2ebd4ef36e4f215140a31204397b0 Signed-off-by: INSUN PYO --- packaging/hal-api-common.spec | 5 +++++ packaging/libhal-api.conf | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 packaging/libhal-api.conf diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index b6e21ee..1831a56 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -10,6 +10,7 @@ Group: Development/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: %{name}.manifest +Source2: libhal-api.conf Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -48,6 +49,9 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install +mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d/ +install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/ + %clean rm -rf %{buildroot} @@ -63,6 +67,7 @@ rm -rf %{buildroot} %manifest %{name}.manifest %defattr(-,root,root,-) %{_libdir}/hal/*.so* +%{_sysconfdir}/ld.so.conf.d/libhal-api.conf %files -n %{devel_name} %defattr(-,root,root,-) diff --git a/packaging/libhal-api.conf b/packaging/libhal-api.conf new file mode 100644 index 0000000..b275885 --- /dev/null +++ b/packaging/libhal-api.conf @@ -0,0 +1,2 @@ +/usr/lib/hal +/usr/lib64/hal -- 2.7.4 From e87d1e2372f7b69b3dc723c22e0ec824fbcc557b Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Wed, 20 Jan 2021 09:42:28 +0900 Subject: [PATCH 09/16] packaging: create hal directory to use backend packages If hal.img will be split from core image, it has to exist hal directory under root directory before mounting hal.img. Otherwise, it can't mount anywhere to use hal-backend. This patch is for preparing to use hal.img. - The mounting hal.img will be did in ramdisk. Change-Id: I8ef56c0e383e142269c4164d7cfeba9560fbb039 Signed-off-by: Jaehoon Chung --- packaging/hal-api-common.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 1831a56..edb494a 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -50,6 +50,7 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d/ +mkdir -p %{buildroot}/hal install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/ %clean @@ -68,6 +69,7 @@ rm -rf %{buildroot} %defattr(-,root,root,-) %{_libdir}/hal/*.so* %{_sysconfdir}/ld.so.conf.d/libhal-api.conf +/hal/ %files -n %{devel_name} %defattr(-,root,root,-) -- 2.7.4 From e4c687e484e1025a33c8e88dfef4a53780381a67 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 20 Jan 2021 13:42:47 +0900 Subject: [PATCH 10/16] packaging: Remove redundant separator The spec file has passed the redundant separator ('/') with %{_libdir}. It is not needed. So that remove it. Change-Id: I531f6a6449e6ab3defec82bb4383ecc22045dc20 Signed-off-by: Chanwoo Choi --- packaging/hal-api-common.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index edb494a..9ec7b05 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -36,7 +36,7 @@ Requires: %{name} = %{version}-%{release} %prep %setup -q -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir}/ +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} %build cp %{SOURCE1} . -- 2.7.4 From 3cf50c793cfacd86070409222b851a718c885c80 Mon Sep 17 00:00:00 2001 From: Chang Joo Lee Date: Thu, 21 Jan 2021 13:11:18 +0900 Subject: [PATCH 11/16] halapi: Fix pkgconfig .pc file about libdir The commit e4c687e484e1 ("packaging: Remove redundant separator") has missed the update of .pc file. This patch fix the wrong path issue. Change-Id: I26847c506dcd801030ed616822fccca8595f97ef Fixes: e4c687e484e1 ("packaging: Remove redundant separator") Signed-off-by: Chang Joo Lee Signed-off-by: Chanwoo Choi --- hal-api-common.pc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hal-api-common.pc b/hal-api-common.pc index 5a281de..782a604 100644 --- a/hal-api-common.pc +++ b/hal-api-common.pc @@ -3,7 +3,7 @@ package_name=hal-api-common prefix=@PREFIX@ exec_prefix=@EXEC_PREFIX@/hal -libdir=@LIBDIR@hal +libdir=@LIBDIR@/hal includedir=@INCLUDEDIR@/hal Name: ${package_name} -- 2.7.4 From 4031522707edd041f57c1b149c018af0c4a60490 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Wed, 27 Jan 2021 09:27:40 +0900 Subject: [PATCH 12/16] halapi: fix wrong module's number about CODEC Fix wrong module's number about CODEC. It's not HAL_MODULE_UNKNOWN. Change-Id: I9cdc3d58ee2feb3bf5137d973972033741c8e352 Signed-off-by: Jaehoon Chung --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 4121c1b..f07d7c6 100644 --- a/src/common.h +++ b/src/common.h @@ -405,7 +405,7 @@ static struct __hal_module_info { }, [HAL_MODULE_CODEC] = { .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_UNKNOWN, + .module = HAL_MODULE_CODEC, .license = HAL_LICENSE_APACHE_2_0, .module_name = "CODEC", .library_name = NULL, -- 2.7.4 From f0ab0f8bc72ecb9c2c27d0c46efcb93c97636a2d Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 29 Jan 2021 16:52:35 +0900 Subject: [PATCH 13/16] halapi: Ignore already fully put hal backend In hal_common_put_backend(), requested module backend can be already put fully. For the case, ignore the hal backend. Change-Id: I7eef57fa12273760d28b22738ee878ac423da651 Signed-off-by: Seung-Woo Kim --- src/hal-api-common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index b07765d..c4e2372 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -163,7 +163,12 @@ int hal_common_put_backend(enum hal_module module, void *data) backend = hal_module_info[module].library_backend; handle = hal_module_info[module].library_handle; - if (backend && backend->exit) { + if (!backend) { + _I("Already fully put for HAL module (%d)\n", module); + return TIZEN_ERROR_NONE; + } + + if (backend->exit) { ret = backend->exit(data); if (ret < 0) { _E("Failed to exit backend: name(%s)/vendor(%s)\n", -- 2.7.4 From 4dbcdebdac3dc54df2c4fe0efaa32cbccabbf4f8 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 29 Jan 2021 19:27:56 +0900 Subject: [PATCH 14/16] halapi: Check enum range for backend_abi_min_version To avoid out-of-bounds access of version str array, check value range for data->backend_abi_min_version always. Change-Id: I3fb05ab9a27394f817937b589ce7751da0467a69 Signed-off-by: Seung-Woo Kim --- src/hal-api-common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index c4e2372..c476024 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -227,6 +227,13 @@ int hal_common_check_backend_abi_version(enum hal_module module, if (g_platform_curr_abi_version != data->platform_abi_version) continue; + if (data->backend_min_abi_version <= HAL_ABI_VERSION_UNKNOWN || + data->backend_min_abi_version >= HAL_ABI_VERSION_END) { + _E("wrong data in backend_min_abi_version %d\n", + data->backend_min_abi_version); + return TIZEN_ERROR_INVALID_PARAMETER; + } + if (abi_version <= data->platform_abi_version && abi_version >= data->backend_min_abi_version) return TIZEN_ERROR_NONE; -- 2.7.4 From 40f47d6fccef8f53e3e7be6d7d328fc024f6c5c5 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 2 Feb 2021 15:46:54 +0900 Subject: [PATCH 15/16] halapi: Fix cpp build issue when including hal-common.h If the defined enum value is not sequential, some build error happen as following. So that fix this issue by making enum hal_module sequential. And remove the temporary defined HAL_MODULE_FOO. [Build error message with cpp compiler] "sorry, unimplemented: non-trivial designated initializers not supported " Change-Id: I8dcd8c7c11807d8873d8e92413e4137ce84a3c6f Signed-off-by: Chanwoo Choi --- include/hal-common.h | 20 +++++++++++--------- src/common.h | 24 ------------------------ 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index 09df968..daffd14 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -41,7 +41,6 @@ enum hal_group { HAL_GROUP_TELEPHONY, HAL_GROUP_LOCATION, HAL_GROUP_SYSTEM, - HAL_GROUP_MISCELLANEOUS, HAL_GROUP_END, }; @@ -49,13 +48,13 @@ enum hal_module { HAL_MODULE_UNKNOWN = 0, /* HAL_GROUP_GRAPHICS */ - HAL_MODULE_TBM = 1, + HAL_MODULE_TBM, HAL_MODULE_TDM, HAL_MODULE_COREGL, HAL_MODULE_INPUT, /* HAL_GROUP_MULTIMEDIA */ - HAL_MODULE_AUDIO = 15, + HAL_MODULE_AUDIO, HAL_MODULE_CAMERA, HAL_MODULE_RADIO, HAL_MODULE_CODEC, @@ -63,7 +62,7 @@ enum hal_module { HAL_MODULE_ALSAUCM, /* HAL_GROUP_CONNECTIVITY */ - HAL_MODULE_BLUETOOTH = 30, + HAL_MODULE_BLUETOOTH, HAL_MODULE_WIFI, HAL_MODULE_NAN, HAL_MODULE_NFC, @@ -72,13 +71,13 @@ enum hal_module { HAL_MODULE_MTP, /* HAL_GROUP_TELEPHONY */ - HAL_MODULE_TELEPHONY = 45, + HAL_MODULE_TELEPHONY, /* HAL_GROUP_LOCATION */ - HAL_MODULE_LOCATION = 50, + HAL_MODULE_LOCATION, /* HAL_GROUP_SYSTEM */ - HAL_MODULE_COMMON = 55, + HAL_MODULE_COMMON, HAL_MODULE_POWER, HAL_MODULE_SENSOR, HAL_MODULE_PERIPHERAL, @@ -94,8 +93,11 @@ enum hal_module { HAL_MODULE_DEVICE_USB_GADGET, HAL_MODULE_DEVICE_HAPTIC, - /* HAL_GROUP_MISCELLANEOUS */ - HAL_MODULE_FOO, /* FIXME: Add for test and will be removed */ + /* + * TODO: If need to add new module, have to add it below + * without modifying already defined module id. + */ + HAL_MODULE_END, }; diff --git a/src/common.h b/src/common.h index f07d7c6..af1a0f1 100644 --- a/src/common.h +++ b/src/common.h @@ -287,16 +287,6 @@ struct hal_abi_version_match { .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, }, }, - - /* FIXME: Add for test and will be removed */ - /* HAL_GROUP_MISCELLANEOUS */ - [HAL_MODULE_FOO] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, }; static struct __hal_module_info { @@ -734,20 +724,6 @@ static struct __hal_module_info { .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_HAPTIC], .hal_api = true, }, - - /* HAL_GROUP_MISCELLANEOUS */ - [HAL_MODULE_FOO] = { /* FIXME: Add for test and will be removed */ - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_FOO, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "FOO", - .library_name = "/hal/lib/libhal-backend-foo.so", - .library_name_64bit = "/hal/lib64/libhal-backend-foo.so", - .symbol_name = "hal_backend_foo_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_FOO]), - .abi_versions = abi_version_match_data[HAL_MODULE_FOO], - .hal_api = true, - }, }; #endif /* __COMMON_H__ */ -- 2.7.4 From ddde380816ced0386888ae8dce8044b1ad129e75 Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Tue, 12 Jan 2021 13:56:35 +0900 Subject: [PATCH 16/16] halapi: Add configuration feature The purpose of this patch is to change the way hal-related information is managed. The information specified in the header file is changed to json format and can be changed at runtime. so that the information changed at runtime can be used without recompiling the library. A testcase to verify the saved json data was added and this testcase is ran at build time. Change-Id: Ia9b83dfa18ea370ed4a3ce680c36a9f39317c6ff Signed-off-by: Seungha Son --- CMakeLists.txt | 9 +- hal-api.json | 429 +++++++++++++++++++++++++++ haltests/CMakeLists.txt | 10 +- haltests/src/test_hal.cc | 247 +++++++++++++++- include/hal-common.h | 62 ++++ packaging/hal-api-common.spec | 9 +- src/common.h | 667 +----------------------------------------- src/hal-api-common.c | 83 ++++-- src/hal-api-conf.c | 330 +++++++++++++++++++++ src/hal-api-conf.h | 42 +++ 10 files changed, 1195 insertions(+), 693 deletions(-) create mode 100644 hal-api.json create mode 100644 src/hal-api-conf.c create mode 100644 src/hal-api-conf.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 060a688..5409058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(hal-api-common C CXX) +PROJECT(hal-api-common) SET(VERSION_MAJOR 0) SET(VERSION "${VERSION_MAJOR}.1.0") @@ -10,11 +10,14 @@ SET(INCLUDEDIR "${PREFIX}/include") SET(LIBDIR ${CMAKE_LIBDIR_PREFIX}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) SET(PKG_MODULES dlog gio-2.0 glib-2.0 + json-glib-1.0 + libtzplatform-config ) INCLUDE(FindPkgConfig) @@ -32,7 +35,8 @@ SET(CMAKE_EXE_LINKER_FLAGS "-pie") ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_COMMON\"") SET(SRCS - src/hal-api-common.c) + src/hal-api-common.c + src/hal-api-conf.c) ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined) @@ -46,5 +50,6 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h") INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/hal-api.json DESTINATION /etc/hal) ADD_SUBDIRECTORY(haltests) diff --git a/hal-api.json b/hal-api.json new file mode 100644 index 0000000..67adc3c --- /dev/null +++ b/hal-api.json @@ -0,0 +1,429 @@ +{ + "PLATFORM_ABI_VERSION" :"HAL_ABI_VERSION_TIZEN_6_5", + "MODULE_INFO" : + { + "HAL_GROUP_GRAPHICS" : + [ + { + "module" :"HAL_MODULE_TBM", + "license" :"MIT", + "library_name" :"/hal/lib/libhal-backend-tbm.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-tbm.so", + "symbol_name" :"hal_backend_tbm_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_TDM", + "license" :"MIT", + "library_name" :"/hal/lib/libhal-backend-tdm.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-tdm.so", + "symbol_name" :"hal_backend_tdm_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_COREGL", + "license" :"UNKNOWN", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + }, + { + "module" :"HAL_MODULE_INPUT", + "license" :"MIT", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + + } + ], + + "HAL_GROUP_MULTIMEDIA": + [ + { + "module" :"HAL_MODULE_AUDIO", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-audio.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-audio.so", + "symbol_name" :"hal_backend_audio_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_CAMERA", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-camera.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-camera.so", + "symbol_name" :"hal_backend_camera_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_RADIO", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-radio.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-radio.so", + "symbol_name" :"hal_backend_radio_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_CODEC", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + }, + { + "module" :"HAL_MODULE_USB_AUDIO", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + }, + { + "module" :"HAL_MODULE_ALSAUCM", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + } + ], + + "HAL_GROUP_CONNECTIVITY": + [ + { + "module" :"HAL_MODULE_BLUETOOTH", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-bluetooth.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-bluetooth.so", + "symbol_name" :"hal_backend_bluetooth_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_WIFI", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-wifi.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-wifi.so", + "symbol_name" :"hal_backend_wifi_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_NAN", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + }, + { + "module" :"HAL_MODULE_NFC", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-nfc.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-nfc.so", + "symbol_name" :"hal_backend_nfc_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_ZIGBEE", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-zigbee.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-zigbee.so", + "symbol_name" :"hal_backend_zigbee_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + + }, + { + "module" :"HAL_MODULE_UWB", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-uwb.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-uwb.so", + "symbol_name" :"hal_backend_uwb_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_MTP", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + } + + ], + + "HAL_GROUP_TELEPHONY" : + [ + { + "module" :"HAL_MODULE_TELEPHONY", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + } + ], + + "HAL_GROUP_LOCATION" : + [ + { + "module" :"HAL_MODULE_LOCATION", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-location.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-location.so", + "symbol_name" :"hal_backend_location_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + } + ], + + "HAL_GROUP_SYSTEM" : + [ + { + "module" :"HAL_MODULE_COMMON", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + }, + { + "module" :"HAL_MODULE_POWER", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-power.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-power.so", + "symbol_name" :"hal_backend_power_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_SENSOR", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-sensor.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-sensor.so", + "symbol_name" :"hal_backend_sensor_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_PERIPHERAL", + "license" :"APACHE_2_0", + "library_name" :null, + "library_name_64bit" :null, + "symbol_name" :null, + "abi_versions" :null + }, + { + "module" :"HAL_MODULE_DEVICE_BATTERY", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-battery.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-battery.so", + "symbol_name" :"hal_backend_device_battery_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_BEZEL", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-bezel.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-bezel.so", + "symbol_name" :"hal_backend_device_bezel_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_DISPLAY", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-display.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-display.so", + "symbol_name" :"hal_backend_device_display_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_IR", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-ir.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-ir.so", + "symbol_name" :"hal_backend_device_ir_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_TOUCHSCREEN", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-touchscreen.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-touchscreen.so", + "symbol_name" :"hal_backend_device_touchscreen_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_LED", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-led.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-led.so", + "symbol_name" :"hal_backend_device_led_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_BOARD", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-board.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-board.so", + "symbol_name" :"hal_backend_device_board_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_EXTERNAL_CONNECTION", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-external-connection.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-external-connection.so", + "symbol_name" :"hal_backend_device_external_connection_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_THERMAL", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-thermal.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-thermal.so", + "symbol_name" :"hal_backend_device_thermal_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_USB_GADGET", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-usb-gadget.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-usb-gadget.so", + "symbol_name" :"hal_backend_device_usb_gadget_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + }, + { + "module" :"HAL_MODULE_DEVICE_HAPTIC", + "license" :"APACHE_2_0", + "library_name" :"/hal/lib/libhal-backend-device-haptic.so", + "library_name_64bit" :"/hal/lib64/libhal-backend-device-haptic.so", + "symbol_name" :"hal_backend_device_haptic_data", + "abi_versions" :[ + { + "platform_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5", + "backend_min_abi_version" :"HAL_ABI_VERSION_TIZEN_6_5" + } + ] + } + ] + } +} diff --git a/haltests/CMakeLists.txt b/haltests/CMakeLists.txt index 30a7992..2ed429c 100644 --- a/haltests/CMakeLists.txt +++ b/haltests/CMakeLists.txt @@ -1,16 +1,14 @@ ENABLE_TESTING() SET(HAL_COMMON_UNITTEST "common-unittest") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g -Wall -Werror") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -g -Wall -Werror") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed,--gc-sections -pie") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Werror") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -Wall -Werror") AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNITTEST_SRCS) ADD_EXECUTABLE(${HAL_COMMON_UNITTEST} ${UNITTEST_SRCS}) TARGET_INCLUDE_DIRECTORIES(${HAL_COMMON_UNITTEST} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include" - "${CMAKE_CURRENT_SOURCE_DIR}/../src" ) INCLUDE(FindPkgConfig) @@ -20,8 +18,8 @@ FOREACH(flag ${hal_common_unittest_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -TARGET_LINK_LIBRARIES(${HAL_COMMON_UNITTEST} ${hal_common_unittest_pkgs_LDFLAGS} hal-api-common) -SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES COMPILE_FLAGS "-fPIE") +TARGET_LINK_LIBRARIES(${HAL_COMMON_UNITTEST} ${hal_common_unittest_pkgs_LDFLAGS} ${PROJECT_NAME}) +SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default") SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES LINK_FLAGS "-pie") ADD_TEST( diff --git a/haltests/src/test_hal.cc b/haltests/src/test_hal.cc index cb51371..1042adb 100644 --- a/haltests/src/test_hal.cc +++ b/haltests/src/test_hal.cc @@ -14,29 +14,268 @@ * limitations under the License. */ +#include + #include +#include -#include #include #include #include "hal-common.h" #include "hal-common-interface.h" +#include "../../src/hal-api-conf.h" +#include "../../src/common.h" + using namespace std; + +extern "C" const char *tzplatform_mkpath( + enum tzplatform_variable id, const char *path) { + return "../hal-api.json"; +} + class CommonHaltest : public testing::Test { public: CommonHaltest() {} - virtual ~CommonHaltest() {} - virtual void SetUp() {} - virtual void TearDown() {} }; +TEST(CommonHaltest, test_symbol_name_invalid_module) { + const char *ret_unknown = hal_common_get_backend_symbol_name(HAL_MODULE_UNKNOWN); + EXPECT_TRUE(ret_unknown == nullptr); + + const char *ret_end = hal_common_get_backend_symbol_name(HAL_MODULE_END); + EXPECT_TRUE(ret_end == nullptr); +} + +TEST(CommonHaltest, test_check_backend_abi_version_invalid_parameter) { + int ret; + + ret = hal_common_check_backend_abi_version(HAL_MODULE_UNKNOWN, HAL_ABI_VERSION_TIZEN_6_5); + EXPECT_EQ(ret, TIZEN_ERROR_INVALID_PARAMETER); + + ret = hal_common_check_backend_abi_version(HAL_MODULE_END, HAL_ABI_VERSION_TIZEN_6_5); + EXPECT_EQ(ret, TIZEN_ERROR_INVALID_PARAMETER); + + ret = hal_common_check_backend_abi_version(HAL_MODULE_TBM, HAL_ABI_VERSION_UNKNOWN); + EXPECT_EQ(ret, TIZEN_ERROR_INVALID_PARAMETER); + + ret = hal_common_check_backend_abi_version(HAL_MODULE_TBM, HAL_ABI_VERSION_END); + EXPECT_EQ(ret, TIZEN_ERROR_INVALID_PARAMETER); +} + TEST(CommonHaltest, get_backend_library_name_unknown) { const char *ret = hal_common_get_backend_library_name(HAL_MODULE_UNKNOWN); EXPECT_TRUE(ret == nullptr); } + +class HalInfo { +public: + enum hal_module module_; + enum hal_group group_; + enum hal_license license_; + const char *module_name_; + const char *library_name_; + const char *library_name_64bit_; + const char *symbol_name_; + + HalInfo(enum hal_module module, enum hal_group group, enum hal_license license, + const char *module_name, const char *library_name, const char *library_name_64bit, const char *symbol_name) : + module_(module), group_(group), license_(license), + module_name_(module_name), library_name_(library_name), + library_name_64bit_(library_name_64bit), symbol_name_(symbol_name) {} +}; + +class HalInfoMatchedTest : public ::testing::TestWithParam {}; + +INSTANTIATE_TEST_CASE_P(CommonHaltest, + HalInfoMatchedTest, + ::testing::Values( + HalInfo(HAL_MODULE_TBM, HAL_GROUP_GRAPHICS, HAL_LICENSE_MIT, + "HAL_MODULE_TBM", "/hal/lib/libhal-backend-tbm.so", + "/hal/lib64/libhal-backend-tbm.so", "hal_backend_tbm_data"), + + HalInfo(HAL_MODULE_TDM, HAL_GROUP_GRAPHICS, HAL_LICENSE_MIT, + "HAL_MODULE_TDM", "/hal/lib/libhal-backend-tdm.so", + "/hal/lib64/libhal-backend-tdm.so", "hal_backend_tdm_data"), + + HalInfo(HAL_MODULE_COREGL, HAL_GROUP_GRAPHICS, HAL_LICENSE_UNKNOWN, + "HAL_MODULE_COREGL", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_INPUT, HAL_GROUP_GRAPHICS, HAL_LICENSE_MIT, + "HAL_MODULE_INPUT", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_AUDIO, HAL_GROUP_MULTIMEDIA, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_AUDIO", "/hal/lib/libhal-backend-audio.so", + "/hal/lib64/libhal-backend-audio.so", "hal_backend_audio_data"), + + HalInfo(HAL_MODULE_CAMERA, HAL_GROUP_MULTIMEDIA, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_CAMERA", "/hal/lib/libhal-backend-camera.so", + "/hal/lib64/libhal-backend-camera.so", "hal_backend_camera_data"), + + HalInfo(HAL_MODULE_RADIO, HAL_GROUP_MULTIMEDIA, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_RADIO", "/hal/lib/libhal-backend-radio.so", + "/hal/lib64/libhal-backend-radio.so", "hal_backend_radio_data"), + + HalInfo(HAL_MODULE_CODEC, HAL_GROUP_MULTIMEDIA, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_CODEC", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_USB_AUDIO, HAL_GROUP_MULTIMEDIA, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_USB_AUDIO", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_ALSAUCM, HAL_GROUP_MULTIMEDIA, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_ALSAUCM", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_BLUETOOTH, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_BLUETOOTH", "/hal/lib/libhal-backend-bluetooth.so", + "/hal/lib64/libhal-backend-bluetooth.so", "hal_backend_bluetooth_data"), + + HalInfo(HAL_MODULE_WIFI, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_WIFI", "/hal/lib/libhal-backend-wifi.so", + "/hal/lib64/libhal-backend-wifi.so", "hal_backend_wifi_data"), + + HalInfo(HAL_MODULE_NAN, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_NAN", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_NFC, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_NFC", "/hal/lib/libhal-backend-nfc.so", + "/hal/lib64/libhal-backend-nfc.so", "hal_backend_nfc_data"), + + HalInfo(HAL_MODULE_ZIGBEE, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_ZIGBEE", "/hal/lib/libhal-backend-zigbee.so", + "/hal/lib64/libhal-backend-zigbee.so", "hal_backend_zigbee_data"), + + HalInfo(HAL_MODULE_UWB, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_UWB", "/hal/lib/libhal-backend-uwb.so", + "/hal/lib64/libhal-backend-uwb.so", "hal_backend_uwb_data"), + + HalInfo(HAL_MODULE_MTP, HAL_GROUP_CONNECTIVITY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_MTP", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_TELEPHONY, HAL_GROUP_TELEPHONY, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_TELEPHONY", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_LOCATION, HAL_GROUP_LOCATION, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_LOCATION", "/hal/lib/libhal-backend-location.so", + "/hal/lib64/libhal-backend-location.so", "hal_backend_location_data"), + + HalInfo(HAL_MODULE_COMMON, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_COMMON", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_POWER, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_POWER", "/hal/lib/libhal-backend-power.so", + "/hal/lib64/libhal-backend-power.so", "hal_backend_power_data"), + + HalInfo(HAL_MODULE_SENSOR, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_SENSOR", "/hal/lib/libhal-backend-sensor.so", + "/hal/lib64/libhal-backend-sensor.so", "hal_backend_sensor_data"), + + HalInfo(HAL_MODULE_PERIPHERAL, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_PERIPHERAL", nullptr, nullptr, nullptr), + + HalInfo(HAL_MODULE_DEVICE_BATTERY, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_BATTERY", "/hal/lib/libhal-backend-device-battery.so", + "/hal/lib64/libhal-backend-device-battery.so", "hal_backend_device_battery_data"), + + HalInfo(HAL_MODULE_DEVICE_BEZEL, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_BEZEL", "/hal/lib/libhal-backend-device-bezel.so", + "/hal/lib64/libhal-backend-device-bezel.so", "hal_backend_device_bezel_data"), + + HalInfo(HAL_MODULE_DEVICE_DISPLAY, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_DISPLAY", "/hal/lib/libhal-backend-device-display.so", + "/hal/lib64/libhal-backend-device-display.so", "hal_backend_device_display_data"), + + HalInfo(HAL_MODULE_DEVICE_IR, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_IR", "/hal/lib/libhal-backend-device-ir.so", + "/hal/lib64/libhal-backend-device-ir.so", "hal_backend_device_ir_data"), + + HalInfo(HAL_MODULE_DEVICE_TOUCHSCREEN, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_TOUCHSCREEN", "/hal/lib/libhal-backend-device-touchscreen.so", + "/hal/lib64/libhal-backend-device-touchscreen.so", "hal_backend_device_touchscreen_data"), + + HalInfo(HAL_MODULE_DEVICE_LED, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_LED", "/hal/lib/libhal-backend-device-led.so", + "/hal/lib64/libhal-backend-device-led.so", "hal_backend_device_led_data"), + + HalInfo(HAL_MODULE_DEVICE_BOARD, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_BOARD", "/hal/lib/libhal-backend-device-board.so", + "/hal/lib64/libhal-backend-device-board.so", "hal_backend_device_board_data"), + + HalInfo(HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_EXTERNAL_CONNECTION", "/hal/lib/libhal-backend-device-external-connection.so", + "/hal/lib64/libhal-backend-device-external-connection.so", "hal_backend_device_external_connection_data"), + + HalInfo(HAL_MODULE_DEVICE_THERMAL, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_THERMAL", "/hal/lib/libhal-backend-device-thermal.so", + "/hal/lib64/libhal-backend-device-thermal.so", "hal_backend_device_thermal_data"), + + HalInfo(HAL_MODULE_DEVICE_USB_GADGET, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_USB_GADGET", "/hal/lib/libhal-backend-device-usb-gadget.so", + "/hal/lib64/libhal-backend-device-usb-gadget.so", "hal_backend_device_usb_gadget_data"), + + HalInfo(HAL_MODULE_DEVICE_HAPTIC, HAL_GROUP_SYSTEM, HAL_LICENSE_APACHE_2_0, + "HAL_MODULE_DEVICE_HAPTIC", "/hal/lib/libhal-backend-device-haptic.so", + "/hal/lib64/libhal-backend-device-haptic.so", "hal_backend_device_haptic_data") + )); + +TEST_P(HalInfoMatchedTest, get_backend_library_name) { + const char *ret_library_name; + + auto info = GetParam(); + + ret_library_name = hal_common_get_backend_library_name(info.module_); +#if defined(__aarch64__) + EXPECT_STREQ(info.library_name_64bit_, ret_library_name) << "module name is " << info.module_name_; +#else + EXPECT_STREQ(info.library_name_, ret_library_name) << "module name is " << info.module_name_; +#endif +} + +TEST_P(HalInfoMatchedTest, test_symbol_name_module_matching) { + const char *ret_symbol_name = NULL; + + auto info = GetParam(); + + ret_symbol_name = hal_common_get_backend_symbol_name(info.module_); + EXPECT_STREQ(ret_symbol_name, info.symbol_name_) << "module name is " << info.module_name_; +} + +TEST_P(HalInfoMatchedTest, test_group_module_matching) { + struct __hal_module_info *info = NULL; + + auto result_info = GetParam(); + + info = _hal_api_conf_get_module_info(result_info.module_); + ASSERT_TRUE(info != nullptr) << "module name is " << result_info.module_name_; + EXPECT_EQ(info->group, result_info.group_) << "module name is " << result_info.module_name_; + + _destroy_module_info(info); +} + +TEST_P(HalInfoMatchedTest, test_license_module_matching) { + struct __hal_module_info *info = NULL; + + auto result_info = GetParam(); + + info = _hal_api_conf_get_module_info(result_info.module_); + ASSERT_TRUE(info != nullptr) << "module name is " << result_info.module_name_; + EXPECT_EQ(info->license, result_info.license_) << "module name is " << result_info.module_name_; + + _destroy_module_info(info); +} + +TEST_P(HalInfoMatchedTest, test_module_name_matching) { + struct __hal_module_info *info = NULL; + + auto result_info = GetParam(); + + info = _hal_api_conf_get_module_info(result_info.module_); + ASSERT_TRUE(info != nullptr) << "module name is " << result_info.module_name_; + EXPECT_STREQ(info->module_name, result_info.module_name_) << "module name is " << result_info.module_name_; + + _destroy_module_info(info); +} diff --git a/include/hal-common.h b/include/hal-common.h index daffd14..c270279 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -44,6 +44,16 @@ enum hal_group { HAL_GROUP_END, }; +static const char *const hal_group_string[] = { + [HAL_GROUP_UNKNOWN] = "HAL_GROUP_UNKNOWN", + [HAL_GROUP_GRAPHICS] = "HAL_GROUP_GRAPHICS", + [HAL_GROUP_MULTIMEDIA] = "HAL_GROUP_MULTIMEDIA", + [HAL_GROUP_CONNECTIVITY] = "HAL_GROUP_CONNECTIVITY", + [HAL_GROUP_TELEPHONY] = "HAL_GROUP_TELEPHONY", + [HAL_GROUP_LOCATION] = "HAL_GROUP_LOCATION", + [HAL_GROUP_SYSTEM] = "HAL_GROUP_SYSTEM", +}; + enum hal_module { HAL_MODULE_UNKNOWN = 0, @@ -101,6 +111,58 @@ enum hal_module { HAL_MODULE_END, }; +static const char *const hal_module_string[] = { + [HAL_MODULE_UNKNOWN] = "HAL_MODULE_UNKNOWN", + + /* HAL_GROUP_GRAPHICS */ + [HAL_MODULE_TBM] = "HAL_MODULE_TBM", + [HAL_MODULE_TDM] = "HAL_MODULE_TDM", + [HAL_MODULE_COREGL] = "HAL_MODULE_COREGL", + [HAL_MODULE_INPUT] = "HAL_MODULE_INPUT", + + /* HAL_GROUP_MULTIMEDIA */ + [HAL_MODULE_AUDIO] = "HAL_MODULE_AUDIO", + [HAL_MODULE_CAMERA] = "HAL_MODULE_CAMERA", + [HAL_MODULE_RADIO] = "HAL_MODULE_RADIO", + [HAL_MODULE_CODEC] = "HAL_MODULE_CODEC", + [HAL_MODULE_USB_AUDIO] = "HAL_MODULE_USB_AUDIO", + [HAL_MODULE_ALSAUCM] = "HAL_MODULE_ALSAUCM", + + /* HAL_GROUP_CONNECTIVITY */ + [HAL_MODULE_BLUETOOTH] = "HAL_MODULE_BLUETOOTH", + [HAL_MODULE_WIFI] = "HAL_MODULE_WIFI", + [HAL_MODULE_NAN] = "HAL_MODULE_NAN", + [HAL_MODULE_NFC] = "HAL_MODULE_NFC", + [HAL_MODULE_ZIGBEE] = "HAL_MODULE_ZIGBEE", + [HAL_MODULE_UWB] = "HAL_MODULE_UWB", + [HAL_MODULE_MTP] = "HAL_MODULE_MTP", + + /* HAL_GROUP_TELEPHONY */ + [HAL_MODULE_TELEPHONY] = "HAL_MODULE_TELEPHONY", + + /* HAL_GROUP_LOCATION */ + [HAL_MODULE_LOCATION] = "HAL_MODULE_LOCATION", + + /* HAL_GROUP_SYSTEM */ + [HAL_MODULE_COMMON] = "HAL_MODULE_COMMON", + [HAL_MODULE_POWER] = "HAL_MODULE_POWER", + [HAL_MODULE_SENSOR] = "HAL_MODULE_SENSOR", + [HAL_MODULE_PERIPHERAL] = "HAL_MODULE_PERIPHERAL", + [HAL_MODULE_DEVICE_BATTERY] = "HAL_MODULE_DEVICE_BATTERY", + [HAL_MODULE_DEVICE_BEZEL] = "HAL_MODULE_DEVICE_BEZEL", + [HAL_MODULE_DEVICE_DISPLAY] = "HAL_MODULE_DEVICE_DISPLAY", + [HAL_MODULE_DEVICE_IR] = "HAL_MODULE_DEVICE_IR", + [HAL_MODULE_DEVICE_TOUCHSCREEN] = "HAL_MODULE_DEVICE_TOUCHSCREEN", + [HAL_MODULE_DEVICE_LED] = "HAL_MODULE_DEVICE_LED", + [HAL_MODULE_DEVICE_BOARD] = "HAL_MODULE_DEVICE_BOARD", + [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = "HAL_MODULE_DEVICE_EXTERNAL_CONNECTION", + [HAL_MODULE_DEVICE_THERMAL] = "HAL_MODULE_DEVICE_THERMAL", + [HAL_MODULE_DEVICE_USB_GADGET] = "HAL_MODULE_DEVICE_USB_GADGET", + [HAL_MODULE_DEVICE_HAPTIC] = "HAL_MODULE_DEVICE_HAPTIC", + + [HAL_MODULE_END] = "HAL_MODULE_END", +}; + /** * @brief Get the backend library name according to the type of HAL module * @param[in] HAL module id among enum hal_moudle diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 9ec7b05..4f5bfa6 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -18,8 +18,9 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(json-glib-1.0) BuildRequires: pkgconfig(gmock) - +BuildRequires: pkgconfig(libtzplatform-config) %description %{name} interface @@ -59,6 +60,11 @@ rm -rf %{buildroot} %post /sbin/ldconfig +if [ ! -d %{TZ_SYS_ETC} ] +then + mkdir -p %{TZ_SYS_RO_ETC}/hal +fi + %postun /sbin/ldconfig @@ -70,6 +76,7 @@ rm -rf %{buildroot} %{_libdir}/hal/*.so* %{_sysconfdir}/ld.so.conf.d/libhal-api.conf /hal/ +%attr(644,root,root) %{TZ_SYS_RO_ETC}/hal/hal-api.json %files -n %{devel_name} %defattr(-,root,root,-) diff --git a/src/common.h b/src/common.h index af1a0f1..55b28ff 100644 --- a/src/common.h +++ b/src/common.h @@ -22,13 +22,16 @@ #include "hal-common.h" +#ifdef __cplusplus +extern "C" { +#endif + #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) #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) -#define HAL_ABI_VERSION_MAX 10 /** * hal-api-common (/platform/hal/api/common) provides the HAL ABI @@ -46,250 +49,12 @@ * 'g_platform_curr_abi_version' must be updated when Tizen platform * will be released officially. */ -/* FIXME: Need to be initialized by configuration file like xml */ -enum hal_abi_version g_platform_curr_abi_version = HAL_ABI_VERSION_TIZEN_6_5; - struct hal_abi_version_match { enum hal_abi_version platform_abi_version; enum hal_abi_version backend_min_abi_version; -} abi_version_match_data[HAL_MODULE_END][HAL_ABI_VERSION_MAX] = { - /* HAL_GROUP_GRAPHICS */ - [HAL_MODULE_TBM] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_TDM] = { - /* FIXME: Need to be filled from configuration file. */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_COREGL] = { - /** - * Don't need to add abi verion for this module. - * because this module don't support HAL API. - */ - }, - [HAL_MODULE_INPUT] = { - /** - * Don't need to add abi verion for this module. - * because this module don't support HAL API. - */ - }, - - /* HAL_GROUP_MULTIMEDIA */ - [HAL_MODULE_AUDIO] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_CAMERA] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_RADIO] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_CODEC] = { - /** - * Don't need to add abi verion for this module. - * because this module don't support HAL API. - */ - }, - [HAL_MODULE_USB_AUDIO] = { - /** - * Don't need to add abi verion for this module. - * because this module don't support HAL API. - */ - }, - [HAL_MODULE_ALSAUCM] = { - /** - * Don't need to add abi verion for this module. - * because this module don't support HAL API. - */ - }, - - /* HAL_GROUP_CONNECTIVITY */ - [HAL_MODULE_BLUETOOTH] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_WIFI] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_NAN] = { - }, - [HAL_MODULE_NFC] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_ZIGBEE] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_UWB] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_MTP] = { - /** - * Don't need to add abi verion for this module. - * because this module don't support HAL API. - */ - }, - - /* HAL_GROUP_TELEPHONY */ - [HAL_MODULE_TELEPHONY] = { - /* FIXME: Need to be determined whehter support HAL API or not. */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - - /* HAL_GROUP_LOCATION */ - [HAL_MODULE_LOCATION] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - - /* HAL_GROUP_SYSTEM */ - [HAL_MODULE_COMMON] = { - }, - [HAL_MODULE_POWER] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_SENSOR] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_PERIPHERAL] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - - [HAL_MODULE_DEVICE_BATTERY] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_BEZEL] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_DISPLAY] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_IR] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_TOUCHSCREEN] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_LED] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_BOARD] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_THERMAL] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_USB_GADGET] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, - [HAL_MODULE_DEVICE_HAPTIC] = { - /* FIXME: Need to be initialized by configuration file like xml */ - [0] = { - .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, - }, - }, }; -static struct __hal_module_info { +struct __hal_module_info { enum hal_group group; enum hal_module module; enum hal_license license; @@ -305,425 +70,9 @@ static struct __hal_module_info { struct hal_abi_version_match *abi_versions; bool hal_api; -} hal_module_info[] = { - /* HAL_GROUP_GRAPHICS */ - [HAL_MODULE_TBM] = { - .group = HAL_GROUP_GRAPHICS, - .module = HAL_MODULE_TBM, - .license = HAL_LICENSE_MIT, - .module_name = "TBM", - .library_name = "/hal/lib/libhal-backend-tbm.so", - .library_name_64bit = "/hal/lib64/libhal-backend-tbm.so", - .symbol_name = "hal_backend_tbm_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_TBM]), - .abi_versions = abi_version_match_data[HAL_MODULE_TBM], - .hal_api = true, - }, - [HAL_MODULE_TDM] = { - .group = HAL_GROUP_GRAPHICS, - .module = HAL_MODULE_TDM, - .license = HAL_LICENSE_MIT, - .module_name = "TDM", - .library_name = "/hal/lib/libhal-backend-tdm.so", - .library_name_64bit = "/hal/lib64/libhal-backend-tdm.so", - .symbol_name = "hal_backend_tdm_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_TDM]), - .abi_versions = abi_version_match_data[HAL_MODULE_TDM], - .hal_api = true, - }, - [HAL_MODULE_COREGL] = { - .group = HAL_GROUP_GRAPHICS, - .module = HAL_MODULE_COREGL, - .license = HAL_LICENSE_UNKNOWN, - .module_name = "COREGL", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - [HAL_MODULE_INPUT] = { - .group = HAL_GROUP_GRAPHICS, - .module = HAL_MODULE_INPUT, - .license = HAL_LICENSE_MIT, - .module_name = "INPUT", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - - /* HAL_GROUP_MULTIMEDIA */ - [HAL_MODULE_AUDIO] = { - .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_AUDIO, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "AUDIO", - .library_name = "/hal/lib/libhal-backend-audio.so", - .library_name_64bit = "/hal/lib64/libhal-backend-audio.so", - .symbol_name = "hal_backend_audio_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_AUDIO]), - .abi_versions = abi_version_match_data[HAL_MODULE_AUDIO], - .hal_api = true, - }, - [HAL_MODULE_CAMERA] = { - .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_CAMERA, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "CAMERA", - .library_name = "/hal/lib/libhal-backend-camera.so", - .library_name_64bit = "/hal/lib64/libhal-backend-camera.so", - .symbol_name = "hal_backend_camera_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_CAMERA]), - .abi_versions = abi_version_match_data[HAL_MODULE_CAMERA], - .hal_api = true, - }, - [HAL_MODULE_RADIO] = { - .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_RADIO, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "RADIO", - .library_name = "/hal/lib/libhal-backend-radio.so", - .library_name_64bit = "/hal/lib64/libhal-backend-radio.so", - .symbol_name = "hal_backend_radio_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_RADIO]), - .abi_versions = abi_version_match_data[HAL_MODULE_RADIO], - .hal_api = true, - }, - [HAL_MODULE_CODEC] = { - .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_CODEC, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "CODEC", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - [HAL_MODULE_USB_AUDIO] = { - .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_USB_AUDIO, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "USB_AUDIO", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - [HAL_MODULE_ALSAUCM] = { - .group = HAL_GROUP_MULTIMEDIA, - .module = HAL_MODULE_ALSAUCM, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "ALSAUCM", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - - /* HAL_GROUP_CONNECTIVITY */ - [HAL_MODULE_BLUETOOTH] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_BLUETOOTH, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "BLUETOOTH", - .library_name = "/hal/lib/libhal-backend-bluetooth.so", - .library_name_64bit = "/hal/lib64/libhal-backend-bluetooth.so", - .symbol_name = "hal_backend_bluetooth_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_BLUETOOTH]), - .abi_versions = abi_version_match_data[HAL_MODULE_BLUETOOTH], - .hal_api = true, - }, - [HAL_MODULE_WIFI] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_WIFI, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "WIFI", - .library_name = "/hal/lib/libhal-backend-wifi.so", - .library_name_64bit = "/hal/lib64/libhal-backend-wifi.so", - .symbol_name = "hal_backend_wifi_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_WIFI]), - .abi_versions = abi_version_match_data[HAL_MODULE_WIFI], - .hal_api = true, - }, - [HAL_MODULE_NAN] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_NAN, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "NAN", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - [HAL_MODULE_NFC] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_NFC, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "NFC", - .library_name = "/hal/lib/libhal-backend-nfc.so", - .library_name_64bit = "/hal/lib64/libhal-backend-nfc.so", - .symbol_name = "hal_backend_nfc_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_NFC]), - .abi_versions = abi_version_match_data[HAL_MODULE_NFC], - .hal_api = true, - }, - [HAL_MODULE_ZIGBEE] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_ZIGBEE, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "ZIGBEE", - .library_name = "/hal/lib/libhal-backend-zigbee.so", - .library_name_64bit = "/hal/lib64/libhal-backend-zigbee.so", - .symbol_name = "hal_backend_zigbee_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_ZIGBEE]), - .abi_versions = abi_version_match_data[HAL_MODULE_ZIGBEE], - .hal_api = true, - }, - [HAL_MODULE_UWB] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_UWB, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "UWB", - .library_name = "/hal/lib/libhal-backend-uwb.so", - .library_name_64bit = "/hal/lib64/libhal-backend-uwb.so", - .symbol_name = "hal_backend_uwb_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_UWB]), - .abi_versions = abi_version_match_data[HAL_MODULE_UWB], - .hal_api = true, - }, - [HAL_MODULE_MTP] = { - .group = HAL_GROUP_CONNECTIVITY, - .module = HAL_MODULE_MTP, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "MTP", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - - /* HAL_GROUP_TELEPHONY */ - [HAL_MODULE_TELEPHONY] = { - .group = HAL_GROUP_TELEPHONY, - .module = HAL_MODULE_TELEPHONY, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "TELEPHONY", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - - /* HAL_GROUP_LOCATION */ - [HAL_MODULE_LOCATION] = { - .group = HAL_GROUP_LOCATION, - .module = HAL_MODULE_LOCATION, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "LOCATION", - .library_name = "/hal/lib/libhal-backend-location.so", - .library_name_64bit = "/hal/lib64/libhal-backend-location.so", - .symbol_name = "hal_backend_location_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_LOCATION]), - .abi_versions = abi_version_match_data[HAL_MODULE_LOCATION], - .hal_api = true, - }, - - /* HAL_GROUP_SYSTEM */ - [HAL_MODULE_COMMON] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_COMMON, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "COMMON", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = true, - }, - [HAL_MODULE_POWER] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_POWER, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "POWER", - .library_name = "/hal/lib/libhal-backend-power.so", - .library_name_64bit = "/hal/lib64/libhal-backend-power.so", - .symbol_name = "hal_backend_power_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_POWER]), - .abi_versions = abi_version_match_data[HAL_MODULE_POWER], - .hal_api = true, - }, - [HAL_MODULE_SENSOR] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_SENSOR, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "SENSOR", - .library_name = "/hal/lib/libhal-backend-sensor.so", - .library_name_64bit = "/hal/lib64/libhal-backend-sensor.so", - .symbol_name = "hal_backend_sensor_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_SENSOR]), - .abi_versions = abi_version_match_data[HAL_MODULE_SENSOR], - .hal_api = true, - }, - [HAL_MODULE_PERIPHERAL] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_PERIPHERAL, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "PERIPHERAL", - .library_name = NULL, - .library_name_64bit = NULL, - .symbol_name = NULL, - .num_abi_versions = 0, - .abi_versions = NULL, - .hal_api = false, - }, - [HAL_MODULE_DEVICE_BATTERY] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_BATTERY, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_BATTERY", - .library_name = "/hal/lib/libhal-backend-device-battery.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-battery.so", - .symbol_name = "hal_backend_device_battery_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_BATTERY]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_BATTERY], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_BEZEL] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_BEZEL, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_BEZEL", - .library_name = "/hal/lib/libhal-backend-device-bezel.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-bezel.so", - .symbol_name = "hal_backend_device_bezel_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_BEZEL]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_BEZEL], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_DISPLAY] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_DISPLAY, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_DISPLAY", - .library_name = "/hal/lib/libhal-backend-device-display.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-display.so", - .symbol_name = "hal_backend_device_display_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_DISPLAY]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_DISPLAY], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_IR] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_IR, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_IR", - .library_name = "/hal/lib/libhal-backend-device-ir.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-ir.so", - .symbol_name = "hal_backend_device_ir_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_IR]), - .hal_api = true, - }, - [HAL_MODULE_DEVICE_TOUCHSCREEN] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_TOUCHSCREEN, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_TOUCHSCREEN", - .library_name = "/hal/lib/libhal-backend-device-touchscreen.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-touchscreen.so", - .symbol_name = "hal_backend_device_touchscreen_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_TOUCHSCREEN]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_TOUCHSCREEN], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_LED] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_LED, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_LED", - .library_name = "/hal/lib/libhal-backend-device-led.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-led.so", - .symbol_name = "hal_backend_device_led_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_LED]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_LED], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_BOARD] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_BOARD, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_BOARD", - .library_name = "/hal/lib/libhal-backend-device-board.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-board.so", - .symbol_name = "hal_backend_device_board_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_BOARD]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_BOARD], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_EXTERNAL_CONNECTION", - .library_name = "/hal/lib/libhal-backend-device-external-connection.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-external-connection.so", - .symbol_name = "hal_backend_device_external_connection_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_EXTERNAL_CONNECTION]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_EXTERNAL_CONNECTION], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_THERMAL] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_THERMAL, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_THERMAL", - .library_name = "/hal/lib/libhal-backend-device-thermal.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-thermal.so", - .symbol_name = "hal_backend_device_thermal_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_THERMAL]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_THERMAL], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_USB_GADGET] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_USB_GADGET, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_USB_GADGET", - .library_name = "/hal/lib/libhal-backend-device-usb-gadget.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-usb-gadget.so", - .symbol_name = "hal_backend_device_usb_gadget_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_USB_GADGET]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_USB_GADGET], - .hal_api = true, - }, - [HAL_MODULE_DEVICE_HAPTIC] = { - .group = HAL_GROUP_SYSTEM, - .module = HAL_MODULE_DEVICE_HAPTIC, - .license = HAL_LICENSE_APACHE_2_0, - .module_name = "DEVICE_HAPTIC", - .library_name = "/hal/lib/libhal-backend-device-haptic.so", - .library_name_64bit = "/hal/lib64/libhal-backend-device-haptic.so", - .symbol_name = "hal_backend_device_haptic_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_HAPTIC]), - .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_HAPTIC], - .hal_api = true, - }, }; +#ifdef __cplusplus +} +#endif #endif /* __COMMON_H__ */ diff --git a/src/hal-api-common.c b/src/hal-api-common.c index c476024..c8fdccd 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -23,15 +23,19 @@ #include #include "common.h" +#include "hal-api-conf.h" #ifndef EXPORT #define EXPORT __attribute__ ((visibility("default"))) #endif +static enum hal_abi_version g_platform_curr_abi_version; + EXPORT const char *hal_common_get_backend_library_name(enum hal_module module) { char *library_name; + struct __hal_module_info *info = NULL; /* Check parameter whether is valid or not */ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { @@ -39,15 +43,21 @@ const char *hal_common_get_backend_library_name(enum hal_module module) return NULL; } + info = _hal_api_conf_get_module_info(module); + if (info == NULL) { + _E("Failed to get module inforamtion\n"); + return NULL; + } + #if defined(__aarch64__) - library_name = hal_module_info[module].library_name_64bit; + library_name = info->library_name_64bit; #else - library_name = hal_module_info[module].library_name; + library_name = info->library_name; #endif if (!library_name) { _E("%s backend library name is NULL\n", - hal_module_info[module].module_name); + info->module_name); return NULL; } return library_name; @@ -56,34 +66,50 @@ const char *hal_common_get_backend_library_name(enum hal_module module) EXPORT const char *hal_common_get_backend_symbol_name(enum hal_module module) { + struct __hal_module_info *info = NULL; + /* 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 NULL; } - if (!hal_module_info[module].symbol_name) { + info = _hal_api_conf_get_module_info(module); + if (info == NULL) { + _E("Failed to get module information\n"); + return NULL; + } + + if (!info->symbol_name) { _E("%s backend library name is NULL\n", - hal_module_info[module].module_name); + info->module_name); return NULL; } - return hal_module_info[module].symbol_name; + return info->symbol_name; } EXPORT int hal_common_get_backend(enum hal_module module, void **data) { + struct __hal_module_info *info = NULL; void *handle = NULL; hal_backend *backend; const char *library_name, *symbol_name; int ret = 0; + info = _hal_api_conf_get_module_info(module); + if (info == NULL) { + _E("Failed to get module information\n"); + ret = TIZEN_ERROR_UNKNOWN; + goto err; + } + /* Load module */ library_name = hal_common_get_backend_library_name(module); if (!library_name) { _E("Failed to get backend library name of %s\n", - hal_module_info[module].module_name); + info->module_name); return TIZEN_ERROR_INVALID_PARAMETER; } @@ -96,7 +122,7 @@ int hal_common_get_backend(enum hal_module module, void **data) symbol_name = hal_common_get_backend_symbol_name(module); if (!symbol_name) { _E("Failed to get backend symbol name of %s\n", - hal_module_info[module].module_name); + info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } @@ -114,7 +140,7 @@ int hal_common_get_backend(enum hal_module module, void **data) ret = hal_common_check_backend_abi_version(module, backend->abi_version); if (ret < 0) { _E("Failed to check ABI version of %s\n", - hal_module_info[module].module_name); + info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } @@ -122,7 +148,7 @@ int hal_common_get_backend(enum hal_module module, void **data) /* Get the backend module data */ if (!backend->init) { _E("hal_backend->init() is NULL for %s\n", - hal_module_info[module].module_name); + info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } @@ -135,8 +161,8 @@ int hal_common_get_backend(enum hal_module module, void **data) goto err; } - hal_module_info[module].library_backend = backend; - hal_module_info[module].library_handle = handle; + info->library_backend = backend; + info->library_handle = handle; _I("Get HAL backend: name(%s)/vendor(%s)\n", backend->name, backend->vendor); @@ -150,6 +176,7 @@ err: EXPORT int hal_common_put_backend(enum hal_module module, void *data) { + struct __hal_module_info *info = NULL; hal_backend *backend = NULL; void *handle = NULL; int ret; @@ -160,8 +187,14 @@ int hal_common_put_backend(enum hal_module module, void *data) return TIZEN_ERROR_INVALID_PARAMETER; } - backend = hal_module_info[module].library_backend; - handle = hal_module_info[module].library_handle; + info = _hal_api_conf_get_module_info(module); + if (info == NULL) { + _E("Failed to get module information\n"); + return TIZEN_ERROR_UNKNOWN; + } + + backend = info->library_backend; + handle = info->library_handle; if (!backend) { _I("Already fully put for HAL module (%d)\n", module); @@ -183,8 +216,8 @@ int hal_common_put_backend(enum hal_module module, void *data) if (handle) dlclose(handle); - hal_module_info[module].library_backend = NULL; - hal_module_info[module].library_handle = NULL; + info->library_backend = NULL; + info->library_handle = NULL; return TIZEN_ERROR_NONE; } @@ -193,6 +226,7 @@ EXPORT int hal_common_check_backend_abi_version(enum hal_module module, enum hal_abi_version abi_version) { + struct __hal_module_info *info = NULL; int i; /* Check parameter whether is valid or not */ @@ -207,22 +241,29 @@ int hal_common_check_backend_abi_version(enum hal_module module, return TIZEN_ERROR_INVALID_PARAMETER; } + info = _hal_api_conf_get_module_info(module); + if (info == NULL) { + _E("Failed to get module information\n"); + return TIZEN_ERROR_UNKNOWN; + } + /* Check abi_version whether is supported or not */ - if (!hal_module_info[module].hal_api) { + if (!info->hal_api) { _E("HAL module(%d) doesn't support HAL API\n", module); return TIZEN_ERROR_INVALID_PARAMETER; } - if (!hal_module_info[module].num_abi_versions - || !hal_module_info[module].abi_versions) { + if (!info->num_abi_versions + || !info->abi_versions) { _E("HAL module(%d) doesn't have the ABI version information\n", module); return TIZEN_ERROR_INVALID_PARAMETER; } - for (i = 0; i < hal_module_info[module].num_abi_versions; i++) { + g_platform_curr_abi_version = _hal_api_conf_get_platform_abi_version(); + for (i = 0; i < info->num_abi_versions; i++) { struct hal_abi_version_match *data - = &hal_module_info[module].abi_versions[i]; + = &info->abi_versions[i]; if (g_platform_curr_abi_version != data->platform_abi_version) continue; diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c new file mode 100644 index 0000000..9f2c693 --- /dev/null +++ b/src/hal-api-conf.c @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "hal-common.h" +#include "hal-common-interface.h" + +#include "hal-api-conf.h" + +#include "common.h" + +static enum hal_abi_version _platform_abi_version = HAL_ABI_VERSION_END; + +static JsonParser *_parser = NULL; +static JsonObject *_root_object = NULL; + +static GHashTable *_module_hash = NULL; + +static bool _initialized = false; + +void __attribute__ ((destructor)) _destroy_configuration(void); + +void _destroy_configuration(void) +{ + if (_parser) + g_object_unref(_parser); + + if (_module_hash) { + g_hash_table_remove_all(_module_hash); + g_hash_table_unref(_module_hash); + } + + _initialized = false; +} + +static const char *__get_group_string_name(enum hal_module module) +{ + if (HAL_MODULE_TBM <= module && module <= HAL_MODULE_INPUT) + return hal_group_string[HAL_GROUP_GRAPHICS]; + + if (HAL_MODULE_AUDIO <= module && module <= HAL_MODULE_ALSAUCM) + return hal_group_string[HAL_GROUP_MULTIMEDIA]; + + if (HAL_MODULE_BLUETOOTH <= module && module <= HAL_MODULE_MTP) + return hal_group_string[HAL_GROUP_CONNECTIVITY]; + + if (HAL_MODULE_TELEPHONY == module) + return hal_group_string[HAL_GROUP_TELEPHONY]; + + if (HAL_MODULE_LOCATION == module) + return hal_group_string[HAL_GROUP_LOCATION]; + + if (HAL_MODULE_COMMON <= module && module <= HAL_MODULE_DEVICE_HAPTIC) + return hal_group_string[HAL_GROUP_SYSTEM]; + + return NULL; +} + +static enum hal_group __get_group_enum_name_by_module(enum hal_module module) +{ + if (HAL_MODULE_TBM <= module && module <= HAL_MODULE_INPUT) + return HAL_GROUP_GRAPHICS; + + if (HAL_MODULE_AUDIO <= module && module <= HAL_MODULE_ALSAUCM) + return HAL_GROUP_MULTIMEDIA; + + if (HAL_MODULE_BLUETOOTH <= module && module <= HAL_MODULE_MTP) + return HAL_GROUP_CONNECTIVITY; + + if (HAL_MODULE_TELEPHONY == module) + return HAL_GROUP_TELEPHONY; + + if (HAL_MODULE_LOCATION == module) + return HAL_GROUP_LOCATION; + + if (HAL_MODULE_COMMON <= module && module <= HAL_MODULE_DEVICE_HAPTIC) + return HAL_GROUP_SYSTEM; + + return HAL_GROUP_UNKNOWN; +} + +static enum hal_abi_version __convert_abi_version_str_to_enum(const char *abi_version) { + int version; + for (version = HAL_ABI_VERSION_UNKNOWN + 1; version < HAL_ABI_VERSION_END; version++){ + if (g_strcmp0(abi_version, hal_abi_version_str[version]) == 0) + return (enum hal_abi_version)version; + } + + return HAL_ABI_VERSION_UNKNOWN; +} + +static const char *__convert_module_to_string(enum hal_module module) +{ + return hal_module_string[module]; +} + +static enum hal_license __convert_license_str_to_enum(const char *license) +{ + if (g_strcmp0(license, "APACHE_2_0") == 0) + return HAL_LICENSE_APACHE_2_0; + + if (g_strcmp0(license, "FLORA") == 0) + return HAL_LICENSE_FLORA; + + if (g_strcmp0(license, "MIT") == 0) + return HAL_LICENSE_MIT; + + return HAL_LICENSE_UNKNOWN; +} + +__attribute__ ((visibility("default"))) +void _destroy_module_info(gpointer data) +{ +#define SAFE_FREE_AND_NULL(x) \ +do { \ + if (x) { \ + free(x); \ + x = NULL; \ + } \ +} while (0); + + struct __hal_module_info *info = (struct __hal_module_info *)data; + gboolean is_contained = false; + + if (info) { + is_contained = g_hash_table_contains(_module_hash, GINT_TO_POINTER(info->module)); + if (is_contained) + g_hash_table_steal(_module_hash, GINT_TO_POINTER(info->module)); + + SAFE_FREE_AND_NULL(info->module_name); + SAFE_FREE_AND_NULL(info->library_name); + SAFE_FREE_AND_NULL(info->library_name_64bit); + SAFE_FREE_AND_NULL(info->symbol_name); + SAFE_FREE_AND_NULL(info->abi_versions); + SAFE_FREE_AND_NULL(info); + } +} + +static bool __init_configuration(void) +{ + JsonNode *root_node = NULL; + GError *error = NULL; + gboolean result; + + if (_initialized) + return _initialized; + + _parser = json_parser_new(); + result = json_parser_load_from_file(_parser, HAL_CONFIGURATION_PATH, &error); + if (result == FALSE) { + _E("Failed to parsing json configuration file : %s\n", error->message); + goto err; + } + + root_node = json_parser_get_root(_parser); + if (JSON_NODE_HOLDS_OBJECT(root_node) == FALSE) { + _E("There is no object in root node\n"); + goto err; + } + + _root_object = json_node_get_object(root_node); + _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info); + + _initialized = true; + + return _initialized; + +err: + if (error) + g_error_free(error); + _destroy_configuration(); + + return _initialized; +} + +static struct __hal_module_info *__create_hal_module_info(enum hal_module module, JsonObject *object) +{ + struct __hal_module_info *info; + JsonArray *abi_versions_array = NULL; + GList *abi_list = NULL; + GList *iter_list = NULL; + int list_index = 0; + const char *tmp; + + info = (struct __hal_module_info *)calloc(1, sizeof(struct __hal_module_info)); + if (info == NULL) { + _E("Out of Memory\n"); + return NULL; + } + + info->module = module; + info->module_name = g_strdup(__convert_module_to_string(module)); + info->group = __get_group_enum_name_by_module(module); + + tmp = json_object_get_string_member(object, "license"); + info->license = __convert_license_str_to_enum(tmp); + + info->library_name = g_strdup(json_object_get_string_member(object, "library_name")); + info->library_name_64bit = g_strdup(json_object_get_string_member(object, "library_name_64bit")); + info->symbol_name = g_strdup(json_object_get_string_member(object, "symbol_name")); + + if (info->library_name && info->library_name_64bit && info->symbol_name) + info->hal_api = true; + + abi_versions_array = json_object_get_array_member(object, "abi_versions"); + if (abi_versions_array == NULL) + return info; + + abi_list = json_array_get_elements(abi_versions_array); + info->num_abi_versions = g_list_length(abi_list); + if (info->num_abi_versions > 0) { + info->abi_versions = (struct hal_abi_version_match*)calloc(info->num_abi_versions, + sizeof(struct hal_abi_version_match)); + if (info->abi_versions == NULL) { + _E("Out of Memory\n"); + _destroy_module_info(info); + g_list_free(abi_list); + return NULL; + } + + for (iter_list = abi_list; iter_list != NULL; iter_list = iter_list->next) { + JsonObject *tmp_object = json_node_get_object(iter_list->data); + + tmp = json_object_get_string_member(tmp_object, "platform_abi_version"); + info->abi_versions[list_index].platform_abi_version = + __convert_abi_version_str_to_enum(tmp); + + tmp = json_object_get_string_member(tmp_object, "backend_min_abi_version"); + info->abi_versions[list_index].backend_min_abi_version = + __convert_abi_version_str_to_enum(tmp); + list_index++; + } + } + + if (abi_list) + g_list_free(abi_list); + + return info; +} + +__attribute__ ((visibility("default"))) +struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module) +{ + struct __hal_module_info *info = NULL; + JsonObject *module_object = NULL; + JsonArray *module_array = NULL; + GList *module_list = NULL; + GList *iter_list; + const char *group_name = NULL; + const char *module_name = NULL; + bool ret_initialized; + + ret_initialized = __init_configuration(); + if (ret_initialized == false) { + _E("Failed to parse json information\n"); + goto ret; + } + + info = (struct __hal_module_info*)g_hash_table_lookup(_module_hash, GINT_TO_POINTER(module)); + if (info != NULL) + return info; + + group_name = __get_group_string_name(module); + if (group_name == NULL) { + _E("There is wrong module\n"); + goto ret; + } + + module_object = json_object_get_object_member(_root_object, "MODULE_INFO"); + module_array = json_object_get_array_member(module_object, group_name); + module_list = json_array_get_elements(module_array); + module_name = __convert_module_to_string(module); + + for (iter_list = module_list; iter_list != NULL; iter_list = iter_list->next) { + JsonObject *tmp_object = json_node_get_object(iter_list->data); + const char *value = json_object_get_string_member(tmp_object, "module"); + if (g_strcmp0(value, module_name) == 0) { + info = __create_hal_module_info(module, tmp_object); + if (info == NULL) + _E("Failed to create hal module info\n"); + else + g_hash_table_insert(_module_hash, GINT_TO_POINTER(module), info); + break; + } + } + +ret: + if (module_list) + g_list_free(module_list); + + return info; +} + +enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) +{ + const char *abi_version = NULL; + bool ret_initialized; + + if (_platform_abi_version != HAL_ABI_VERSION_END) + return _platform_abi_version; + + ret_initialized = __init_configuration(); + if (ret_initialized == false) { + _E("Failed to parser json file\n"); + return HAL_ABI_VERSION_UNKNOWN; + } + + abi_version = json_object_get_string_member(_root_object, "PLATFORM_ABI_VERSION"); + _platform_abi_version = __convert_abi_version_str_to_enum(abi_version); + + return _platform_abi_version; +} diff --git a/src/hal-api-conf.h b/src/hal-api-conf.h new file mode 100644 index 0000000..4920483 --- /dev/null +++ b/src/hal-api-conf.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __HAL_API_CONF__ +#define __HAL_API_CONF__ + +#include +#include + +#include + +#include "hal-common-interface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define HAL_CONFIGURATION_PATH tzplatform_mkpath(TZ_SYS_RO_ETC, "hal/hal-api.json") + +struct __hal_module_info *_hal_api_conf_get_module_info(enum hal_module module); + +enum hal_abi_version _hal_api_conf_get_platform_abi_version(void); + +void _destroy_module_info(gpointer data); + +#ifdef __cplusplus +} +#endif +#endif -- 2.7.4