Detection stopped event updated with detection cycle mid/end
authorLokesh <l.kasana@samsung.com>
Wed, 6 Nov 2019 10:12:39 +0000 (15:42 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 15 Nov 2019 09:11:01 +0000 (18:11 +0900)
Every one minute we receive environmental presence/absence and detection
stopped calls. Earlier _uam_core_handle_detection_stopped() sends
detection_stopped_event which then called __ua_user_state_clean() and
cleaned recorded WIFI/BLE data in CAPI. Hence it cannot be used for
next one minute cycles of environmental sensors.

Change-Id: Ibad4cbf5e05840b31a593984a0f00f1ca4b72ae9
Signed-off-by: Lokesh <l.kasana@samsung.com>
include/ua-api.h
ua-api/src/ua-event-handler.c
ua-daemon/src/ua-manager-core.c

index c804679..0dc8f17 100644 (file)
@@ -446,6 +446,15 @@ typedef enum {
 } uam_presence_state_e;
 
 /**
+ * @brief Enumerations for detection cycle state.
+ * @since_tizen 5.5
+ */
+typedef enum {
+       UAM_DETECTION_CYCLE_MID = 0x00, /**< Invaild state */
+       UAM_DETECTION_CYCLE_END, /**< Presence state */
+} uam_cycle_state_e;
+
+/**
  * @brief Enumerations for OS type.
  * @since_tizen 5.5
  */
@@ -551,6 +560,15 @@ typedef struct {
 } uam_user_event_data_s;
 
 /**
+ * @brief Detection stopped event structure.
+ * @since_tizen 5.5
+ */
+typedef struct {
+       char service[UAM_SERVICE_MAX_STRING_LEN]; /**< Service name */
+       uam_cycle_state_e cycle_state; /**< detection cycle state */
+} uam_detection_stopped_event_data_s;
+
+/**
  * @brief Application info structure.
  * @since_tizen 5.5
  */
index dbd1dbc..a9951fb 100644 (file)
@@ -280,7 +280,19 @@ static void __uam_event_handler(GDBusConnection *connection,
                __uam_send_event(UAM_EVENT_DETECTION_STARTED, result, NULL,
                                event_info->cb, event_info->user_data);
        } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DETECTION_STOPPED)) {
-               __uam_send_event(UAM_EVENT_DETECTION_STOPPED, result, NULL,
+               uam_detection_stopped_event_data_s event_data;
+               char *svc_name = NULL;
+               uam_cycle_state_e cycle_state;
+
+               g_variant_get(parameters, "(&si)", &svc_name, &cycle_state);
+
+               UAM_DBG("Service: %s, cycle_state: %s", svc_name,
+                               cycle_state ? "end" : "mid");
+
+               g_strlcpy(event_data.service, svc_name, UAM_SERVICE_MAX_STRING_LEN);
+               event_data.cycle_state = cycle_state;
+
+               __uam_send_event(UAM_EVENT_DETECTION_STOPPED, result, &event_data,
                                event_info->cb, event_info->user_data);
        } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_DEVICE_FOUND)) {
                uam_device_info_s dev_info;
index f4ab8da..22a30cc 100644 (file)
@@ -3191,7 +3191,10 @@ void _uam_core_handle_detection_started(unsigned int sensor)
 void _uam_core_handle_detection_stopped(unsigned int sensor)
 {
        FUNC_ENTRY;
+
        uam_tech_type_e type = UAM_TECH_TYPE_NONE;
+       uam_cycle_state_e cycle_state;
+       GSList *l = NULL;
 
        ret_if((detecting_sensors & sensor) == 0);
        UAM_DBG("Sensor: 0x%8.8X, detecting_sensors: 0x%8.8X",
@@ -3206,10 +3209,26 @@ void _uam_core_handle_detection_stopped(unsigned int sensor)
        if (UAM_TECH_TYPE_NONE != type)
                __send_user_absence_event(type, sensor);
 
-       if (0 == detecting_sensors)
+       if (0 == detecting_sensors) {
                /* Send detection stopped event */
-               _uam_manager_send_event(NULL, UAM_EVENT_DETECTION_STOPPED, NULL);
+               for (l = monitors; l; l = g_slist_next(l)) {
+                       uam_monitor_info_t *mon = l->data;
+
+                       if (!mon || !mon->name || !mon->service)
+                               continue;
+                       uam_db_service_info_t *service = mon->service;
 
+                       UAM_DBG("service->remaining_time: %d", service->remaining_time);
+                       cycle_state = (service->remaining_time <= UAM_DETECTION_CYCLE_MIN) ?
+                                       UAM_DETECTION_CYCLE_END : UAM_DETECTION_CYCLE_MID;
+
+                       _uam_manager_send_event(mon->name, UAM_EVENT_DETECTION_STOPPED,
+                                       g_variant_new("(si)", service->name, cycle_state));
+                       UAM_DBG("Sent UAM_EVENT_DETECTION_STOPPED to %s, Service: %s,"
+                                       " cycle state:[%s]",
+                                       mon->name, service->name, cycle_state ? "end" : "mid");
+               }
+       }
        FUNC_EXIT;
 }