#ifndef __HAL_COMMON__
#define __HAL_COMMON__
+#include <stdint.h>
#include "hal-common-interface.h"
#ifdef __cplusplus
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 */
};
/**
* @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
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;
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");
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);
}
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)
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);
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;
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 */
<version>3.1</version>
</hal-module>
</manifest>
+ <manifest platform-version="13.0">
+ <hal-module>
+ <name>HAL_MODULE_TBM</name>
+ <version transport="ipc,passthrough">4.0</version>
+ <version transport="passthrough,ipc">5.0</version>
+ <version transport="invalid,ipc">6.0</version>
+ <version transport="passthrough,invalid">7.0</version>
+ </hal-module>
+ </manifest>
</hal-api>
*/
#include <unistd.h>
+#include <stdint.h>
#include <string.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
struct versions_info {
unsigned int *major_versions;
unsigned int *minor_versions;
- enum hal_common_transport *transports;
+ uint32_t *transports;
int num_versions;
};
}
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;
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)
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;
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);
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);
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), ",