Add functionality to report instant sensor status change
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 21 Oct 2019 11:35:16 +0000 (20:35 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 1 Nov 2019 03:53:48 +0000 (12:53 +0900)
- Problem: in ABSENCE case, even the motion sensor detects ABSENCE
ua-manager reports this ABSENCE state after the detection window complete.
- Cause: If ABSENCE case, the ABSENCE can be jurged only when the
detction window complete.
- Solution: Whenever the sensor status is changed, plugin reports status
changed event immediately so that the user can recognize ABSENCE event
takes place during uncompleted ABSENCE detection window.

Change-Id: Ia5b12304976db4b89e5fa0977ea366a08361fc0e
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
14 files changed:
include/ua-api.h
include/ua-internal.h
packaging/ua-manager.spec
ua-api/src/ua-common.c
ua-api/src/ua-event-handler.c
ua-daemon/include/ua-manager-core.h
ua-daemon/src/pm/ua-ble-plugin-handler.c
ua-daemon/src/pm/ua-light-plugin-handler.c
ua-daemon/src/pm/ua-motion-plugin-handler.c
ua-daemon/src/pm/ua-pm-util.c
ua-daemon/src/pm/ua-wifi-plugin-handler.c
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-event-sender.c
ua-plugins/include/ua-plugin.h

index c305b48..a33fea6 100644 (file)
@@ -162,6 +162,7 @@ typedef enum {
        UAM_EVENT_SCAN_COMPLETED, /**< Scan completed */
        UAM_EVENT_SERVICE_REGISTERED, /**< Service registered */
        UAM_EVENT_SERVICE_UNREGISTERED, /**< Service registered */
+       UAM_EVENT_SENSOR_STATUS_CHANGED, /**< Sensor status changed */
        UAM_EVENT_MAX, /**< Max. event number */
 } uam_event_e;
 
@@ -501,6 +502,7 @@ typedef struct {
  * @since_tizen 5.5
  */
 typedef struct {
+       unsigned int status; /**< Sensor status */
        unsigned int sensor_bitmask; /**< sensor bitmask of discovered sensor */
        long timestamp; /**< Latest timestamp when sensor was discoverd */
        int accuracy; /**< Accuracy info from sensor sensor */
index c70a401..6f57de6 100644 (file)
@@ -106,6 +106,7 @@ typedef enum {
 #define UAM_SIGNAL_SCAN_COMPLETED "ScanCompleted"
 #define UAM_SIGNAL_SERVICE_REGISTERED "ServiceRegistered"
 #define UAM_SIGNAL_SERVICE_UNREGISTERED "ServiceUnregistered"
+#define UAM_SIGNAL_SENSOR_STATUS_CHANGED "SensorStatusChanged"
 
 #define CASE_TO_STR(x) case x: return #x;
 
index 0244ca3..a1ba30d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.11.7
+Version:    0.12.0
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 4bf3793..e2282ec 100644 (file)
@@ -110,6 +110,7 @@ const char *_uam_event_to_str(unsigned int event)
        CASE_TO_STR(UAM_EVENT_SCAN_COMPLETED)
        CASE_TO_STR(UAM_EVENT_SERVICE_REGISTERED)
        CASE_TO_STR(UAM_EVENT_SERVICE_UNREGISTERED)
+       CASE_TO_STR(UAM_EVENT_SENSOR_STATUS_CHANGED)
        default:
                return "UNKNOWN ERROR";
        }
index f371671..e09fe62 100644 (file)
@@ -28,6 +28,32 @@ typedef struct {
 static gboolean is_registered = FALSE;
 static uam_event_handler_data_t *event_handler_data = NULL;
 
+static void __uam_copy_sensor_data(uam_sensor_info_s *sensor_info, int status,
+       unsigned int bitmask, long int timestamp, int accuracy, int count, double *values)
+{
+       FUNC_ENTRY;
+
+       ret_if(NULL == sensor_info);
+
+       memset(sensor_info, 0, sizeof(uam_sensor_info_s));
+       sensor_info->status = status;
+       sensor_info->sensor_bitmask = bitmask;
+       sensor_info->timestamp = timestamp;
+       sensor_info->accuracy = accuracy;
+       sensor_info->count = count;
+       for (int i = 0; i < UAM_SENSOR_MAX_VALUES; i++) {
+               sensor_info->values[i] = values[i];
+       }
+
+       UAM_INFO("status [%d] sensor bitmask [%u] timestamp [%ld] accuracy [%d]" \
+               "count [%d] value0 [%f] value1 [%f] value2 [%f] value3 [%f]",
+               sensor_info->status, sensor_info->sensor_bitmask, sensor_info->timestamp,
+               sensor_info->accuracy, sensor_info->count, sensor_info->values[0],
+               sensor_info->values[1], sensor_info->values[2], sensor_info->values[3]);
+
+       FUNC_EXIT;
+}
+
 static void __uam_send_event(int event, int result,
                void *data, void *callback, void *user_data)
 {
@@ -121,7 +147,7 @@ static void __uam_event_handler(GDBusConnection *connection,
                int accuracy, count;
                double values[UAM_SENSOR_MAX_VALUES];
 
-               g_variant_get(parameters, "(uxiidddd)", &sensor_bitmask, &timestamp,
+               g_variant_get(parameters, "(uiiidddd)", &sensor_bitmask, &timestamp,
                                                &accuracy, &count, &values[0], &values[1],
                                                &values[2], &values[3]);
                memset(&sensor_info, 0, sizeof(uam_sensor_info_s));
@@ -148,7 +174,7 @@ static void __uam_event_handler(GDBusConnection *connection,
                int accuracy, count;
                double values[UAM_SENSOR_MAX_VALUES];
 
-               g_variant_get(parameters, "(uxiidddd)", &sensor_bitmask, &timestamp,
+               g_variant_get(parameters, "(uiiidddd)", &sensor_bitmask, &timestamp,
                                                &accuracy, &count, &values[0], &values[1],
                                                &values[2], &values[3]);
                memset(&sensor_info, 0, sizeof(uam_sensor_info_s));
@@ -323,6 +349,23 @@ static void __uam_event_handler(GDBusConnection *connection,
                event = UAM_EVENT_SERVICE_UNREGISTERED;
                __uam_send_event(event, result, &svc_info,
                                event_info->cb, event_info->user_data);
+       } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_SENSOR_STATUS_CHANGED)) {
+               uam_sensor_info_s sensor_info;
+               unsigned int sensor_bitmask;
+               long int timestamp;
+               int status, accuracy, count;
+               double values[UAM_SENSOR_MAX_VALUES];
+
+               g_variant_get(parameters, "(uuiiidddd)", &status, &sensor_bitmask, &timestamp,
+                                               &accuracy, &count, &values[0], &values[1],&values[2], &values[3]);
+
+               __uam_copy_sensor_data(&sensor_info, status, sensor_bitmask, timestamp,
+                                       accuracy, count, values);
+
+               event = UAM_EVENT_SENSOR_STATUS_CHANGED;
+
+               __uam_send_event(event, result, &sensor_info,
+                       event_info->cb, event_info->user_data);
        } else {
                UAM_WARN("Unknown signal received: %s", signal_name);
        }
index c9b1c04..76f9493 100644 (file)
@@ -231,6 +231,9 @@ int _uam_core_update_device(const uam_device_info_s *a_device);
 
 int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv);
 
+void _uam_core_handle_status_changed(unsigned int sensor,
+       unsigned int type, void *info);
+
 #ifdef __cplusplus
 }
 #endif
index 1818488..52e9263 100644 (file)
@@ -111,6 +111,7 @@ static void ble_device_added_callback(int status, uas_device_info_t *device)
 uas_callbacks_t ble_cbs = {
        .state_changed_cb = ble_state_changed_callback,
        .detection_state_cb = ble_detection_state_changed_cb,
+       .detection_status_cb = NULL,
        .detected_cb = ble_lpm_detection_callback,
        .device_detected_cb = ble_device_detection_callback,
        .device_added_cb = ble_device_added_callback,
index 9f0d4e7..51e873d 100644 (file)
@@ -70,6 +70,7 @@ void light_detection_callback(uas_detection_type_e type, void *sensor_info)
 uas_callbacks_t light_cbs = {
        .state_changed_cb = light_state_changed_callback,
        .detection_state_cb = light_detection_state_changed_cb,
+       .detection_status_cb = NULL,
        .detected_cb = light_detection_callback,
        .device_detected_cb = NULL,
        .device_added_cb = NULL,
index 713a848..32f8b3a 100644 (file)
@@ -43,6 +43,28 @@ static void motion_detection_state_changed_cb(int state)
        FUNC_EXIT;
 }
 
+
+static void motion_detection_status_changed_cb(uas_detection_type_e type,
+       void *sensor_info)
+{
+       FUNC_ENTRY;
+
+       uas_sensor_info_t *info = NULL;
+       uam_sensor_info_s *motion_info = NULL;
+
+       UAM_ERR("Motion: %s", type == UAS_PRESENCE ? "PRESENCE" : "ABSENCE");
+
+       if (sensor_info)
+               info = sensor_info;
+       motion_info = _pm_util_uas_sensor_info_to_uam_sensor_info(info);
+
+       _uam_core_handle_status_changed(UAM_SENSOR_BITMASK_MOTION, type, motion_info);
+
+       g_free(motion_info);
+
+       FUNC_EXIT;
+}
+
 void motion_detection_callback(uas_detection_type_e type, void *sensor_info)
 {
        FUNC_ENTRY;
@@ -71,6 +93,7 @@ void motion_detection_callback(uas_detection_type_e type, void *sensor_info)
 uas_callbacks_t motion_cbs = {
        .state_changed_cb = motion_state_changed_callback,
        .detection_state_cb = motion_detection_state_changed_cb,
+       .detection_status_cb = motion_detection_status_changed_cb,
        .detected_cb = motion_detection_callback,
        .device_detected_cb = NULL,
        .device_added_cb = NULL,
index b46242f..c9c1b30 100644 (file)
@@ -358,7 +358,8 @@ uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_sca
        }
 }
 
-uam_sensor_info_s *_pm_util_uas_sensor_info_to_uam_sensor_info(const uas_sensor_info_t *info)
+uam_sensor_info_s *_pm_util_uas_sensor_info_to_uam_sensor_info(
+       const uas_sensor_info_t *info)
 {
        FUNC_ENTRY;
        uam_sensor_info_s *sensor_info;
index 02353ba..39ce9bb 100644 (file)
@@ -135,6 +135,7 @@ static void wifi_active_scan_callback(uas_active_scan_event_e event,
 uas_callbacks_t wifi_cbs = {
        .state_changed_cb = wifi_state_changed_callback,
        .detection_state_cb = wifi_detection_state_changed_cb,
+       .detection_status_cb = NULL,
        .detected_cb = wifi_lpm_detection_callback,
        .device_detected_cb = wifi_device_detection_callback,
        .device_added_cb = wifi_device_added_callback,
index 191e378..05d00d7 100644 (file)
@@ -18,6 +18,7 @@
 #include <time.h>
 
 #include "ua-api.h"
+#include "ua-plugin.h"
 #include "ua-internal.h"
 #include "ua-manager-common.h"
 #include "ua-plugin-manager.h"
@@ -2537,7 +2538,7 @@ void __send_sensor_presence_event(uam_sensor_info_s *sensor_info, unsigned int s
 
        if (NULL == sensor_info) {
                _uam_manager_send_event(NULL, UAM_EVENT_PRESENCE_DETECTED,
-                       g_variant_new("(uxiidddd)", sensor, 0, 0, 0, 0, 0, 0, 0));
+                       g_variant_new("(uiiidddd)", sensor, 0, 0, 0, 0, 0, 0, 0));
                UAM_DBG("Sent UAM_EVENT_PRESENCE_DETECTED for 0x%8.8X", sensor);
                FUNC_EXIT;
                return;
@@ -2545,7 +2546,7 @@ void __send_sensor_presence_event(uam_sensor_info_s *sensor_info, unsigned int s
 
        if (UAM_SENSOR_BITMASK_LIGHT != sensor) {
                _uam_manager_send_event(NULL, UAM_EVENT_PRESENCE_DETECTED,
-                       g_variant_new("(uxiidddd)", sensor, sensor_info->timestamp,
+                       g_variant_new("(uiiidddd)", sensor, sensor_info->timestamp,
                        sensor_info->accuracy, sensor_info->count, sensor_info->values[0],
                        sensor_info->values[1], sensor_info->values[2], sensor_info->values[3]));
                UAM_DBG("Sent UAM_EVENT_PRESENCE_DETECTED for 0x%8.8X", sensor);
@@ -2583,7 +2584,7 @@ void __send_sensor_presence_event(uam_sensor_info_s *sensor_info, unsigned int s
                                continue;
 
                        _uam_manager_send_event(mon->name, UAM_EVENT_PRESENCE_DETECTED,
-                               g_variant_new("(uxiidddd)", sensor, sensor_info->timestamp,
+                               g_variant_new("(uiiidddd)", sensor, sensor_info->timestamp,
                                sensor_info->accuracy, sensor_info->count, sensor_info->values[0],
                                sensor_info->values[1], sensor_info->values[2], sensor_info->values[3]));
                        UAM_DBG("Sent UAM_EVENT_PRESENCE_DETECTED to %s for 0x%8.8X",
@@ -2603,7 +2604,7 @@ void __send_sensor_absence_event(uam_sensor_info_s *sensor_info, unsigned int se
 
        if (NULL == sensor_info) {
                _uam_manager_send_event(NULL, UAM_EVENT_ABSENCE_DETECTED,
-                       g_variant_new("(uxiidddd)", sensor, 0, 0, 0, 0, 0, 0, 0));
+                       g_variant_new("(uiiidddd)", sensor, 0, 0, 0, 0, 0, 0, 0));
                UAM_DBG("Sent UAM_EVENT_ABSENCE_DETECTED for 0x%8.8X", sensor);
                FUNC_EXIT;
                return;
@@ -2611,7 +2612,7 @@ void __send_sensor_absence_event(uam_sensor_info_s *sensor_info, unsigned int se
 
        if (UAM_SENSOR_BITMASK_LIGHT != sensor) {
                _uam_manager_send_event(NULL, UAM_EVENT_ABSENCE_DETECTED,
-                       g_variant_new("(uxiidddd)", sensor, sensor_info->timestamp,
+                       g_variant_new("(uiiidddd)", sensor, sensor_info->timestamp,
                        sensor_info->accuracy, sensor_info->count, sensor_info->values[0],
                        sensor_info->values[1], sensor_info->values[2], sensor_info->values[3]));
                UAM_DBG("Sent UAM_EVENT_ABSENCE_DETECTED for 0x%8.8X", sensor);
@@ -2646,7 +2647,7 @@ void __send_sensor_absence_event(uam_sensor_info_s *sensor_info, unsigned int se
                                continue;
 
                        _uam_manager_send_event(mon->name, UAM_EVENT_ABSENCE_DETECTED,
-                               g_variant_new("(uxiidddd)", sensor, sensor_info->timestamp,
+                               g_variant_new("(uiiidddd)", sensor, sensor_info->timestamp,
                                sensor_info->accuracy, sensor_info->count, sensor_info->values[0],
                                sensor_info->values[1], sensor_info->values[2], sensor_info->values[3]));
                        UAM_DBG("Sent UAM_EVENT_ABSENCE_DETECTED for 0x%8.8X", sensor);
@@ -3693,3 +3694,31 @@ int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv)
        FUNC_EXIT;
        return UAM_ERROR_NONE;
 }
+
+void _uam_core_handle_status_changed(unsigned int sensor, unsigned int type,
+       void *info)
+{
+       FUNC_ENTRY;
+
+       uam_sensor_info_s *sensor_info = info;
+
+       ret_if(NULL == info);
+
+       sensor_info->status = type;
+
+       UAM_INFO("sensor: 0x%8.8X, detection_type: %d", sensor, type);
+
+       if (UAS_ABSENCE == type) {
+               _uam_manager_send_event(NULL, UAM_EVENT_SENSOR_STATUS_CHANGED,
+                       g_variant_new("(uuiiidddd)", type, sensor, 0, 0, 0, 0, 0, 0, 0));
+               UAM_DBG("Sent UAM_EVENT_ABSENCE_DETECTED for 0x%8.8X", sensor);
+       } else {
+               _uam_manager_send_event(NULL, UAM_EVENT_SENSOR_STATUS_CHANGED,
+                       g_variant_new("(uuiiidddd)", type, sensor, sensor_info->timestamp,
+                       sensor_info->accuracy, sensor_info->count, sensor_info->values[0],
+                       sensor_info->values[1], sensor_info->values[2], sensor_info->values[3]));
+       }
+
+       FUNC_EXIT;
+}
+
index f7cbdf4..d2b381f 100644 (file)
@@ -178,6 +178,9 @@ int _uam_manager_send_event(
        case UAM_EVENT_SERVICE_UNREGISTERED:
                signal = UAM_SIGNAL_SERVICE_UNREGISTERED;
                break;
+       case UAM_EVENT_SENSOR_STATUS_CHANGED:
+               signal = UAM_SIGNAL_SENSOR_STATUS_CHANGED;
+               break;
        default:
                UAM_ERR("Unhandled event");
                return UAM_ERROR_INTERNAL;
index 9bfc5c2..25838b3 100644 (file)
@@ -144,6 +144,13 @@ typedef void (*uas_state_changed_callback)(int state);
 typedef void (*uas_detection_state_changed_callback)(int state);
 
 /*
+ * Callback to be invoked on Presen/Absence detection status during detection operation
+ * by plug-in's which do not support User identification.
+ */
+typedef void (*uas_detection_status_changed_callback)(uas_detection_type_e type,
+       void *sensor_info);
+
+/*
  * Callback to be invoked on Presen/Absence detection by plug-in's which do
  * not support User identification.
  */
@@ -155,7 +162,8 @@ typedef void (*uas_detection_callback)(uas_detection_type_e type, void *sensor_i
  *
  * [Param] device - Device for which Presence/Absence is detected.
  */
-typedef void (*uas_device_detection_callback)(uas_detection_type_e type, uas_device_info_t *device);
+typedef void (*uas_device_detection_callback)(uas_detection_type_e type,
+       uas_device_info_t *device);
 
 /*
  * Callback to be invoked in response to add_device() API
@@ -172,17 +180,18 @@ typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device)
  * [Param] device - Found registerd device info if event is UAS_ACTIVE_DEVICE_FOUND
  * or, NULL if event is UAS_ACTIVE_SCAN_COMPLETED.
  */
-typedef void (*uas_active_device_scan_callback)(
+typedef void (*uas_device_active_scan_callback)(
                uas_active_scan_event_e event, const uas_device_info_t *device);
 
 /* UA plug-in callback structure */
 typedef struct {
-       uas_state_changed_callback state_changed_cb;
-       uas_detection_state_changed_callback detection_state_cb;
-       uas_detection_callback detected_cb;
-       uas_device_detection_callback device_detected_cb;
-       uas_device_added_callback device_added_cb;
-       uas_active_device_scan_callback active_scan_cb;
+       uas_state_changed_callback state_changed_cb; /**< 0:Not ready 1:Ready */
+       uas_detection_state_changed_callback detection_state_cb; /**< 0:Stop 1:Start */
+       uas_detection_status_changed_callback detection_status_cb; /**< 1: change with param */
+       uas_detection_callback detected_cb; /**< For environmental sensors */
+       uas_device_detection_callback device_detected_cb; /**< For connectivity sensors */
+       uas_device_added_callback device_added_cb; /**< For connectivity sensors */
+       uas_device_active_scan_callback active_scan_cb; /**< For connectivity sensors */
 } uas_callbacks_t;
 
 typedef struct {