Provide sensor information in detection callback
authorAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 20 Sep 2019 10:13:35 +0000 (19:13 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 26 Sep 2019 06:44:47 +0000 (15:44 +0900)
Change-Id: Ic36c9180ad27660ab20059f05cd5441a3cbc6ae1
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
12 files changed:
include/ua-api.h
packaging/ua-manager.spec
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-pm-util.h
ua-daemon/src/pm/ua-wifi-plugin-handler.c
ua-daemon/src/ua-manager-core.c
ua-plugins/include/ua-plugin.h

index c6fe915..ad15013 100644 (file)
@@ -122,6 +122,12 @@ typedef enum {
 #define UAM_IBEACON_ADV_MAX_LEN 31
 
 /**
+ * @brief Maximum number of values from sensor.
+ * @since_tizen 5.5
+ */
+#define UAM_SENSOR_MAX_VALUES 4
+
+/**
  * @brief Enumerations macro of UA framework event codes.
  * @since_tizen 5.5
  */
@@ -479,6 +485,18 @@ typedef struct {
 } uam_device_info_s;
 
 /**
+ * @brief Light info structure.
+ * @since_tizen 5.5
+ */
+typedef struct {
+       unsigned int sensor_bitmask; /**< sensor bitmask of discovered sensor */
+       long timestamp; /**< Latest timestamp when sensor was discoverd */
+       int accuracy; /**< Accuracy info from sensor sensor */
+       int count; /**< count of values from sensor sensor */
+       double values[UAM_SENSOR_MAX_VALUES]; /**< info from sensor */
+} uam_sensor_info_s;
+
+/**
  * @brief User info structure.
  * @since_tizen 5.5
  */
index 17e30c6..404aea5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.9.6
+Version:    0.10.0
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 25fde44..d0768cc 100644 (file)
@@ -115,13 +115,35 @@ static void __uam_event_handler(GDBusConnection *connection,
                __uam_send_event(event, result, &event_data,
                                event_info->cb, event_info->user_data);
        } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_PRESENCE_DETECTED)) {
+               uam_sensor_info_s sensor_info;
                unsigned int sensor_bitmask;
-
-               g_variant_get(parameters, "(u)", &sensor_bitmask);
+               long int timestamp;
+               int accuracy, count;
+               double values[UAM_SENSOR_MAX_VALUES];
+
+               UAM_DBG("Get sensor values");
+               memset(&sensor_info, 0, sizeof(uam_sensor_info_s));
+               memset(&sensor_info.values, 0, UAM_SENSOR_MAX_VALUES);
+               g_variant_get(parameters, "(uxiidddd)", &sensor_bitmask, &timestamp,
+                                               &accuracy, &count, &values[0], &values[1],
+                                               &values[2], &values[2]);
+               sensor_info.sensor_bitmask = sensor_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_DBG("sensor bitmask [%u] timestamp [%ld] accuracy [%d] count [%d] " \
+                               "value0 [%f] value1 [%f] value2 [%f] value3 [%f]",
+                               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]);
 
                event = UAM_EVENT_PRESENCE_DETECTED;
 
-               __uam_send_event(event, result, &sensor_bitmask,
+               __uam_send_event(event, result, &sensor_info,
                                event_info->cb, event_info->user_data);
        } else if (0 == strcasecmp(signal_name, UAM_SIGNAL_ABSENCE_DETECTED)) {
                unsigned int sensor_bitmask;
index 8fbb1a7..844220e 100644 (file)
@@ -167,10 +167,10 @@ void _uam_core_handle_device_added(int status,
                int user_id, const uam_device_info_s *dev_info);
 
 void _uam_core_handle_presence_detected(unsigned int sensor,
-               int user_id, uam_device_info_s *dev_info);
+               int user_id, void *sensor_info);
 
 void _uam_core_handle_absence_detected(unsigned int sensor,
-               int user_id, uam_device_info_s *dev_info);
+               int user_id, void *sensor_info);
 
 void _uam_core_cleanup_monitor(char *name);
 
index fea2216..1818488 100644 (file)
@@ -37,7 +37,7 @@ static void ble_state_changed_callback(int state)
        FUNC_EXIT;
 }
 
-static void ble_lpm_detection_callback(uas_detection_type_e type)
+static void ble_lpm_detection_callback(uas_detection_type_e type, void *sensor_info)
 {
        FUNC_ENTRY;
 
index fbf0ed4..3effd70 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <ua-plugin.h>
 #include <ua-plugin-manager.h>
+#include "ua-pm-util.h"
 
 void light_state_changed_callback(int state)
 {
@@ -42,18 +43,22 @@ static void light_detection_state_changed_cb(int state)
        FUNC_EXIT;
 }
 
-void light_detection_callback(uas_detection_type_e type)
+void light_detection_callback(uas_detection_type_e type, void *sensor_info)
 {
        FUNC_ENTRY;
+       uas_sensor_info_t *info;
+       uam_sensor_info_s *light_info = NULL;
 
        UAM_DBG("Light: %s", type == UAS_PRESENCE ? "PRESENCE" : "ABSENCE");
 
+       info = sensor_info;
+       light_info = _pm_util_uas_sensor_info_to_uam_sensor_info(info);
        if (UAS_PRESENCE == type) {
                UAM_DBG("Presence detected by light sensor");
-               _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_LIGHT, 0, NULL);
+               _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_LIGHT, 0, light_info);
        } else {
                UAM_DBG("Absence detected by light sensor");
-               _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_LIGHT, 0, NULL);
+               _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_LIGHT, 0, light_info);
        }
 
        FUNC_EXIT;
index 5248fd9..39223dd 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <ua-plugin.h>
 #include <ua-plugin-manager.h>
