Handle device found callback 97/260597/3
authorAbhay Agarwal <ay.agarwal@samsung.com>
Wed, 20 Jan 2021 09:42:55 +0000 (15:12 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 1 Jul 2021 10:51:16 +0000 (16:21 +0530)
Change-Id: Ic3c177ac5a99be3a3ed4a05cf73836bc4265f957
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/wifi-location-plugin.h
src/wifi-location-plugin-scan.c
src/wifi-location-plugin-util.c
src/wifi-location-plugin.c

index 055d6ef..3b02dc7 100755 (executable)
@@ -40,6 +40,7 @@ typedef struct {
        char mac_addr[MAC_ADDRESS_MAX_LEN]; /**< Mac address */
        gboolean presence_reported; /**< Presence reported or not */
        gboolean discriminant; /**< Weather to check or not */
+       int distance_mm; /** Distance of the device */
 } uas_wifi_location_info_t;
 
 int _wifi_location_plugin_initialize(void);
@@ -55,6 +56,9 @@ int _wifi_location_plugin_stop_scan(void);
 void _wifi_location_plugin_handle_device_added(int status,
                uas_wifi_location_info_t *wifi_location_info);
 
+void _wifi_location_plugin_handle_device_found(
+                       const char *address, int distance_mm);
+
 #ifdef __cplusplus
 }
 #endif
index 0365cf2..cc558e2 100755 (executable)
@@ -138,10 +138,13 @@ static void __wifi_location_result_received_cb(
        else
                UA_WIFI_LOCATION_DBG("Result distance(mm) %d", distance_mm);
 
+       _wifi_location_plugin_handle_device_found((const char*)mac, distance_mm);
+
        FUNC_EXIT;
 }
 
-int _wifi_location_plugin_start_scan(int scan_mode) {
+int _wifi_location_plugin_start_scan(int scan_mode)
+{
        FUNC_ENTER;
        int ret = UAS_STATUS_SUCCESS;
 
@@ -154,13 +157,16 @@ int _wifi_location_plugin_start_scan(int scan_mode) {
        return ret;
 }
 
-int _wifi_location_plugin_stop_scan(void) {
+int _wifi_location_plugin_stop_scan(void)
+{
        FUNC_ENTER;
        int ret = UAS_STATUS_SUCCESS;
 
+       /*
        ret = wifi_location_cancel(g_request);
        retv_if_with_log(WIFI_LOCATION_ERROR_NONE != ret,
                UAS_STATUS_FAIL, "return %d", ret);
+       */
 
        FUNC_EXIT;
        return ret;
index f92f641..e346168 100644 (file)
@@ -84,10 +84,15 @@ uas_device_info_t *_wifi_location_plugin_util_get_dev_info_from_wifi_location_in
        dev_info->addr_list[0].type = UAS_ADDR_TYPE_WIFI;
        dev_info->addr_list[0].address = g_strdup(wifi_location_info->mac_addr);
 
+       /* update location */
+       dev_info->location = g_new0(uas_location_info_t, 1);
+       dev_info->location->distance_mm = wifi_location_info->distance_mm;
+
        UA_WIFI_LOCATION_DBG("User Id: [0x%X], OS: [0x%X], Device Id: [%s], " \
-                       "WIFI_LOCATION Addr: [%s] Discriminant [%d],",
+                       "wifi location Addr: [%s] Discriminant [%d], distance(mm) [%d]",
                        dev_info->user_id, dev_info->os, dev_info->device_id,
-                       dev_info->addr_list[0].address, dev_info->discriminant);
+                       dev_info->addr_list[0].address, dev_info->discriminant,
+                       dev_info->location->distance_mm);
 
        FUNC_EXIT;
        return dev_info;
@@ -106,6 +111,7 @@ void _wifi_location_plugin_util_uas_device_info_free(uas_device_info_t *device)
                g_free(device->addr_list[i].address);
 
        g_free(device->addr_list);
+       g_free(device->location);
        g_free(device);
 
        FUNC_EXIT;
index 172122d..5ae5077 100755 (executable)
@@ -418,3 +418,64 @@ void _wifi_location_plugin_handle_device_added(int status,
        _wifi_location_plugin_util_uas_device_info_free(dev_info);
        FUNC_EXIT;
 }
+
+static void __wifi_location_nofity_device_detected(
+       uas_wifi_location_info_t *wifi_location_info)
+{
+       uas_device_info_t *dev_info = NULL;
+
+       if (!wifi_location_info)
+               return;
+
+       if (wifi_location_info->presence_reported)
+               return;
+
+       dev_info = _wifi_location_plugin_util_get_dev_info_from_wifi_location_info(
+                                                               wifi_location_info);
+       if (!dev_info) {
+               UA_WIFI_LOCATION_ERR("Unable to get dev_info");
+               return;
+       }
+
+       /* Save current time */
+       dev_info->last_seen = _wifi_location_plugin_util_get_curr_time();
+
+       if (uas_cbs && uas_cbs->device_detected_cb) {
+               uas_cbs->device_detected_cb(PLUGIN_ID, UAS_PRESENCE, dev_info);
+               wifi_location_info->presence_reported = TRUE;
+       } else {
+               UA_WIFI_LOCATION_ERR("uas_cbs not ready");
+       }
+
+       _wifi_location_plugin_util_uas_device_info_free(dev_info);
+}
+
+void _wifi_location_plugin_handle_device_found(const char *address, int distance_mm)
+{
+       FUNC_ENTER;
+
+       GSList *l;
+
+       ret_if(!(UAS_PRESENCE & wifi_location_detection_type));
+
+       for (l = dev_list; NULL != l; l = g_slist_next(l)) {
+               uas_wifi_location_info_t *wifi_location_info = l->data;
+
+               if (!wifi_location_info)
+                       continue;
+
+               if (strncasecmp(wifi_location_info->mac_addr, address, MAC_ADDRESS_MAX_LEN))
+                       continue;
+
+               UA_WIFI_LOCATION_INFO("Device [%s] found in list with device_id [%s]",
+                               wifi_location_info->mac_addr, wifi_location_info->device_id);
+
+               /* Update location info */
+               wifi_location_info->distance_mm = distance_mm;
+
+               __wifi_location_nofity_device_detected(wifi_location_info);
+               break;
+       }
+
+       FUNC_EXIT;
+}