Detection stopped event updated with detection cycle mid/end
authorLokesh <l.kasana@samsung.com>
Wed, 6 Nov 2019 10:22:05 +0000 (15:52 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 15 Nov 2019 09:44:16 +0000 (18:44 +0900)
Clean user_state only when it is end of detection cycle.

Change-Id: Iadd958c6048b8cf5935c8c85217709ada4942c51
Signed-off-by: Lokesh <l.kasana@samsung.com>
include/user-awareness-private.h
src/user-awareness-event-handler.c
src/user-awareness-monitors.c

index a436cdc348037dd6885edb3809e315798d1a3871..f4b77f0fe5801ccc0625f5305d03dcc6b44fa4ea 100644 (file)
@@ -364,11 +364,14 @@ void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *sensor_info,
  * @brief Stops monitoring detection.
  * @since_tizen 5.5
  *
+ * @param[in] svc_name Service name.
+ * @param[in] cycle_state Detection cycle in mid or end.
+ *
  * @exception
  * @pre
  * @post
  */
-void _ua_monitor_handle_detection_stopped(void);
+void _ua_monitor_handle_detection_stopped(char *svc_name, uam_cycle_state_e cycle_state);
 
 /**
  * @brief Changes sensor state.
index 9a293486a215592a1c9381f476ac2f090ffea78f..e591c8449bfefeb059358b6f6328a2e245704b06 100644 (file)
@@ -141,7 +141,12 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param,
                break;
        }
        case UAM_EVENT_DETECTION_STOPPED: {
-               _ua_monitor_handle_detection_stopped();
+               uam_detection_stopped_event_data_s *event_data = event_param->data;
+               ret_if(NULL == event_data);
+               ret_if(NULL == event_data->service);
+
+               _ua_monitor_handle_detection_stopped(event_data->service,
+                               event_data->cycle_state);
                break;
        }
        case UAM_EVENT_SENSOR_STATE_READY: {
index 6123708d18cf1a7b49fa23006a32fb0ebab6b0c8..2c6fc44e4d6244920e3d3f1ed76f7556cc11d704 100644 (file)
@@ -154,7 +154,7 @@ static void __ua_free_user_state_info_t(gpointer data)
        FUNC_EXIT;
 }
 
-static void __ua_user_state_clean()
+static void __ua_user_state_clean(char *svc_name)
 {
        FUNC_ENTRY;
        GSList *l;
@@ -162,10 +162,12 @@ static void __ua_user_state_clean()
        for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
 
-               if (!monitor)
+               if (!monitor || g_strcmp0(monitor->service, svc_name))
                        continue;
 
                g_slist_free_full(monitor->user_state, __ua_free_user_state_info_t);
+               monitor->presence_detected_bitmask = 0;
+               monitor->absence_detected_bitmask = 0;
                monitor->user_state = NULL;
                monitor->env_user_cb_sent = FALSE;
        }
@@ -389,7 +391,7 @@ static void __ua_monitor_send_env_user_presence_cb(ua_monitor_s *monitor)
        return;
 }
 
-static void __ua_send_presence_detection()
+static void __ua_send_presence_detection(char *svc_name)
 {
        FUNC_ENTRY;
        GSList *l;
@@ -398,7 +400,7 @@ static void __ua_send_presence_detection()
        for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
 
-               if (!monitor)
+               if (!monitor || g_strcmp0(monitor->service, svc_name))
                        continue;
 
                if (monitor->presence_mode != UA_DETECT_MODE_ANY_SENSOR) {
@@ -423,7 +425,9 @@ static void __ua_send_presence_detection()
                        }
                }
 
-               monitor->presence_detected_bitmask = 0;
+               /* Only reset environmental sensors presence data */
+               monitor->presence_detected_bitmask &=
+                               ~(UA_SENSOR_MOTION | UA_SENSOR_LIGHT);
        }
 
        FUNC_EXIT;
@@ -639,7 +643,7 @@ static void __ua_monitor_send_user_absence_cb(ua_monitor_s *monitor,
        return;
 }
 
-static void __ua_send_absence_detection()
+static void __ua_send_absence_detection(char *svc_name)
 {
        FUNC_ENTRY;
        GSList *l;
@@ -648,7 +652,7 @@ static void __ua_send_absence_detection()
        for (l = ua_monitor_list; NULL != l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
 
-               if (!monitor)
+               if (!monitor || g_strcmp0(monitor->service, svc_name))
                        continue;
 
                UA_INFO("monitor->sensor_bitmask: 0x%8.8X, monitor->absence_detected_bitmask: 0x%8.8X",
@@ -686,7 +690,9 @@ static void __ua_send_absence_detection()
                        }
                }
 
-               monitor->absence_detected_bitmask = 0;
+               /* Only reset environmental sensors presence data */
+               monitor->absence_detected_bitmask &=
+                               ~(UA_SENSOR_MOTION | UA_SENSOR_LIGHT);
        }
 
        FUNC_EXIT;
@@ -886,13 +892,16 @@ void _ua_monitor_handle_user_absence_detected(uam_sensor_info_s *info,
        FUNC_EXIT;
 }
 
-void _ua_monitor_handle_detection_stopped()
+void _ua_monitor_handle_detection_stopped(char *svc_name,
+               uam_cycle_state_e cycle_state)
 {
        FUNC_ENTRY;
 
-       __ua_send_presence_detection();
-       __ua_send_absence_detection();
-       __ua_user_state_clean();
+       __ua_send_presence_detection(svc_name);
+       __ua_send_absence_detection(svc_name);
+
+       if (cycle_state == UAM_DETECTION_CYCLE_END)
+               __ua_user_state_clean(svc_name);
 
        FUNC_EXIT;
 }