From: SangYoun Kwak Date: Tue, 13 Aug 2024 06:08:30 +0000 (+0900) Subject: Modify to use enum instead of int X-Git-Tag: accepted/tizen/9.0/unified/20250116.154257~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F316062%2F1;p=platform%2Fhal%2Fapi%2Fsensor.git Modify to use enum instead of int The variable 'hal_initialized' stores an integer value: * -1: init fail * 0: not initialized * 1: init success But it is hard to know what this value means before reading comment about it. To increase readability and maintainability, integer value is replaced as enum values. Change-Id: I17bd7ee3b743b4ba8c73c1241ca0ad809aec4674 Signed-off-by: SangYoun Kwak --- diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 7357cf7..cd5b24c 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -30,12 +30,12 @@ static hal_backend_sensor_funcs **hal_sensor_funcs = NULL; static char **hal_sensor_names = NULL; static int hal_sensor_count = 0; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; + +enum { + HAL_SENSOR_INIT_FAIL = -1, + HAL_SENSOR_INIT_NOT_INITIALIZED = 0, + HAL_SENSOR_INIT_SUCCESS = 1, +} static hal_initialized = HAL_SENSOR_INIT_NOT_INITIALIZED; static std::vector hal_backend_devs; @@ -113,7 +113,7 @@ int hal_sensor_get_backend(void) goto FREE_MEMORY; } - hal_initialized = 1; + hal_initialized = HAL_SENSOR_INIT_SUCCESS; return 0; FREE_MEMORY: @@ -129,7 +129,7 @@ FREE_MEMORY: FREE(hal_sensor_names); hal_sensor_count = 0; - hal_initialized = -1; + hal_initialized = HAL_SENSOR_INIT_FAIL; return -ENODEV; } @@ -150,7 +150,7 @@ int hal_sensor_put_backend(void) FREE(hal_sensor_names); FREE(hal_sensor_funcs); - hal_initialized = 0; + hal_initialized = HAL_SENSOR_INIT_NOT_INITIALIZED; return 0; } @@ -162,7 +162,7 @@ int hal_sensor_create(sensor_device_t **devices) int i, j; sensor_device_t *device; - if (!hal_sensor_funcs && !hal_initialized) { + if (!hal_sensor_funcs && (hal_initialized == HAL_SENSOR_INIT_NOT_INITIALIZED)) { if ((ret = hal_sensor_get_backend()) < 0) return ret; }