Add API set to get sensor information from sensor handle
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 1 Oct 2019 10:09:47 +0000 (19:09 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Tue, 1 Oct 2019 12:39:06 +0000 (21:39 +0900)
This commit add an API set which can be used by the application to get the detected
sensor information of the sensor using sensor handle.

Change-Id: I10dec7bd427ab5d616bb6860f68e4d318d1234fe
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness.h
packaging/capi-network-ua.spec
src/user-awareness-util.c
test/uat-detections.c

index ff276fe0b85cc2b9173a62c325256c8031678eeb..638b3b89b35b95ef0dce0873a05f59b48ae9b14d 100644 (file)
@@ -2680,6 +2680,68 @@ int ua_device_foreach_added_by_user(
                ua_registered_dev_cb foreach_cb,
                void *user_data);
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor's timestamp.
+ * @since_tizen 5.5
+ *
+ * @param[in] sensor_handle The sensor handle
+ * @param[out] timestamp The sensor's timestamp.
+ *
+ * @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_timestamp(
+               ua_sensor_h sensor_handle,
+               long int *timestamp);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor's information values count.
+ * @since_tizen 5.5
+ *
+ * @param[in] sensor_handle The sensor handle
+ * @param[out] info_count The sensor's information count.
+ *
+ * @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_info_count(
+               ua_sensor_h sensor_handle,
+               int *info_count);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets sensor's information values.
+ * @since_tizen 5.5
+ *
+ * @param[in] sensor_handle The sensor handle
+ * @param[out] info_values The sensor's information values.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+GSList *ua_sensor_get_info_values(
+               ua_sensor_h sensor_handle);
+
 /**
  * @}
  */
index 5fd430d2e532ee0153d13302871dd4f1f476d0b2..8ef4a93b279f384e7935436700842e29105b9d4d 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.10.3
+Version: 0.10.4
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index e64cf6616967614e1cf8cf11f713986867811089..b8ba5fdf74e1ee333535b4e983d0e3b50534e70f 100644 (file)
@@ -328,3 +328,64 @@ done:
        FUNC_EXIT;
        return ret;
 }
+
+int ua_sensor_get_timestamp(
+               ua_sensor_h sensor_handle,
+               long int *timestamp)
+{
+       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;
+
+       *timestamp = sensor->timestamp;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_sensor_get_info_count(
+               ua_sensor_h sensor_handle,
+               int *count)
+{
+       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;
+
+       *count = sensor->count;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+GSList *ua_sensor_get_info_values(
+               ua_sensor_h sensor_handle)
+{
+       FUNC_ENTRY;
+       unsigned int i = 0;
+       GSList *values = NULL;
+       ua_sensor_info_s *sensor;
+
+       if (!sensor_handle) {
+               goto done;
+       }
+       UA_INFO("Sensor Handle [%p]", sensor_handle);
+       sensor = (ua_sensor_info_s *)sensor_handle;
+
+       if (!sensor->values) {
+               goto done;
+       }
+
+       for(i = 0; i < UA_SENSOR_MAX_VALUES; i++) {
+               values = g_slist_append(values, &sensor->values[i]);
+       }
+
+done:
+       FUNC_EXIT;
+       return values;
+}
index b6cb71e03f566b39f7664ee5c123098766b2e22b..75a53069a9a22aeeedf35c3591ca8f2d5e446981 100644 (file)
@@ -70,22 +70,45 @@ static void __sensor_presence_detected_device(ua_device_h device_handle)
        g_free(mac);
 }
 
-static void __sensor_presence_detected_sensor_info(ua_sensor_h sensor_handle)
+static void __sensor_presence_detected_sensor_info(ua_sensor_e sensor, ua_sensor_h sensor_handle)
 {
-/*
+       int ret;
        char buf[MENU_DATA_SIZE] = {0, };
        char final_buf[MENU_DATA_SIZE * 4] = {0, };
-       for (int i = 0; i < info->count ; i++) {
-               if (i >= 4)
-                       break;
-               snprintf(buf, MENU_DATA_SIZE, "%lF ", info->values[i]);
+       long int timestamp;
+       int info_count = 0;
+       GSList *values = NULL;
+       double *value;
+       GSList *l = 0;
+
+       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(info->bitmask), info->timestamp,
+               uat_get_sensor_bitmask_str(sensor), timestamp,
                        final_buf);
-*/
+
+       g_slist_free(values);
 }
 
 static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor,
@@ -118,7 +141,7 @@ static void __sensor_presence_detected_cb(int result, ua_monitor_h monitor,
                __sensor_presence_detected_device(device_handle);
        /* For sensor information */
        if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION)))
-               __sensor_presence_detected_sensor_info(sensor_handle);
+               __sensor_presence_detected_sensor_info(sensor, sensor_handle);
 }
 
 static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor,
@@ -146,7 +169,7 @@ static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor,
        }
        /* For sensor information */
        if (sensor_handle && (sensor & (UA_SENSOR_LIGHT | UA_SENSOR_MOTION)))
-               __sensor_presence_detected_sensor_info(sensor_handle);
+               __sensor_presence_detected_sensor_info(sensor, sensor_handle);
 }
 
 void __ua_test_scan_completed_cb(ua_active_scan_type_e result, ua_monitor_h handle,