From 60863d840e5ed256bafddc2c98067dd28166df07 Mon Sep 17 00:00:00 2001 From: Andrew Dolby Date: Sun, 18 Nov 2018 22:54:04 -0500 Subject: Android: Emit deviceDiscovered before deviceUpdated And continue to update device info when continuous scanning (lowEnergyDiscoveryTimeout <= 0). Task-number: QTBUG-46008 Change-Id: I019c540205ae39c60deac165def7d0da572ae291 Reviewed-by: Alex Blasche --- .../qbluetoothdevicediscoveryagent_android.cpp | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index 50f3aef9..6369cedb 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -332,21 +332,29 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices( updatedFields.setFlag(QBluetoothDeviceInfo::Field::ManufacturerData); } - if (!updatedFields.testFlag(QBluetoothDeviceInfo::Field::None)) { - emit q->deviceUpdated(discoveredDevices[i], updatedFields); + if (lowEnergySearchTimeout > 0) { + if (discoveredDevices[i] != info) { + if (discoveredDevices.at(i).name() == info.name()) { + qCDebug(QT_BT_ANDROID) << "Almost Duplicate " << info.address() + << info.name() << "- replacing in place"; + discoveredDevices.replace(i, info); + emit q->deviceDiscovered(info); + } + } else { + if (!updatedFields.testFlag(QBluetoothDeviceInfo::Field::None)) + emit q->deviceUpdated(discoveredDevices[i], updatedFields); + } + return; } - if (discoveredDevices[i] == info) - return; + discoveredDevices.replace(i, info); + emit q->deviceDiscovered(info); - if (discoveredDevices.at(i).name() == info.name()) { - qCDebug(QT_BT_ANDROID) << "Almost Duplicate "<< info.address() - << info.name() << "- replacing in place"; - discoveredDevices.replace(i, info); - emit q->deviceDiscovered(info); - return; - } + if (!updatedFields.testFlag(QBluetoothDeviceInfo::Field::None)) + emit q->deviceUpdated(discoveredDevices[i], updatedFields); + + return; } } -- cgit v1.2.3 From 47673cc99431bc92de866da6b22b84313b7092f2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 28 Nov 2018 15:50:13 +0100 Subject: Compile-fix (g++ 8): move #include of mocs outside namespace Change-Id: I9adaa11043c94e0c4d5530fbafa2ef2f15681cac Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent.cpp | 4 ++-- src/bluetooth/qbluetoothlocaldevice.cpp | 4 ++-- src/bluetooth/qbluetoothserver.cpp | 4 ++-- src/bluetooth/qbluetoothservicediscoveryagent.cpp | 4 ++-- src/bluetooth/qbluetoothsocket.cpp | 4 ++-- src/bluetooth/qbluetoothtransfermanager.cpp | 3 ++- src/bluetooth/qbluetoothtransferreply.cpp | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index e69dcce3..b132a3a6 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -431,6 +431,6 @@ QString QBluetoothDeviceDiscoveryAgent::errorString() const return d->errorString; } -#include "moc_qbluetoothdevicediscoveryagent.cpp" - QT_END_NAMESPACE + +#include "moc_qbluetoothdevicediscoveryagent.cpp" diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp index 173650a0..38dd56f4 100644 --- a/src/bluetooth/qbluetoothlocaldevice.cpp +++ b/src/bluetooth/qbluetoothlocaldevice.cpp @@ -326,6 +326,6 @@ bool QBluetoothLocalDevice::isValid() const the resulting local device selects the local default device. */ -#include "moc_qbluetoothlocaldevice.cpp" - QT_END_NAMESPACE + +#include "moc_qbluetoothlocaldevice.cpp" diff --git a/src/bluetooth/qbluetoothserver.cpp b/src/bluetooth/qbluetoothserver.cpp index 8f760eed..6991518f 100644 --- a/src/bluetooth/qbluetoothserver.cpp +++ b/src/bluetooth/qbluetoothserver.cpp @@ -323,6 +323,6 @@ QBluetoothServer::Error QBluetoothServer::error() const return d->m_lastError; } -#include "moc_qbluetoothserver.cpp" - QT_END_NAMESPACE + +#include "moc_qbluetoothserver.cpp" diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 390b9f74..a5fc7654 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -575,6 +575,6 @@ bool QBluetoothServiceDiscoveryAgentPrivate::isDuplicatedService( return false; } -#include "moc_qbluetoothservicediscoveryagent.cpp" - QT_END_NAMESPACE + +#include "moc_qbluetoothservicediscoveryagent.cpp" diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 16461bd3..25c115fa 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -840,6 +840,6 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketState state) } #endif -#include "moc_qbluetoothsocket.cpp" - QT_END_NAMESPACE + +#include "moc_qbluetoothsocket.cpp" diff --git a/src/bluetooth/qbluetoothtransfermanager.cpp b/src/bluetooth/qbluetoothtransfermanager.cpp index 165faceb..37a3191a 100644 --- a/src/bluetooth/qbluetoothtransfermanager.cpp +++ b/src/bluetooth/qbluetoothtransfermanager.cpp @@ -130,6 +130,7 @@ QBluetoothTransferReply *QBluetoothTransferManager::put(const QBluetoothTransfer return 0; #endif } -#include "moc_qbluetoothtransfermanager.cpp" QT_END_NAMESPACE + +#include "moc_qbluetoothtransfermanager.cpp" diff --git a/src/bluetooth/qbluetoothtransferreply.cpp b/src/bluetooth/qbluetoothtransferreply.cpp index 0faea96c..a5da8f8f 100644 --- a/src/bluetooth/qbluetoothtransferreply.cpp +++ b/src/bluetooth/qbluetoothtransferreply.cpp @@ -209,6 +209,6 @@ QBluetoothTransferReplyPrivate::QBluetoothTransferReplyPrivate() { } -#include "moc_qbluetoothtransferreply.cpp" - QT_END_NAMESPACE + +#include "moc_qbluetoothtransferreply.cpp" -- cgit v1.2.3 From a88d0ea41e5aab406e9d465a5165fc16fb9ca9fb Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Mon, 3 Dec 2018 14:27:28 +0200 Subject: Fix compilation with gcc 4.8 GCC 4.8 doesn't like duplicate friend declarations. Change-Id: I2ec48ca7415b9fd7fe1c24f390519833b7d1f0aa Reviewed-by: Simon Hausmann --- src/bluetooth/qbluetoothsocket.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h index cf76e8b8..d2535544 100644 --- a/src/bluetooth/qbluetoothsocket.h +++ b/src/bluetooth/qbluetoothsocket.h @@ -186,7 +186,6 @@ protected: explicit QBluetoothSocket(QBluetoothSocketBasePrivate *d, QBluetoothServiceInfo::Protocol socketType, QObject *parent = nullptr); - friend class QBluetoothServerPrivate; #endif #ifndef QT_OSX_BLUETOOTH QBluetoothSocketBasePrivate *d_ptr; -- cgit v1.2.3 From 9f5c8e5253a742d148f713dcbb137ba26ffa4089 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 13 Dec 2018 15:34:23 +0100 Subject: GCD timer - refactor and fix warnings 1. We move the logic 'object we are watching after and the query's type' into the GCD timer, since we'll need several timers in osxbtcentralmanager (and after all it's not a timer really, it's 'a timeout watchdog' more like. 2. Move i-vars into the implementation to suppress compiler warnings. Task-number: QTBUG-72487 Change-Id: I090e4cc2e0e747211aae8ec91c4e0ff4a53f570b Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtcentralmanager.mm | 4 ++- src/bluetooth/osx/osxbtcentralmanager_p.h | 12 --------- src/bluetooth/osx/osxbtgcdtimer.mm | 41 ++++++++++++++++++++++++++++--- src/bluetooth/osx/osxbtgcdtimer_p.h | 38 +++++++++++++++++++--------- src/bluetooth/osx/osxbtledeviceinquiry.mm | 4 ++- 5 files changed, 70 insertions(+), 29 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 9254bd98..75d9f5c0 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -197,8 +197,10 @@ QT_END_NAMESPACE timeoutType = OSXBluetooth::OperationTimeout::none; } -- (void)timeout +- (void)timeout:(id)sender { + Q_UNUSED(sender) + using namespace OSXBluetooth; Q_ASSERT(objectUnderWatch); diff --git a/src/bluetooth/osx/osxbtcentralmanager_p.h b/src/bluetooth/osx/osxbtcentralmanager_p.h index e172d874..a1d2db66 100644 --- a/src/bluetooth/osx/osxbtcentralmanager_p.h +++ b/src/bluetooth/osx/osxbtcentralmanager_p.h @@ -87,18 +87,6 @@ enum CentralManagerState CentralManagerDisconnecting }; -enum class OperationTimeout -{ - none, - serviceDiscovery, - includedServicesDiscovery, - characteristicsDiscovery, - characteristicRead, - descriptorsDiscovery, - descriptorRead, - characteristicWrite -}; - // In Qt we work with handles and UUIDs. Core Bluetooth // has NSArrays (and nested NSArrays inside servces/characteristics). // To simplify a navigation, I need a simple way to map from a handle diff --git a/src/bluetooth/osx/osxbtgcdtimer.mm b/src/bluetooth/osx/osxbtgcdtimer.mm index 095f8680..9663ca93 100644 --- a/src/bluetooth/osx/osxbtgcdtimer.mm +++ b/src/bluetooth/osx/osxbtgcdtimer.mm @@ -44,7 +44,23 @@ #include -@implementation QT_MANGLE_NAMESPACE(OSXBTGCDTimer) +QT_USE_NAMESPACE +using namespace OSXBluetooth; + +@implementation QT_MANGLE_NAMESPACE(OSXBTGCDTimer) { +@private + qint64 timeoutMS; + qint64 timeoutStepMS; + + // Optional: + id objectUnderWatch; + OperationTimeout timeoutType; + + QElapsedTimer timer; + id timeoutHandler; + + bool cancelled; +} - (instancetype)initWithDelegate:(id)delegate { @@ -52,11 +68,19 @@ timeoutHandler = delegate; timeoutMS = 0; timeoutStepMS = 0; + objectUnderWatch = nil; + timeoutType = OperationTimeout::none; cancelled = false; } return self; } +- (void)watchAfter:(id)object withTimeoutType:(OperationTimeout)type +{ + objectUnderWatch = object; + timeoutType = type; +} + - (void)startWithTimeout:(qint64)ms step:(qint64)stepMS { Q_ASSERT(!timeoutMS && !timeoutStepMS); @@ -86,9 +110,8 @@ const qint64 elapsed = timer.elapsed(); if (elapsed >= timeoutMS) { - [timeoutHandler timeout]; + [timeoutHandler timeout:self]; } else { - using namespace QT_PREPEND_NAMESPACE(OSXBluetooth); // Re-schedule: dispatch_queue_t leQueue(qt_LE_queue()); Q_ASSERT(leQueue); @@ -106,6 +129,18 @@ { cancelled = true; timeoutHandler = nil; + objectUnderWatch = nil; + timeoutType = OperationTimeout::none; +} + +- (id)objectUnderWatch +{ + return objectUnderWatch; +} + +- (OperationTimeout)timeoutType +{ + return timeoutType; } @end diff --git a/src/bluetooth/osx/osxbtgcdtimer_p.h b/src/bluetooth/osx/osxbtgcdtimer_p.h index 007a004b..153e9033 100644 --- a/src/bluetooth/osx/osxbtgcdtimer_p.h +++ b/src/bluetooth/osx/osxbtgcdtimer_p.h @@ -58,25 +58,39 @@ #include +QT_BEGIN_NAMESPACE + +namespace OSXBluetooth { + +enum class OperationTimeout +{ + none, + serviceDiscovery, + includedServicesDiscovery, + characteristicsDiscovery, + characteristicRead, + descriptorsDiscovery, + descriptorRead, + characteristicWrite +}; + +} // namespace OSXBluetooth + +QT_END_NAMESPACE + @protocol QT_MANGLE_NAMESPACE(GCDTimerDelegate) @required -- (void)timeout; +- (void)timeout:(id)sender; @end -@interface QT_MANGLE_NAMESPACE(OSXBTGCDTimer) : NSObject { -@private - qint64 timeoutMS; - qint64 timeoutStepMS; - QT_PREPEND_NAMESPACE(QElapsedTimer) timer; - id timeoutHandler; - bool cancelled; -} - +@interface QT_MANGLE_NAMESPACE(OSXBTGCDTimer) : NSObject - (instancetype)initWithDelegate:(id)delegate; +- (void)watchAfter:(id)object withTimeoutType:(QT_PREPEND_NAMESPACE(OSXBluetooth)::OperationTimeout)type; - (void)startWithTimeout:(qint64)ms step:(qint64)stepMS; - (void)handleTimeout; - (void)cancelTimer; - +- (id)objectUnderWatch; +- (QT_PREPEND_NAMESPACE(OSXBluetooth)::OperationTimeout)timeoutType; @end QT_BEGIN_NAMESPACE @@ -86,7 +100,7 @@ namespace OSXBluetooth { using GCDTimerObjC = QT_MANGLE_NAMESPACE(OSXBTGCDTimer); using GCDTimer = ObjCScopedPointer; -} +} // namespace OSXBluetooth QT_END_NAMESPACE diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index e61968ed..c82cb31d 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -151,8 +151,10 @@ QT_USE_NAMESPACE [super dealloc]; } -- (void)timeout +- (void)timeout:(id)sender { + Q_UNUSED(sender) + if (internalState == InquiryActive) { [manager stopScan]; [manager setDelegate:nil]; -- cgit v1.2.3 From db0f1f7ab0892c84744608e073fc99999ef28fdd Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 13 Dec 2018 15:48:57 +0100 Subject: Fix broken timeout handling in osxbtcentral manager Trying to do several things (for example, discovering chars on several services) in non-sequential manner is allowed but will result in the broken 'object under watch' logic and thus a failure to report some operation finished. Task-number: QTBUG-72487 Change-Id: I9674f93e0c4d5cbfd50ac2f828d0d650031e056c Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtcentralmanager.mm | 184 +++++++++++++++++++++--------- src/bluetooth/osx/osxbtcentralmanager_p.h | 45 +------- src/bluetooth/osx/osxbtgcdtimer_p.h | 2 +- src/bluetooth/osx/osxbtledeviceinquiry.mm | 4 +- src/bluetooth/qlowenergycontroller_osx.mm | 2 +- 5 files changed, 136 insertions(+), 101 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 75d9f5c0..cadabbaf 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -46,6 +46,7 @@ #include #include +#include #include Q_DECLARE_METATYPE(QLowEnergyHandle) @@ -92,13 +93,24 @@ ObjCStrongReference qt_timeoutNSError(OperationTimeout type) return ObjCStrongReference(nsError, false /*do not retain, done already*/); } +auto qt_find_watchdog(const std::vector &watchdogs, id object, OperationTimeout type) +{ + return std::find_if(watchdogs.begin(), watchdogs.end(), [object, type](const GCDTimer &other){ + return [other objectUnderWatch] == object && [other timeoutType] == type;}); +} + } // namespace OSXBluetooth QT_END_NAMESPACE +QT_USE_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTCentralManager) (PrivateAPI) +- (void)watchAfter:(id)object timeout:(OSXBluetooth::OperationTimeout)type; +- (bool)objectIsUnderWatch:(id)object operation:(OSXBluetooth::OperationTimeout)type; +- (void)stopWatchingAfter:(id)object operation:(OSXBluetooth::OperationTimeout)type; +- (void)stopWatchers; - (void)retrievePeripheralAndConnect; - (void)connectToPeripheral; - (void)discoverIncludedServices; @@ -125,6 +137,45 @@ QT_END_NAMESPACE @end @implementation QT_MANGLE_NAMESPACE(OSXBTCentralManager) +{ +@private + CBCentralManager *manager; + OSXBluetooth::CentralManagerState managerState; + bool disconnectPending; + + QBluetoothUuid deviceUuid; + + OSXBluetooth::LECBManagerNotifier *notifier; + + // Quite a verbose service discovery machinery + // (a "graph traversal"). + OSXBluetooth::ObjCStrongReference servicesToVisit; + // The service we're discovering now (included services discovery): + NSUInteger currentService; + // Included services, we'll iterate through at the end of 'servicesToVisit': + OSXBluetooth::ObjCStrongReference servicesToVisitNext; + // We'd like to avoid loops in a services' topology: + OSXBluetooth::ObjCStrongReference visitedServices; + + QList servicesToDiscoverDetails; + + OSXBluetooth::ServiceHash serviceMap; + OSXBluetooth::CharHash charMap; + OSXBluetooth::DescHash descMap; + + QLowEnergyHandle lastValidHandle; + + bool requestPending; + OSXBluetooth::RequestQueue requests; + QLowEnergyHandle currentReadHandle; + + OSXBluetooth::ValueHash valuesToWrite; + + qint64 timeoutMS; + std::vector timeoutWatchdogs; + + CBPeripheral *peripheral; +} - (id)initWith:(OSXBluetooth::LECBManagerNotifier *)aNotifier { @@ -140,7 +191,6 @@ QT_END_NAMESPACE lastValidHandle = 0; requestPending = false; currentReadHandle = 0; - timeoutType = OperationTimeout::none; if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("BLUETOOTH_GATT_TIMEOUT"))) { bool ok = false; @@ -176,25 +226,44 @@ QT_END_NAMESPACE if (notifier) notifier->deleteLater(); + [self stopWatchers]; [super dealloc]; } +- (CBPeripheral *)peripheral +{ + return peripheral; +} + - (void)watchAfter:(id)object timeout:(OSXBluetooth::OperationTimeout)type { using namespace OSXBluetooth; - objectUnderWatch = object; - timeoutType = type; - [timeoutWatchdog cancelTimer]; - timeoutWatchdog.reset([[GCDTimerObjC alloc] initWithDelegate:self]); - [timeoutWatchdog startWithTimeout:timeoutMS step:200]; + GCDTimer newWatcher([[GCDTimerObjC alloc] initWithDelegate:self], false /*do not retain*/); + [newWatcher watchAfter:object withTimeoutType:type]; + timeoutWatchdogs.push_back(newWatcher); + [newWatcher startWithTimeout:timeoutMS step:200]; +} + +- (bool)objectIsUnderWatch:(id)object operation:(OSXBluetooth::OperationTimeout)type +{ + return OSXBluetooth::qt_find_watchdog(timeoutWatchdogs, object, type) != timeoutWatchdogs.end(); } -- (void)stopWatchdog +- (void)stopWatchingAfter:(id)object operation:(OSXBluetooth::OperationTimeout)type { - [timeoutWatchdog cancelTimer]; - objectUnderWatch = nil; - timeoutType = OSXBluetooth::OperationTimeout::none; + auto pos = OSXBluetooth::qt_find_watchdog(timeoutWatchdogs, object, type); + if (pos != timeoutWatchdogs.end()) { + [*pos cancelTimer]; + timeoutWatchdogs.erase(pos); + } +} + +- (void)stopWatchers +{ + for (auto &watchdog : timeoutWatchdogs) + [watchdog cancelTimer]; + timeoutWatchdogs.clear(); } - (void)timeout:(id)sender @@ -203,37 +272,45 @@ QT_END_NAMESPACE using namespace OSXBluetooth; - Q_ASSERT(objectUnderWatch); - NSLog(@"Timeout caused by: %@", objectUnderWatch); - const ObjCStrongReference nsError(qt_timeoutNSError(timeoutType)); - switch (timeoutType) { + GCDTimerObjC *watcher = static_cast(sender); + id cbObject = [watcher objectUnderWatch]; + const OperationTimeout type = [watcher timeoutType]; + + Q_ASSERT([self objectIsUnderWatch:cbObject operation:type]); + + NSLog(@"Timeout caused by: %@", cbObject); + + // Note that after this switch the 'watcher' is released (we don't + // own it anymore), though GCD is probably still holding a reference. + const ObjCStrongReference nsError(qt_timeoutNSError(type)); + switch (type) { case OperationTimeout::serviceDiscovery: qCWarning(QT_BT_OSX, "Timeout in services discovery"); [self peripheral:peripheral didDiscoverServices:nsError]; break; case OperationTimeout::includedServicesDiscovery: qCWarning(QT_BT_OSX, "Timeout in included services discovery"); - [self peripheral:peripheral didDiscoverIncludedServicesForService:objectUnderWatch error:nsError]; + [self peripheral:peripheral didDiscoverIncludedServicesForService:cbObject error:nsError]; break; case OperationTimeout::characteristicsDiscovery: qCWarning(QT_BT_OSX, "Timeout in characteristics discovery"); - [self peripheral:peripheral didDiscoverCharacteristicsForService:objectUnderWatch error:nsError]; + [self peripheral:peripheral didDiscoverCharacteristicsForService:cbObject error:nsError]; break; case OperationTimeout::characteristicRead: qCWarning(QT_BT_OSX, "Timeout while reading a characteristic"); - [self peripheral:peripheral didUpdateValueForCharacteristic:objectUnderWatch error:nsError]; + [self peripheral:peripheral didUpdateValueForCharacteristic:cbObject error:nsError]; break; case OperationTimeout::descriptorsDiscovery: qCWarning(QT_BT_OSX, "Timeout in descriptors discovery"); - [self peripheral:peripheral didDiscoverDescriptorsForCharacteristic:objectUnderWatch error:nsError]; + [self peripheral:peripheral didDiscoverDescriptorsForCharacteristic:cbObject error:nsError]; break; case OperationTimeout::descriptorRead: qCWarning(QT_BT_OSX, "Timeout while reading a descriptor"); - [self peripheral:peripheral didUpdateValueForDescriptor:objectUnderWatch error:nsError]; + [self peripheral:peripheral didUpdateValueForDescriptor:cbObject error:nsError]; break; case OperationTimeout::characteristicWrite: qCWarning(QT_BT_OSX, "Timeout while writing a characteristic with response"); - [self peripheral:peripheral didWriteValueForCharacteristic:objectUnderWatch error:nsError]; + [self peripheral:peripheral didWriteValueForCharacteristic:cbObject error:nsError]; default:; } } @@ -1121,7 +1198,7 @@ QT_END_NAMESPACE charMap.clear(); descMap.clear(); currentReadHandle = 0; - [self stopWatchdog]; + [self stopWatchers]; // TODO: also serviceToVisit/VisitNext and visitedServices ? } @@ -1274,12 +1351,14 @@ QT_END_NAMESPACE return; } - if (objectUnderWatch != aPeripheral) { - // Timed out. + using namespace OSXBluetooth; + if (![self objectIsUnderWatch:aPeripheral operation:OperationTimeout::serviceDiscovery]) // Timed out already return; - } - [self stopWatchdog]; + QT_BT_MAC_AUTORELEASEPOOL; + + [self stopWatchingAfter:aPeripheral operation:OperationTimeout::serviceDiscovery]; + managerState = OSXBluetooth::CentralManagerIdle; if (error) { @@ -1305,16 +1384,14 @@ QT_END_NAMESPACE return; } - if (service != objectUnderWatch) { - // Timed out. + if (![self objectIsUnderWatch:service operation:OperationTimeout::includedServicesDiscovery]) return; - } QT_BT_MAC_AUTORELEASEPOOL; Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)"); - [self stopWatchdog]; + [self stopWatchingAfter:service operation:OperationTimeout::includedServicesDiscovery]; managerState = CentralManagerIdle; if (error) { @@ -1382,14 +1459,14 @@ QT_END_NAMESPACE return; } - if (service != objectUnderWatch) { - // Timed out already? + using namespace OSXBluetooth; + + if (![self objectIsUnderWatch:service operation:OperationTimeout::characteristicsDiscovery]) return; - } - [self stopWatchdog]; + QT_BT_MAC_AUTORELEASEPOOL; - using namespace OSXBluetooth; + [self stopWatchingAfter:service operation:OperationTimeout::characteristicsDiscovery]; Q_ASSERT_X(managerState != CentralManagerUpdating, Q_FUNC_INFO, "invalid state"); @@ -1409,21 +1486,21 @@ QT_END_NAMESPACE { Q_UNUSED(aPeripheral) - if (!notifier) { - // Detached. + if (!notifier) // Detached. return; - } - - const bool readMatch = characteristic == objectUnderWatch; - if (readMatch) - [self stopWatchdog]; using namespace OSXBluetooth; + QT_BT_MAC_AUTORELEASEPOOL; + + const bool readMatch = [self objectIsUnderWatch:characteristic operation:OperationTimeout::characteristicRead]; + if (readMatch) + [self stopWatchingAfter:characteristic operation:OperationTimeout::characteristicRead]; + Q_ASSERT_X(managerState != CentralManagerUpdating, Q_FUNC_INFO, "invalid state"); Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)"); - QT_BT_MAC_AUTORELEASEPOOL; + // First, let's check if we're discovering a service details now. CBService *const service = characteristic.service; const QBluetoothUuid qtUuid(qt_uuid(service.UUID)); @@ -1497,12 +1574,12 @@ QT_END_NAMESPACE QT_BT_MAC_AUTORELEASEPOOL; - if (characteristic != objectUnderWatch) - return; + using namespace OSXBluetooth; - [self stopWatchdog]; + if (![self objectIsUnderWatch:characteristic operation:OperationTimeout::descriptorsDiscovery]) + return; - using namespace OSXBluetooth; + [self stopWatchingAfter:characteristic operation:OperationTimeout::descriptorsDiscovery]; if (error) { NSLog(@"%s failed with error %@", Q_FUNC_INFO, error); @@ -1535,12 +1612,12 @@ QT_END_NAMESPACE QT_BT_MAC_AUTORELEASEPOOL; - if (descriptor != objectUnderWatch) - return; + using namespace OSXBluetooth; - [self stopWatchdog]; + if (![self objectIsUnderWatch:descriptor operation:OperationTimeout::descriptorRead]) + return; - using namespace OSXBluetooth; + [self stopWatchingAfter:descriptor operation:OperationTimeout::descriptorRead]; CBService *const service = descriptor.characteristic.service; const QBluetoothUuid qtUuid(qt_uuid(service.UUID)); @@ -1627,13 +1704,12 @@ QT_END_NAMESPACE QT_BT_MAC_AUTORELEASEPOOL; - if (characteristic != objectUnderWatch) + if (![self objectIsUnderWatch:characteristic operation:OperationTimeout::characteristicWrite]) return; - [self stopWatchdog]; + [self stopWatchingAfter:characteristic operation:OperationTimeout::characteristicWrite]; requestPending = false; - // Error or not, but the cached value has to be deleted ... const QByteArray valueToReport(valuesToWrite.value(characteristic, QByteArray())); if (!valuesToWrite.remove(characteristic)) { @@ -1729,7 +1805,7 @@ QT_END_NAMESPACE notifier = nullptr; } - [self stopWatchdog]; + [self stopWatchers]; [self disconnectFromDevice]; } diff --git a/src/bluetooth/osx/osxbtcentralmanager_p.h b/src/bluetooth/osx/osxbtcentralmanager_p.h index a1d2db66..ce348dc6 100644 --- a/src/bluetooth/osx/osxbtcentralmanager_p.h +++ b/src/bluetooth/osx/osxbtcentralmanager_p.h @@ -136,52 +136,11 @@ QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTCentralManager) : NSObject -{ -@private - CBCentralManager *manager; - QT_PREPEND_NAMESPACE(OSXBluetooth)::CentralManagerState managerState; - bool disconnectPending; - - QT_PREPEND_NAMESPACE(QBluetoothUuid) deviceUuid; - - QT_PREPEND_NAMESPACE(OSXBluetooth)::LECBManagerNotifier *notifier; - - // Quite a verbose service discovery machinery - // (a "graph traversal"). - QT_PREPEND_NAMESPACE(OSXBluetooth)::ObjCStrongReference servicesToVisit; - // The service we're discovering now (included services discovery): - NSUInteger currentService; - // Included services, we'll iterate through at the end of 'servicesToVisit': - QT_PREPEND_NAMESPACE(OSXBluetooth)::ObjCStrongReference servicesToVisitNext; - // We'd like to avoid loops in a services' topology: - QT_PREPEND_NAMESPACE(OSXBluetooth)::ObjCStrongReference visitedServices; - - QT_PREPEND_NAMESPACE(QList) servicesToDiscoverDetails; - - QT_PREPEND_NAMESPACE(OSXBluetooth)::ServiceHash serviceMap; - QT_PREPEND_NAMESPACE(OSXBluetooth)::CharHash charMap; - QT_PREPEND_NAMESPACE(OSXBluetooth)::DescHash descMap; - - QT_PREPEND_NAMESPACE(QLowEnergyHandle) lastValidHandle; - - bool requestPending; - QT_PREPEND_NAMESPACE(OSXBluetooth)::RequestQueue requests; - QT_PREPEND_NAMESPACE(QLowEnergyHandle) currentReadHandle; - - QT_PREPEND_NAMESPACE(OSXBluetooth)::ValueHash valuesToWrite; - - qint64 timeoutMS; - id objectUnderWatch; - QT_PREPEND_NAMESPACE(OSXBluetooth)::OperationTimeout timeoutType; - QT_PREPEND_NAMESPACE(OSXBluetooth)::GCDTimer timeoutWatchdog; - -@public - CBPeripheral *peripheral; -} - - (id)initWith:(QT_PREPEND_NAMESPACE(OSXBluetooth)::LECBManagerNotifier *)notifier; - (void)dealloc; +- (CBPeripheral *)peripheral; + // IMPORTANT: _all_ these methods are to be executed on qt_LE_queue, // when passing parameters - C++ objects _must_ be copied (see the controller's code). - (void)connectToDevice:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)aDeviceUuid; diff --git a/src/bluetooth/osx/osxbtgcdtimer_p.h b/src/bluetooth/osx/osxbtgcdtimer_p.h index 153e9033..6bd82c9a 100644 --- a/src/bluetooth/osx/osxbtgcdtimer_p.h +++ b/src/bluetooth/osx/osxbtgcdtimer_p.h @@ -98,7 +98,7 @@ QT_BEGIN_NAMESPACE namespace OSXBluetooth { using GCDTimerObjC = QT_MANGLE_NAMESPACE(OSXBTGCDTimer); -using GCDTimer = ObjCScopedPointer; +using GCDTimer = ObjCStrongReference; } // namespace OSXBluetooth diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index c82cb31d..c616d470 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -206,7 +206,7 @@ QT_USE_NAMESPACE if (inquiryTimeoutMS > 0) { [elapsedTimer cancelTimer]; - elapsedTimer.reset([[GCDTimerObjC alloc] initWithDelegate:self]); + elapsedTimer.resetWithoutRetain([[GCDTimerObjC alloc] initWithDelegate:self]); [elapsedTimer startWithTimeout:inquiryTimeoutMS step:timeStepMS]; } @@ -241,7 +241,7 @@ QT_USE_NAMESPACE // we'll receive 'PoweredOn' state update later. // No change in internalState. Wait for 30 seconds. [elapsedTimer cancelTimer]; - elapsedTimer.reset([[GCDTimerObjC alloc] initWithDelegate:self]); + elapsedTimer.resetWithoutRetain([[GCDTimerObjC alloc] initWithDelegate:self]); [elapsedTimer startWithTimeout:powerOffTimeoutMS step:300]; return; #else diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm index d01686ae..8cef621c 100644 --- a/src/bluetooth/qlowenergycontroller_osx.mm +++ b/src/bluetooth/qlowenergycontroller_osx.mm @@ -234,7 +234,7 @@ void QLowEnergyControllerPrivateOSX::_q_serviceDiscoveryFinished() QT_BT_MAC_AUTORELEASEPOOL; - NSArray *const services = centralManager.data()->peripheral.services; + NSArray *const services = [centralManager.data() peripheral].services; // Now we have to traverse the discovered services tree. // Essentially it's an iterative version of more complicated code from the // OSXBTCentralManager's code. -- cgit v1.2.3 From e9967647ffe20df0473a1fa9eb10957b4e32fbf3 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 13 Dec 2018 15:58:08 +0100 Subject: CoreBluetooth - fix warnings ('-Wobjc-interface-ivars') Move all i-vars into implementation part of declaration. Change-Id: I9ee71bc85308d899871dc680d438c504e591b091 Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtconnectionmonitor.mm | 5 +++++ src/bluetooth/osx/osxbtconnectionmonitor_p.h | 5 ----- src/bluetooth/osx/osxbtdeviceinquiry.mm | 5 +++++ src/bluetooth/osx/osxbtdeviceinquiry_p.h | 5 ----- src/bluetooth/osx/osxbtdevicepair.mm | 7 +++++++ src/bluetooth/osx/osxbtdevicepair_p.h | 7 ------- src/bluetooth/osx/osxbtl2capchannel.mm | 6 ++++++ src/bluetooth/osx/osxbtl2capchannel_p.h | 6 ------ src/bluetooth/osx/osxbtledeviceinquiry.mm | 10 ++++++++++ src/bluetooth/osx/osxbtledeviceinquiry_p.h | 11 ----------- src/bluetooth/osx/osxbtobexsession.mm | 21 +++++++++++++++++++++ src/bluetooth/osx/osxbtobexsession_p.h | 21 --------------------- src/bluetooth/osx/osxbtperipheralmanager.mm | 27 +++++++++++++++++++++++++++ src/bluetooth/osx/osxbtperipheralmanager_p.h | 27 --------------------------- src/bluetooth/osx/osxbtrfcommchannel.mm | 6 ++++++ src/bluetooth/osx/osxbtrfcommchannel_p.h | 6 ------ src/bluetooth/osx/osxbtsdpinquiry.mm | 5 +++++ src/bluetooth/osx/osxbtsdpinquiry_p.h | 5 ----- src/bluetooth/osx/osxbtsocketlistener.mm | 5 +++++ src/bluetooth/osx/osxbtsocketlistener_p.h | 5 ----- 20 files changed, 97 insertions(+), 98 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtconnectionmonitor.mm b/src/bluetooth/osx/osxbtconnectionmonitor.mm index dcd38726..b777af8e 100644 --- a/src/bluetooth/osx/osxbtconnectionmonitor.mm +++ b/src/bluetooth/osx/osxbtconnectionmonitor.mm @@ -59,6 +59,11 @@ using namespace QT_NAMESPACE; #endif @implementation QT_MANGLE_NAMESPACE(OSXBTConnectionMonitor) +{ + QT_PREPEND_NAMESPACE(OSXBluetooth::ConnectionMonitor) *monitor; + IOBluetoothUserNotification *discoveryNotification; + NSMutableArray *foundConnections; +} - (id)initWithMonitor:(OSXBluetooth::ConnectionMonitor *)aMonitor { diff --git a/src/bluetooth/osx/osxbtconnectionmonitor_p.h b/src/bluetooth/osx/osxbtconnectionmonitor_p.h index 18ffc86a..679f6124 100644 --- a/src/bluetooth/osx/osxbtconnectionmonitor_p.h +++ b/src/bluetooth/osx/osxbtconnectionmonitor_p.h @@ -79,11 +79,6 @@ public: QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTConnectionMonitor) : NSObject -{ - QT_PREPEND_NAMESPACE(OSXBluetooth::ConnectionMonitor) *monitor; - IOBluetoothUserNotification *discoveryNotification; - NSMutableArray *foundConnections; -} - (id)initWithMonitor:(QT_PREPEND_NAMESPACE(OSXBluetooth::ConnectionMonitor) *)monitor; - (void)connectionNotification:(id)notification withDevice:(IOBluetoothDevice *)device; diff --git a/src/bluetooth/osx/osxbtdeviceinquiry.mm b/src/bluetooth/osx/osxbtdeviceinquiry.mm index 79a8a92c..57cd73e1 100644 --- a/src/bluetooth/osx/osxbtdeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtdeviceinquiry.mm @@ -60,6 +60,11 @@ QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(OSXBTDeviceInquiry) +{ + IOBluetoothDeviceInquiry *m_inquiry; + bool m_active; + QT_PREPEND_NAMESPACE(OSXBluetooth::DeviceInquiryDelegate) *m_delegate;//C++ "delegate" +} - (id)initWithDelegate:(OSXBluetooth::DeviceInquiryDelegate *)delegate { diff --git a/src/bluetooth/osx/osxbtdeviceinquiry_p.h b/src/bluetooth/osx/osxbtdeviceinquiry_p.h index 777184f9..0fec2db2 100644 --- a/src/bluetooth/osx/osxbtdeviceinquiry_p.h +++ b/src/bluetooth/osx/osxbtdeviceinquiry_p.h @@ -80,11 +80,6 @@ public: QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTDeviceInquiry) : NSObject -{ - IOBluetoothDeviceInquiry *m_inquiry; - bool m_active; - QT_PREPEND_NAMESPACE(OSXBluetooth::DeviceInquiryDelegate) *m_delegate;//C++ "delegate" -} - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::DeviceInquiryDelegate) *)delegate; - (void)dealloc; diff --git a/src/bluetooth/osx/osxbtdevicepair.mm b/src/bluetooth/osx/osxbtdevicepair.mm index dcaa3536..75dbbcad 100644 --- a/src/bluetooth/osx/osxbtdevicepair.mm +++ b/src/bluetooth/osx/osxbtdevicepair.mm @@ -69,6 +69,13 @@ QT_END_NAMESPACE QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(OSXBTPairing) +{ + QT_PREPEND_NAMESPACE(QBluetoothAddress) m_targetAddress; + + bool m_active; + IOBluetoothDevicePair *m_pairing; // The real pairing request + QT_PREPEND_NAMESPACE(OSXBluetooth)::PairingDelegate *m_object; +} - (id)initWithTarget:(const QBluetoothAddress &)address delegate:(OSXBluetooth::PairingDelegate *)object diff --git a/src/bluetooth/osx/osxbtdevicepair_p.h b/src/bluetooth/osx/osxbtdevicepair_p.h index d5db5e35..1a2c7d6b 100644 --- a/src/bluetooth/osx/osxbtdevicepair_p.h +++ b/src/bluetooth/osx/osxbtdevicepair_p.h @@ -90,13 +90,6 @@ ObjCStrongReference device_with_address(const QBluetoothAddre QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTPairing) : NSObject -{ - QT_PREPEND_NAMESPACE(QBluetoothAddress) m_targetAddress; - - bool m_active; - IOBluetoothDevicePair *m_pairing; // The real pairing request - QT_PREPEND_NAMESPACE(OSXBluetooth)::PairingDelegate *m_object; -} - (id)initWithTarget:(const QBluetoothAddress &)address delegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::PairingDelegate) *)object; diff --git a/src/bluetooth/osx/osxbtl2capchannel.mm b/src/bluetooth/osx/osxbtl2capchannel.mm index 474fe04b..dc8468a0 100644 --- a/src/bluetooth/osx/osxbtl2capchannel.mm +++ b/src/bluetooth/osx/osxbtl2capchannel.mm @@ -48,6 +48,12 @@ QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(OSXBTL2CAPChannel) +{ + QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *delegate; + IOBluetoothDevice *device; + IOBluetoothL2CAPChannel *channel; + bool connected; +} - (id)initWithDelegate:(OSXBluetooth::ChannelDelegate *)aDelegate { diff --git a/src/bluetooth/osx/osxbtl2capchannel_p.h b/src/bluetooth/osx/osxbtl2capchannel_p.h index a8a08975..512087b4 100644 --- a/src/bluetooth/osx/osxbtl2capchannel_p.h +++ b/src/bluetooth/osx/osxbtl2capchannel_p.h @@ -72,12 +72,6 @@ class ChannelDelegate; QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTL2CAPChannel) : NSObject -{ - QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *delegate; - IOBluetoothDevice *device; - IOBluetoothL2CAPChannel *channel; - bool connected; -} - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate; - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index c616d470..ccf1c279 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -122,6 +122,16 @@ QT_END_NAMESPACE QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry) +{ + LECBManagerNotifier *notifier; + ObjCScopedPointer manager; + + QList devices; + LEInquiryState internalState; + int inquiryTimeoutMS; + + QT_PREPEND_NAMESPACE(OSXBluetooth)::GCDTimer elapsedTimer; +} -(id)initWithNotifier:(LECBManagerNotifier *)aNotifier { diff --git a/src/bluetooth/osx/osxbtledeviceinquiry_p.h b/src/bluetooth/osx/osxbtledeviceinquiry_p.h index a19055ab..d99a93bd 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry_p.h +++ b/src/bluetooth/osx/osxbtledeviceinquiry_p.h @@ -89,17 +89,6 @@ enum LEInquiryState }; @interface QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry) : NSObject -{ - LECBManagerNotifier *notifier; - ObjCScopedPointer manager; - - QList devices; - LEInquiryState internalState; - int inquiryTimeoutMS; - - QT_PREPEND_NAMESPACE(OSXBluetooth)::GCDTimer elapsedTimer; -} - - (id)initWithNotifier:(LECBManagerNotifier *)aNotifier; - (void)dealloc; diff --git a/src/bluetooth/osx/osxbtobexsession.mm b/src/bluetooth/osx/osxbtobexsession.mm index 9fbc2c12..868b2319 100644 --- a/src/bluetooth/osx/osxbtobexsession.mm +++ b/src/bluetooth/osx/osxbtobexsession.mm @@ -418,6 +418,27 @@ QT_USE_NAMESPACE @end @implementation QT_MANGLE_NAMESPACE(OSXBTOBEXSession) +{ + QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXSessionDelegate *delegate; + IOBluetoothDevice *device; + quint16 channelID; + IOBluetoothOBEXSession *session; + + QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXRequest currentRequest; + + bool connected; + bool connectionIDFound; + quint32 connectionID; + + QT_PREPEND_NAMESPACE(QIODevice) *inputStream; + + // TODO: switch to scoped pointers or strong reference objects instead. + NSMutableData *headersData; + NSMutableData *bodyData; + + quint32 bytesSent; + bool pendingAbort; +} + (OBEXMaxPacketLength) maxPacketLength { diff --git a/src/bluetooth/osx/osxbtobexsession_p.h b/src/bluetooth/osx/osxbtobexsession_p.h index 78c93452..49465f24 100644 --- a/src/bluetooth/osx/osxbtobexsession_p.h +++ b/src/bluetooth/osx/osxbtobexsession_p.h @@ -101,27 +101,6 @@ QT_END_NAMESPACE // (it does not have an interface to re-send data or re-use the same transfer reply). // It either succeeds or fails and tries to cleanup in any case. @interface QT_MANGLE_NAMESPACE(OSXBTOBEXSession) : NSObject -{ - QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXSessionDelegate *delegate; - IOBluetoothDevice *device; - quint16 channelID; - IOBluetoothOBEXSession *session; - - QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXRequest currentRequest; - - bool connected; - bool connectionIDFound; - quint32 connectionID; - - QT_PREPEND_NAMESPACE(QIODevice) *inputStream; - - // TODO: switch to scoped pointers or strong reference objects instead. - NSMutableData *headersData; - NSMutableData *bodyData; - - quint32 bytesSent; - bool pendingAbort; -} - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *)aDelegate remoteDevice:(const QBluetoothAddress &)deviceAddress channelID:(quint16)port; diff --git a/src/bluetooth/osx/osxbtperipheralmanager.mm b/src/bluetooth/osx/osxbtperipheralmanager.mm index d3d92f41..1998340a 100644 --- a/src/bluetooth/osx/osxbtperipheralmanager.mm +++ b/src/bluetooth/osx/osxbtperipheralmanager.mm @@ -178,6 +178,33 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data) @end @implementation QT_MANGLE_NAMESPACE(OSXBTPeripheralManager) +{ + ObjCScopedPointer manager; + LECBManagerNotifier *notifier; + + QLowEnergyHandle lastHandle; + // Services in this vector are placed in such order: + // the one that has included services, must + // follow its included services to avoid exceptions from CBPeripheralManager. + std::vector> services; + decltype(services.size()) nextServiceToAdd; + + // Lookup map for included services: + std::map serviceIndex; + ObjCScopedPointer advertisementData; + + GenericLEMap charMap; + GenericLEMap> charValues; + + QMap valueRanges; + + std::deque updateQueue; + + ObjCScopedPointer connectedCentrals; + + PeripheralState state; + NSUInteger maxNotificationValueLength; +} - (id)initWith:(LECBManagerNotifier *)aNotifier { diff --git a/src/bluetooth/osx/osxbtperipheralmanager_p.h b/src/bluetooth/osx/osxbtperipheralmanager_p.h index 19a831d8..fcf55698 100644 --- a/src/bluetooth/osx/osxbtperipheralmanager_p.h +++ b/src/bluetooth/osx/osxbtperipheralmanager_p.h @@ -122,33 +122,6 @@ struct UpdateRequest using ValueRange = QPair; @interface QT_MANGLE_NAMESPACE(OSXBTPeripheralManager) : NSObject -{ - ObjCScopedPointer manager; - LECBManagerNotifier *notifier; - - QLowEnergyHandle lastHandle; - // Services in this vector are placed in such order: - // the one that has included services, must - // follow its included services to avoid exceptions from CBPeripheralManager. - std::vector> services; - decltype(services.size()) nextServiceToAdd; - - // Lookup map for included services: - std::map serviceIndex; - ObjCScopedPointer advertisementData; - - GenericLEMap charMap; - GenericLEMap> charValues; - - QMap valueRanges; - - std::deque updateQueue; - - ObjCScopedPointer connectedCentrals; - - PeripheralState state; - NSUInteger maxNotificationValueLength; -} - (id)initWith:(LECBManagerNotifier *)notifier; - (void)dealloc; diff --git a/src/bluetooth/osx/osxbtrfcommchannel.mm b/src/bluetooth/osx/osxbtrfcommchannel.mm index bd87aae0..00b67ee0 100644 --- a/src/bluetooth/osx/osxbtrfcommchannel.mm +++ b/src/bluetooth/osx/osxbtrfcommchannel.mm @@ -45,6 +45,12 @@ QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(OSXBTRFCOMMChannel) +{ + QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *delegate; + IOBluetoothDevice *device; + IOBluetoothRFCOMMChannel *channel; + bool connected; +} - (id)initWithDelegate:(OSXBluetooth::ChannelDelegate *)aDelegate { diff --git a/src/bluetooth/osx/osxbtrfcommchannel_p.h b/src/bluetooth/osx/osxbtrfcommchannel_p.h index bb615559..775999ed 100644 --- a/src/bluetooth/osx/osxbtrfcommchannel_p.h +++ b/src/bluetooth/osx/osxbtrfcommchannel_p.h @@ -72,12 +72,6 @@ class ChannelDelegate; QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTRFCOMMChannel) : NSObject -{ - QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *delegate; - IOBluetoothDevice *device; - IOBluetoothRFCOMMChannel *channel; - bool connected; -} - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate; - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate diff --git a/src/bluetooth/osx/osxbtsdpinquiry.mm b/src/bluetooth/osx/osxbtsdpinquiry.mm index 23d1bd84..591d75a5 100644 --- a/src/bluetooth/osx/osxbtsdpinquiry.mm +++ b/src/bluetooth/osx/osxbtsdpinquiry.mm @@ -212,6 +212,11 @@ QT_USE_NAMESPACE using namespace OSXBluetooth; @implementation QT_MANGLE_NAMESPACE(OSXBTSDPInquiry) +{ + QT_PREPEND_NAMESPACE(OSXBluetooth::SDPInquiryDelegate) *delegate; + IOBluetoothDevice *device; + bool isActive; +} - (id)initWithDelegate:(SDPInquiryDelegate *)aDelegate { diff --git a/src/bluetooth/osx/osxbtsdpinquiry_p.h b/src/bluetooth/osx/osxbtsdpinquiry_p.h index 6b39634e..c63738bb 100644 --- a/src/bluetooth/osx/osxbtsdpinquiry_p.h +++ b/src/bluetooth/osx/osxbtsdpinquiry_p.h @@ -88,11 +88,6 @@ QList extract_services_uuids(IOBluetoothDevice *device); QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTSDPInquiry) : NSObject -{ - QT_PREPEND_NAMESPACE(OSXBluetooth::SDPInquiryDelegate) *delegate; - IOBluetoothDevice *device; - bool isActive; -} - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::SDPInquiryDelegate) *)aDelegate; - (void)dealloc; diff --git a/src/bluetooth/osx/osxbtsocketlistener.mm b/src/bluetooth/osx/osxbtsocketlistener.mm index 52243990..517b7f2d 100644 --- a/src/bluetooth/osx/osxbtsocketlistener.mm +++ b/src/bluetooth/osx/osxbtsocketlistener.mm @@ -57,6 +57,11 @@ QT_END_NAMESPACE QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(OSXBTSocketListener) +{ + IOBluetoothUserNotification *connectionNotification; + QT_PREPEND_NAMESPACE(OSXBluetooth::SocketListener) *delegate; + quint16 port; +} - (id)initWithListener:(OSXBluetooth::SocketListener *)aDelegate { diff --git a/src/bluetooth/osx/osxbtsocketlistener_p.h b/src/bluetooth/osx/osxbtsocketlistener_p.h index afe3eadc..cac0b7c4 100644 --- a/src/bluetooth/osx/osxbtsocketlistener_p.h +++ b/src/bluetooth/osx/osxbtsocketlistener_p.h @@ -82,11 +82,6 @@ QT_END_NAMESPACE // RFCOMM or L2CAP protocol. It must be deleted to stop listening. @interface QT_MANGLE_NAMESPACE(OSXBTSocketListener) : NSObject -{ - IOBluetoothUserNotification *connectionNotification; - QT_PREPEND_NAMESPACE(OSXBluetooth::SocketListener) *delegate; - quint16 port; -} - (id)initWithListener:(QT_PREPEND_NAMESPACE(OSXBluetooth::SocketListener) *)aDelegate; - (void)dealloc; -- cgit v1.2.3 From fb03b1e921e641a106722f8f3d59861ce7e6789e Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 2 Jan 2019 13:24:56 +0100 Subject: Add missing dbus registrations and change documentation Qt DBus registration for Bluez specific types was done by isBluez5(). However Qt 5.12 introduced bluetoothdVersion() which is a bit more precise. It became necessary because runtime decisions based on exact minor release versions of Bluez became necessary. Therefore some code paths (depending on the user's use case) never called isBluez5() anymore. Subsequently the dbus registrations were missed out on. In the future isBLuez5() should be replaced by bluetoothdVersion(). QBluetoothSocket changed its underlying implementation when addressing QTBUG-68550. It uses dbus sockets to establish rfcomm socket connections to remote devices. The QBluetoothSocket::connectToService() overload that expects a port number is no longer possible as Bluez DBus API does not support connection establishment based on port numbers. Fixes: QTBUG-72742 Change-Id: If6adb391b0524cabc3a702d761e0cbd263508396 Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov --- src/bluetooth/bluez/bluez5_helper.cpp | 7 +++++++ src/bluetooth/qbluetoothsocket.cpp | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index bacdfe3c..7ce67690 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -195,6 +195,13 @@ bool mandatoryHciIoctlsAvailable() QVersionNumber bluetoothdVersion() { if (bluezDaemonVersion()->isNull()) { + // Register DBus specific meta types (copied from isBluez5()) + // Not all code paths run through isBluez5() but still need the + // registration. + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qCDebug(QT_BT_BLUEZ) << "Detecting bluetoothd version"; //Order of matching // 1. Pick whatever the user decides via BLUETOOTH_FORCE_DBUS_LE_VERSION diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 16461bd3..eecb1401 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -427,8 +427,8 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const At any point, the socket can emit error() to signal that an error occurred. - On Android, a connection to a service can not be established using a port. Calling this function - will emit a \l {QBluetoothSocket::ServiceNotFoundError}{ServiceNotFoundError}. + On Android and BlueZ (version 5.46 or above), a connection to a service can not be established using a port. + Calling this function will emit a \l {QBluetoothSocket::ServiceNotFoundError}{ServiceNotFoundError}. Note that most platforms require a pairing prior to connecting to the remote device. Otherwise the connection process may fail. -- cgit v1.2.3 From 45608abda7b9470ec0b3ea26e849ec71b637288d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 8 Jan 2019 10:52:41 +0100 Subject: Don't reverse uuids which are derived from Bluetooth's base uuid The related bug only happens for custom uuids. Fixes: QTBUG-72681 Change-Id: I22d87b84bf3958ecce9b6020e3323f1e6c6a9255 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothsocket_android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index a478819b..d7f17d17 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -196,7 +196,7 @@ static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid) bool isBaseUuid = false; serviceUuid.toUInt32(&isBaseUuid); if (isBaseUuid) - return QBluetoothUuid(); + return serviceUuid; const quint128 original = serviceUuid.toUInt128(); quint128 reversed; -- cgit v1.2.3 From e957470ae0e61eea1afa96d76468dbdc87168421 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 7 Jan 2019 14:55:21 +0100 Subject: Ensure custom uuids are returned by QBluetoothServiceInfo::serviceUuid() QBluetoothServiceDiscoveryAgent::start(FullDiscovery) uses an external tool called sdpscanner to perform the SDP inquiry. The tool uses Bluez's own API to perform the task and is GPL. In case a remote device offers a custom service the service uuid is returned as serviceClassUuid. QBluetoothServiceInfo::serviceUuid() remains empty although it should be populated as per API contract. This patch ensures that the first custom uuid is shifted from the serviceClassUuid list to serviceUuid(). The fix is limited because it picks the first custom uuid and does not consider a secondary custom uuid. Such a case is extremely unlikely though and I have not come across it. Fixes: QTBUG-72800 Change-Id: I7256440bcb1c9b0b2fb75249f977c43fecf1d910 Reviewed-by: Timur Pocheptsov --- .../qbluetoothservicediscoveryagent_bluez.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index e16caff6..6a93143b 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -291,7 +291,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD emit q->error(error); } else if (!xmlRecords.isEmpty() && discoveryState() != Inactive) { for (const QString &record : xmlRecords) { - const QBluetoothServiceInfo serviceInfo = parseServiceXml(record); + QBluetoothServiceInfo serviceInfo = parseServiceXml(record); //apply uuidFilter if (!uuidFilter.isEmpty()) { @@ -313,6 +313,22 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD if (!serviceInfo.isValid()) continue; + // Bluez sdpscanner declares custom uuids into the service class uuid list. + // Let's move a potential custom uuid from QBluetoothServiceInfo::serviceClassUuids() + // to QBluetoothServiceInfo::serviceUuid(). If there is more than one, just move the first uuid + const QList serviceClassUuids = serviceInfo.serviceClassUuids(); + for (const QBluetoothUuid &id : serviceClassUuids) { + if (id.minimumSize() == 16) { + serviceInfo.setServiceUuid(id); + serviceInfo.setServiceName(QBluetoothServiceDiscoveryAgent::tr("Custom Service")); + QBluetoothServiceInfo::Sequence modSeq = + serviceInfo.attribute(QBluetoothServiceInfo::ServiceClassIds).value(); + modSeq.removeOne(QVariant::fromValue(id)); + serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, modSeq); + break; + } + } + if (!isDuplicatedService(serviceInfo)) { discoveredServices.append(serviceInfo); qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString() -- cgit v1.2.3 From 1d964be81b0081d2ccdbf5c9a875672f447b5977 Mon Sep 17 00:00:00 2001 From: Konstantin Marchenko Date: Fri, 9 Dec 2016 18:58:35 +0300 Subject: LE/Android: fix crash when destroying DiscoveryAgent during scan happens due to accessing already destroyed receiver from the queued call Change-Id: Ibc4a9abbb8c00ef9c8985f481b70db36fa508df8 Reviewed-by: Alex Blasche --- src/bluetooth/android/jni_android.cpp | 3 +++ src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp index 176416c8..0688c869 100644 --- a/src/bluetooth/android/jni_android.cpp +++ b/src/bluetooth/android/jni_android.cpp @@ -193,6 +193,9 @@ static void QtBluetoothInputStreamThread_readyData(JNIEnv */*env*/, jobject /*ja void QtBluetoothLE_leScanResult(JNIEnv *env, jobject, jlong qtObject, jobject bluetoothDevice, jint rssi, jbyteArray scanRecord) { + if (Q_UNLIKELY(qtObject == 0)) + return; + reinterpret_cast(qtObject)->onReceiveLeScan( env, bluetoothDevice, rssi, scanRecord); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index 6369cedb..443be14d 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -88,6 +88,9 @@ QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate() if (m_active != NoScanActive) stop(); + if (leScanner.isValid()) + leScanner.setField("qtObject", reinterpret_cast(nullptr)); + if (receiver) { receiver->unregisterReceiver(); delete receiver; -- cgit v1.2.3