diff options
author | Yunmi Ha <yunmi.ha@samsung.com> | 2021-04-05 20:10:04 +0900 |
---|---|---|
committer | Yunmi Ha <yunmi.ha@samsung.com> | 2021-04-09 13:24:58 +0900 |
commit | 4b985b6a8a86ec9289f38d07e95d784dde4b82c5 (patch) | |
tree | 8861e611a00289931c3b1829e8532d635517ea63 | |
parent | 31562d6e5c6d66d21002c45d0e3eac9b88f6796f (diff) | |
download | sensor-4b985b6a8a86ec9289f38d07e95d784dde4b82c5.tar.gz sensor-4b985b6a8a86ec9289f38d07e95d784dde4b82c5.tar.bz2 sensor-4b985b6a8a86ec9289f38d07e95d784dde4b82c5.zip |
Load HAL module before running API
Change-Id: Ibe74a9b72c30ea96f61efb7110a8c897eeffd5c7
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
-rw-r--r-- | src/hal-api-sensor.cpp | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index e4b535a..01683b7 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -25,43 +25,58 @@ #define EXPORT __attribute__((visibility("default"))) #endif -static hal_backend_sensor_funcs *g_sensor_funcs = NULL; +static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; +/* +-1 : failed to initialize +0 : not initialized +1 : succeeded to initialize +*/ +static int hal_initialized = 0; EXPORT -int hal_sensor_get_backend(void) { - int ret; +int hal_sensor_get_backend(void) +{ + int ret; - if (g_sensor_funcs) return 0; + if (hal_sensor_funcs) + return 0; - ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&g_sensor_funcs); - if (ret < 0) { - _E("Failed to get backend\n"); - return -EINVAL; - } + ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs); + if (ret < 0) { + _E("Failed to get backend"); + hal_initialized = -1; + return -ENODEV; + } - return 0; + hal_initialized = 1; + return 0; } EXPORT -int hal_sensor_put_backend(void) { - int ret; - - if (!g_sensor_funcs) return -EINVAL; +int hal_sensor_put_backend(void) +{ + if (!hal_sensor_funcs) + return -ENODEV; - ret = hal_common_put_backend(HAL_MODULE_SENSOR, (void *)g_sensor_funcs); - if (ret < 0) { - _E("Failed to put backend\n"); - return -EINVAL; - } - g_sensor_funcs = NULL; + hal_common_put_backend(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs); + hal_sensor_funcs = NULL; + hal_initialized = 0; - return 0; + return 0; } EXPORT -int hal_sensor_create(sensor_device_t **devices) { - if (!g_sensor_funcs) { - return -ENOTSUP; - } - return g_sensor_funcs->create(devices); +int hal_sensor_create(sensor_device_t **devices) +{ + int ret; + + if (!hal_sensor_funcs && !hal_initialized) { + if ((ret = hal_sensor_get_backend()) < 0) + return ret; + } + + if (!hal_sensor_funcs || !hal_sensor_funcs->create) + return -ENODEV; + + return hal_sensor_funcs->create(devices); } |