Modified test app for sensor info in callback
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 23 Sep 2019 10:03:45 +0000 (19:03 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 26 Sep 2019 06:47:06 +0000 (15:47 +0900)
Change-Id: I79de27fcc552a788f348ffca6ad63c3edcec2539
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness-private.h
include/user-awareness-util.h
include/user-awareness.h
packaging/capi-network-ua.spec
src/user-awareness-event-handler.c
src/user-awareness-monitors.c
src/user-awareness-util.c
test/uat-detections.c

index 07cb6facbff8595fd2a007bca4882d6f143f7b38..41b52d265f3895641f85757a1113015521046631 100644 (file)
@@ -129,6 +129,12 @@ extern "C" {
  */
 #define UA_MIN_DETECTION_CYCLE 60 /**< 1 min */
 
+/**
+ * @brief Maximum sensor values count.
+ * @since_tizen 5.5
+ */
+#define UA_SENSOR_MAX_VALUES 4 /**< 4 values */
+
 /**
  * @brief Default service name.
  * @since_tizen 5.5
@@ -321,7 +327,7 @@ void _ua_monitor_handle_scan_complete(int result);
  * @pre
  * @post
  */
-void _ua_monitor_handle_user_presence_detected(unsigned int bitmask,
+void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *sensor_info,
                                               char *service, char *account,
                                               long timestamp, char *device_id);
 
index 0f93d13733f5a5b82174909dd2a323a9e42a69b0..6a70257115c774b725ce6cc94c9eea462cf6178b 100644 (file)
@@ -197,6 +197,25 @@ ua_sensor_e _ua_dev_type_to_sensor(ua_mac_type_e type);
  */
 ua_sensor_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @internal
+ * @brief Converts uam sensor info to ua sensor info.
+ * @since_tizen 5.5
+ *
+ * @remarks The returned value can be used until return call function is valid.
+ *
+ * @param[in] Struct uam sensor info to be converted.
+ *
+ * @return Sensor info struct
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info);
+
 #ifdef __cplusplus
 }
 #endif
index 2831e4c691780b5f8509b28abc7d9f2d39f7e8fc..ad5b34cef3e607b6fcfd1d4dffe37d1a50d40e7e 100644 (file)
@@ -244,6 +244,18 @@ typedef enum {
        UA_AND_OPERATION = 0x01 /**< AND & OR */
 } ua_condition_conjunction_e;
 
