Add the scan timeout in bluetooth capi 94/24294/1
authorWu Zheng <wu.zheng@intel.com>
Thu, 10 Jul 2014 03:26:01 +0000 (11:26 +0800)
committerWu Zheng <wu.zheng@intel.com>
Thu, 10 Jul 2014 03:26:01 +0000 (11:26 +0800)
According to the design of Bluetooth-Frwk,
start scan need to stop automatically.

Change-Id: I73f65d101330d7ce919ba552926fb420d87d3eb8
Signed-off-by: Wu Zheng <wu.zheng@intel.com>
capi/bluetooth.c

index a90ea18..f211956 100644 (file)
@@ -34,6 +34,8 @@
 
 #define DEVICE_SERVICE_CLASS_DISCOVERABLE_MODE 0x002000
 
+#define BT_STOP_DISCOVERY_TIMEOUT (1000*15)
+
 #define BT_SPP_BUFFER_MAX 1024
 #define BLUETOOTH_IDENT_LEN 6
 #define CONNMAN_DBUS_NAME "net.connman"
@@ -54,6 +56,8 @@ static GDBusConnection *conn;
 
 static bluez_adapter_t *default_adapter;
 
+static guint event_id;
+
 static void profile_connect_callback(bluez_device_t *device,
                                        enum device_profile_state state);
 
@@ -1316,6 +1320,24 @@ int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode,
        return BT_SUCCESS;
 }
 
+static gboolean bt_stop_discovery_timeout_cb(gpointer user_data)
+{
+       event_id = 0;
+
+       bt_adapter_stop_device_discovery();
+
+       return FALSE;
+}
+
+static void bt_stop_discovery_timeout(void)
+{
+       if (event_id > 0)
+               return;
+
+       event_id = g_timeout_add(BT_STOP_DISCOVERY_TIMEOUT,
+               (GSourceFunc)bt_stop_discovery_timeout_cb, NULL);
+}
+
 int bt_adapter_start_device_discovery(void)
 {
        DBG("");
@@ -1328,6 +1350,8 @@ int bt_adapter_start_device_discovery(void)
 
        bluez_adapter_start_discovery(default_adapter);
 
+       bt_stop_discovery_timeout();
+
        return BT_SUCCESS;
 }