Add API for start_detection 90/260590/2
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 11 Jan 2021 05:39:18 +0000 (11:09 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 1 Jul 2021 07:32:19 +0000 (13:02 +0530)
Change-Id: If57d81f5ae9ce8eeebc876d463f1c91c94ab23ff
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/wifi-location-plugin.h
src/wifi-location-plugin-scan.c
src/wifi-location-plugin.c

index dd37193..ffdab61 100755 (executable)
@@ -31,6 +31,8 @@ extern "C" {
 
 #define PLUGIN_ID UAS_PLUGIN_ID_WIFI_LOCATION
 
+int _wifi_location_plugin_start_scan(int scan_mode);
+
 #ifdef __cplusplus
 }
 #endif
index 70308de..651e194 100755 (executable)
 
 #include "wifi-location-plugin.h"
 #include "wifi-location-plugin-util.h"
+
+int _wifi_location_plugin_start_scan(int scan_mode) {
+       FUNC_ENTER;
+       int ret = UAS_STATUS_SUCCESS;
+
+       FUNC_EXIT;
+       return ret;
+}
index 1753e41..8ac2c77 100755 (executable)
 
 #define DETECTION_WINDOW_DEFAULT       55 /* 55 seconds */
 
+#define DETECTION_STARTED 1
+#define DETECTION_STOPPED 0
+
+static unsigned int wifi_location_detection_window = DETECTION_WINDOW_DEFAULT;
 static const uas_callbacks_t *uas_cbs = NULL;
 static GSList *dev_list = NULL;
+static int wifi_location_detection_type = 0;
+static guint stop_scan_timer = 0;
+
+static void __report_absence(gpointer data, gpointer user_data)
+{
+       FUNC_ENTER;
+
+       /* TODO: Implement this function */
+
+       FUNC_EXIT;
+}
+
+static void __reset_devices(gpointer data, gpointer user_data)
+{
+       /* TODO: Implement this function */
+       return;
+}
+
+static int __stop_scan()
+{
+       FUNC_ENTER;
+       int ret = UAS_STATUS_SUCCESS;
+
+       g_slist_foreach(dev_list, __reset_devices, NULL);
+
+       /* TODO: stop scan */
+       if (UAS_STATUS_SUCCESS != ret) {
+               UA_WIFI_LOCATION_ERR("Fail to stop wifi_location scan [%d]", ret);
+               return ret;
+       }
+
+       /* Send detection stopped */
+       if (uas_cbs && uas_cbs->detection_state_cb) {
+               uas_cbs->detection_state_cb(PLUGIN_ID, DETECTION_STOPPED);
+       } else {
+               UA_WIFI_LOCATION_ERR("uas_cbs not ready");
+       }
+
+       /* Reset detection flags */
+       wifi_location_detection_type = 0;
+
+       FUNC_EXIT;
+       return ret;
+}
+
+static gboolean __stop_scan_expired_timer_cb(gpointer user_data)
+{
+       int ret = UAS_STATUS_SUCCESS;
+
+       stop_scan_timer = 0;
+
+       /* Report absence for undetected devices */
+       g_slist_foreach(dev_list, __report_absence, NULL);
+
+       /* Stop detection */
+       ret = __stop_scan();
+       retv_if_with_log(UAS_STATUS_SUCCESS != ret, FALSE, "return %d", ret);
+
+       return FALSE;
+}
+
+static int __start_scan(gpointer user_data, int scan_mode)
+{
+       FUNC_ENTER;
+       int ret = UAS_STATUS_SUCCESS;
+
+       ret = _wifi_location_plugin_start_scan(scan_mode);
+       retv_if_with_log(UAS_STATUS_SUCCESS != ret, ret, "return %d", ret);
+
+       if (0 < stop_scan_timer)
+               g_source_remove(stop_scan_timer);
+       stop_scan_timer = g_timeout_add_seconds(wifi_location_detection_window,
+                                       __stop_scan_expired_timer_cb, NULL);
+
+       /* Send detection started */
+       if (uas_cbs && uas_cbs->detection_state_cb) {
+               uas_cbs->detection_state_cb(PLUGIN_ID, DETECTION_STARTED);
+       } else {
+               UA_WIFI_LOCATION_ERR("uas_cbs not ready");
+               ret = UAS_STATUS_FAIL;
+       }
+
+       FUNC_EXIT;
+       return ret;
+}
 
 static int init(const uas_callbacks_t *callbacks)
 {
@@ -105,6 +194,32 @@ static int get_capability(uas_capability_e *capability)
        return UAS_STATUS_SUCCESS;
 }
 
+static int start_detection(unsigned int detection_type, int scan_mode)
+{
+       FUNC_ENTER;
+
+       int ret = UAS_STATUS_SUCCESS;
+
+       retv_if(NULL == uas_cbs, UAS_STATUS_NOT_READY);
+       retv_if(detection_type == (wifi_location_detection_type & detection_type),
+                       UAS_STATUS_ALREADY_DONE);
+
+       /* Check if detection already in progress */
+       if (0 != wifi_location_detection_type)
+               goto done;
+
+       /* Start detection */
+       ret = __start_scan(NULL, scan_mode);
+       retv_if_with_log(UAS_STATUS_SUCCESS != ret, ret, "return %d", ret);
+
+done:
+       wifi_location_detection_type |= detection_type;
+       UA_WIFI_LOCATION_INFO_C("wifi_location_detection_type = 0x%8.8X", wifi_location_detection_type);
+
+       FUNC_EXIT;
+       return ret;
+}
+
 static uas_api_t wifi_location_api = {
        .init = init,
        .deinit = deinit,
@@ -113,7 +228,7 @@ static uas_api_t wifi_location_api = {
        .set_registered_devices = NULL,
        .add_device = NULL,
        .remove_device = NULL,
-       .start_detection = NULL,
+       .start_detection = start_detection,
        .stop_detection = NULL,
        .set_low_power_mode = NULL,
        .set_detection_window = NULL,