diff options
author | Mayank Haarit <mayank.h@samsung.com> | 2019-04-25 20:39:42 +0530 |
---|---|---|
committer | saerome kim <saerome.kim@samsung.com> | 2019-04-26 11:15:40 +0900 |
commit | 7e6b097bf9145a6cf01c72559c4a01a49a8b0b65 (patch) | |
tree | 7294d5997a75f83975d27b4a42fa20225a2ffa75 | |
parent | c652757c4aef923e3cbf94241e6a6cb3f5f855a9 (diff) | |
download | user-awareness-7e6b097bf9145a6cf01c72559c4a01a49a8b0b65.tar.gz user-awareness-7e6b097bf9145a6cf01c72559c4a01a49a8b0b65.tar.bz2 user-awareness-7e6b097bf9145a6cf01c72559c4a01a49a8b0b65.zip |
Implemenation to handle all sensors at the same time.submit/tizen/20190426.022428accepted/tizen/unified/20190426.054218
This patch adds the following implementation:
1) Handle DETECTION Started/Stopped event from daemon.
2) Consider all sensors at a same time to send absence/presence detection.
3) Set/Unset user presence detection callback.
4) test case for setting/unsetting user presence detection.
Change-Id: I0e8992373971f57a3e5924cb6b47838d2a264b06
Signed-off-by: Mayank Haarit <mayank.h@samsung.com>
-rw-r--r-- | include/user-awareness-private.h | 9 | ||||
-rw-r--r-- | include/user-awareness.h | 111 | ||||
-rw-r--r-- | src/user-awareness-event-handler.c | 8 | ||||
-rw-r--r-- | src/user-awareness-monitors.c | 239 | ||||
-rw-r--r-- | src/user-awareness-users.c | 24 | ||||
-rw-r--r-- | test/uat-detections.c | 26 | ||||
-rw-r--r-- | test/uat-init.c | 137 |
7 files changed, 368 insertions, 186 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index d853b14..d323b19 100644 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -98,9 +98,10 @@ extern "C" { unsigned int presence_detection_timer; /**< Presence detection timer */ unsigned int absence_detection_timer; /**< Absence detection timer */ ua_callback_t sensor_state_cb; /**< Callback to let apps know sensors added or not */ - ua_callback_t absence_all_users_cb; /**< Callback to let apps know noboty in here */ - ua_presence_user_detected_cb presence_cb; /**< User presence detection callback */ - ua_absence_user_detected_cb absence_cb; /**< User absence detection callback */ + ua_callback_t absence_user_cb; /**< Callback to let apps know user is absence */ + ua_callback_t presence_user_cb; /**< Callback to let apps know user is presence */ + ua_presence_detected_cb presence_cb; /**< User presence detection callback */ + ua_absence_detected_cb absence_cb; /**< Absence detection callback */ void *user_data; /**< User data */ } ua_monitor_s; @@ -147,6 +148,8 @@ extern "C" { void _ua_monitor_handle_user_presence_detected( unsigned int bitmask, ua_user_info_s *user_info); + void _ua_monitor_handle_detection_stopped(); + void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready); void _ua_monitor_handle_user_absence_detected( diff --git a/include/user-awareness.h b/include/user-awareness.h index dba6498..56588d4 100644 --- a/include/user-awareness.h +++ b/include/user-awareness.h @@ -222,27 +222,20 @@ typedef void (*ua_monitor_sensor_state_changed_cb)( * * @remarks The @a handle should not be released. * @remarks The @a handle can be used only in the callback. - * @remarks The @a user_handle should not be released. - * @remarks The @a user_handle can be used only in the callback. * * @param[in] result The result of the requested operation. * @param[in] handle The monitor handle * @param[in] sensor Sensor type, In case monitor has more than one sensor and detection * mode is not #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to last sensor which * reported user absence before invoking callback. - * @param[in] user_handle The user handle to detected user's information. \n - * user_handle can be NULL (In case of detection by MOTION/LIGHT/.. Etc sensors). If - * user_handle is not NULL application can invoke get APIs with the user handle to fetch - * detailed user info. * @param[in] user_data The user data passed in ua_monitor_start_absence_detection() * * @see ua_monitor_start_presence_detection() */ -typedef void (*ua_presence_user_detected_cb)( +typedef void (*ua_presence_detected_cb)( int result, ua_monitor_h handle, ua_sensor_e sensor, - ua_user_h user_handle, void *user_data); /** @@ -252,8 +245,6 @@ typedef void (*ua_presence_user_detected_cb)( * * @remarks The @a handle should not be released. * @remarks The @a handle can be used only in the callback. - * @remarks The @a user_handle should not be released. - * @remarks The @a user_handle can be used only in the callback. * * @param[in] result The result of the requested operation. * @param[in] handle The monitor handle with which absence detection start was invoked. \n @@ -261,40 +252,70 @@ typedef void (*ua_presence_user_detected_cb)( * In case monitor has more than one sensor and detection mode is not * #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to #UA_SENSOR_MAX before * invoking callback. - * @param[in] user_handle The user handle to detected user's information. * @param[in] user_data The user data passed in ua_monitor_start_absence_detection() * * @see ua_monitor_start_absence_detection() */ -typedef void (*ua_absence_user_detected_cb)( +typedef void (*ua_absence_detected_cb)( int result, ua_monitor_h handle, ua_sensor_e sensor, - ua_user_h user_handle, void *user_data); /** * @ingroup CAPI_NETWORK_UA_MODULE - * @brief Callback to be invoked on absence detection for all users. + * @brief Callback to be invoked on absence detection for one user. * @since_tizen 5.5 * * @remarks The @a handle should not be released. * @remarks The @a handle can be used only in the callback. + * @remarks The @a user_handle should not be released. + * @remarks The @a user_handle can be used only in the callback. * * @param[in] result The result of the requested operation. * @param[in] handle The monitor handle with which absence detection start was invoked. + * @param[in] user_handle The user handle to detected user's information. * @param[in] sensor Sensor type by which absence was detected. \n * In case monitor has more than one sensor and detection mode is not * #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to #UA_SENSOR_MAX before invoking * callback. - * @param[in] user_data The user data passed in ua_monitor_start_absence_detection() + * @param[in] user_data The user data passed in ua_monitor_set_user_absence_detected_cb() * - * @see ua_monitor_set_absence_detected_cb() + * @see ua_monitor_set_user_absence_detected_cb() */ -typedef void (*ua_absence_detected_cb)( +typedef void (*ua_absence_user_detected_cb)( int result, ua_monitor_h handle, ua_sensor_e sensor, + ua_user_h user_handle, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Callback to be invoked on presence detection for one user. + * @since_tizen 5.5 + * + * @remarks The @a handle should not be released. + * @remarks The @a handle can be used only in the callback. + * @remarks The @a user_handle should not be released. + * @remarks The @a user_handle can be used only in the callback. + * + * @param[in] result The result of the requested operation. + * @param[in] handle The monitor handle with which presence detection start was invoked. + * @param[in] user_handle The user handle to detected user's information. + * @param[in] sensor Sensor type by which presence was detected. \n + * In case monitor has more than one sensor and detection mode is not + * #UA_DETECT_MODE_ANY_SENSOR, sensor will be set to #UA_SENSOR_MAX before invoking + * callback. + * @param[in] user_data The user data passed in ua_monitor_set_user_presence_detected_cb() + * + * @see ua_monitor_set_user_presence_detected_cb() + */ +typedef void (*ua_presence_user_detected_cb)( + int result, + ua_monitor_h handle, + ua_sensor_e sensor, + ua_user_h user_handle, void *user_data); /** @@ -488,11 +509,31 @@ int ua_monitor_set_sensor_state_cb( * @retval #UA_ERROR_NONE Successful * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter * - * @see ua_monitor_unset_absence_detected_cb() + * @see ua_monitor_unset_user_absence_detected_cb() */ -int ua_monitor_set_absence_detected_cb( +int ua_monitor_set_user_absence_detected_cb( ua_monitor_h handle, - ua_absence_detected_cb callback, + ua_absence_user_detected_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Sets presence detected callback for all users. + * @since_tizen 5.5 + * + * @param[in] handle The monitor handle + * @param[in] callback Presence detected callback + * @param[in] user_data The user data + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see ua_monitor_unset_user_presence_detected_cb() + */ +int ua_monitor_set_user_presence_detected_cb( + ua_monitor_h handle, + ua_presence_user_detected_cb callback, void *user_data); /** @@ -522,9 +563,25 @@ int ua_monitor_unset_sensor_state_cb( * @retval #UA_ERROR_NONE Successful * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter * - * @see ua_monitor_set_absence_detected_cb() + * @see ua_monitor_set_user_absence_detected_cb() + */ +int ua_monitor_unset_user_absence_detected_cb( + ua_monitor_h handle); + +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Unsets presence detected callback for all users. + * @since_tizen 5.5 + * + * @param[in] handle The monitor handle + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see ua_monitor_set_user_presence_detected_cb() */ -int ua_monitor_unset_absence_detected_cb( +int ua_monitor_unset_user_presence_detected_cb( ua_monitor_h handle); /** @@ -551,13 +608,13 @@ int ua_monitor_unset_absence_detected_cb( * @retval #UA_ERROR_NO_DATA No sensor available * @retval #UA_ERROR_OPERATION_FAILED Operation failed * - * @see ua_presence_user_detected_cb() + * @see ua_presence_detected_cb() * @see ua_monitor_stop_presence_detection() */ int ua_monitor_start_presence_detection( ua_monitor_h handle, ua_detection_mode_e mode, - ua_presence_user_detected_cb callback, + ua_presence_detected_cb callback, void *user_data); /** @@ -592,7 +649,7 @@ int ua_monitor_stop_presence_detection( * detected by all sensors added to monitor. \n * #UA_DETECT_MODE_ANY_SENSOR : Detection callback will be invoked as soon as no user is * detected by any one of the sensors. \n - * @param[in] callback Callback to be invoked after user's absence detection. + * @param[in] callback Callback to be invoked after absence detection. * @param[in] user_data The user data to be passed when callback is called. * * @return 0 on success, otherwise a negative error value @@ -602,13 +659,13 @@ int ua_monitor_stop_presence_detection( * @retval #UA_ERROR_NO_DATA No sensor available * @retval #UA_ERROR_OPERATION_FAILED Operation failed * - * @see ua_absence_user_detected_cb() + * @see ua_absence_detected_cb() * @see ua_monitor_stop_absence_detection() */ int ua_monitor_start_absence_detection( ua_monitor_h handle, ua_detection_mode_e mode, - ua_absence_user_detected_cb callback, + ua_absence_detected_cb callback, void *user_data); /** diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c index 08c7c2a..1b981e4 100644 --- a/src/user-awareness-event-handler.c +++ b/src/user-awareness-event-handler.c @@ -91,6 +91,14 @@ static void __ua_event_handler(int event, uam_event_data_t *event_param, void *u _ua_monitor_handle_user_absence_detected(*sensor_bitmask, NULL); break; } + case UAM_EVENT_DETECTION_STARTED: { + UA_INFO("Received DETECTION STARTED event !!"); + break; + } + case UAM_EVENT_DETECTION_STOPPED: { + _ua_monitor_handle_detection_stopped(); + break; + } case UAM_EVENT_SENSOR_STATE_READY: { unsigned int *sensor_bitmask = event_param->data; diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index 349ff6b..3c7bc24 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -44,7 +44,6 @@ static GSList *ua_monitor_list; static char presence_ref_count[UA_SENSOR_MAX]; static char absence_ref_count[UA_SENSOR_MAX]; -static guint absence_timer = 0; static unsigned int __ua_sensor_type_to_bitmask(ua_sensor_e sensor_type) { @@ -238,8 +237,8 @@ int ua_monitor_unset_sensor_state_cb(ua_monitor_h handle) return UA_ERROR_NONE; } -int ua_monitor_set_absence_detected_cb(ua_monitor_h handle, - ua_absence_detected_cb callback, void *user_data) +int ua_monitor_set_user_absence_detected_cb(ua_monitor_h handle, + ua_absence_user_detected_cb callback, void *user_data) { FUNC_ENTRY; ua_monitor_s *monitor = (ua_monitor_s *)handle; @@ -248,14 +247,46 @@ int ua_monitor_set_absence_detected_cb(ua_monitor_h handle, UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_HANDLE(handle, ua_monitor_list); - monitor->absence_all_users_cb.callback = callback; - monitor->absence_all_users_cb.user_data = user_data; + monitor->absence_user_cb.callback = callback; + monitor->absence_user_cb.user_data = user_data; FUNC_EXIT; return UA_ERROR_NONE; } -int ua_monitor_unset_absence_detected_cb(ua_monitor_h handle) +int ua_monitor_set_user_presence_detected_cb(ua_monitor_h handle, + ua_presence_user_detected_cb callback, void *user_data) +{ + FUNC_ENTRY; + ua_monitor_s *monitor = (ua_monitor_s *)handle; + + UA_VALIDATE_INPUT_PARAMETER(callback); + UA_VALIDATE_INPUT_PARAMETER(handle); + UA_VALIDATE_HANDLE(handle, ua_monitor_list); + + monitor->presence_user_cb.callback = callback; + monitor->presence_user_cb.user_data = user_data; + + FUNC_EXIT; + return UA_ERROR_NONE; +} + +int ua_monitor_unset_user_absence_detected_cb(ua_monitor_h handle) +{ + FUNC_ENTRY; + ua_monitor_s *monitor = (ua_monitor_s *)handle; + + UA_VALIDATE_INPUT_PARAMETER(handle); + UA_VALIDATE_HANDLE(handle, ua_monitor_list); + + monitor->absence_user_cb.callback = NULL; + monitor->absence_user_cb.user_data = NULL; + + FUNC_EXIT; + return UA_ERROR_NONE; +} + +int ua_monitor_unset_user_presence_detected_cb(ua_monitor_h handle) { FUNC_ENTRY; ua_monitor_s *monitor = (ua_monitor_s *)handle; @@ -263,8 +294,8 @@ int ua_monitor_unset_absence_detected_cb(ua_monitor_h handle) UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_HANDLE(handle, ua_monitor_list); - monitor->absence_all_users_cb.callback = NULL; - monitor->absence_all_users_cb.user_data = NULL; + monitor->presence_user_cb.callback = NULL; + monitor->presence_user_cb.user_data = NULL; FUNC_EXIT; return UA_ERROR_NONE; @@ -477,7 +508,7 @@ static int __ua_start_monitoring(unsigned int bitmask, ua_detection_type_e detec int ua_monitor_start_presence_detection( ua_monitor_h handle, ua_detection_mode_e mode, - ua_presence_user_detected_cb callback, + ua_presence_detected_cb callback, void *user_data) { FUNC_ENTRY; @@ -515,7 +546,7 @@ int ua_monitor_start_presence_detection( int ua_monitor_start_absence_detection( ua_monitor_h handle, ua_detection_mode_e mode, - ua_absence_user_detected_cb callback, + ua_absence_detected_cb callback, void *user_data) { FUNC_ENTRY; @@ -753,20 +784,68 @@ int ua_monitor_stop_absence_detection(ua_monitor_h handle) return UA_ERROR_NONE; } -/* LCOV_EXCL_START */ -static gboolean __ua_reset_presence_detected_history(gpointer data) +static void __ua_send_presence_detection() { FUNC_ENTRY; - ua_monitor_s *monitor = data; + GSList *l; + GSList *l1; + GSList *user_list; + unsigned int bitmask; + + user_list = _ua_user_get_users(); + + for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) { + ua_monitor_s *monitor = l->data; + + if (!monitor) + continue; + + if (monitor->presence_mode == UA_DETECT_MODE_ANY_SENSOR) { + monitor->presence_detected_bitmask = 0; + continue; + } + + UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X", + monitor->sensor_bitmask, monitor->absence_detected_bitmask); + if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) { + if (monitor->presence_cb) + monitor->presence_cb(UA_ERROR_NONE, monitor, + UA_SENSOR_MAX, monitor->user_data); + } - if (0 < monitor->presence_detected_bitmask) monitor->presence_detected_bitmask = 0; + if (!monitor->presence_user_cb.callback) + continue; + + /* + * As MOTION and LIGHT sensors do not support user info, If only MOTION and LIGHT + * sensors are registered, do not invoke user absence callback. + */ + if (monitor->sensor_bitmask == (UA_SENSOR_MOTION | UA_SENSOR_LIGHT)) + continue; + + bitmask = monitor->sensor_bitmask; + bitmask &= ~(UA_SENSOR_MOTION | UA_SENSOR_LIGHT); + + for (l1 = user_list; NULL != l1; l1 = g_slist_next(l1)) { + ua_user_info_s *user_info = l1->data; + + UA_INFO("Scanning user list..."); + if (!user_info) + continue; + + if ((bitmask & ~(user_info->sensor_bitmask)) == 0) + ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)( + UA_ERROR_NONE, monitor, UA_SENSOR_MAX, user_info->user_handle, + monitor->presence_user_cb.user_data); + } + } + FUNC_EXIT; - return FALSE; } -static void __ua_sensor_send_presence_detected(ua_monitor_s *monitor, unsigned int bitmask, ua_user_info_s *user_info) +static void __ua_sensor_presence_detected(ua_monitor_s *monitor, unsigned int bitmask, ua_user_info_s *user_info) { FUNC_ENTRY; ua_sensor_e sensor_type; @@ -775,49 +854,32 @@ static void __ua_sensor_send_presence_detected(ua_monitor_s *monitor, unsigned i switch (monitor->presence_mode) { case UA_DETECT_MODE_ALL_SENSOR: - monitor->presence_detected_bitmask |= bitmask; - - if (monitor->sensor_bitmask == monitor->presence_detected_bitmask) { - UA_DBG("Presence detected by all sensors, invoke callback"); - if (user_info) { - /* - * Sends presence if it is detected by all sensors irrespective of device/user i.e if - * presence will be detected by device 1 for sensor 1 and by device 2 for sensor 2 then - * send presence detection callback to application. This will make sure that each sensor is - * detected at least one device from registered devices list. - */ - monitor->presence_cb(UA_ERROR_NONE, monitor, - sensor_type, user_info->user_handle, monitor->user_data); - } else - monitor->presence_cb(UA_ERROR_NONE, monitor, - sensor_type, NULL, monitor->user_data); + /* + * Sends presence if it is detected by all sensors irrespective of device/user i.e if + * presence will be detected by device 1 for sensor 1 and by device 2 for sensor 2 then + * send presence detection callback to application. This will make sure that each sensor is + * detected at least one device from registered devices list. + */ + 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); + else + monitor->presence_detected_bitmask |= bitmask; - monitor->presence_detected_bitmask = 0; - /* Remove presence timer if timer is running */ - if (0 < monitor->presence_detection_timer) { - g_source_remove(monitor->presence_detection_timer); - monitor->presence_detection_timer = 0; - } - } else { - /* - * Do not invoke presence detected callback until user is detected by all the sensors. - * Wait for at most UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME for all sensor to report - * user presence detected event. If all sensors do not detect the users by said time, then - * user presence detected by few sensors will be ignored and detection history is cleared. - */ - monitor->presence_detection_timer = g_timeout_add_seconds( - UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME, - __ua_reset_presence_detected_history, monitor); - } break; case UA_DETECT_MODE_ANY_SENSOR: - if (user_info) - monitor->presence_cb(UA_ERROR_NONE, monitor, - sensor_type, user_info->user_handle, monitor->user_data); - else + if (user_info && monitor->presence_user_cb.callback) + ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)( + UA_ERROR_NONE, monitor, sensor_type, user_info->user_handle, + monitor->presence_user_cb.user_data); + + if ((monitor->presence_detected_bitmask & bitmask) == 0) monitor->presence_cb(UA_ERROR_NONE, monitor, - sensor_type, NULL, monitor->user_data); + sensor_type, monitor->user_data); + + + monitor->presence_detected_bitmask |= bitmask; break; @@ -828,7 +890,7 @@ static void __ua_sensor_send_presence_detected(ua_monitor_s *monitor, unsigned i FUNC_EXIT; } -static gboolean __ua_absence_detection_timeout(gpointer data) +static void __ua_send_absence_detection() { FUNC_ENTRY; GSList *l; @@ -843,25 +905,29 @@ static gboolean __ua_absence_detection_timeout(gpointer data) if (!monitor) continue; + if (monitor->absence_mode == UA_DETECT_MODE_ANY_SENSOR) { + monitor->absence_detected_bitmask = 0; + continue; + } + UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X", monitor->sensor_bitmask, monitor->absence_detected_bitmask); if (monitor->sensor_bitmask == monitor->absence_detected_bitmask) { - if (monitor->absence_all_users_cb.callback) - ((ua_absence_detected_cb)monitor->absence_all_users_cb.callback)( - UA_ERROR_NONE, monitor, UA_SENSOR_MAX, monitor->absence_all_users_cb.user_data); + if (monitor->absence_cb) + monitor->absence_cb(UA_ERROR_NONE, monitor, + UA_SENSOR_MAX, monitor->user_data); } monitor->absence_detected_bitmask = 0; - if (!monitor->absence_cb) + if (!monitor->absence_user_cb.callback) continue; /* - * As MOTION and LIGHT sensors do not support user info, If MOTION and LIGHT + * As MOTION and LIGHT sensors do not support user info, If only MOTION and LIGHT * sensors are registered, do not invoke user absence callback. */ - if ((monitor->sensor_bitmask & UA_SENSOR_MOTION) || - (monitor->sensor_bitmask & UA_SENSOR_LIGHT)) + if (monitor->sensor_bitmask == (UA_SENSOR_MOTION | UA_SENSOR_LIGHT)) continue; for (l1 = user_list; NULL != l1; l1 = g_slist_next(l1)) { @@ -871,17 +937,16 @@ static gboolean __ua_absence_detection_timeout(gpointer data) if (!user_info || (monitor->sensor_bitmask & user_info->sensor_bitmask)) continue; - monitor->absence_cb(UA_ERROR_NONE, monitor, - UA_SENSOR_MAX, user_info->user_handle, monitor->user_data); + ((ua_absence_user_detected_cb)monitor->absence_user_cb.callback)( + UA_ERROR_NONE, monitor, UA_SENSOR_MAX, user_info->user_handle, + monitor->absence_user_cb.user_data); } } - absence_timer = 0; FUNC_EXIT; - return FALSE; } -static void __ua_sensor_send_absence_detected(ua_monitor_s *monitor, unsigned int bitmask, ua_user_info_s *user_info) +static void __ua_sensor_absence_detected(ua_monitor_s *monitor, unsigned int bitmask, ua_user_info_s *user_info) { FUNC_ENTRY; ua_sensor_e sensor_type; @@ -895,30 +960,26 @@ static void __ua_sensor_send_absence_detected(ua_monitor_s *monitor, unsigned in if (all_absence) monitor->absence_detected_bitmask |= bitmask; - if (0 != absence_timer) - return; - - absence_timer = g_timeout_add_seconds( - UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME, - __ua_absence_detection_timeout, NULL); break; case UA_DETECT_MODE_ANY_SENSOR: /* First add user info to local users list and then invoke callback */ if (user_info) { - monitor->absence_cb(UA_ERROR_NONE, monitor, - sensor_type, user_info->user_handle, monitor->user_data); + if (monitor->absence_user_cb.callback) + ((ua_absence_user_detected_cb)monitor->absence_user_cb.callback)( + UA_ERROR_NONE, monitor, sensor_type, user_info->user_handle, + monitor->absence_user_cb.user_data); all_absence = _ua_check_all_users_absence_any(bitmask); if (all_absence) { - if (monitor->absence_all_users_cb.callback) - ((ua_absence_detected_cb)monitor->absence_all_users_cb.callback)( - UA_ERROR_NONE, monitor, sensor_type, monitor->absence_all_users_cb.user_data); + if (monitor->absence_cb) + monitor->absence_cb(UA_ERROR_NONE, monitor, + sensor_type, monitor->user_data); } } else { - if (monitor->absence_all_users_cb.callback) - ((ua_absence_detected_cb)monitor->absence_all_users_cb.callback)( - UA_ERROR_NONE, monitor, sensor_type, monitor->absence_all_users_cb.user_data); + if (monitor->absence_cb) + monitor->absence_cb(UA_ERROR_NONE, monitor, + sensor_type, monitor->user_data); } break; @@ -945,7 +1006,7 @@ void _ua_monitor_handle_user_presence_detected(unsigned int bitmask, ua_user_inf if (monitor->presence_cb) { /* Presence detection ongoing */ - __ua_sensor_send_presence_detected(monitor, bitmask, user_info); + __ua_sensor_presence_detected(monitor, bitmask, user_info); } else { UA_WARN("Unexpected, detection started but callbacks are NULL"); } @@ -969,12 +1030,22 @@ void _ua_monitor_handle_user_absence_detected(unsigned int bitmask, ua_user_info continue; /* Absence detection ongoing */ - __ua_sensor_send_absence_detected(monitor, bitmask, user_info); + __ua_sensor_absence_detected(monitor, bitmask, user_info); } FUNC_EXIT; } +void _ua_monitor_handle_detection_stopped() +{ + FUNC_ENTRY; + + __ua_send_presence_detection(); + __ua_send_absence_detection(); + + FUNC_EXIT; +} + static void __ua_remove_sensor(ua_monitor_s *monitor, ua_sensor_e sensor_type) { FUNC_ENTRY; @@ -1171,4 +1242,4 @@ int ua_set_detection_params(int cycle, int period, int retries) FUNC_EXIT; return UA_ERROR_NONE; } -/* LCOV_EXCL_STOP */
\ No newline at end of file +/* LCOV_EXCL_STOP */ diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c index faf8c29..b14e6f4 100644 --- a/src/user-awareness-users.c +++ b/src/user-awareness-users.c @@ -271,12 +271,12 @@ int _ua_user_add_info_to_list_from_uapi_data(uam_user_info_t* uam_info) user_info->isadded = true; user_info->user_handle = (ua_user_h)user_info; - /* Set user state by default ACTIVATE as this field will be use - * during absence detection where by default all users and in ACTIVATE state + /* Set user state by default INACTIVATE as this field will be use + * during absence detection where by default all users are in INACTIVATE state * user will go in ACTIVATE state after presence is detected for thst user. */ - user_info->state = UA_PRESENCE_STATE_ACTIVATE; - user_info->sensor_bitmask = UAM_SENSOR_BITMASK_BLE | UAM_SENSOR_BITMASK_WIFI; + user_info->state = UA_PRESENCE_STATE_INACTIVATE; + user_info->sensor_bitmask = 0; ua_users_list = g_slist_append(ua_users_list, user_info); FUNC_EXIT; @@ -325,12 +325,12 @@ int _ua_user_add_info_to_list(ua_user_info_s* ua_info) user_info->isadded = true; user_info->user_handle = (ua_user_h)user_info; - /* Set user state by default ACTIVATE as this field will be use - * during absence detection where by default all users and in ACTIVATE state + /* Set user state by default INACTIVATE as this field will be use + * during absence detection where by default all users are in INACTIVATE state * user will go in ACTIVATE state after presence is detected for thst user. */ - user_info->state = UA_PRESENCE_STATE_ACTIVATE; - user_info->sensor_bitmask = UAM_SENSOR_BITMASK_BLE | UAM_SENSOR_BITMASK_WIFI; + user_info->state = UA_PRESENCE_STATE_INACTIVATE; + user_info->sensor_bitmask = 0; ua_users_list = g_slist_append(ua_users_list, user_info); FUNC_EXIT; @@ -675,8 +675,8 @@ int ua_user_get_default_user(ua_user_h* user_handle) } user->account = g_strdup(uam_user.account); user->name = g_strdup(uam_user.name); - user->state = UA_PRESENCE_STATE_ACTIVATE; - user->sensor_bitmask = UAM_SENSOR_BITMASK_BLE | UAM_SENSOR_BITMASK_WIFI; + user->state = UA_PRESENCE_STATE_INACTIVATE; + user->sensor_bitmask = 0; user->user_handle = (ua_user_h)user; *user_handle = (ua_user_h)user; @@ -2046,8 +2046,8 @@ int _ua_intr_get_default_user(void) } user->account = g_strdup(uam_user.account); user->name = g_strdup(uam_user.name); - user->state = UA_PRESENCE_STATE_ACTIVATE; - user->sensor_bitmask = UAM_SENSOR_BITMASK_BLE | UAM_SENSOR_BITMASK_WIFI; + user->state = UA_PRESENCE_STATE_INACTIVATE; + user->sensor_bitmask = 0; user->user_handle = (ua_user_h)user; user->default_user = true; user->isadded = true; diff --git a/test/uat-detections.c b/test/uat-detections.c index d0d2390..0d94f6f 100644 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -32,39 +32,17 @@ static char presence_type[MENU_DATA_SIZE + 1] = "2"; static char absence_type[MENU_DATA_SIZE + 1] = "2"; static void __presence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_user_h user_handle, void *user_data) + ua_sensor_e sensor, void *user_data) { - int ret = UA_ERROR_NONE; - char *account = NULL; - msgp("result : %s", uat_get_error_str(result)); msgp("sensor %s PRESENCE detected", uat_get_sensor_bitmask_str(sensor)); - - if (user_handle) { - ret = ua_user_get_account(user_handle, &account); - if (UA_ERROR_NONE == ret) { - msgp("User account info %s", account); - free(account); - } - } } static void __absence_detected_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensor, ua_user_h user_handle, void *user_data) + ua_sensor_e sensor, void *user_data) { - int ret = UA_ERROR_NONE; - char *account = NULL; - msgp("result : %s", uat_get_error_str(result)); msgp("sensor %s ABSENCE detected", uat_get_sensor_bitmask_str(sensor)); - - if (user_handle) { - ret = ua_user_get_account(user_handle, &account); - if (UA_ERROR_NONE == ret) { - msgp("User account info %s", account); - free(account); - } - } } static int run_ua_monitor_start_presence_detection( diff --git a/test/uat-init.c b/test/uat-init.c index 4f03cac..4a67f34 100644 --- a/test/uat-init.c +++ b/test/uat-init.c @@ -36,16 +36,46 @@ static char detection_period[MENU_DATA_SIZE + 1] = {0,}; static char detection_retries[MENU_DATA_SIZE + 1] = {0,}; static void __absence_detected_all_cb(int result, ua_monitor_h monitor, - ua_sensor_e sensors, void *user_data) + ua_sensor_e sensor, ua_user_h user_handle, void *user_data) { - msgb("absence all detected"); + int ret = UA_ERROR_NONE; + char *account = NULL; + + msgp("result : %s", uat_get_error_str(result)); + msgp("sensor %s ABSENCE detected", uat_get_sensor_bitmask_str(sensor)); + + if (user_handle) { + ret = ua_user_get_account(user_handle, &account); + if (UA_ERROR_NONE == ret) { + msgp("User account info %s", account); + free(account); + } + } +} + +static void __presence_detected_all_cb(int result, ua_monitor_h monitor, + ua_sensor_e sensor, ua_user_h user_handle, void *user_data) +{ + int ret = UA_ERROR_NONE; + char *account = NULL; + + msgp("result : %s", uat_get_error_str(result)); + msgp("sensor %s PRESENCE detected", uat_get_sensor_bitmask_str(sensor)); + + if (user_handle) { + ret = ua_user_get_account(user_handle, &account); + if (UA_ERROR_NONE == ret) { + msgp("User account info %s", account); + free(account); + } + } } static void __sensor_state_changed_cb(bool ready, - ua_sensor_e sensor, ua_monitor_h monitor, void *user_data) + ua_sensor_e sensor, ua_monitor_h monitor, void *user_data) { msgb("sensor: %s is %s", - uat_get_sensor_bitmask_str(sensor), (ready ? "Ready" : "Not Ready")); + uat_get_sensor_bitmask_str(sensor), (ready ? "Ready" : "Not Ready")); } static int run_ua_monitor_create(MManager *mm, struct menu_data *menu) @@ -99,55 +129,86 @@ static int run_ua_monitor_destroy(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_ua_monitor_set_absence_detected_cb( - MManager *mm, struct menu_data *menu) +static int run_ua_monitor_set_user_absence_detected_cb( + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_set_absence_detected_cb"); - ret = ua_monitor_set_absence_detected_cb(ua_mon, - __absence_detected_all_cb, ua_mon); + ret = ua_monitor_set_user_absence_detected_cb(ua_mon, + __absence_detected_all_cb, ua_mon); msg(" - ua_monitor_set_absence_detected_cb() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_monitor_set_user_presence_detected_cb( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_monitor_set_presence_detected_cb"); + + ret = ua_monitor_set_user_presence_detected_cb(ua_mon, + __presence_detected_all_cb, ua_mon); + + msg(" - ua_monitor_set_presence_detected_cb() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_set_sensor_state_cb( - MManager *mm, struct menu_data *menu) + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_set_sensor_state_cb"); ret = ua_monitor_set_sensor_state_cb(ua_mon, - __sensor_state_changed_cb, ua_mon); + __sensor_state_changed_cb, ua_mon); msg(" - ua_monitor_set_sensor_state_cb() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); return RET_SUCCESS; } -static int run_ua_monitor_unset_absence_detected_cb( - MManager *mm, struct menu_data *menu) +static int run_ua_monitor_unset_user_absence_detected_cb( + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_unset_absence_detected_cb"); - ret = ua_monitor_unset_absence_detected_cb(ua_mon); + ret = ua_monitor_unset_user_absence_detected_cb(ua_mon); msg(" - ua_monitor_unset_absence_detected_cb() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_monitor_unset_user_presence_detected_cb( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_monitor_unset_presence_detected_cb"); + + ret = ua_monitor_unset_user_presence_detected_cb(ua_mon); + + msg(" - ua_monitor_unset_presence_detected_cb() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_unset_sensor_state_cb( - MManager *mm, struct menu_data *menu) + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; @@ -156,13 +217,13 @@ static int run_ua_monitor_unset_sensor_state_cb( ret = ua_monitor_unset_sensor_state_cb(ua_mon); msg(" - ua_monitor_unset_sensor_state_cb() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_enable_low_power_mode( - MManager *mm, struct menu_data *menu) + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; @@ -171,13 +232,13 @@ static int run_ua_enable_low_power_mode( ret = ua_enable_low_power_mode(); msg(" - ua_enable_low_power_mode() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_disable_low_power_mode( - MManager *mm, struct menu_data *menu) + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; @@ -186,13 +247,13 @@ static int run_ua_disable_low_power_mode( ret = ua_enable_low_power_mode(); msg(" - ua_disable_low_power_mode() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_get_detection_params( - MManager *mm, struct menu_data *menu) + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; int cycle = 0; @@ -204,7 +265,7 @@ static int run_ua_get_detection_params( ret = ua_get_detection_params(&cycle, &period, &retries); msg(" - ua_get_detection_params() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); if (UA_ERROR_NONE == ret) msgb("Detection params: [cycle = %d], [period = %d], [retries = %d]", @@ -214,7 +275,7 @@ static int run_ua_get_detection_params( } static int run_ua_set_detection_params( - MManager *mm, struct menu_data *menu) + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; int cycle = 0; @@ -235,7 +296,7 @@ static int run_ua_set_detection_params( ret = ua_set_detection_params(cycle, period, retries); msg(" - ua_set_detection_params() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret, uat_get_error_str(ret)); return RET_SUCCESS; } @@ -259,21 +320,25 @@ struct menu_data menu_ua_init[] = { NULL, run_ua_monitor_create, NULL }, { "2", "ua_monitor_destroy", NULL, run_ua_monitor_destroy, NULL }, - { "3", "ua_monitor_set_absence_detected_cb", - NULL, run_ua_monitor_set_absence_detected_cb, NULL }, - { "4", "ua_monitor_set_sensor_state_cb", + { "3", "ua_monitor_set_user_sensor_state_cb", NULL, run_ua_monitor_set_sensor_state_cb, NULL }, - { "5", "ua_monitor_unset_absence_detected_cb", - NULL, run_ua_monitor_unset_absence_detected_cb, NULL }, - { "6", "ua_monitor_unset_sensor_state_cb", + { "4", "ua_monitor_unset_user_sensor_state_cb", NULL, run_ua_monitor_unset_sensor_state_cb, NULL }, - { "7", "ua_enable_low_power_mode", + { "5", "ua_monitor_set_user_absence_detected_cb", + NULL, run_ua_monitor_set_user_absence_detected_cb, NULL }, + { "6", "ua_monitor_unset_absence_detected_cb", + NULL, run_ua_monitor_unset_user_absence_detected_cb, NULL }, + { "7", "ua_monitor_set_user_presence_detected_cb", + NULL, run_ua_monitor_set_user_presence_detected_cb, NULL }, + { "8", "ua_monitor_unset_presence_detected_cb", + NULL, run_ua_monitor_unset_user_presence_detected_cb, NULL }, + { "9", "ua_enable_low_power_mode", NULL, run_ua_enable_low_power_mode, NULL }, - { "8", "ua_disable_low_power_mode", + { "10", "ua_disable_low_power_mode", NULL, run_ua_disable_low_power_mode, NULL }, - { "9", "ua_get_detection_params", + { "11", "ua_get_detection_params", NULL, run_ua_get_detection_params, NULL }, - { "10", "ua_set_detection_params", + { "12", "ua_set_detection_params", menu_ua_set_detection_params, NULL, NULL }, { NULL, NULL, }, }; |