summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhay Agarwal <ay.agarwal@samsung.com>2021-05-17 11:24:40 +0530
committerAbhay Agarwal <ay.agarwal@samsung.com>2021-06-25 17:33:12 +0530
commita62143bb6238c82a7ca261f202d8eea4e927f39b (patch)
treee6fe78820fc23036a3298523c3318f60962b32fa
parent4c8019a9f5843934db1f1f072faa6779eab434d3 (diff)
downloaduser-awareness-a62143bb6238c82a7ca261f202d8eea4e927f39b.tar.gz
user-awareness-a62143bb6238c82a7ca261f202d8eea4e927f39b.tar.bz2
user-awareness-a62143bb6238c82a7ca261f202d8eea4e927f39b.zip
Handle location detection event
Change-Id: I9f6f7433bfc2e39f0ef52d20dbca695799eea8cb Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rwxr-xr-xinclude/user-awareness-private.h28
-rwxr-xr-xinclude/user-awareness-util.h20
-rwxr-xr-xsrc/user-awareness-event-handler.c35
-rwxr-xr-xsrc/user-awareness-monitors.c111
-rwxr-xr-xsrc/user-awareness-util.c29
5 files changed, 223 insertions, 0 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h
index 61a8d5c..6bcc486 100755
--- a/include/user-awareness-private.h
+++ b/include/user-awareness-private.h
@@ -316,6 +316,17 @@ typedef struct {
} ua_sensor_info_s;
/**
+ * @brief location info data structure.
+ * @since_tizen 6.5
+ */
+typedef struct {
+ unsigned int distance; /**< Device distance in mm */
+ unsigned int x; /**< Device x coordinate */
+ unsigned int y; /**< Device y coordinate */
+ unsigned int z; /**< Device z coordinate */
+} ua_location_info_s;
+
+/**
* @brief User state data structure.
* @since_tizen 6.5
*/
@@ -583,6 +594,23 @@ void _ua_monitor_handle_user_absence_detected(
uam_sensor_info_s *sensor_info, char *service, char *account);
/**
+ * @brief Calls the location callback when detected registerd devices.
+ * @since_tizen 6.5
+ *
+ * @param[in] bitmask Bitmask for sensors
+ * @param[in] service Service information
+ * @param[in] account Account information
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+void _ua_monitor_handle_user_location_detected(
+ uam_sensor_info_s *sensor_info, char *service,
+ char *account, uam_device_info_s *device,
+ char *device_id);
+
+/**
* @brief Calls the sensor status changed callback when notified of sensor status changed.
* @since_tizen 6.5
*
diff --git a/include/user-awareness-util.h b/include/user-awareness-util.h
index 506adbc..88b9871 100755
--- a/include/user-awareness-util.h
+++ b/include/user-awareness-util.h
@@ -239,6 +239,26 @@ ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info);
/**
* @ingroup CAPI_NETWORK_UA_MODULE
+ * @internal
+ * @brief Converts uam location info to ua location info.
+ * @since_tizen 6.5
+ *
+ * @remarks The returned value can be used until return call function is valid.
+ *
+ * @param[in] Struct uam device info to be converted.
+ *
+ * @return Location info struct
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ */
+ua_location_info_s* _uam_to_ua_location_info(uam_device_info_s *info);
+
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
* @brief Gets sensor handle by sensor info.
* @since_tizen 6.5
*
diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c
index 1a231bf..053ad57 100755
--- a/src/user-awareness-event-handler.c
+++ b/src/user-awareness-event-handler.c
@@ -100,6 +100,41 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param,
break;
}
+ case UAM_EVENT_USER_LOCATION_DETECTED: {
+ uam_detection_event_data_s *event_data = NULL;
+ uam_sensor_info_s *sensor_info = NULL;
+ uam_device_info_s *device_info = NULL;
+
+ event_data = event_param->data;
+ ret_if(NULL == event_data);
+ ret_if(NULL == event_data->service);
+ ret_if(NULL == event_data->account);
+ ret_if(NULL == event_data->device_id);
+
+ sensor_info = g_new0(uam_sensor_info_s, 1);
+ ret_if(NULL == sensor_info);
+
+ sensor_info->sensor_bitmask = event_data->sensor_bitmask;
+ sensor_info->timestamp = event_data->last_seen;
+
+ device_info = g_new0(uam_device_info_s, 1);
+ ret_if(NULL == device_info);
+ device_info->distance_mm = event_data->distance_mm;
+ device_info->x = event_data->x;
+ device_info->y = event_data->y;
+ device_info->z = event_data->z;
+
+ UA_INFO("sensor_info: bitmask[%u], timestamp [%llu]",
+ sensor_info->sensor_bitmask, sensor_info->timestamp);
+
+ _ua_monitor_handle_user_location_detected(
+ sensor_info, event_data->service,
+ event_data->account, device_info,
+ event_data->device_id);
+ g_free(sensor_info);
+
+ break;
+ }
case UAM_EVENT_PRESENCE_DETECTED: {
uam_sensor_info_s *sensor_info = NULL;
diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c
index 7c7cdb8..2d3f03e 100755
--- a/src/user-awareness-monitors.c
+++ b/src/user-awareness-monitors.c
@@ -844,6 +844,78 @@ static void __ua_sensor_absence_detected(ua_monitor_s *monitor,
FUNC_EXIT;
}
+static void __ua_monitor_send_location_cb(ua_monitor_s *monitor,
+ ua_device_h device_handle, ua_sensor_info_s *sensor_info,
+ char* account, ua_location_info_s *location_info)
+{
+ FUNC_ENTRY;
+ ua_sensor_type_e bitmask = sensor_info->bitmask;
+ ua_sensor_h sensor_handle;
+ ua_service_info_s *service = NULL;
+ ua_service_h service_handle = NULL;
+ ua_service_h user_handle = NULL;
+ ua_location_h location_handle = NULL;
+ int ret;
+
+ /* Get sensor handle */
+ ret = _ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle);
+ if (UA_ERROR_NONE != ret) {
+ UA_INFO("_ua_sensor_get_by_sensor_info returned %s",
+ _ua_get_error_string(ret));
+ }
+
+ /* Get service handle */
+ service = __ua_get_service_from_list(monitor->service);
+ if (service)
+ service_handle = service->service_handle;
+
+ /* Get user handle */
+ if (account)
+ user_handle = _ua_get_user_handle_by_account(account);
+
+ /* Get location handle */
+ location_handle = (ua_location_h)location_info;
+
+ /* Send location callback */
+ monitor->location_cb(UA_ERROR_NONE, monitor,
+ service_handle, bitmask, sensor_handle,
+ device_handle, user_handle, location_handle,
+ monitor->user_data);
+
+ FUNC_EXIT;
+ return;
+}
+
+static void __ua_sensor_location_detected(ua_monitor_s *monitor,
+ ua_sensor_info_s *sensor_info, char *account,
+ ua_location_info_s *location_info, char *device_id)
+{
+ FUNC_ENTRY;
+
+ int ret = UA_ERROR_NONE;
+ ua_device_h device_handle = NULL;
+ ua_sensor_type_e bitmask = sensor_info->bitmask;
+
+ ret_if(NULL == monitor);
+
+ if (!monitor->location_detection_started) {
+ FUNC_EXIT;
+ return;
+ }
+
+ /* Get device */
+ ret = ua_device_get_by_device_id(device_id,
+ _ua_sensor_to_dev_type(bitmask), &device_handle);
+ UA_INFO("ua_device_get_by_device_id returned %s",
+ _ua_get_error_string(ret));
+
+ __ua_monitor_send_location_cb(monitor, device_handle,
+ sensor_info, account, location_info);
+
+ FUNC_EXIT;
+}
+
+
void _ua_monitor_handle_scanned_device(int result, uam_device_info_s *uam_info)
{
FUNC_ENTRY;
@@ -968,6 +1040,45 @@ void _ua_monitor_handle_user_absence_detected(uam_sensor_info_s *info,
FUNC_EXIT;
}
+void _ua_monitor_handle_user_location_detected(
+ uam_sensor_info_s *info, char *service, char *account,
+ uam_device_info_s *device_info, char *device_id)
+{
+ FUNC_ENTRY;
+ GSList *l;
+ ua_sensor_info_s *sensor_info;
+ ua_sensor_type_e bitmask;
+ ua_location_info_s *location_info;
+ ret_if(NULL == info || NULL == device_info);
+
+ sensor_info = _uam_to_ua_sensor_info(info);
+ ret_if(NULL == sensor_info);
+ bitmask = sensor_info->bitmask;
+
+ location_info = _uam_to_ua_location_info(device_info);
+ ret_if(NULL == location_info);
+
+ for (l = ua_monitor_list; l; l = g_slist_next(l)) {
+ ua_monitor_s *monitor = l->data;
+
+ if (!monitor || (!monitor->location_detection_started))
+ continue;
+
+ if (0 == (bitmask & monitor->sensor_bitmask))
+ continue;
+
+ if (!service || !g_strcmp0(service, monitor->service)) {
+ /* Location detection ongoing */
+ __ua_sensor_location_detected(monitor, sensor_info,
+ account, location_info, device_id);
+ }
+ }
+ _ua_free_sensor_info(sensor_info);
+ g_free(location_info);
+
+ FUNC_EXIT;
+}
+
void _ua_monitor_handle_detection_stopped(char *svc_name,
uam_cycle_state_e cycle_state)
{
diff --git a/src/user-awareness-util.c b/src/user-awareness-util.c
index 6629cc2..8af37af 100755
--- a/src/user-awareness-util.c
+++ b/src/user-awareness-util.c
@@ -501,3 +501,32 @@ int ua_sensor_get_type(
FUNC_EXIT;
return UA_ERROR_NONE;
}
+
+static ua_location_info_s* __ua_allocate_ua_location_info()
+{
+ ua_location_info_s *location_info;
+ location_info = g_malloc0(sizeof(ua_location_info_s));
+ if (!location_info) {
+ UA_ERR("g_malloc0 failed");
+ return NULL;
+ }
+ return location_info;
+}
+
+ua_location_info_s* _uam_to_ua_location_info(uam_device_info_s *info)
+{
+ FUNC_ENTRY;
+ ua_location_info_s *location_info = NULL;
+
+ location_info = __ua_allocate_ua_location_info();
+ if (!location_info)
+ return NULL;
+
+ location_info->distance = info->distance_mm;
+ location_info->x = info->x;
+ location_info->y = info->y;
+ location_info->z = info->z;
+
+ return location_info;
+}
+