From fb85cbef0f170ebcae7a51137d5f99d83132efdb Mon Sep 17 00:00:00 2001 From: Lokesh Date: Wed, 6 Nov 2019 15:42:39 +0530 Subject: [PATCH] Detection stopped event updated with detection cycle mid/end 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 --- include/ua-api.h | 18 ++++++++++++++++++ ua-api/src/ua-event-handler.c | 14 +++++++++++++- ua-daemon/src/ua-manager-core.c | 23 +++++++++++++++++++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index c804679..0dc8f17 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -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 */ diff --git a/ua-api/src/ua-event-handler.c b/ua-api/src/ua-event-handler.c index dbd1dbc..a9951fb 100644 --- a/ua-api/src/ua-event-handler.c +++ b/ua-api/src/ua-event-handler.c @@ -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; diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index f4ab8da..22a30cc 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -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; } -- 2.7.4