+#include "ua-pm-util.h"
 
 void motion_state_changed_callback(int state)
 {
@@ -42,18 +43,24 @@ static void motion_detection_state_changed_cb(int state)
        FUNC_EXIT;
 }
 
-void motion_detection_callback(uas_detection_type_e type)
+void motion_detection_callback(uas_detection_type_e type, void *sensor_info)
 {
        FUNC_ENTRY;
+       uas_sensor_info_t *info = NULL;
+       uam_sensor_info_s *motion_info = NULL;
 
        UAM_DBG("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);
+
        if (UAS_PRESENCE == type) {
                UAM_DBG("Presence detected by motion sensor");
-               _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_MOTION, 0, NULL);
+               _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_MOTION, 0, motion_info);
        } else {
                UAM_DBG("Absence detected by motion sensor");
-               _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_MOTION, 0, NULL);
+               _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_MOTION, 0, motion_info);
        }
 
        FUNC_EXIT;
index 4bf7b99..ff8a622 100644 (file)
@@ -352,3 +352,29 @@ uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_sca
                return 0;
        }
 }
+
+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;
+       unsigned int i = 0;
+       retv_if(NULL == info, NULL);
+
+       sensor_info = g_new0(uam_sensor_info_s, 1);
+       retv_if(NULL == sensor_info, NULL);
+
+       sensor_info->timestamp = info->timestamp;
+       sensor_info->accuracy = info->accuracy;
+       sensor_info->count = info->count;
+       for (i = 0; i < info->count; i++) {
+               sensor_info->values[i] = info->values[i];
+       }
+
+       UAM_INFO("t [%ld] Accuaracy [%d] Count [%d] Lux [%f] CCT [%f] Lv[%f] Cv[%f]",
+               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;
+       return sensor_info;
+}
index 1af6fcf..3be4a94 100644 (file)
@@ -51,6 +51,8 @@ const char *_pm_util_uas_status_to_str(int status);
 
 uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event);
 
+uam_sensor_info_s *_pm_util_uas_sensor_info_to_uam_sensor_info(const uas_sensor_info_t *info);
+
 #ifdef __cplusplus
 }
 #endif
index 28029b3..02353ba 100644 (file)
@@ -37,7 +37,7 @@ static void wifi_state_changed_callback(int state)
        FUNC_EXIT;
 }
 
-static void wifi_lpm_detection_callback(uas_detection_type_e type)
+static void wifi_lpm_detection_callback(uas_detection_type_e type, void *sensor_info)
 {
        FUNC_ENTRY;
 
index 2a10ecf..520a2a4 100644 (file)
@@ -2371,21 +2371,31 @@ void __send_user_presence_event(uam_db_tech_info_t *tech, unsigned int sensor,
 }
 
 void _uam_core_handle_presence_detected(unsigned int sensor,
-               int user_id, uam_device_info_s *dev_info)
+               int user_id, void *info)
 {
        FUNC_ENTRY;
        uam_db_user_info_t *user;
        uam_db_device_info_t *device;
        uam_db_tech_info_t *tech;
        GSList *l;
+       uam_device_info_s *dev_info = NULL;
+       uam_sensor_info_s *sensor_info = NULL;
 
        UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id);
 
+       sensor_info = g_new0(uam_sensor_info_s, 1);
+       if (info && (UAM_SENSOR_BITMASK_LIGHT == sensor || UAM_SENSOR_BITMASK_MOTION == sensor))
+               sensor_info = info;
+       if (info && (UAM_SENSOR_BITMASK_BLE == sensor || UAM_SENSOR_BITMASK_WIFI == sensor))
+               dev_info = info;
+
        _uam_ppm_send_presence_detection_event(sensor);
 
        if (NULL == dev_info) {
                _uam_manager_send_event(NULL, UAM_EVENT_PRESENCE_DETECTED,
-                       g_variant_new("(u)", sensor));
+                       g_variant_new("(uxiidddd)", 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);
                FUNC_EXIT;
                return;
@@ -2580,16 +2590,20 @@ static void __send_user_absence_event(uam_tech_type_e type, unsigned int sensor)
 }
 
 void _uam_core_handle_absence_detected(unsigned int sensor,
-               int user_id, uam_device_info_s *dev_info)
+               int user_id, void *info)
 {
        FUNC_ENTRY;
        uam_db_user_info_t *user;
        uam_db_device_info_t *device;
        uam_db_tech_info_t *tech;
        GSList *l;
+       uam_device_info_s *dev_info = NULL;
 
        UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id);
 
+       if (info && (UAM_SENSOR_BITMASK_BLE == sensor || UAM_SENSOR_BITMASK_WIFI == sensor))
+               dev_info = info;
+
        if (NULL == dev_info) {
                _uam_manager_send_event(NULL, UAM_EVENT_ABSENCE_DETECTED,
                        g_variant_new("(u)", sensor));
index 3e4d60c..9bfc5c2 100644 (file)
@@ -120,6 +120,14 @@ typedef struct {
        uas_ble_payload_t *payload;
 } uas_device_info_t;
 
+/* Sensor information structure */
+typedef struct {
+       long int timestamp;
+       int accuracy;
+       int count;
+       double *values;
+} uas_sensor_info_t;
+
 /* Active scan event types */
 typedef enum {
        UAS_ACTIVE_DEVICE_FOUND = 0x01,
@@ -139,7 +147,7 @@ typedef void (*uas_detection_state_changed_callback)(int state);
  * Callback to be invoked on Presen/Absence detection by plug-in's which do
  * not support User identification.
  */
-typedef void (*uas_detection_callback)(uas_detection_type_e type);
+typedef void (*uas_detection_callback)(uas_detection_type_e type, void *sensor_info);
 
 /*
  * Callback to be invoked on Presen/Absence detection by plug-in's which