diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 9f2a109eea31da2dedc020bda669cd01ebf774e4..920fbe9a45aaf60a578fb479ffbc275d4e9361c6 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -166,7 +166,7 @@ config_bluez:qtHaveModule(dbus) { SOURCES -= qlowenergyservice.cpp SOURCES -= qlowenergycontroller.cpp SOURCES -= qlowenergycontroller_p.cpp -} else:ios { +} else:ios|tvos { DEFINES += QT_IOS_BLUETOOTH LIBS += -framework Foundation -framework CoreBluetooth @@ -209,4 +209,3 @@ config_bluez:qtHaveModule(dbus) { OTHER_FILES += HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS - diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index 384b9979308a8219c71fb1d2f74df8fb4a7bba05..14e064e12551d312e2e2a187cbb56b700b32633c 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -339,4 +339,26 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok = return QString(); // nothing matching found } +/* + Removes every character that cannot be used in QDbusObjectPath + + See QDbusUtil::isValidObjectPath(QString) for more details. + */ +QString sanitizeNameForDBus(const QString &text) +{ + QString appName = text; + for (int i = 0; i < appName.length(); i++) { + ushort us = appName[i].unicode(); + bool valid = (us >= 'a' && us <= 'z') + || (us >= 'A' && us <= 'Z') + || (us >= '0' && us <= '9') + || (us == '_'); + + if (!valid) + appName[i] = QLatin1Char('_'); + } + + return appName; +} + QT_END_NAMESPACE diff --git a/src/bluetooth/bluez/bluez5_helper_p.h b/src/bluetooth/bluez/bluez5_helper_p.h index a3f164b0518a16dbbdec4eced9232569065eb510..019fe63597bfc28ce4b9309b46f6518a0b04af9c 100644 --- a/src/bluetooth/bluez/bluez5_helper_p.h +++ b/src/bluetooth/bluez/bluez5_helper_p.h @@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE bool isBluez5(); +QString sanitizeNameForDBus(const QString& text); + QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok); class QtBluezDiscoveryManagerPrivate; diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 2f881f794a61f9f1c9e8c20da7bc0375902c7bb6..21ba1b81f7125ff6bb6b24b9f39c5e4bc1767bdc 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -43,12 +43,12 @@ #include <algorithm> #include <limits> -QT_BEGIN_NAMESPACE - Q_DECLARE_METATYPE(QLowEnergyCharacteristic) Q_DECLARE_METATYPE(QLowEnergyDescriptor) Q_DECLARE_METATYPE(QLowEnergyHandle) +QT_BEGIN_NAMESPACE + namespace OSXBluetooth { NSUInteger qt_countGATTEntries(CBService *service) @@ -80,7 +80,6 @@ NSUInteger qt_countGATTEntries(CBService *service) QT_END_NAMESPACE -QT_USE_NAMESPACE @interface QT_MANGLE_NAMESPACE(OSXBTCentralManager) (PrivateAPI) diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h index 3506b0d184a58f54748ec0e29145fc3ad2f70cdf..8816d6f3f2d08ad6f2ed499fd850cf83deec18c0 100644 --- a/src/bluetooth/osx/osxbtutility_p.h +++ b/src/bluetooth/osx/osxbtutility_p.h @@ -94,8 +94,7 @@ public: } }; -typedef ObjCScopedPointer<NSAutoreleasePool> AutoreleasePool; -#define QT_BT_MAC_AUTORELEASEPOOL const OSXBluetooth::AutoreleasePool pool([[NSAutoreleasePool alloc] init]) +#define QT_BT_MAC_AUTORELEASEPOOL const QMacAutoReleasePool pool; template<class T> class ObjCStrongReference { diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp index e3fa81d117a8ad6a893ffa6e80388e1ea1b9c3f4..d18f4bb13ccec79d944507d9734242080c314026 100644 --- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp @@ -294,7 +294,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca // create path profilePath = profilePathTemplate; profilePath.append(QString::fromLatin1("/%1%2/%3"). - arg(QCoreApplication::applicationName()). + arg(sanitizeNameForDBus(QCoreApplication::applicationName())). arg(QCoreApplication::applicationPid()). arg(pathCounter.fetchAndAddOrdered(1))); diff --git a/src/bluetooth/qbluetoothsocket_osx_p.h b/src/bluetooth/qbluetoothsocket_osx_p.h index cfd653d34bfc0c13312f2eb4571df4b577920f1f..969dcef65ae512aff904acfac71475e6dc04a277 100644 --- a/src/bluetooth/qbluetoothsocket_osx_p.h +++ b/src/bluetooth/qbluetoothsocket_osx_p.h @@ -98,7 +98,7 @@ public: quint16 peerPort() const; void _q_readNotify(); - void _q_writeNotify(); + void _q_writeNotify() Q_DECL_OVERRIDE; private: // Create a socket from an external source (without connectToService). diff --git a/src/bluetooth/qbluetoothtransferreply_bluez.cpp b/src/bluetooth/qbluetoothtransferreply_bluez.cpp index f7f72873532f418654a5d93d4126929ec2e12827..3362b2c19db11ac47f96c1e2e92f461885a79ada 100644 --- a/src/bluetooth/qbluetoothtransferreply_bluez.cpp +++ b/src/bluetooth/qbluetoothtransferreply_bluez.cpp @@ -91,7 +91,7 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con m_agent_path = agentPath; m_agent_path.append(QStringLiteral("/%1%2/%3"). - arg(QCoreApplication::applicationName()). + arg(sanitizeNameForDBus(QCoreApplication::applicationName())). arg(QCoreApplication::applicationPid()). arg(agentPathCounter.fetchAndAddOrdered(1))); diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index d4d41d69ac6995b96e4e5e56d36d197501211fc2..8a6a2e1d23b1bb3b96218fea3a885adfd049afa9 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -271,11 +271,12 @@ void QLowEnergyControllerPrivate::setError( case QLowEnergyController::AdvertisingError: errorString = QLowEnergyController::tr("Error occurred trying to start advertising"); break; + case QLowEnergyController::NoError: + return; + default: case QLowEnergyController::UnknownError: errorString = QLowEnergyController::tr("Unknown Error"); break; - case QLowEnergyController::NoError: - return; } emit q->error(newError); diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 1ad57a8fb976e9e47db2bcdf72394b9b80e3afbf..3e3ea830f2ddfa90828c5f55457822560eb6096a 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -326,6 +326,14 @@ void QLowEnergyControllerPrivate::connectionUpdated( if (newState == QLowEnergyController::UnconnectedState && !(oldState == QLowEnergyController::UnconnectedState || oldState == QLowEnergyController::ConnectingState)) { + + // Invalidate the services if the disconnect came from the remote end. + // Qtherwise we disconnected via QLowEnergyController::disconnectDevice() which + // triggered invalidation already + if (!serviceList.isEmpty()) { + Q_ASSERT(oldState != QLowEnergyController::ClosingState); + invalidateServices(); + } emit q->disconnected(); } else if (newState == QLowEnergyController::ConnectedState && oldState != QLowEnergyController::ConnectedState ) { diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm index 975c03c4da418313b60e79bb6cf08b4043df00af..7ca0d9ac76485356bea9b53fcff2f8a2154e61bc 100644 --- a/src/bluetooth/qlowenergycontroller_osx.mm +++ b/src/bluetooth/qlowenergycontroller_osx.mm @@ -132,7 +132,6 @@ UUIDList qt_servicesUuids(NSArray *services) QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyController *q) : q_ptr(q), - isConnecting(false), lastError(QLowEnergyController::NoError), controllerState(QLowEnergyController::UnconnectedState), addressType(QLowEnergyController::PublicAddress) @@ -165,7 +164,6 @@ QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyControl : q_ptr(q), deviceUuid(deviceInfo.deviceUuid()), deviceName(deviceInfo.name()), - isConnecting(false), lastError(QLowEnergyController::NoError), controllerState(QLowEnergyController::UnconnectedState), addressType(QLowEnergyController::PublicAddress) @@ -214,20 +212,18 @@ void QLowEnergyControllerPrivateOSX::_q_connected() controllerState = QLowEnergyController::ConnectedState; - if (!isConnecting) { - emit q_ptr->stateChanged(QLowEnergyController::ConnectedState); - emit q_ptr->connected(); - } + emit q_ptr->stateChanged(QLowEnergyController::ConnectedState); + emit q_ptr->connected(); } void QLowEnergyControllerPrivateOSX::_q_disconnected() { controllerState = QLowEnergyController::UnconnectedState; - if (!isConnecting) { - emit q_ptr->stateChanged(QLowEnergyController::UnconnectedState); - emit q_ptr->disconnected(); - } + invalidateServices(); + emit q_ptr->stateChanged(QLowEnergyController::UnconnectedState); + emit q_ptr->disconnected(); + } void QLowEnergyControllerPrivateOSX::_q_serviceDiscoveryFinished() @@ -512,8 +508,6 @@ void QLowEnergyControllerPrivateOSX::connectToDevice() Q_FUNC_INFO, "invalid state"); Q_ASSERT_X(!deviceUuid.isNull(), Q_FUNC_INFO, "invalid private controller (no device uuid)"); - Q_ASSERT_X(!isConnecting, Q_FUNC_INFO, - "recursive connectToDevice call"); dispatch_queue_t leQueue(OSXBluetooth::qt_LE_queue()); if (!leQueue) { diff --git a/src/bluetooth/qlowenergycontroller_osx_p.h b/src/bluetooth/qlowenergycontroller_osx_p.h index 58804243b121f4986cbfe50b4ef00cc3a9569030..190f2ac5d8d976cf46a3f681cece3cbd62903f83 100644 --- a/src/bluetooth/qlowenergycontroller_osx_p.h +++ b/src/bluetooth/qlowenergycontroller_osx_p.h @@ -148,12 +148,6 @@ private: QLowEnergyController *q_ptr; QBluetoothUuid deviceUuid; QString deviceName; - // To be sure we set controller's state correctly - // (Connecting or Connected) we have to know if we're - // still inside connectToDevice - this is important, - // if a peripheral is _already_ connected from Core Bluetooth's - // point of view. - bool isConnecting; QString errorString; QLowEnergyController::Error lastError; diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp index 0d57e5f32531067b4cd8bc0696a7367ac04d1f95..1cb8d30cd08d91c73fdede3967496946c9f4c1b6 100644 --- a/src/nfc/qnearfieldtarget.cpp +++ b/src/nfc/qnearfieldtarget.cpp @@ -135,7 +135,7 @@ static const quint16 crc_tbl[16] = { */ quint16 qNfcChecksum(const char *data, uint len) { - register quint16 crc = 0x6363; + quint16 crc = 0x6363; uchar c; const uchar *p = reinterpret_cast<const uchar *>(data); while (len--) { diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 8c924925ebc2b3a7024dba603f003ac1ab97f50a..1386f75c95c31ebcf2bce489ffe188f0f1c45da8 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -189,7 +189,7 @@ void tst_QLowEnergyController::initTestCase() */ void tst_QLowEnergyController::init() { -#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_TVOS) /* * Add a delay to give Android/iOS stack time to catch up in between * the multiple connect/disconnects within each test function. @@ -249,7 +249,7 @@ void tst_QLowEnergyController::tst_connect() { QList<QBluetoothHostInfo> localAdapters = QBluetoothLocalDevice::allDevices(); -#ifdef Q_OS_IOS +#if defined(Q_OS_IOS) || defined(Q_OS_TVOS) if (remoteDeviceInfo.isValid()) #else if (localAdapters.isEmpty() || !remoteDeviceInfo.isValid()) @@ -265,7 +265,7 @@ void tst_QLowEnergyController::tst_connect() else QCOMPARE(control.remoteName(), remoteDeviceInfo.name()); -#ifndef Q_OS_IOS +#if !defined(Q_OS_IOS) && !defined(Q_OS_TVOS) const QBluetoothAddress localAdapter = localAdapters.at(0).address(); QCOMPARE(control.localAddress(), localAdapter); QVERIFY(!control.localAddress().isNull());