diff options
author | saerome.kim <saerome.kim@samsung.com> | 2019-07-17 21:11:17 +0900 |
---|---|---|
committer | saerome.kim <saerome.kim@samsung.com> | 2019-07-17 21:19:28 +0900 |
commit | faa6377d636244ec0b528dbd185703b8fd072462 (patch) | |
tree | 6b0fb0fca81cabfd474908df7d53df39bf2c8999 | |
parent | ee0ff38df1ec43714779de71b3c2c3227edef4c5 (diff) | |
download | user-awareness-faa6377d636244ec0b528dbd185703b8fd072462.tar.gz user-awareness-faa6377d636244ec0b528dbd185703b8fd072462.tar.bz2 user-awareness-faa6377d636244ec0b528dbd185703b8fd072462.zip |
Fix that user PRESENCE/ABSENCE callback or device PRESENCE/ABSENCEsubmit/tizen/20190718.035616accepted/tizen/unified/20190718.075206
callback does not come when a user starts/stops both detection again and
again.
Cause. If the user stops detections sequentially before all detections
are completed, the user/device information previously detected remains
and does not notified even though either the user or the device is detected.
Change-Id: Id32cb9d182509cbe31eb8b40d2faf23341c672fb
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
-rw-r--r-- | packaging/capi-network-ua.spec | 2 | ||||
-rw-r--r-- | src/user-awareness-monitors.c | 17 | ||||
-rw-r--r-- | test/uat-common.c | 2 | ||||
-rw-r--r-- | test/uat-detections.c | 119 | ||||
-rw-r--r-- | test/uat-init.c | 36 |
5 files changed, 127 insertions, 49 deletions
diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec index 717d3c8..f220122 100644 --- a/packaging/capi-network-ua.spec +++ b/packaging/capi-network-ua.spec @@ -1,6 +1,6 @@ Name: capi-network-ua Summary: User Awareness Framework CAPI -Version: 0.5 +Version: 0.6 Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index 61228b1..842b953 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -832,8 +832,7 @@ static ua_user_state_info_s* __ua_monitor_user_state_create(char *account) static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bitmask, char *account) { FUNC_ENTRY; - ua_sensor_e sensor_type; - sensor_type = __ua_sensor_bitmask_to_type(bitmask); + GSList *l; int found = 0; ua_user_state_info_s *user_state; @@ -842,8 +841,11 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bi if (account) { for (l = monitor->user_state; l; l = g_slist_next(l)) { user_state = (ua_user_state_info_s *)l->data; + UA_DBG("user_state->account [%s] account [%s]", user_state->account, account); - if (!g_strcmp0(account, user_state->account)) { + if (!g_strcmp0(account, user_state->account) + && user_state->sensor_bitmask != 0) { + UA_DBG("Found!!"); found = 1; break; } @@ -851,9 +853,10 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bi if (!found) { user_state = __ua_monitor_user_state_create(account); - - if (!user_state) + if (!user_state) { + UA_WARN("user_state is invalid"); return; + } monitor->user_state = g_slist_append(monitor->user_state, user_state); @@ -887,12 +890,10 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bi break; case UA_DETECT_MODE_ANY_SENSOR: - if ((monitor->presence_detected_bitmask & bitmask) == 0) if (monitor->presence_cb) monitor->presence_cb(UA_ERROR_NONE, monitor, - sensor_type, monitor->user_data); - + bitmask, monitor->user_data); monitor->presence_detected_bitmask |= bitmask; diff --git a/test/uat-common.c b/test/uat-common.c index 2a16e4d..d1964f6 100644 --- a/test/uat-common.c +++ b/test/uat-common.c @@ -111,7 +111,7 @@ const char* uat_get_sensor_bitmask_str(int sensor) case UA_SENSOR_AUDIO: return "AUDIO"; default: - return "Unknown Sesnor"; + return "Unknown"; } } diff --git a/test/uat-detections.c b/test/uat-detections.c index 7236acb..85840e3 100644 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -34,28 +34,54 @@ static char g_presence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected PRESENCE ty static char g_absence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected ABSENCE type */ static char g_scan_time_multiplier[MENU_DATA_SIZE + 1] = {0,}; /**< 10ms * what number */ -static void __presence_detected_cb(int result, ua_monitor_h monitor, +static void __device_presence_detected_cb(int result, ua_monitor_h monitor, ua_sensor_e sensor, void *user_data) { char *pbuf = uat_get_time(); - - msgb("[%s]", pbuf); + msg("\n[%s] Device PRESENCE", pbuf); free(pbuf); - msgb("sensor %s PRESENCE detected [%s]", - uat_get_sensor_bitmask_str(sensor), uat_get_error_str(result)); + if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) { + msgb("[%s] PRESENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_BLE), uat_get_error_str(result)); + } + if (UA_SENSOR_WIFI == (UA_SENSOR_WIFI & sensor)) { + msgb("[%s] PRESENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_WIFI), uat_get_error_str(result)); + } + if (UA_SENSOR_LIGHT == (UA_SENSOR_LIGHT & sensor)) { + msgb("[%s] PRESENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_LIGHT),uat_get_error_str(result)); + } + if (UA_SENSOR_MOTION == (UA_SENSOR_MOTION & sensor)) { + msgb("[%s] PRESENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_MOTION), uat_get_error_str(result)); + } } -static void __absence_detected_cb(int result, ua_monitor_h monitor, +static void __device_absence_detected_cb(int result, ua_monitor_h monitor, ua_sensor_e sensor, void *user_data) { char *pbuf = uat_get_time(); - - msgp("[%s]", pbuf); + msg("\n[%s] Device ABSENCE", pbuf); free(pbuf); - msgp("sensor %s ABSENCE detected [%s]", - uat_get_sensor_bitmask_str(sensor), uat_get_error_str(result)); + if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) { + msgp("[%s] ABSENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_BLE), uat_get_error_str(result)); + } + if (UA_SENSOR_WIFI == (UA_SENSOR_WIFI & sensor)) { + msgp("[%s] ABSENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_WIFI), uat_get_error_str(result)); + } + if (UA_SENSOR_LIGHT == (UA_SENSOR_LIGHT & sensor)) { + msgp("[%s] ABSENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_LIGHT), uat_get_error_str(result)); + } + if (UA_SENSOR_MOTION == (UA_SENSOR_MOTION & sensor)) { + msgp("[%s] ABSENCE detected [%s]", + uat_get_sensor_bitmask_str(UA_SENSOR_MOTION), uat_get_error_str(result)); + } } static int run_ua_monitor_start_presence_detection( @@ -74,7 +100,7 @@ static int run_ua_monitor_start_presence_detection( ret = ua_monitor_start_presence_detection(g_ua_mon_h, (g_service_str[0] == '\0' ? NULL : g_service_h), - detection_mode, __presence_detected_cb, g_ua_mon_h); + detection_mode, __device_presence_detected_cb, g_ua_mon_h); msg(" - ua_monitor_start_presence_detection() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); @@ -115,7 +141,7 @@ static int run_ua_monitor_start_absence_detection( ret = ua_monitor_start_absence_detection(g_ua_mon_h, (g_service_str[0] == '\0' ? NULL : g_service_h), - detection_mode, __absence_detected_cb, g_ua_mon_h); + detection_mode, __device_absence_detected_cb, g_ua_mon_h); msg(" - ua_monitor_start_absence_detection() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); @@ -213,11 +239,68 @@ static int run_ua_monitor_cancel_scan_devices( return RET_SUCCESS; } +static int run_ua_monitor_start_absence_presence( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + ua_detection_mode_e detection_mode = UA_DETECT_MODE_INVALID; + + msg("run_ua_monitor_start_absence_presence"); + + check_if(NULL == g_ua_mon_h); + + if (strlen(g_absence_type)) + detection_mode = (unsigned char)strtol((g_absence_type), NULL, 10); + + ret = ua_monitor_start_absence_detection(g_ua_mon_h, + (g_service_str[0] == '\0' ? NULL : g_service_h), + detection_mode, __device_absence_detected_cb, g_ua_mon_h); + msg(" - ua_monitor_start_absence_detection() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + if (strlen(g_presence_type)) + detection_mode = (unsigned char)strtol(g_presence_type, NULL, 10); + + ret = ua_monitor_start_presence_detection(g_ua_mon_h, + (g_service_str[0] == '\0' ? NULL : g_service_h), + detection_mode, __device_presence_detected_cb, g_ua_mon_h); + msg(" - ua_monitor_start_presence_detection() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_monitor_stop_absence_presence( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("run_ua_monitor_stop_absence_presence,"); + + check_if(NULL == g_ua_mon_h); + + ret = ua_monitor_stop_absence_detection(g_ua_mon_h); + msg(" - ua_monitor_stop_absence_detection() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + ret = ua_monitor_stop_presence_detection(g_ua_mon_h); + msg(" - ua_monitor_stop_presence_detection() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + static struct menu_data menu_start_device_scan[] = { - { "1", "Device scan time multiplier", - NULL, NULL, g_scan_time_multiplier}, - { "2", "run", NULL, - run_ua_monitor_start_scan_devices, NULL }, + { "1", "Device scan time multiplier", NULL, NULL, g_scan_time_multiplier}, + { "2", "run", NULL, run_ua_monitor_start_scan_devices, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_start_absence_presence[] = { + { "1", "ABSENCE detection type (1:ALL 2:ANY)", NULL, NULL, g_absence_type }, + { "2", "PRESENCE detection type (1:ALL 2:ANY)", NULL, NULL, g_presence_type }, + { "3", "start", NULL, run_ua_monitor_start_absence_presence, NULL }, + { "4", "stop", NULL, run_ua_monitor_stop_absence_presence, NULL }, { NULL, NULL, }, }; @@ -233,6 +316,8 @@ struct menu_data menu_ua_detections[] = { { "5", "ua_monitor_start_device_scan", menu_start_device_scan, NULL, NULL }, { "6", "ua_monitor_cancel_scan_devices", - NULL, run_ua_monitor_cancel_scan_devices, NULL }, + menu_start_device_scan, run_ua_monitor_cancel_scan_devices, NULL }, + { "7", "start/stop absence/presence simulataneously", + menu_start_absence_presence, NULL, NULL }, { NULL, NULL, }, }; diff --git a/test/uat-init.c b/test/uat-init.c index 183b3ee..12d1ee0 100644 --- a/test/uat-init.c +++ b/test/uat-init.c @@ -39,45 +39,37 @@ static char g_uid[MENU_DATA_SIZE + 1] = {0,}; /**< User id */ static char cycle_time[MENU_DATA_SIZE + 1] = {0,}; static char window[MENU_DATA_SIZE + 1] = {0,}; -static void __absence_detected_all_cb(int result, ua_monitor_h monitor, +static void __user_absence_detected_cb(int result, ua_monitor_h monitor, ua_user_h user_handle, void *user_data) { - int ret = UA_ERROR_NONE; char *account = NULL; char *pbuf = uat_get_time(); - msgp("[%s]", pbuf); + msg("\n[%s]", pbuf); free(pbuf); - msgp("ABSENCE ALL detectd [%s]", uat_get_error_str(result)); + ua_user_get_account(user_handle, &account); + msgp("[%s] ABSENCE detected [%s]", account, uat_get_error_str(result)); - if (user_handle) { - ret = ua_user_get_account(user_handle, &account); - if (UA_ERROR_NONE == ret) { - msgp("User account info %s", account); - free(account); - } + if (account) { + free(account); } } -static void __presence_detected_all_cb(int result, ua_monitor_h monitor, +static void __user_presence_detected_cb(int result, ua_monitor_h monitor, ua_user_h user_handle, void *user_data) { - int ret = UA_ERROR_NONE; char *account = NULL; char *pbuf = uat_get_time(); - msgp("[%s]", pbuf); + msg("\n[%s]", pbuf); free(pbuf); - msgb("PRESENCE ALL detectd [%s]", uat_get_error_str(result)); + ua_user_get_account(user_handle, &account); + msgb("[%s] PRESENCE detected [%s]", account, uat_get_error_str(result)); - if (user_handle) { - ret = ua_user_get_account(user_handle, &account); - if (UA_ERROR_NONE == ret) { - msgb("User account info %s", account); - free(account); - } + if (account) { + free(account); } } @@ -147,7 +139,7 @@ static int run_ua_monitor_set_user_absence_detected_cb( msg("ua_monitor_set_absence_detected_cb"); ret = ua_monitor_set_user_absence_detected_cb(g_ua_mon_h, - __absence_detected_all_cb, g_ua_mon_h); + __user_absence_detected_cb, g_ua_mon_h); msg(" - ua_monitor_set_absence_detected_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); @@ -163,7 +155,7 @@ static int run_ua_monitor_set_user_presence_detected_cb( msg("ua_monitor_set_presence_detected_cb"); ret = ua_monitor_set_user_presence_detected_cb(g_ua_mon_h, - __presence_detected_all_cb, g_ua_mon_h); + __user_presence_detected_cb, g_ua_mon_h); msg(" - ua_monitor_set_presence_detected_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); |