summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/osx
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2015-03-23 16:34:48 +0100
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2015-03-24 14:27:32 +0000
commit4103cc487bb92c375fdf4c0b9ab064435320e0a5 (patch)
tree0b6ef0dccfb0b3e3211df2dfeb0d142c7dc13ef8 /src/bluetooth/osx
parent0ae7051fbee32bc7bd2cbe452c78400ac7bb18d1 (diff)
Bluetooth - LE device discovery agent, timer bug (OS X)
CBCentralManager does not have a timeout while scanning and we had to use a delayed selector (via performSelector) to interrupt the scan. This is a bug in the case we're in NSModalPanelRunLoopMode mode (for example) - selector never gets performed (it waits for the default mode) or performed too late. Found in our btchat example. Now we use external QTimer instead to check if it's time to stop a scan. Change-Id: I159bf5821398f3aa76f03a52a8334dea97cbf688 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/osx')
-rw-r--r--src/bluetooth/osx/osxbtcentralmanager.mm8
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry.mm25
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry_p.h6
3 files changed, 26 insertions, 13 deletions
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm
index e539788d..bacea96b 100644
--- a/src/bluetooth/osx/osxbtcentralmanager.mm
+++ b/src/bluetooth/osx/osxbtcentralmanager.mm
@@ -680,9 +680,7 @@ using namespace QT_NAMESPACE;
writeQueue.enqueue(request);
[self performNextWriteRequest];
- // TODO: this is quite ugly: true value can be returned after
- // write actually. If I have any problems with the order later,
- // I'll use performSelector afterDelay with some delay.
+
return true;
}
@@ -705,9 +703,7 @@ using namespace QT_NAMESPACE;
writeQueue.enqueue(request);
[self performNextWriteRequest];
- // TODO: this is quite ugly: true value can be returned after
- // write actually. If I have any problems with the order later,
- // I'll use performSelector afterDelay with some delay.
+
return true;
}
diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm
index 4e9235af..1dbe63a6 100644
--- a/src/bluetooth/osx/osxbtledeviceinquiry.mm
+++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm
@@ -115,11 +115,12 @@ using namespace QT_NAMESPACE;
@implementation QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry)
-+ (NSTimeInterval)inquiryLength
++ (int)inquiryLength
{
// There is no default timeout,
// scan does not stop if not asked.
- return 10;
+ // Return in milliseconds
+ return 10 * 1000;
}
- (id)initWithDelegate:(OSXBluetooth::LEDeviceInquiryDelegate *)aDelegate
@@ -188,6 +189,7 @@ using namespace QT_NAMESPACE;
[manager release];
}
+ startTime = QTime();
pendingStart = true;
manager = [CBCentralManager alloc];
manager = [manager initWithDelegate:self queue:nil];
@@ -215,8 +217,12 @@ using namespace QT_NAMESPACE;
if (pendingStart) {
pendingStart = false;
isActive = true;
- [self performSelector:@selector(stopScan) withObject:nil
- afterDelay:[QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry) inquiryLength]];
+#ifndef Q_OS_OSX
+ const NSTimeInterval timeout([QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry) inquiryLength] / 1000);
+ Q_ASSERT_X(timeout > 0., Q_FUNC_INFO, "invalid scan timeout");
+ [self performSelector:@selector(stopScan) withObject:nil afterDelay:timeout];
+#endif
+ startTime = QTime::currentTime();
[manager scanForPeripheralsWithServices:nil options:nil];
} // Else we ignore.
} else if (state == CBCentralManagerStateUnsupported || state == CBCentralManagerStateUnauthorized) {
@@ -285,10 +291,10 @@ using namespace QT_NAMESPACE;
using namespace OSXBluetooth;
- Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
- Q_ASSERT_X(isActive,Q_FUNC_INFO, "called while there is no active scan");
- Q_ASSERT_X(!pendingStart, Q_FUNC_INFO, "both pendingStart and isActive are true");
+ if (!isActive)
+ return;
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_6_0)
if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_6_0)) {
@@ -323,4 +329,9 @@ using namespace QT_NAMESPACE;
return pendingStart || isActive;
}
+- (const QTime&)startTime
+{
+ return startTime;
+}
+
@end
diff --git a/src/bluetooth/osx/osxbtledeviceinquiry_p.h b/src/bluetooth/osx/osxbtledeviceinquiry_p.h
index 65005894..7e6d0c8f 100644
--- a/src/bluetooth/osx/osxbtledeviceinquiry_p.h
+++ b/src/bluetooth/osx/osxbtledeviceinquiry_p.h
@@ -36,6 +36,7 @@
#include "qbluetoothdevicediscoveryagent.h"
+#include <QtCore/qdatetime.h>
#include <QtCore/qglobal.h>
#include <QtCore/qlist.h>
@@ -88,8 +89,12 @@ QT_END_NAMESPACE
bool cancelled;
// scan actually started.
bool isActive;
+ QTime startTime;
}
+// Inquiry length in milliseconds.
++ (int)inquiryLength;
+
- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::LEDeviceInquiryDelegate *)aDelegate;
- (void)dealloc;
@@ -99,6 +104,7 @@ QT_END_NAMESPACE
- (void)stop;
- (bool)isActive;
+- (const QTime &)startTime;
@end