diff options
author | Andre Guedes <andre.guedes@openbossa.org> | 2011-04-29 21:27:23 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2011-05-05 01:07:14 -0700 |
commit | 9235d4b5aea5f420c5330c22a411ab780b272aa6 (patch) | |
tree | 11fc86d90c2fc535ba4ddfda0a309ddffca316d5 /plugins | |
parent | 6da7ea2e80e55fffb0df63b3bd49fb54d2644973 (diff) |
Add 'timeout' param to start_scanning callback
This patch adds a timeout parameter to start_scanning callback in
btd_adapter. The parameter should be used to stop scanning after
'timeout' milliseconds.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/hciops.c | 38 | ||||
-rw-r--r-- | plugins/mgmtops.c | 2 |
2 files changed, 37 insertions, 3 deletions
diff --git a/plugins/hciops.c b/plugins/hciops.c index 81a0f2989..61ae4041a 100644 --- a/plugins/hciops.c +++ b/plugins/hciops.c @@ -139,6 +139,8 @@ static struct dev_info { GSList *uuids; GSList *connections; + + guint stop_scan_id; } *devs = NULL; static inline int get_state(int index) @@ -2303,6 +2305,9 @@ static void stop_hci_dev(int index) if (dev->watch_id > 0) g_source_remove(dev->watch_id); + if (dev->stop_scan_id > 0) + g_source_remove(dev->stop_scan_id); + if (dev->io != NULL) g_io_channel_unref(dev->io); @@ -3031,10 +3036,25 @@ static int le_set_scan_enable(int index, uint8_t enable) return 0; } -static int hciops_start_scanning(int index) +static gboolean stop_le_scan_cb(gpointer user_data) +{ + struct dev_info *dev = user_data; + int err; + + err = le_set_scan_enable(dev->id, 0); + if (err < 0) + return TRUE; + + dev->stop_scan_id = 0; + + return FALSE; +} + +static int hciops_start_scanning(int index, int timeout) { struct dev_info *dev = &devs[index]; le_set_scan_parameters_cp cp; + int err; DBG("hci%d", index); @@ -3051,13 +3071,27 @@ static int hciops_start_scanning(int index) LE_SET_SCAN_PARAMETERS_CP_SIZE, &cp) < 0) return -errno; - return le_set_scan_enable(index, 1); + err = le_set_scan_enable(index, 1); + if (err < 0) + return err; + + /* Schedule a le scan disable in 'timeout' milliseconds */ + dev->stop_scan_id = g_timeout_add(timeout, stop_le_scan_cb, dev); + + return 0; } static int hciops_stop_scanning(int index) { + struct dev_info *dev = &devs[index]; + DBG("hci%d", index); + if (dev->stop_scan_id > 0) { + g_source_remove(dev->stop_scan_id); + dev->stop_scan_id = 0; + } + return le_set_scan_enable(index, 0); } diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index ac180f9ea..9fa195d2b 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -1632,7 +1632,7 @@ static int mgmt_stop_inquiry(int index) return 0; } -static int mgmt_start_scanning(int index) +static int mgmt_start_scanning(int index, int timeout) { DBG("index %d", index); return -ENOSYS; |