diff options
author | Abhay Agarwal <ay.agarwal@samsung.com> | 2019-10-01 18:19:22 +0900 |
---|---|---|
committer | saerome.kim <saerome.kim@samsung.com> | 2019-10-01 21:38:52 +0900 |
commit | 0ef75a979e22f14b25a342d4b41c60740701df32 (patch) | |
tree | f2a53ec3a3993cc59fc20f608642154743c3c62b /src/user-awareness-util.c | |
parent | 2b6d543def36441ca3e21ebf44a0e38dd3fcf565 (diff) | |
download | user-awareness-0ef75a979e22f14b25a342d4b41c60740701df32.tar.gz user-awareness-0ef75a979e22f14b25a342d4b41c60740701df32.tar.bz2 user-awareness-0ef75a979e22f14b25a342d4b41c60740701df32.zip |
use sensor handle to send sensor information to application
This commit provides the sensor information to application using a sensor handle
instead of providing directly using sensor struct, so that sensor struct need not
to be disclosed to the application.
Change-Id: Iab7ff5c6898404412f0fbb3d2d3586f2306d3237
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
Diffstat (limited to 'src/user-awareness-util.c')
-rw-r--r-- | src/user-awareness-util.c | 96 |
1 files changed, 91 insertions, 5 deletions
diff --git a/src/user-awareness-util.c b/src/user-awareness-util.c index 6b479a6..e64cf66 100644 --- a/src/user-awareness-util.c +++ b/src/user-awareness-util.c @@ -22,6 +22,8 @@ #include <user-awareness-log.h> #include <user-awareness-private.h> +GSList *ua_sensors_list = NULL; /* ua_sensor_info_s */ + ua_mac_type_e _to_ua_mac_type(uam_tech_type_e tech_type) { switch (tech_type) { @@ -214,12 +216,9 @@ ua_sensor_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask) FUNC_EXIT; } -ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info) +static ua_sensor_info_s* __ua_allocate_ua_sensor_info() { - FUNC_ENTRY; - ua_sensor_info_s *sensor_info = NULL; - unsigned int i = 0; - + ua_sensor_info_s *sensor_info; sensor_info = g_malloc0(sizeof(ua_sensor_info_s)); if (!sensor_info) { UA_ERR("g_malloc0 failed"); @@ -232,6 +231,57 @@ ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info) g_free(sensor_info); return NULL; } + return sensor_info; +} + +static ua_sensor_info_s *__ua_get_sensor_info_from_list(ua_sensor_e bitmask) +{ + GSList *l; + ua_sensor_info_s *sensor; + + for (l = ua_sensors_list; NULL != l; l = g_slist_next(l)) { + sensor = (ua_sensor_info_s *)l->data; + + if (bitmask == sensor->bitmask) { + UA_INFO("Sensor info found, sensor bitmask[%d]", sensor->bitmask); + return sensor; + } + } + + return NULL; +} + +static int __ua_update_sensor_info( + ua_sensor_info_s *sensor, + ua_sensor_info_s *info) +{ + FUNC_ENTRY; + unsigned int i = 0; + + UA_VALIDATE_INPUT_PARAMETER(sensor); + UA_VALIDATE_INPUT_PARAMETER(info); + + sensor->timestamp = info->timestamp; + sensor->count = info->count; + sensor->bitmask = info->bitmask; + for(i = 0; i < UA_SENSOR_MAX_VALUES; i++) { + sensor->values[i] = info->values[i]; + } + + FUNC_EXIT; + return UA_ERROR_NONE; +} + +ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info) +{ + FUNC_ENTRY; + ua_sensor_info_s *sensor_info = NULL; + unsigned int i = 0; + + sensor_info = __ua_allocate_ua_sensor_info(); + if (!sensor_info) + return NULL; + sensor_info->timestamp = info->timestamp; sensor_info->count = info->count; sensor_info->bitmask = _uam_to_ua_sensor(info->sensor_bitmask); @@ -242,3 +292,39 @@ ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info) return sensor_info; FUNC_EXIT; } + +int ua_sensor_get_by_sensor_info( + ua_sensor_info_s *info, + ua_sensor_h *sensor_handle) +{ + FUNC_ENTRY; + int ret = UA_ERROR_NONE; + ua_sensor_info_s *sensor; + *sensor_handle = NULL; + + UA_VALIDATE_INPUT_PARAMETER(info); + UA_VALIDATE_INPUT_PARAMETER(sensor_handle); + + sensor = __ua_get_sensor_info_from_list(info->bitmask); + + if (NULL != sensor) { + ret = __ua_update_sensor_info(sensor, info); + *sensor_handle = (ua_sensor_h)sensor; + goto done; + } + + sensor = __ua_allocate_ua_sensor_info(); + if (!sensor) + return UA_ERROR_OUT_OF_MEMORY; + + ret = __ua_update_sensor_info(sensor, info); + + /* Add sensor to list of sensors */ + *sensor_handle = (ua_sensor_h)sensor; + sensor->handle = *sensor_handle; + ua_sensors_list = g_slist_append(ua_sensors_list, sensor); + +done: + FUNC_EXIT; + return ret; +} |