summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/osx/osxbtledeviceinquiry.mm
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/osxbtledeviceinquiry.mm
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/osxbtledeviceinquiry.mm')
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry.mm25
1 files changed, 18 insertions, 7 deletions
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