From: Youngjae Cho Date: Mon, 17 Mar 2025 08:57:19 +0000 (+0900) Subject: common: Support multi-transport on platform manifest X-Git-Tag: accepted/tizen/unified/20250428.091720~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e85c39071ca794adfe14091dc5b681ec445c2fd;p=platform%2Fhal%2Fapi%2Fcommon.git common: Support multi-transport on platform manifest It has changed to specify more than one transport on hal manifest if necessary. To support this, changed 'enum hal_common_transort' to be bitmap. Note that the actual values are same as before, 0, 1, and 2. The property //hal/version/@transport can now have more than two transport seperated by comma. And when it comes to an invalid transport string, it applies passthrough as a default transport. • As-is: Only one transport could be specified ... • To-be: All the belows are possible ... ... ... ... ... Change-Id: I8a1eefe8350ee8df3e2b0f5321920df83eefc7c5 Signed-off-by: Youngjae Cho --- diff --git a/include/hal-common.h b/include/hal-common.h index 0a37294..fd28dc9 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -19,6 +19,7 @@ #ifndef __HAL_COMMON__ #define __HAL_COMMON__ +#include #include "hal-common-interface.h" #ifdef __cplusplus @@ -114,10 +115,16 @@ enum hal_common_backend_compatibility { HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE, }; +/** + * @brief Transport supported by platform hal module + * @details Each hal module can specify more than one transports that it supports. + * @see hal_common_get_supported_interface_versions() + * @see hal_common_get_transport() + */ enum hal_common_transport { HAL_COMMON_TRANSPORT_UNKNOWN = 0, /**< This indicates undefined communication way with hal-backend */ - HAL_COMMON_TRANSPORT_IPC, /**< This indicates ipc communication way with hal-backend */ - HAL_COMMON_TRANSPORT_PASSTHROUGH, /**< This indicates dlopen communication way with hal-backend */ + HAL_COMMON_TRANSPORT_IPC = (1 << 0), /**< This indicates ipc communication way with hal-backend */ + HAL_COMMON_TRANSPORT_PASSTHROUGH = (1 << 1), /**< This indicates dlopen communication way with hal-backend */ }; /** @@ -326,15 +333,16 @@ int hal_common_check_backend_compatibility(enum hal_module module, * @param[out] minor_versions Array of minor version. An index is paired with the same * index in the array major_versions. The caller takes ownership of the data * so it is responsible for caller to free it using free() - * @param[out] transports Array of transport by each version. An index is paired with the - * same index in the array major_versions and minor_versions. The caller takes - * ownership of the data so it is responsible for caller to free it using free() + * @param[out] transports Array of transport by each version. Each transport is bitwise OR of + * enum #hal_common_transport. An index is paired with the same index in the array + * major_versions and minor_versions. The caller takes ownership of the data so it + * is responsible for caller to free it using free() * @param[out] num_versions Number of returned major and minor versions * @return @c 0 on success, otherwise a negative error value */ int hal_common_get_supported_interface_versions(enum hal_module module, unsigned int **major_versions, unsigned int **minor_versions, - enum hal_common_transport **transports, int *num_versions); + uint32_t **transports, int *num_versions); /** * @brief Get the transport that compatible with the current hal backend diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 4a5e3c6..0464c17 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -774,7 +774,7 @@ int hal_common_check_backend_compatibility(enum hal_module module, EXPORT int hal_common_get_supported_interface_versions(enum hal_module module, unsigned int **major_versions, unsigned int **minor_versions, - enum hal_common_transport **transports, int *num_versions) + uint32_t **transports, int *num_versions) { if (!major_versions || !minor_versions || !transports || !num_versions) return -EINVAL; diff --git a/src/hal-api-compatibility-checker-parser.c b/src/hal-api-compatibility-checker-parser.c index 0c06d1c..eab1b3a 100644 --- a/src/hal-api-compatibility-checker-parser.c +++ b/src/hal-api-compatibility-checker-parser.c @@ -85,7 +85,8 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) if (xmlStrEqual(child->name, "version")) { int major, minor; int scanned; - enum hal_common_transport transport = HAL_COMMON_TRANSPORT_PASSTHROUGH; + enum hal_common_transport transports = HAL_COMMON_TRANSPORT_UNKNOWN; + const char *transport = NULL; __xmlchar__ xmlChar *version = xmlNodeGetContent(child); __xmlchar__ xmlChar *property = xmlGetProp(child, "transport"); @@ -95,12 +96,33 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) continue; } - if (xmlStrEqual(property, "passthrough")) - transport = HAL_COMMON_TRANSPORT_PASSTHROUGH; - else if (xmlStrEqual(property, "ipc")) - transport = HAL_COMMON_TRANSPORT_IPC; + transport = (const char *) property; + while (transport) { + if (*transport == '\0') + break; + + if (*transport == ',') { + transport += 1; + continue; + } + + if (strncmp(transport, "passthrough", strlen("passtrhough")) == 0) { + transports |= HAL_COMMON_TRANSPORT_PASSTHROUGH; + transport += strlen("passthrough"); + } else if (strncmp(transport, "ipc", strlen("ipc")) == 0) { + transports |= HAL_COMMON_TRANSPORT_IPC; + transport += strlen("ipc"); + } else { + _W("Invalid transport=%s", transport); + transports = HAL_COMMON_TRANSPORT_UNKNOWN; + break; + } + } + + if (transports == HAL_COMMON_TRANSPORT_UNKNOWN) + transports = HAL_COMMON_TRANSPORT_PASSTHROUGH; // set default - ret = halcc_hal_add_version(hal, major, minor, transport); + ret = halcc_hal_add_version(hal, major, minor, transports); if (ret != 0) _E("Failed to halcc_hal_add_version(), ret=%d\n", ret); } diff --git a/src/hal-api-compatibility-checker.c b/src/hal-api-compatibility-checker.c index 7a6f4d8..31312f2 100644 --- a/src/hal-api-compatibility-checker.c +++ b/src/hal-api-compatibility-checker.c @@ -468,14 +468,14 @@ int hal_api_cc_check_backend_compatibility_by_version(enum hal_module module, int hal_api_cc_get_supported_interface_versions(enum hal_module module, unsigned int **major_versions, unsigned int **minor_versions, - enum hal_common_transport **transports, + uint32_t **transports, int *num_versions) { int ret; int ret_num_versions = 0; unsigned int *ret_major_versions = NULL; unsigned int *ret_minor_versions = NULL; - enum hal_common_transport *ret_transports = NULL; + uint32_t *ret_transports = NULL; struct compatibility_info info = { 0 , }; if (!major_versions || !minor_versions || !num_versions) @@ -502,7 +502,7 @@ int hal_api_cc_get_supported_interface_versions(enum hal_module module, return -ENOMEM; } - ret_transports = calloc(ret_num_versions, sizeof(enum hal_common_transport)); + ret_transports = calloc(ret_num_versions, sizeof(uint32_t)); if (!ret_transports) { free(ret_major_versions); free(ret_minor_versions); @@ -512,7 +512,7 @@ int hal_api_cc_get_supported_interface_versions(enum hal_module module, for (int i = 0; i < ret_num_versions; ++i) { ret_major_versions[i] = info.version_list[i][0]; ret_minor_versions[i] = info.version_list[i][1]; - ret_transports[i] = info.version_list[i][2]; + ret_transports[i] = (uint32_t) info.version_list[i][2]; } *major_versions = ret_major_versions; diff --git a/src/hal-api-compatibility-checker.h b/src/hal-api-compatibility-checker.h index 41e5afb..daab0f1 100644 --- a/src/hal-api-compatibility-checker.h +++ b/src/hal-api-compatibility-checker.h @@ -30,7 +30,7 @@ int hal_api_cc_check_backend_compatibility_by_version(enum hal_module module, enum hal_common_backend_compatibility *backend_compatibility); int hal_api_cc_get_supported_interface_versions(enum hal_module module, unsigned int **major_versions, unsigned int **minor_versions, - enum hal_common_transport **transports, int *num_versions); + uint32_t **transports, int *num_versions); int hal_api_cc_get_transport(enum hal_module module, enum hal_common_transport *transport); #ifdef HAL_API_COMMON_UNITTEST /* For test use only */ diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tbm-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tbm-manifest.xml index 5fc2e1d..d64d107 100644 --- a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tbm-manifest.xml +++ b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tbm-manifest.xml @@ -27,5 +27,14 @@ 3.1 + + + HAL_MODULE_TBM + 4.0 + 5.0 + 6.0 + 7.0 + + diff --git a/tests/unittest/test-hal-compatibility-checker.cc b/tests/unittest/test-hal-compatibility-checker.cc index 9a94e1d..89712ef 100644 --- a/tests/unittest/test-hal-compatibility-checker.cc +++ b/tests/unittest/test-hal-compatibility-checker.cc @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -129,7 +130,7 @@ static bool have_exact_version_within_halcc_hal(halcc_hal *hal, const char *vers struct versions_info { unsigned int *major_versions; unsigned int *minor_versions; - enum hal_common_transport *transports; + uint32_t *transports; int num_versions; }; @@ -160,7 +161,7 @@ static bool have_exact_version_within_array(const struct versions_info *vi, cons } static bool have_exact_version_transport_within_array(const struct versions_info *vi, - const char *version, enum hal_common_transport transport) + const char *version, uint32_t transport) { unsigned int major, minor; int ret; @@ -172,8 +173,8 @@ static bool have_exact_version_transport_within_array(const struct versions_info return false; ret = sscanf(version, "%u.%u", &major, &minor); - if (ret != 2) - return false; + if (ret != 2) + return false; for (int i = 0; i < vi->num_versions; ++i) { if (vi->major_versions[i] != major) @@ -372,11 +373,16 @@ TEST_F(HalccObjectTest, hal_get_manifest_version_transport_with_result_file) ret = hal_common_get_supported_interface_versions(HAL_MODULE_TBM, &vi.major_versions, &vi.minor_versions, &vi.transports, &vi.num_versions); + ASSERT_EQ(ret, 0); ASSERT_THAT(&vi, HasExactVersionTransportArray("1.0", HAL_COMMON_TRANSPORT_PASSTHROUGH)); /* default : PASSTHROUGH */ ASSERT_THAT(&vi, HasExactVersionTransportArray("2.1", HAL_COMMON_TRANSPORT_IPC)); ASSERT_THAT(&vi, HasExactVersionTransportArray("3.1", HAL_COMMON_TRANSPORT_PASSTHROUGH)); + ASSERT_THAT(&vi, HasExactVersionTransportArray("4.0", HAL_COMMON_TRANSPORT_PASSTHROUGH | HAL_COMMON_TRANSPORT_IPC)); + ASSERT_THAT(&vi, HasExactVersionTransportArray("5.0", HAL_COMMON_TRANSPORT_PASSTHROUGH | HAL_COMMON_TRANSPORT_IPC)); + ASSERT_THAT(&vi, HasExactVersionTransportArray("6.0", HAL_COMMON_TRANSPORT_PASSTHROUGH)); /* invalid: default: PASSTHROUGH */ + ASSERT_THAT(&vi, HasExactVersionTransportArray("7.0", HAL_COMMON_TRANSPORT_PASSTHROUGH)); /* invalid: default: PASSTHROUGH */ free(vi.major_versions); vi.major_versions = NULL; @@ -433,7 +439,7 @@ TEST_F(HalccObjectTest, hal_get_transport_with_result_file) hal_api_cc_reset_compatibility_info(); /* incompatible version should return error */ - mock_hal_backend_data_set_version(HAL_MODULE_TBM, 4, 0); + mock_hal_backend_data_set_version(HAL_MODULE_TBM, 8, 0); ret = hal_common_get_transport(HAL_MODULE_TBM, &transport); ASSERT_EQ(ret, -ELIBBAD); diff --git a/tools/lshal/lshal.c b/tools/lshal/lshal.c index 175d374..3dfde76 100644 --- a/tools/lshal/lshal.c +++ b/tools/lshal/lshal.c @@ -152,7 +152,7 @@ static void lshal_print_hal_backend_info(u_int32_t flags) { if (LSHAL_FLAG_MANIFEST_VERSION & flags) { unsigned int *major_versions = NULL; unsigned int *minor_versions = NULL; - enum hal_common_transport *transports = NULL; + uint32_t *transports = NULL; int num_versions = 0; strncpy(str, "", BUFF_MAX - 1); @@ -172,6 +172,7 @@ static void lshal_print_hal_backend_info(u_int32_t flags) { transport = (transports[i] == HAL_COMMON_TRANSPORT_IPC ? "ipc" : transports[i] == HAL_COMMON_TRANSPORT_PASSTHROUGH ? "passthrough" + : transports[i] == (HAL_COMMON_TRANSPORT_IPC | HAL_COMMON_TRANSPORT_PASSTHROUGH) ? "ipc,passthrough" : "Unknown"); pos += snprintf(pos, end - pos, "%u.%u(%s), ",