diff options
author | Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> | 2015-11-20 13:12:41 +0100 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> | 2015-11-20 15:45:28 +0000 |
commit | 03cbe371dbd8b5eb51986d27d312813d91a8d380 (patch) | |
tree | 9258d9627f4e1da0bc69721e8669de9ec14f0ac1 | |
parent | 9fcc4f6ec048c98c45a05c974094de9efdef072f (diff) | |
download | qtconnectivity-03cbe371dbd8b5eb51986d27d312813d91a8d380.tar.gz |
LE discovery - change a timer creation time (iOS/OS X)
Create the LE scan timer when it's really needed,
so that I do not have to later move it between threads if somebody
scans from a different thread.
Change-Id: I71669f4c1512432fc94f80446d400336d39def64
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index ebf9352d..ad4183a7 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -44,6 +44,7 @@ #include "qbluetoothuuid.h" #include <QtCore/qloggingcategory.h> +#include <QtCore/qscopedpointer.h> #include <QtCore/qdatetime.h> #include <QtCore/qglobal.h> #include <QtCore/qstring.h> @@ -127,7 +128,7 @@ private: typedef QList<QBluetoothDeviceInfo> DevicesList; DevicesList discoveredDevices; - OSXBluetooth::DDATimerHandler timer; + QScopedPointer<OSXBluetooth::DDATimerHandler> timer; }; namespace OSXBluetooth { @@ -173,8 +174,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con startPending(false), stopPending(false), lastError(QBluetoothDeviceDiscoveryAgent::NoError), - inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry), - timer(this) + inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry) { Q_ASSERT_X(q != Q_NULLPTR, Q_FUNC_INFO, "invalid q_ptr (null)"); @@ -267,12 +267,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startLE() // CoreBluetooth does not have a timeout. We start a timer here // and check if scan really started and if yes if we have a timeout. - timer.start([LEDeviceInquiryObjC inquiryLength]); + timer.reset(new OSXBluetooth::DDATimerHandler(this)); + timer->start([LEDeviceInquiryObjC inquiryLength]); if (![inquiryLE start]) { // We can be here only if we have some kind of resource allocation error, so we // do not emit finished, we emit error. - timer.stop(); + timer->stop(); setError(QBluetoothDeviceDiscoveryAgent::UnknownError, QCoreApplication::translate(DEV_DISCOVERY, DD_NOT_STARTED_LE)); agentState = NonActive; @@ -438,10 +439,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::checkLETimeout() if (elapsed >= timeout) [inquiryLE stop]; else - timer.start(timeout - elapsed); + timer->start(timeout - elapsed); } else { // Scan not started yet. Wait 5 seconds more. - timer.start(timeout / 2); + timer->start(timeout / 2); } } @@ -452,7 +453,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryError(QBluetoothDevic Q_ASSERT_X(error == QBluetoothDeviceDiscoveryAgent::PoweredOffError, Q_FUNC_INFO, "unexpected error code"); - timer.stop(); + timer->stop(); agentState = NonActive; setError(error); @@ -466,7 +467,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEnotSupported() // After we call startLE and before receive NotSupported, // the user can call stop (setting a pending stop). // So the same rule apply: - timer.stop(); + timer->stop(); LEdeviceInquiryFinished(); } @@ -500,7 +501,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryFinished() // The same logic as in inquiryFinished, but does not start LE scan. agentState = NonActive; - timer.stop(); + timer->stop(); if (stopPending && !startPending) { stopPending = false; |