Fix : LE scanning malfunction
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter-le.c
index d85f6bb..ff39a67 100644 (file)
@@ -59,6 +59,7 @@ typedef struct {
        char *sender;
        GSList *filter_list;
        gboolean is_scanning;
+       gboolean stop_pending;
 } bt_adapter_le_scanner_t;
 
 static bluetooth_advertising_params_t adv_params = {
@@ -1371,6 +1372,15 @@ int _bt_unregister_all_scan_filters(const char *sender)
        return BLUETOOTH_ERROR_NONE;
 }
 
+static gboolean __start_le_scan_timeout(gpointer user_data)
+{
+       char *sender = (char *)user_data;
+       _bt_start_le_scan(sender);
+
+       return FALSE;
+}
+
+
 int _bt_start_le_scan(const char *sender)
 {
        GDBusProxy *proxy;
@@ -1384,6 +1394,12 @@ int _bt_start_le_scan(const char *sender)
                scanner_list = g_slist_append(scanner_list, scanner);
        }
 
+       if (scanner->stop_pending == TRUE) {
+               BT_DBG("Waiting LEDiscoveryFinished");
+               g_timeout_add(500, (GSourceFunc)__start_le_scan_timeout, scanner->sender);
+               return BLUETOOTH_ERROR_NONE;
+       }
+
        if (scanner->is_scanning == TRUE) {
                BT_ERR("BT is already in LE scanning");
                return BLUETOOTH_ERROR_IN_PROGRESS;
@@ -1401,7 +1417,7 @@ int _bt_start_le_scan(const char *sender)
                                                G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
                                if (error) {
-                                       BT_ERR("scan_filter_clear Fail: %s", error->message);
+                                       BT_ERR("scan_filter_enable Fail: %s", error->message);
                                        g_clear_error(&error);
                                }
 
@@ -1435,7 +1451,7 @@ int _bt_start_le_scan(const char *sender)
                                        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
                        if (error) {
-                               BT_ERR("scan_filter_clear Fail: %s", error->message);
+                               BT_ERR("scan_filter_enable Fail: %s", error->message);
                                g_clear_error(&error);
                        }
 
@@ -1466,15 +1482,17 @@ int _bt_stop_le_scan(const char *sender)
        GDBusProxy *proxy;
        GError *error = NULL;
        GVariant *ret;
-       bt_adapter_le_scanner_t *scanner = __bt_find_scanner_from_list(sender);
+       bt_adapter_le_scanner_t *scan_sender = __bt_find_scanner_from_list(sender);
+       bt_adapter_le_scanner_t *scanner;
        GSList *l;
        gboolean next_scanning = FALSE;
        gboolean need_scan_filter = TRUE;
 
-       if (scanner == NULL || scanner->is_scanning == FALSE)
+       if (scan_sender == NULL || scan_sender->is_scanning == FALSE)
                return BLUETOOTH_ERROR_NOT_IN_OPERATION;
 
-       scanner->is_scanning = FALSE;
+       scan_sender->is_scanning = FALSE;
+       scan_sender->stop_pending = TRUE;
 
        for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
                scanner = l->data;
@@ -1496,7 +1514,7 @@ int _bt_stop_le_scan(const char *sender)
                                        -1, NULL, &error);
 
                        if (error) {
-                               BT_ERR("scan_filter_clear Fail: %s", error->message);
+                               BT_ERR("scan_filter_enable Fail: %s", error->message);
                                g_clear_error(&error);
                        }
 
@@ -1505,6 +1523,8 @@ int _bt_stop_le_scan(const char *sender)
                        BT_INFO("Enable LE Scan Filter");
                        scan_filter_enabled = TRUE;
                }
+               BT_INFO("next_scanning exists. Keep the LE scanning");
+               scan_sender->stop_pending = FALSE;
                return BLUETOOTH_ERROR_NONE;
        } else {
                if (scan_filter_enabled == TRUE) {
@@ -1514,7 +1534,7 @@ int _bt_stop_le_scan(const char *sender)
                                        -1, NULL, &error);
 
                        if (error) {
-                               BT_ERR("scan_filter_clear Fail: %s", error->message);
+                               BT_ERR("scan_filter_enable Fail: %s", error->message);
                                g_clear_error(&error);
                        }
 
@@ -1549,6 +1569,7 @@ void _bt_disable_all_scanner_status(void)
        for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
                scanner = l->data;
                scanner->is_scanning = FALSE;
+               scanner->stop_pending = FALSE;
        }
 }
 
@@ -1574,6 +1595,7 @@ static void __bt_free_le_scanner(void)
 
 void _bt_set_le_scan_status(gboolean mode)
 {
+       BT_DBG("set is_le_scanning : %d -> %d", is_le_scanning, mode);
        is_le_scanning = mode;
 }