+/**
+ * @brief sensor info data structure.
+ * @since_tizen 5.5
+ */
+typedef struct {
+       ua_sensor_e bitmask;
+       long int timestamp;
+       int accuracy;
+       int count;
+       double *values;
+} ua_sensor_info_s;
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief The handle of user presence/absence monitor.
index 3ab6d7f2c390a1977cb5483e3989d626e97267a2..56f1ec1eeec01156e7c542c8e6f8c29c52fa6fa7 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.9.4
+Version: 0.10.0
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index 1498865cac5afef0c6ad60ab3c97cf3f39519e24..0b3af80c7e816c60ca94d2e949a456cef7e05995 100644 (file)
@@ -43,6 +43,7 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u
        switch (event) {
        case UAM_EVENT_USER_PRESENCE_DETECTED: {
                uam_detection_event_data_s *event_data = NULL;
+               uam_sensor_info_s *sensor_info = NULL;
 
                event_data = event_param->data;
                ret_if(NULL == event_data);
@@ -51,8 +52,9 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u
                ret_if(0 == event_data->timestamp);
                ret_if(NULL == event_data->device_id);
 
+               sensor_info->sensor_bitmask = event_data->sensor_bitmask;
                _ua_monitor_handle_user_presence_detected(
-                               event_data->sensor_bitmask, event_data->service,
+                               sensor_info, event_data->service,
                                event_data->account, event_data->timestamp,
                                event_data->device_id);
 
@@ -73,15 +75,15 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u
                break;
        }
        case UAM_EVENT_PRESENCE_DETECTED: {
-               uam_sensor_info_s *event_data = NULL;
+               uam_sensor_info_s *sensor_info = NULL;
 
-               event_data = event_param->data;
-               ret_if(NULL == event_data);
+               sensor_info = event_param->data;
+               ret_if(NULL == sensor_info);
 
                UA_INFO("sensor: [%u], timestamp [%ld], accuracy [%d], value [%f]",
-                               event_data->sensor_bitmask, event_data->timestamp,
-                               event_data->accuracy, event_data->values[0]);
-               _ua_monitor_handle_user_presence_detected(event_data->sensor_bitmask, NULL,
+                               sensor_info->sensor_bitmask, sensor_info->timestamp,
+                               sensor_info->accuracy, sensor_info->values[0]);
+               _ua_monitor_handle_user_presence_detected(sensor_info, NULL,
                                NULL, 0, NULL);
 
                break;
index 2ca3a099861f215892698bc7f8cfcb1a3516f501..b9bb7224efcd687362d73591319bf3dba454c063 100644 (file)
@@ -676,12 +676,18 @@ void _ua_monitor_handle_scan_complete(int result)
        FUNC_EXIT;
 }
 
-void _ua_monitor_handle_user_presence_detected(unsigned int uam_bitmask,
+void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *info,
                char *service, char *account, long timestamp, char *device_id)
 {
        FUNC_ENTRY;
        GSList *l;
-       ua_sensor_e bitmask = _uam_to_ua_sensor(uam_bitmask);
+       ua_sensor_info_s *sensor_info;
+       ua_sensor_e bitmask;
+       ret_if(NULL == info);
+
+       sensor_info = _uam_to_ua_sensor_info(info);
+       ret_if(NULL == sensor_info);
+       bitmask = sensor_info->bitmask;
 
        for (l = ua_monitor_list; l; l = g_slist_next(l)) {
                ua_monitor_s *monitor = l->data;
@@ -695,6 +701,7 @@ void _ua_monitor_handle_user_presence_detected(unsigned int uam_bitmask,
 
                if (!service || !g_strcmp0(service, monitor->service)) {
                        /* Presence detection ongoing */
+                       monitor->user_data = sensor_info;
                        __ua_sensor_presence_detected(monitor, bitmask, account,
                                                      timestamp, device_id);
                }
index f16dbf3dcb73e2f7e830231e5a78e1747d930ed4..6b479a602266387e4fb852bd4b96937ed8583e32 100644 (file)
@@ -213,3 +213,32 @@ ua_sensor_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask)
        }
        FUNC_EXIT;
 }
+
+ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info)
+{
+       FUNC_ENTRY;
+       ua_sensor_info_s *sensor_info = NULL;
+       unsigned int i = 0;
+
+       sensor_info = g_malloc0(sizeof(ua_sensor_info_s));
+       if (!sensor_info) {
+               UA_ERR("g_malloc0 failed");
+               return NULL;
+       }
+       sensor_info->values = NULL;
+       sensor_info->values = g_malloc0(UA_SENSOR_MAX_VALUES*sizeof(double));
+       if (!sensor_info->values) {
+               UA_ERR("g_malloc0 failed");
+               g_free(sensor_info);
+               return NULL;
+       }
+       sensor_info->timestamp = info->timestamp;
+       sensor_info->count = info->count;
+       sensor_info->bitmask = _uam_to_ua_sensor(info->sensor_bitmask);
+       for(i = 0; i < UA_SENSOR_MAX_VALUES; i++) {
+               sensor_info->values[i] = info->values[i];
+       }
+
+       return sensor_info;
+       FUNC_EXIT;
+}
index cb76c172d58104a3a0586a7d1eb566895412c097..088eb014b300206fe0608fa17d2d7e2272c39723 100644 (file)
@@ -55,6 +55,8 @@ static void __device_presence_detected_cb(int result, ua_monitor_h monitor,
        msg("\n[%s] Device PRESENCE [%d]", pbuf, sensor);
        free(pbuf);
 
+       ua_sensor_info_s *info;
+       info = user_data;
        if (UA_SENSOR_BLE == (UA_SENSOR_BLE & sensor)) {
                msgb("[%s] PRESENCE detected [%s]",
                        uat_get_sensor_bitmask_str(UA_SENSOR_BLE), uat_get_error_str(result));
@@ -64,12 +66,13 @@ static void __device_presence_detected_cb(int result, ua_monitor_h monitor,
                        uat_get_sensor_bitmask_str(UA_SENSOR_WIFI), uat_get_error_str(result));
        }
        if (UA_SENSOR_LIGHT == (UA_SENSOR_LIGHT & sensor)) {
-               msgb("[%s] PRESENCE detected [%s]",
-                       uat_get_sensor_bitmask_str(UA_SENSOR_LIGHT),uat_get_error_str(result));
+               msgb("[%s] PRESENCE detected at timestamp [%ld] lux [%f] [%s]",
+                       uat_get_sensor_bitmask_str(UA_SENSOR_LIGHT), info->timestamp,
+                               info->values[0], uat_get_error_str(result));
        }
        if (UA_SENSOR_MOTION == (UA_SENSOR_MOTION & sensor)) {
-               msgb("[%s] PRESENCE detected [%s]",
-                       uat_get_sensor_bitmask_str(UA_SENSOR_MOTION), uat_get_error_str(result));
+               msgb("[%s] PRESENCE detected at timestamp [%ld] [%s]",
+                       uat_get_sensor_bitmask_str(UA_SENSOR_MOTION), info->timestamp, uat_get_error_str(result));
        }
 }