diff options
author | Lokesh <l.kasana@samsung.com> | 2019-08-30 15:31:21 +0530 |
---|---|---|
committer | saerome.kim <saerome.kim@samsung.com> | 2019-09-16 21:03:45 +0900 |
commit | 2f6d5f9faefc80157f8092fe2595b8662264837f (patch) | |
tree | 96e5001466a2269fa586bfc0cafdf664edfedf74 | |
parent | 3859c8525efca5d63cc5c165387fb4c1a4b10de0 (diff) | |
download | user-awareness-2f6d5f9faefc80157f8092fe2595b8662264837f.tar.gz user-awareness-2f6d5f9faefc80157f8092fe2595b8662264837f.tar.bz2 user-awareness-2f6d5f9faefc80157f8092fe2595b8662264837f.zip |
Fix presence_user_cb AND/OR condition
1/ Incorporate environmental sensors
2/ Send only one presence_user_cb for a user within a cycle
Change-Id: I0510fe074e4da808c3078d8ff15f20fc1ae4716f
Signed-off-by: Lokesh <l.kasana@samsung.com>
-rw-r--r-- | include/user-awareness-private.h | 2 | ||||
-rw-r--r-- | packaging/capi-network-ua.spec | 2 | ||||
-rw-r--r-- | src/user-awareness-event-handler.c | 3 | ||||
-rw-r--r-- | src/user-awareness-monitors.c | 104 | ||||
-rw-r--r-- | test/uat-detections.c | 36 |
5 files changed, 82 insertions, 65 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index 7b5e089..536060a 100644 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -193,6 +193,8 @@ typedef struct { typedef struct { char *account; /**< Account */ unsigned int sensor_bitmask; /**< Detected sensor type bit mask */ + GSList *found_devices; /**< Detected devices' handles list */ + gboolean cb_sent; /** User presence callback sent or not flag */ } ua_user_state_info_s; /** diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec index db50dcd..fd65670 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.7.3 +Version: 0.8.0 Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c index b0e114d..be99124 100644 --- a/src/user-awareness-event-handler.c +++ b/src/user-awareness-event-handler.c @@ -78,7 +78,8 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u ret_if(NULL == sensor_bitmask); _ua_monitor_handle_user_presence_detected(*sensor_bitmask, NULL, - NULL, 0, NULL); + NULL, 0, NULL); + break; } case UAM_EVENT_ABSENCE_DETECTED: { diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index ffad5e7..1c387d4 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -170,6 +170,7 @@ static void __ua_free_user_state_info_t(gpointer data) ret_if(NULL == user_state); g_free(user_state->account); + g_slist_free(user_state->found_devices); g_free(user_state); FUNC_EXIT; } @@ -225,8 +226,8 @@ static void __ua_send_presence_detection() continue; } - UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X", - monitor->sensor_bitmask, monitor->absence_detected_bitmask); + UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->presence_detected_bitmask: 0x%8.8X", + monitor->sensor_bitmask, monitor->presence_detected_bitmask); if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) { if (monitor->presence_cb) monitor->presence_cb(UA_ERROR_NONE, monitor, @@ -261,31 +262,38 @@ static ua_user_state_info_s* __ua_monitor_user_state_create(char *account) } static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor, - ua_user_h user_handle, - unsigned int user_sensor_bitmask, - char *device_id) + ua_user_state_info_s *user_state) { FUNC_ENTRY; + unsigned int env_presence_bm = 0; + unsigned int user_sensor_bitmask = user_state->sensor_bitmask; + + ua_user_h user_handle = _ua_get_user_handle_by_account( + user_state->account); + env_presence_bm = monitor->presence_detected_bitmask & UA_SENSOR_MOTION + & UA_SENSOR_LIGHT; /** * Check whether user_handle present or not and also check * whether presence has been started or not. */ - if (!user_handle || !monitor->presence_user_cb.callback || - !monitor->presence_detection_started) { + if (!user_handle || user_state->cb_sent + || !monitor->presence_user_cb.callback + || !monitor->presence_detection_started) { FUNC_EXIT; return; } UA_DBG("User's sensor bitmask [0x%u], monior presence bitmask AND [0x%u], OR [0x%u]", - user_sensor_bitmask, - monitor->presence_bitmask_and, monitor->presence_bitmask_or); + user_sensor_bitmask, monitor->presence_bitmask_and, + monitor->presence_bitmask_or); /** * Check AND conditions for sensors. */ if (monitor->presence_bitmask_and != - (user_sensor_bitmask & monitor->presence_bitmask_and)) { + (monitor->presence_bitmask_and + & (user_sensor_bitmask | env_presence_bm))) { FUNC_EXIT; return; } @@ -296,42 +304,20 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor, * Check OR conditions for sensors. */ if (monitor->presence_bitmask_or && - !(user_sensor_bitmask & monitor->presence_bitmask_or)) { + !(monitor->presence_bitmask_or + & (user_sensor_bitmask | env_presence_bm))) { FUNC_EXIT; return; } UA_DBG("OR condition matched"); - GSList *device_handles = NULL; - ua_device_h device_handle; - - if (user_sensor_bitmask & UA_SENSOR_BT) { - ua_device_get_by_device_id(device_id, - user_sensor_bitmask & UA_SENSOR_BT, - &device_handle); - device_handles = g_slist_prepend(device_handles, device_handle); - } - - if (user_sensor_bitmask & UA_SENSOR_BLE) { - ua_device_get_by_device_id(device_id, - user_sensor_bitmask & UA_SENSOR_BLE, - &device_handle); - device_handles = g_slist_prepend(device_handles, device_handle); - } - - if (user_sensor_bitmask & UA_SENSOR_WIFI) { - ua_device_get_by_device_id(device_id, - user_sensor_bitmask & UA_SENSOR_WIFI, - &device_handle); - device_handles = g_slist_prepend(device_handles, device_handle); - } ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)( - UA_ERROR_NONE, monitor, user_handle, - device_handles, - monitor->presence_user_cb.user_data); + UA_ERROR_NONE, monitor, user_handle, + user_state->found_devices, + monitor->presence_user_cb.user_data); - g_slist_free(device_handles); + user_state->cb_sent = TRUE; } static void __ua_sensor_presence_detected(ua_monitor_s *monitor, @@ -340,8 +326,12 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, FUNC_ENTRY; GSList *l; + GSList *us; int found = 0; + int ret = UA_ERROR_NONE; ua_user_state_info_s *user_state; + ua_device_h device_handle = NULL; + ret_if(NULL == monitor); if (account) { @@ -366,14 +356,19 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, monitor->user_state = g_slist_append(monitor->user_state, user_state); } - ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account); - - _ua_set_user_last_presence_timestamp(user_handle, timestamp); user_state->sensor_bitmask |= bitmask; - __ua_monitor_send_user_presence_cb(monitor, user_handle, - user_state->sensor_bitmask, - device_id); + ret = ua_device_get_by_device_id(device_id, bitmask, &device_handle); + UA_INFO("ua_device_get_by_device_id returned %s", + _ua_get_error_string(ret)); + if (device_handle) + user_state->found_devices = g_slist_prepend(user_state->found_devices, + device_handle); + + __ua_monitor_send_user_presence_cb(monitor, user_state); + + ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account); + _ua_set_user_last_presence_timestamp(user_handle, timestamp); } switch (monitor->presence_mode) { @@ -384,6 +379,7 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, * send presence detection callback to application. This will make sure that each sensor is * detected at least one device from registered devices list. */ +//TODO remove this (BLE | WIFI) condition and the ALL/ANY thing. if (((bitmask == UA_SENSOR_BLE) && (monitor->sensor_bitmask & UA_SENSOR_WIFI)) || ((bitmask == UA_SENSOR_WIFI) && (monitor->sensor_bitmask & UA_SENSOR_BLE))) monitor->presence_detected_bitmask |= (UA_SENSOR_BLE | UA_SENSOR_WIFI); @@ -412,6 +408,16 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, UA_WARN("Unexpected detection mode: %d", monitor->presence_mode); } + /* if environmental sensor comes after connectivity sensor */ + if (!account) { + for (us = monitor->user_state; us; us = g_slist_next(us)) { + user_state = (ua_user_state_info_s *)us->data; + UA_DBG("user_state->account [%s]", user_state->account); + + __ua_monitor_send_user_presence_cb(monitor, user_state); + } + } + FUNC_EXIT; } @@ -655,7 +661,8 @@ void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, for (l = ua_monitor_list; l; l = g_slist_next(l)) { ua_monitor_s *monitor = l->data; - if (!monitor || (!monitor->presence_detection_started && !monitor->internal_presence_started)) + if (!monitor || (!monitor->presence_detection_started + && !monitor->internal_presence_started)) continue; if (0 == (bitmask & monitor->sensor_bitmask)) @@ -817,6 +824,7 @@ void _ua_free_ua_monitor_t(gpointer data) ua_monitor_s *monitor = data; ret_if(NULL == monitor); +//TODO lk, where are these timers used? if (monitor->presence_detection_timer) { /* LCOV_EXCL_START */ g_source_remove(monitor->presence_detection_timer); @@ -1091,6 +1099,12 @@ int ua_monitor_set_user_presence_condition(ua_monitor_h handle, return UA_ERROR_INVALID_PARAMETER; } + if (!(bitmask_and | bitmask_or)) { + UA_ERR("Both of AND/OR bitmask are zero"); + FUNC_EXIT; + return UA_ERROR_INVALID_PARAMETER; + } + _uam_get_available_sensors(&available_sensors); if (bitmask_and != (available_sensors & bitmask_and)) { diff --git a/test/uat-detections.c b/test/uat-detections.c index b09ca87..656ff9d 100644 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -37,10 +37,10 @@ extern char g_service_str[MENU_DATA_SIZE + 1]; /**< Service string */ static char cycle_time[MENU_DATA_SIZE + 1] = {"900", }; /**< cycle time */ static char window[MENU_DATA_SIZE + 1] = {"60", }; /**< Detection window */ -static char g_presence_and_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< PRESENCE AND condition */ -static char g_presence_or_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< PRESENCE OR condition */ -static char g_absence_and_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< ABSENCE AND condition */ -static char g_absence_or_cond[MENU_DATA_SIZE + 1] = {"00", }; /**< ABSENCE OR condition */ +static char g_presence_and_cond[MENU_DATA_SIZE + 1] = {0,}; /**< PRESENCE AND condition */ +static char g_presence_or_cond[MENU_DATA_SIZE + 1] = {0,}; /**< PRESENCE OR condition */ +static char g_absence_and_cond[MENU_DATA_SIZE + 1] = {0,}; /**< ABSENCE AND condition */ +static char g_absence_or_cond[MENU_DATA_SIZE + 1] = {0,}; /**< ABSENCE OR condition */ static char g_presence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected PRESENCE type */ static char g_absence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected ABSENCE type */ @@ -215,17 +215,17 @@ static int run_ua_monitor_set_user_presence_condition( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; - unsigned int bitmask_and = 0x00; - unsigned int bitmask_or = 0x00; + unsigned int bitmask_and = 0; + unsigned int bitmask_or = 0; msg("ua_monitor_set_user_presence_condition"); if (strlen(g_presence_and_cond)) - bitmask_and = (unsigned char)strtol(g_presence_and_cond, NULL, 10); + bitmask_and = (unsigned int)strtol(g_presence_and_cond, NULL, 10); if (strlen(g_presence_or_cond)) - bitmask_or = (unsigned char)strtol(g_absence_or_cond, NULL, 10); + bitmask_or = (unsigned int)strtol(g_presence_or_cond, NULL, 10); - msgb("AND [0x%u] OR [0x%u]", bitmask_and, bitmask_or); + msgb("AND [%u] - OR [%u]", bitmask_and, bitmask_or); ret = ua_monitor_set_user_presence_condition(g_ua_mon_h, bitmask_and, bitmask_or); @@ -239,17 +239,17 @@ static int run_ua_monitor_set_user_absence_condition( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; - unsigned int bitmask_and = 0x00; - unsigned int bitmask_or = 0x00; + unsigned int bitmask_and = 0; + unsigned int bitmask_or = 0; msg("ua_monitor_set_user_absence_condition"); if (strlen(g_absence_and_cond)) - bitmask_and = (unsigned char)strtol(g_absence_and_cond, NULL, 10); + bitmask_and = (unsigned int)strtol(g_absence_and_cond, NULL, 10); if (strlen(g_absence_or_cond)) - bitmask_or = (unsigned char)strtol(g_absence_or_cond, NULL, 10); + bitmask_or = (unsigned int)strtol(g_absence_or_cond, NULL, 10); - msgb("AND [0x%u] OR [0x%u]", bitmask_and, bitmask_or); + msgb("AND [%u] - OR [%u]", bitmask_and, bitmask_or); ret = ua_monitor_set_user_absence_condition(g_ua_mon_h, bitmask_and, bitmask_or); @@ -526,9 +526,9 @@ static struct menu_data menu_ua_set_detection_window[] = { }; static struct menu_data menu_ua_set_presence_condition[] = { - { "1", "AND Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 10:Light 20:Audio", + { "1", "AND Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio", NULL, NULL, g_presence_and_cond }, - { "2", "OR Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 10:Light 20:Audio", + { "2", "OR Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 16:Light 32:Audio", NULL, NULL, g_presence_or_cond }, { "3", "run", NULL, run_ua_monitor_set_user_presence_condition, NULL }, @@ -536,9 +536,9 @@ static struct menu_data menu_ua_set_presence_condition[] = { }; static struct menu_data menu_ua_set_absence_condition[] = { - { "1", "AND Bitmask (0x01:BT 0x02:BLE 0x04:Wi-Fi 0x08:Motion 0x10:Light 0x20:Audio", + { "1", "AND Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio", NULL, NULL, g_absence_and_cond }, - { "2", "OR Bitmask (0x01:BT 0x02:BLE 0x04:Wi-Fi 0x08:Motion 0x10:Light 0x20:Audio", + { "2", "OR Bitmask (01:BT 02:BLE 04:Wi-Fi 08:Motion 16:Light 32:Audio", NULL, NULL, g_absence_or_cond }, { "3", "run", NULL, run_ua_monitor_set_user_absence_condition, NULL }, |