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 | |
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>
-rw-r--r-- | include/user-awareness-private.h | 13 | ||||
-rw-r--r-- | include/user-awareness-util.h | 25 | ||||
-rw-r--r-- | include/user-awareness.h | 15 | ||||
-rw-r--r-- | src/user-awareness-monitors.c | 4 | ||||
-rw-r--r-- | src/user-awareness-util.c | 96 | ||||
-rw-r--r-- | test/uat-detections.c | 54 |
6 files changed, 162 insertions, 45 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index f33b0b4..357e7cc 100644 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -195,6 +195,19 @@ typedef struct { } ua_monitor_s; /** + * @brief sensor info data structure. + * @since_tizen 5.5 + */ +typedef struct { + ua_sensor_h handle; + ua_sensor_e bitmask; + long int timestamp; + int accuracy; + int count; + double *values; +} ua_sensor_info_s; + +/** * @brief User state data structure. * @since_tizen 5.5 */ diff --git a/include/user-awareness-util.h b/include/user-awareness-util.h index 6a70257..0fc4555 100644 --- a/include/user-awareness-util.h +++ b/include/user-awareness-util.h @@ -216,6 +216,31 @@ ua_sensor_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask); */ ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info); +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Gets sensor handle by sensor info. + * @since_tizen 5.5 + * + * @remarks The @a sensor_handle should not be released. + * @remarks The @a sensor_handle can be used only in the function. + * + * @param[in] sensor_info The detected sensor information + * @param[out] sensor_handle The sensor handle. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory + * + * @exception + * @pre + * @post + * + */ +int ua_sensor_get_by_sensor_info( + ua_sensor_info_s *sensor_info, + ua_sensor_h * sensor_handle); + #ifdef __cplusplus } #endif diff --git a/include/user-awareness.h b/include/user-awareness.h index 1eaa5aa..ff276fe 100644 --- a/include/user-awareness.h +++ b/include/user-awareness.h @@ -245,16 +245,11 @@ typedef enum { } ua_condition_conjunction_e; /** - * @brief sensor info data structure. + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief The handle of sensor information. * @since_tizen 5.5 */ -typedef struct { - ua_sensor_e bitmask; - long int timestamp; - int accuracy; - int count; - double *values; -} ua_sensor_info_s; +typedef void *ua_sensor_h; /** * @ingroup CAPI_NETWORK_UA_MODULE @@ -383,7 +378,7 @@ typedef void (*ua_presence_detected_cb)( ua_monitor_h handle, ua_sensor_e sensor, ua_device_h device_handle, - ua_sensor_info_s *sensor_info, + ua_sensor_h sensor_handle, void *user_data); /** @@ -413,7 +408,7 @@ typedef void (*ua_absence_detected_cb)( int result, ua_monitor_h handle, ua_sensor_e sensor, - ua_sensor_info_s *sensor_info, + ua_sensor_h sensor_info, void *user_data); /** diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index 3058686..9ada0e1 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -334,6 +334,10 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, { FUNC_ENTRY; ua_sensor_e bitmask = sensor_info->bitmask; + ua_sensor_h sensor_handle; + int ret = ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle); + UA_INFO("ua_device_get_by_device_id returned %s", + _ua_get_error_string(ret)); switch (monitor->presence_mode) { case UA_DETECT_MODE_ALL_SENSOR: /* 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; +} diff --git a/test/uat-detections.c b/test/uat-detections.c index 54502de..b6cb71e 100644 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -70,12 +70,28 @@ static void __sensor_presence_detected_device(ua_device_h device_handle) g_free(mac); } -static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_device_h device_handle, ua_sensor_info_s *info, - void *user_data) +static void __sensor_presence_detected_sensor_info(ua_sensor_h sensor_handle) { +/* char buf[MENU_DATA_SIZE] = {0, }; char final_buf[MENU_DATA_SIZE * 4] = {0, }; + for (int i = 0; i < info->count ; i++) { + if (i >= 4) + break; + snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]); + strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1); + memset(buf, 0, MENU_DATA_SIZE); + } + msgb("[%s] information detected at timestamp [%ld] value [%s]", + uat_get_sensor_bitmask_str(info->bitmask), info->timestamp, + final_buf); +*/ +} + +static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor, + ua_sensor_e sensor, ua_device_h device_handle, ua_sensor_h sensor_handle, + void *user_data) +{ char *pbuf = uat_get_time(); msg("\n[%s] Sensor PRESENCE [%d]", pbuf, sensor); free(pbuf); @@ -101,25 +117,13 @@ static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor, if (device_handle) __sensor_presence_detected_device(device_handle); /* For sensor information */ - if (info && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION))) { - for (int i = 0; i < info->count ; i++) { - if (i >= 4) - break; - snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]); - strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1); - memset(buf, 0, MENU_DATA_SIZE); - } - msgb("[%s] information detected at timestamp [%ld] value [%s]", - uat_get_sensor_bitmask_str(info->bitmask), info->timestamp, - final_buf); - } + if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION))) + __sensor_presence_detected_sensor_info(sensor_handle); } static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_sensor_info_s *info, void *user_data) + ua_sensor_e sensor, ua_sensor_h sensor_handle, void *user_data) { - char buf[MENU_DATA_SIZE] = {0, }; - char final_buf[MENU_DATA_SIZE * 4] = {0, }; char *pbuf = uat_get_time(); msg("\n[%s] Sensor ABSENCE", pbuf); free(pbuf); @@ -141,18 +145,8 @@ static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor, uat_get_sensor_bitmask_str(UA_SENSOR_MOTION), uat_get_error_str(result)); } /* For sensor information */ - if (info && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION))) { - for (int i = 0; i < info->count ; i++) { - if (i >= 4) - break; - snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]); - strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1); - memset(buf, 0, MENU_DATA_SIZE); - } - msgb("[%s] information detected at timestamp [%ld] value [%s]", - uat_get_sensor_bitmask_str(info->bitmask), info->timestamp, - final_buf); - } + if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION))) + __sensor_presence_detected_sensor_info(sensor_handle); } void __ua_test_scan_completed_cb(ua_active_scan_type_e result, ua_monitor_h handle, |