Handle location detection event 94/260394/2
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 17 May 2021 05:54:40 +0000 (11:24 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 25 Jun 2021 12:03:12 +0000 (17:33 +0530)
Change-Id: I9f6f7433bfc2e39f0ef52d20dbca695799eea8cb
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness-private.h
include/user-awareness-util.h
src/user-awareness-event-handler.c
src/user-awareness-monitors.c
src/user-awareness-util.c

index 61a8d5c8043c499fc9c328df0d2064f325d9e56b..6bcc4862206f0de9f561f672741e6dbc3ed4f2d7 100755 (executable)
@@ -315,6 +315,17 @@ typedef struct {
        double *values; /**< Sensor data */
 } 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
@@ -582,6 +593,23 @@ void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready);
 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
index 506adbcaae3507c87f938379012ec060c234e17b..88b9871519e75e27ba658f2f71e6d70785486a36 100755 (executable)
@@ -237,6 +237,26 @@ ua_sensor_type_e _uam_to_ua_sensor(uam_sensor_bitmask_e bitmask);
  */
 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.
index 1a231bf5f3458dded3d32a9f7d25ceabcf1c5ade..053ad57ceecdc68db801d76451c8503ad12954f9 100755 (executable)
@@ -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;
 
index 7c7cdb84e3a28be504cfeb2f97b277af6d4085b5..2d3f03ec7f95d385eeb69052bf17f77aaa6cafa3 100755 (executable)
@@ -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)
 {
index 6629cc2d51de19b9d142492a84b149f53c9e1965..8af37afa850d8349629f472fbf18e9c2bff0fba0 100755 (executable)
@@ -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;
+}
+