Provide sensor information in user detection callback
authorAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 4 Oct 2019 10:39:01 +0000 (19:39 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 4 Oct 2019 11:22:56 +0000 (20:22 +0900)
Change-Id: I79c1256f8bd1ea21f8421d3964b573d6eba45cef
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness-util.h
include/user-awareness.h
packaging/capi-network-ua.spec
src/user-awareness-monitors.c
src/user-awareness-util.c
test/uat-common.c
test/uat-init.c

index 1534e60f1f58019e825a1a65a2ae170dc341b868..8b23af7cc26f2c9f015e34f92cb9d24df0410302 100755 (executable)
@@ -241,6 +241,30 @@ int ua_sensor_get_by_sensor_info(
                ua_sensor_info_s *sensor_info,
                ua_sensor_h * sensor_handle);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor handle by sensor info.
+ * @since_tizen 5.5
+ *
+ * @remarks The @a sensor_handle should not be released.
+ * @remarks The @a sensor_handle can be used only in the function.
+ *
+ * @param[in] sensor_bitmask The detected sensors bitmask
+ * @param[out] sensor_handle The sensor handles list
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+GSList *ua_sensor_get_sensor_handle_list(
+               unsigned int sensor_bitmask);
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Releases sensor info.
index b36d51047382357a1ffbf025fe0f597b11a51ca6..88c6388556533a5d8432cb9e01e7e3de85590d25 100644 (file)
@@ -470,6 +470,7 @@ typedef void (*ua_presence_user_detected_cb)(
                ua_monitor_h handle,
                ua_user_h user_handle,
                GSList *device_handles,
+               GSList *sensor_handle,
                void *user_data);
 
 /**
@@ -2751,6 +2752,27 @@ int ua_sensor_get_timestamp(
                ua_sensor_h sensor_handle,
                long int *timestamp);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor's timestamp.
+ * @since_tizen 5.5
+ *
+ * @param[in] sensor_handle The sensor handle
+ * @param[out] bitmask The sensor's bitmask.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+int ua_sensor_get_bitmask(
+               ua_sensor_h sensor_handle,
+               ua_sensor_e *bitmask);
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Gets sensor's information values count.
index a09984faacf447a4ba8a98e27c7d05bef06c00af..64d76ecef2efb6f85f85d25a0094494216ce886a 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.11.0
+Version: 0.11.1
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index fcbdd777976736784c0c886fe9061ec1d64bc8b5..d0a3ba63b3871afb8e38f96f59044fedc1dd2900 100644 (file)
@@ -250,6 +250,7 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
        gboolean or_condition = 0;
        gboolean condition_result = 0;
        ua_dev_info_s *dev = 0;
+       GSList *sensors = 0;
 
        ret_if(NULL == user_state);
 
@@ -300,6 +301,9 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
                return;
        }
 
+       /** Get sensor list*/
+       sensors = ua_sensor_get_sensor_handle_list(monitor->presence_detected_bitmask);
+
        /**
         * Filter the list of found_devices according to sensors mentioned in
         * AND/OR conditions.
@@ -318,12 +322,13 @@ static void __ua_monitor_send_user_presence_cb(ua_monitor_s *monitor,
 
        ((ua_presence_user_detected_cb)monitor->presence_user_cb.callback)(
                                        UA_ERROR_NONE, monitor, user_handle,
-                                       devices,
+                                       devices, sensors,
                                        monitor->presence_user_cb.user_data);
 
        user_state->cb_sent = TRUE;
 
        g_slist_free(devices);
+       g_slist_free(sensors);
 
        FUNC_EXIT;
        return;
index 415acef73d8012d87c35770d11bfa2bc899402a0..5e113f39b01cc80307cff2369c704121319a0591 100644 (file)
@@ -338,6 +338,27 @@ done:
        return ret;
 }
 
+GSList *ua_sensor_get_sensor_handle_list(
+               unsigned int bitmask)
+{
+       FUNC_ENTRY;
+       GSList *sensors = NULL;
+       GSList *l;
+       ua_sensor_info_s *sensor;
+
+       for (l = ua_sensors_list; NULL != l; l = g_slist_next(l)) {
+               sensor = (ua_sensor_info_s *)l->data;
+
+               if (bitmask & sensor->bitmask) {
+                       UA_INFO("Sensor info found, sensor bitmask[%d]", sensor->bitmask);
+                       sensors = g_slist_append(sensors, sensor->handle);
+               }
+       }
+
+       FUNC_EXIT;
+       return sensors;
+}
+
 int ua_sensor_get_timestamp(
                ua_sensor_h sensor_handle,
                long int *timestamp)
@@ -355,6 +376,23 @@ int ua_sensor_get_timestamp(
        return UA_ERROR_NONE;
 }
 
+int ua_sensor_get_bitmask(
+               ua_sensor_h sensor_handle,
+               ua_sensor_e *bitmask)
+{
+       FUNC_ENTRY;
+       ua_sensor_info_s *sensor;
+
+       UA_VALIDATE_INPUT_PARAMETER(sensor_handle);
+       UA_INFO("Sensor Handle [%p]", sensor_handle);
+       sensor = (ua_sensor_info_s *)sensor_handle;
+
+       *bitmask = sensor->bitmask;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
 int ua_sensor_get_info_count(
                ua_sensor_h sensor_handle,
                int *count)
index 4b9b8381db100a588c5076802c4163ed46b55468..466a757f42a30088e93f0e5ae9ce6d4c35c54c57 100644 (file)
@@ -151,5 +151,3 @@ char* uat_get_time()
 
        return pbuf;
 }
-
-
index 640b913b73d059dd9340c53897f42000938679d9..2381cfd409fca1c92cac011385b67d2f524c8c81 100644 (file)
@@ -101,8 +101,58 @@ static void __user_presence_detected_foreach_devices(gpointer data,
        g_free(mac);
 }
 
+static void __user_presence_detected_foreach_sensors(gpointer data,
+                                                    gpointer user_data)
+{
+       int ret;
+       char buf[MENU_DATA_SIZE] = {0, };
+       char final_buf[MENU_DATA_SIZE * 4] = {0, };
+       long int timestamp;
+       int info_count = 0;
+       GSList *values = NULL;
+       double *value;
+       GSList *l = 0;
+       ua_sensor_e bitmask;
+       ua_device_h sensor_handle = (ua_sensor_h)data;
+
+       ret = ua_sensor_get_bitmask(sensor_handle, &bitmask);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_sensor_get_bitmask() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
+
+       ret = ua_sensor_get_timestamp(sensor_handle, &timestamp);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_sensor_get_timestamp() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
+
+       ret = ua_sensor_get_info_count(sensor_handle, &info_count);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_sensor_get_info_count() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
+
+       values = ua_sensor_get_info_values(sensor_handle);
+       if (NULL == values) {
+               msg(" - ua_sensor_get_info_values() failed");
+       }
+
+       for (l = values; l; l = g_slist_next(l)) {
+               value = (double *)l->data;
+               snprintf(buf, MENU_DATA_SIZE, "%lF ", *value);
+               strncat(final_buf, buf, sizeof(buf) - strlen(buf) - 1);
+               memset(buf, 0, MENU_DATA_SIZE);
+       }
+       msgb("[%s] information detected at timestamp [%ld] value [%s]",
+               uat_get_sensor_bitmask_str(bitmask), timestamp,
+                       final_buf);
+
+       g_slist_free(values);
+}
+
 static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
-               ua_user_h user_handle, GSList *device_handles,
+               ua_user_h user_handle, GSList *device_handles, GSList *sensor_handles,
                void *user_data)
 {
        int ret;
@@ -122,6 +172,9 @@ static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
                        __user_presence_detected_foreach_devices,
                        account);
 
+       g_slist_foreach(sensor_handles,
+                       __user_presence_detected_foreach_sensors, NULL);
+
        g_free(account);
 }