From 61de2a96250ec140233b96f81b1bbb015dad48dc Mon Sep 17 00:00:00 2001 From: Lars Schmertmann Date: Fri, 24 Mar 2017 11:20:14 +0100 Subject: Register additional meta types Register QLowEnergyCharacteristic and QLowEnergyDescriptor as meta types because they are used in signals. [ChangeLog][QtBluetooth] Register QLowEnergyCharacteristic and QLowEnergyDescriptor as meta types. It is therefore necessary to declare them as meta types in the header files. This commit will cause conflicts with existing meta type declarations in applications using Qt. These declarations need to be removed. Change-Id: I18f33b1b2f159cffd6efbacc37178286b86a06e0 Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtcentralmanager.mm | 2 -- src/bluetooth/qlowenergycharacteristic.h | 2 ++ src/bluetooth/qlowenergycontroller_p.h | 5 ----- src/bluetooth/qlowenergydescriptor.h | 2 ++ src/bluetooth/qlowenergyservice.cpp | 2 ++ 5 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index f7218ca6..c8eee733 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -48,8 +48,6 @@ #include #include -Q_DECLARE_METATYPE(QLowEnergyCharacteristic) -Q_DECLARE_METATYPE(QLowEnergyDescriptor) Q_DECLARE_METATYPE(QLowEnergyHandle) QT_BEGIN_NAMESPACE diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h index b991e9a2..154c9936 100644 --- a/src/bluetooth/qlowenergycharacteristic.h +++ b/src/bluetooth/qlowenergycharacteristic.h @@ -107,4 +107,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QLowEnergyCharacteristic::PropertyTypes) QT_END_NAMESPACE +Q_DECLARE_METATYPE(QLowEnergyCharacteristic) + #endif // QLOWENERGYCHARACTERISTIC_H diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index 1c309c95..ad978ce1 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -490,11 +490,6 @@ Q_DECLARE_TYPEINFO(QLowEnergyControllerPrivate::Attribute, Q_MOVABLE_TYPE); QT_END_NAMESPACE -#ifdef QT_WINRT_BLUETOOTH -Q_DECLARE_METATYPE(QLowEnergyCharacteristic) -Q_DECLARE_METATYPE(QLowEnergyDescriptor) -#endif // QT_WINRT_BLUETOOTH - #endif // QT_OSX_BLUETOOTH || QT_IOS_BLUETOOTH #endif // QLOWENERGYCONTROLLERPRIVATE_P_H diff --git a/src/bluetooth/qlowenergydescriptor.h b/src/bluetooth/qlowenergydescriptor.h index 1dfe1c35..9e71fc56 100644 --- a/src/bluetooth/qlowenergydescriptor.h +++ b/src/bluetooth/qlowenergydescriptor.h @@ -89,4 +89,6 @@ protected: QT_END_NAMESPACE +Q_DECLARE_METATYPE(QLowEnergyDescriptor) + #endif // QLOWENERGYDESCRIPTOR_H diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 6e33c565..9d3129fd 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -380,6 +380,8 @@ QLowEnergyService::QLowEnergyService(QSharedPointer p, qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); connect(p.data(), SIGNAL(error(QLowEnergyService::ServiceError)), this, SIGNAL(error(QLowEnergyService::ServiceError))); -- cgit v1.2.3 From 13afaaf749947e495569a47183a497deb9068940 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 3 May 2017 09:22:19 +0200 Subject: Make heart rate game a highlighted example This shows the example prominently on the Qt Creator Welcome screen. Change-Id: I6f207e888e6129235356b839a2bb7fecc1fe28a4 Reviewed-by: Nico Vertriest Reviewed-by: Sami Makkonen Reviewed-by: Martin Smith --- src/bluetooth/doc/qtbluetooth.qdocconf | 1 + 1 file changed, 1 insertion(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/doc/qtbluetooth.qdocconf b/src/bluetooth/doc/qtbluetooth.qdocconf index aa485cdb..a994652b 100644 --- a/src/bluetooth/doc/qtbluetooth.qdocconf +++ b/src/bluetooth/doc/qtbluetooth.qdocconf @@ -48,6 +48,7 @@ exampledirs += ../../../examples/bluetooth \ ../ manifestmeta.thumbnail.names = "QtBluetooth/Bluetooth Low Energy Heart Rate Server Example" +manifestmeta.highlighted.names += "QtBluetooth/Bluetooth Low Energy Heart Rate Game" imagedirs += images -- cgit v1.2.3 From df6b10cb829e4d992170318fa2ed02461d8392db Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 12 May 2017 15:42:01 +0200 Subject: Fix readvertisement failure on peripheral restart on BlueZ When the QLowEnergyController disconnects and immediately restarts the re-advertisement, it fails when sending the OcfLeSetAdvEnable ocf command. Subsequenly an advertisement error is thrown which stops the QLowEnergyCOntroller instance itself. Starting with this patch we choose to ignore failures when trying to disable advertisement. The API cannot report the error back anyway. Task-number: QTBUG-58941 Change-Id: Ifd6b43193c41e6cdc22d4876441bcdcbcc2ca7b6 Reviewed-by: Christian Kandeler --- src/bluetooth/qleadvertiser_bluez.cpp | 16 +++++++--------- src/bluetooth/qleadvertiser_p.h | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qleadvertiser_bluez.cpp b/src/bluetooth/qleadvertiser_bluez.cpp index ff00b2b1..652d28f9 100644 --- a/src/bluetooth/qleadvertiser_bluez.cpp +++ b/src/bluetooth/qleadvertiser_bluez.cpp @@ -102,7 +102,6 @@ void QLeAdvertiserBluez::doStartAdvertising() return; } - m_disableCommandFinished = false; m_sendPowerLevel = advertisingData().includePowerLevel() || scanResponseData().includePowerLevel(); if (m_sendPowerLevel) @@ -408,14 +407,17 @@ void QLeAdvertiserBluez::handleCommandCompleted(quint16 opCode, quint8 status, if (m_pendingCommands.isEmpty()) return; const quint16 ocf = ocfFromOpCode(opCode); - if (m_pendingCommands.first().ocf != ocf) + const Command currentCmd = m_pendingCommands.first(); + if (currentCmd.ocf != ocf) return; // Not one of our commands. m_pendingCommands.takeFirst(); if (status != 0) { qCDebug(QT_BT_BLUEZ) << "command" << ocf << "failed with status" << status; - if (ocf == OcfLeSetAdvEnable && !m_disableCommandFinished && status == 0xc) { - qCDebug(QT_BT_BLUEZ) << "initial advertising disable failed, ignoring"; - m_disableCommandFinished = true; + if (ocf == OcfLeSetAdvEnable && status == 0xc && currentCmd.data == QByteArray(1, '\0')) { + // we ignore OcfLeSetAdvEnable if it tries to disable an active advertisement + // it seems the platform often automatically turns off advertisements + // subsequently the explicit stopAdvertisement call fails when re-issued + qCDebug(QT_BT_BLUEZ) << "Advertising disable failed, ignoring"; sendNextCommand(); return; } @@ -439,10 +441,6 @@ void QLeAdvertiserBluez::handleCommandCompleted(quint16 opCode, quint8 status, } queueAdvertisingCommands(); break; - case OcfLeSetAdvEnable: - if (!m_disableCommandFinished) - m_disableCommandFinished = true; - break; default: break; } diff --git a/src/bluetooth/qleadvertiser_p.h b/src/bluetooth/qleadvertiser_p.h index 922fdf64..e8f55bda 100644 --- a/src/bluetooth/qleadvertiser_p.h +++ b/src/bluetooth/qleadvertiser_p.h @@ -145,7 +145,6 @@ private: quint8 m_powerLevel; bool m_sendPowerLevel; - bool m_disableCommandFinished; }; #endif // QT_CONFIG(bluez) -- cgit v1.2.3 From 1287cb093a89c9f21d50ffa590967700e17891e7 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 12 May 2017 15:54:36 +0200 Subject: BlueZ: Ensure stop advertisement calls are actually sent when issued The command queue was not flushed out to the HCI socket. Change-Id: Ic249fc6d7c93c8ca1026ec010f667b7e155d9c46 Reviewed-by: Christian Kandeler --- src/bluetooth/qleadvertiser_bluez.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qleadvertiser_bluez.cpp b/src/bluetooth/qleadvertiser_bluez.cpp index 652d28f9..b964f620 100644 --- a/src/bluetooth/qleadvertiser_bluez.cpp +++ b/src/bluetooth/qleadvertiser_bluez.cpp @@ -114,6 +114,7 @@ void QLeAdvertiserBluez::doStartAdvertising() void QLeAdvertiserBluez::doStopAdvertising() { toggleAdvertising(false); + sendNextCommand(); } void QLeAdvertiserBluez::queueCommand(OpCodeCommandField ocf, const QByteArray &data) -- cgit v1.2.3 From 79bebc91995821586bdde245c9b13a50d63090c9 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 17 May 2017 09:22:24 +0200 Subject: Fix string Change-Id: I719dc5f2cd49d7c503f14e56416b384081c86f4c Reviewed-by: Leena Miettinen --- src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index e76ddff7..3d34b477 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -165,7 +165,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent { qCWarning(QT_BT_ANDROID) << "Search not possible due to missing permission (ACCESS_COARSE_LOCATION)"; lastError = QBluetoothDeviceDiscoveryAgent::UnknownError; - errorString = QBluetoothDeviceDiscoveryAgent::tr("Missing Location permission. Search is not possible"); + errorString = QBluetoothDeviceDiscoveryAgent::tr("Missing Location permission. Search is not possible."); emit q->error(lastError); return; } -- cgit v1.2.3 From 4593b79d84b9c8cc818d3c30e3882d699228339f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 May 2017 21:21:47 -0700 Subject: Fix GCC 7 warnings about implicit fallthroughs Make them explicit. Change-Id: I9bf1e35bffb044dcbf62fffd14bfe71bc374febf Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycontroller_bluez.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index e5a3d8de..3873664a 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -1768,8 +1768,10 @@ bool QLowEnergyControllerPrivate::setSecurityLevel(int level) switch (level) { // fall through intendeds case BT_SECURITY_HIGH: optval |= L2CAP_LM_SECURE; + Q_FALLTHROUGH(); case BT_SECURITY_MEDIUM: optval |= L2CAP_LM_ENCRYPT; + Q_FALLTHROUGH(); case BT_SECURITY_LOW: optval |= L2CAP_LM_AUTH; break; -- cgit v1.2.3 From ca248e3667f52f951bdd60d923b25a6b8fb4296d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 16 May 2017 15:11:57 +0200 Subject: Make it more obvious that another active BTLE connection prevents connect Task-number: QTBUG-55150 Change-Id: I223e2b2015e210162e59fb994b9352e790b036d4 Reviewed-by: Oliver Wolff Reviewed-by: Christian Kandeler --- src/bluetooth/bluez/bluez_data_p.h | 4 +++ src/bluetooth/bluez/hcimanager.cpp | 44 ++++++++++++++++++++++++++++ src/bluetooth/bluez/hcimanager_p.h | 4 +++ src/bluetooth/qlowenergycontroller_bluez.cpp | 11 +++++++ 4 files changed, 63 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/bluez_data_p.h b/src/bluetooth/bluez/bluez_data_p.h index 8c2dc43e..25edc661 100644 --- a/src/bluetooth/bluez/bluez_data_p.h +++ b/src/bluetooth/bluez/bluez_data_p.h @@ -99,6 +99,10 @@ struct bt_security { #define BDADDR_LE_PUBLIC 0x01 #define BDADDR_LE_RANDOM 0x02 +#define SCO_LINK 0x00 +#define ACL_LINK 0x01 +#define ESCO_LINK 0x02 +#define LE_LINK 0x80 // based on hcitool.c -> no fixed constant available /* Byte order conversions */ #if __BYTE_ORDER == __LITTLE_ENDIAN diff --git a/src/bluetooth/bluez/hcimanager.cpp b/src/bluetooth/bluez/hcimanager.cpp index 93bf941b..c524117c 100644 --- a/src/bluetooth/bluez/hcimanager.cpp +++ b/src/bluetooth/bluez/hcimanager.cpp @@ -288,6 +288,50 @@ QBluetoothAddress HciManager::addressForConnectionHandle(quint16 handle) const return QBluetoothAddress(); } +QVector HciManager::activeLowEnergyConnections() const +{ + if (!isValid()) + return QVector(); + + hci_conn_info *info; + hci_conn_list_req *infoList; + + const int maxNoOfConnections = 20; + infoList = (hci_conn_list_req *) + malloc(sizeof(hci_conn_list_req) + maxNoOfConnections * sizeof(hci_conn_info)); + + if (!infoList) + return QVector(); + + QScopedPointer p(infoList); + p->conn_num = maxNoOfConnections; + p->dev_id = hciDev; + info = p->conn_info; + + if (ioctl(hciSocket, HCIGETCONNLIST, (void *) infoList) < 0) { + qCWarning(QT_BT_BLUEZ) << "Cannot retrieve connection list"; + return QVector(); + } + + QVector activeLowEnergyHandles; + for (int i = 0; i < infoList->conn_num; i++) { + switch (info[i].type) { + case SCO_LINK: + case ACL_LINK: + case ESCO_LINK: + continue; + case LE_LINK: + activeLowEnergyHandles.append(info[i].handle); + break; + default: + qCWarning(QT_BT_BLUEZ) << "Unknown active connection type:" << hex << info[i].type; + break; + } + } + + return activeLowEnergyHandles; +} + quint16 forceIntervalIntoRange(double connectionInterval) { return qMin(qMax(7.5, connectionInterval), 4000) / 1.25; diff --git a/src/bluetooth/bluez/hcimanager_p.h b/src/bluetooth/bluez/hcimanager_p.h index 3bae92e5..3127a747 100644 --- a/src/bluetooth/bluez/hcimanager_p.h +++ b/src/bluetooth/bluez/hcimanager_p.h @@ -55,6 +55,7 @@ #include #include #include +#include #include "bluez/bluez_data_p.h" QT_BEGIN_NAMESPACE @@ -82,6 +83,9 @@ public: void stopEvents(); QBluetoothAddress addressForConnectionHandle(quint16 handle) const; + // active connections + QVector activeLowEnergyConnections() const; + bool sendConnectionUpdateCommand(quint16 handle, const QLowEnergyConnectionParameters ¶ms); bool sendConnectionParameterUpdateRequest(quint16 handle, const QLowEnergyConnectionParameters ¶ms); diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 3873664a..40744670 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -527,6 +527,17 @@ void QLowEnergyControllerPrivate::connectToDevice() if (l2cpSocket) delete l2cpSocket; + // check for active running connections + // BlueZ 5.37+ (maybe even earlier versions) can have pending BTLE connections + // Only one active L2CP socket to CID 0x4 possible at a time + QVector activeHandles = hciManager->activeLowEnergyConnections(); + if (!activeHandles.isEmpty()) { + qCWarning(QT_BT_BLUEZ) << "Cannot connect due to pending active LE connections"; + setError(QLowEnergyController::ConnectionError); + setState(QLowEnergyController::UnconnectedState); + return; + } + l2cpSocket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol, this); connect(l2cpSocket, SIGNAL(connected()), this, SLOT(l2cpConnected())); connect(l2cpSocket, SIGNAL(disconnected()), this, SLOT(l2cpDisconnected())); -- cgit v1.2.3 From 8692ff9d1c32bcc56e4c8c0c9f07ee2eb1a2681d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 18 May 2017 09:08:29 +0200 Subject: Avoid bluetoothd and QtBluetooth collision when connecting to BTLE dev BlueZ's improving support for BTLE creates a new collision when attenpting to connect to remote BTLE devices. There can only ever be one connection. This patch ensures that when QtBluetooth attempts to connect we do not have a pending BTLE connection. This could have been caused via other QtBLuetooth based processes or applications such as bluetoothctl or bluetoothd in general. If a connection is pending we close the connection external to the current QtBLuetooth instance. This is not an ideal situation as several processes can potentially fight over btle access. The long term solution is a port of QtBluetooth to BlueZ's new DBus API. Task-number: QTBUG-55150 Change-Id: I96b30ae180d1348027e8f9f09c997f44409dfc48 Reviewed-by: Christian Kandeler --- src/bluetooth/bluez/bluez.pri | 6 +- src/bluetooth/bluez/remotedevicemanager.cpp | 170 +++++++++++++++++++++++++++ src/bluetooth/bluez/remotedevicemanager_p.h | 99 ++++++++++++++++ src/bluetooth/qlowenergycontroller_bluez.cpp | 55 ++++++++- src/bluetooth/qlowenergycontroller_p.h | 4 + 5 files changed, 331 insertions(+), 3 deletions(-) create mode 100644 src/bluetooth/bluez/remotedevicemanager.cpp create mode 100644 src/bluetooth/bluez/remotedevicemanager_p.h (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/bluez.pri b/src/bluetooth/bluez/bluez.pri index 46727cbc..3ff2e9d8 100644 --- a/src/bluetooth/bluez/bluez.pri +++ b/src/bluetooth/bluez/bluez.pri @@ -18,7 +18,8 @@ HEADERS += bluez/manager_p.h \ bluez/obex_objectpush1_bluez5_p.h \ bluez/obex_transfer1_bluez5_p.h \ bluez/bluez_data_p.h \ - bluez/hcimanager_p.h + bluez/hcimanager_p.h \ + bluez/remotedevicemanager_p.h SOURCES += bluez/manager.cpp \ bluez/adapter.cpp \ @@ -39,4 +40,5 @@ SOURCES += bluez/manager.cpp \ bluez/obex_client1_bluez5.cpp \ bluez/obex_objectpush1_bluez5.cpp \ bluez/obex_transfer1_bluez5.cpp \ - bluez/hcimanager.cpp + bluez/hcimanager.cpp \ + bluez/remotedevicemanager.cpp diff --git a/src/bluetooth/bluez/remotedevicemanager.cpp b/src/bluetooth/bluez/remotedevicemanager.cpp new file mode 100644 index 00000000..f63b21e6 --- /dev/null +++ b/src/bluetooth/bluez/remotedevicemanager.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "remotedevicemanager_p.h" +#include "bluez5_helper_p.h" +#include "device1_bluez5_p.h" +#include "objectmanager_p.h" + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ) + +/*! + * Convenience wrapper around org.bluez.Device1 management + * + * Very simple and not thread safe. + */ + +RemoteDeviceManager::RemoteDeviceManager( + const QBluetoothAddress &address, QObject *parent) + : QObject(parent), localAddress(address) +{ + if (!isBluez5()) + return; + + bool ok = false; + adapterPath = findAdapterForAddress(address, &ok); + if (!ok || adapterPath.isEmpty()) { + qCWarning(QT_BT_BLUEZ) << "Cannot initialize RemoteDeviceManager"; + } +} + +bool RemoteDeviceManager::scheduleJob( + JobType job, const QVector &remoteDevices) +{ + if (adapterPath.isEmpty()) + return false; + + for (const auto& remote : remoteDevices) + jobQueue.push_back(std::make_pair(job, remote)); + + QTimer::singleShot(0, this, [this](){ runQueue(); }); + return true; +} + +void RemoteDeviceManager::runQueue() +{ + if (jobInProgress || adapterPath.isEmpty()) + return; + + if (jobQueue.empty()) + return; + + jobInProgress = true; + switch (jobQueue.front().first) { + case JobType::JobDisconnectDevice: + disconnectDevice(jobQueue.front().second); + break; + default: + break; + } +} + +void RemoteDeviceManager::prepareNextJob() +{ + Q_ASSERT(!jobQueue.empty()); + + jobQueue.pop_front(); + jobInProgress = false; + + if (jobQueue.empty()) + emit finished(); + else + runQueue(); +} + +void RemoteDeviceManager::disconnectDevice(const QBluetoothAddress &remote) +{ + // collect initial set of information + OrgFreedesktopDBusObjectManagerInterface managerBluez5( + QStringLiteral("org.bluez"), + QStringLiteral("/"), + QDBusConnection::systemBus(), this); + QDBusPendingReply reply = managerBluez5.GetManagedObjects(); + reply.waitForFinished(); + if (reply.isError()) { + QTimer::singleShot(0, this, [this](){ prepareNextJob(); }); + return; + } + + bool jobStarted = false; + ManagedObjectList managedObjectList = reply.value(); + for (auto it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) { + const QDBusObjectPath &path = it.key(); + const InterfaceList &ifaceList = it.value(); + + for (auto jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) { + const QString &iface = jt.key(); + + if (path.path().indexOf(adapterPath) != 0) + continue; //devices whose path doesn't start with same path we skip + + if (iface != QStringLiteral("org.bluez.Device1")) + continue; + + const QBluetoothAddress foundAddress(ifaceList.value(iface).value(QStringLiteral("Address")).toString()); + if (foundAddress != remote) + continue; + + // found the correct Device1 path + OrgBluezDevice1Interface* device1 = new OrgBluezDevice1Interface(QStringLiteral("org.bluez"), + path.path(), + QDBusConnection::systemBus(), + this); + QDBusPendingReply<> asyncReply = device1->Disconnect(); + QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(asyncReply, this); + const auto watcherFinished = [this, device1](QDBusPendingCallWatcher* call) { + call->deleteLater(); + device1->deleteLater(); + prepareNextJob(); + }; + connect(watcher, &QDBusPendingCallWatcher::finished, this, watcherFinished); + jobStarted = true; + break; + } + } + + if (!jobStarted) + QTimer::singleShot(0, this, [this](){ prepareNextJob(); }); +} + +QT_END_NAMESPACE diff --git a/src/bluetooth/bluez/remotedevicemanager_p.h b/src/bluetooth/bluez/remotedevicemanager_p.h new file mode 100644 index 00000000..a6af8f44 --- /dev/null +++ b/src/bluetooth/bluez/remotedevicemanager_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REMOTEDEVICEMANAGER_P_H +#define REMOTEDEVICEMANAGER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include +#include +#include + +#include + + +QT_BEGIN_NAMESPACE + +// This API is kept a bit more generic in anticipation of further changes in the future. + +class RemoteDeviceManager : public QObject +{ + Q_OBJECT +public: + enum class JobType + { + JobDisconnectDevice, + }; + + explicit RemoteDeviceManager(const QBluetoothAddress& localAddress, QObject *parent = 0); + + bool isJobInProgress() const { return jobInProgress; } + bool scheduleJob(JobType job, const QVector& remoteDevices); + +signals: + void finished(); + +private slots: + void runQueue(); + void prepareNextJob(); + +private: + void disconnectDevice(const QBluetoothAddress& remote); + + bool jobInProgress = false; + QBluetoothAddress localAddress; + std::deque> jobQueue; + QString adapterPath; +}; + +QT_END_NAMESPACE + +#endif // REMOTEDEVICEMANAGER_P_H diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 40744670..1649fe8c 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2016 Javier S. Pedro ** Contact: https://www.qt.io/licensing/ ** @@ -44,6 +44,8 @@ #include "qleadvertiser_p.h" #include "bluez/bluez_data_p.h" #include "bluez/hcimanager_p.h" +#include "bluez/remotedevicemanager_p.h" +#include "bluez/bluez5_helper_p.h" #include #include @@ -530,13 +532,64 @@ void QLowEnergyControllerPrivate::connectToDevice() // check for active running connections // BlueZ 5.37+ (maybe even earlier versions) can have pending BTLE connections // Only one active L2CP socket to CID 0x4 possible at a time + // this check is not performed for BlueZ 4 based platforms as bluetoothd + // does not support BTLE management + + if (!isBluez5()) { + establishL2cpClientSocket(); + return; + } + QVector activeHandles = hciManager->activeLowEnergyConnections(); if (!activeHandles.isEmpty()) { qCWarning(QT_BT_BLUEZ) << "Cannot connect due to pending active LE connections"; + + if (!device1Manager) { + device1Manager = new RemoteDeviceManager(localAdapter, this); + connect(device1Manager, &RemoteDeviceManager::finished, + this, &QLowEnergyControllerPrivate::activeConnectionTerminationDone); + } + + QVector connectedAddresses; + for (const auto handle: activeHandles) { + const QBluetoothAddress addr = hciManager->addressForConnectionHandle(handle); + if (!addr.isNull()) + connectedAddresses.push_back(addr); + } + device1Manager->scheduleJob(RemoteDeviceManager::JobType::JobDisconnectDevice, connectedAddresses); + } else { + establishL2cpClientSocket(); + } +} + +/*! + * Handles outcome of attempts to close external connections. + */ +void QLowEnergyControllerPrivate::activeConnectionTerminationDone() +{ + if (!device1Manager) + return; + + qCDebug(QT_BT_BLUEZ) << "RemoteDeviceManager finished attempting" + << "to close external connections"; + + QVector activeHandles = hciManager->activeLowEnergyConnections(); + if (!activeHandles.isEmpty()) { + qCWarning(QT_BT_BLUEZ) << "Cannot close pending external BTLE connections. Aborting connect attempt"; setError(QLowEnergyController::ConnectionError); setState(QLowEnergyController::UnconnectedState); return; + } else { + establishL2cpClientSocket(); } +} + +/*! + * Establishes the L2CP client socket. + */ +void QLowEnergyControllerPrivate::establishL2cpClientSocket() +{ + //we are already in Connecting state l2cpSocket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol, this); connect(l2cpSocket, SIGNAL(connected()), this, SLOT(l2cpConnected())); diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index 5fcc46a4..5811376b 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -100,6 +100,7 @@ class QTimer; class HciManager; class LeCmacCalculator; class QSocketNotifier; +class RemoteDeviceManager; #elif defined(QT_ANDROID_BLUETOOTH) class LowEnergyNotificationHub; #endif @@ -279,6 +280,7 @@ private: QLeAdvertiser *advertiser; QSocketNotifier *serverSocketNotifier; QTimer *requestTimer = nullptr; + RemoteDeviceManager* device1Manager = nullptr; /* Defines the maximum number of milliseconds the implementation will @@ -413,6 +415,7 @@ private: const QByteArray &newValue); void restartRequestTimer(); + void establishL2cpClientSocket(); private slots: void l2cpConnected(); @@ -421,6 +424,7 @@ private slots: void l2cpReadyRead(); void encryptionChangedEvent(const QBluetoothAddress&, bool); void handleGattRequestTimeout(); + void activeConnectionTerminationDone(); #elif defined(QT_ANDROID_BLUETOOTH) LowEnergyNotificationHub *hub; -- cgit v1.2.3 From 3796886c20574d23f690d76358139baa386436ab Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 12 Jun 2017 13:23:24 +0200 Subject: Fix memory overrun due to wrong header size definition being used At the same time we remove the redudant and temporary packet variable. This was highlighted by a compiler warning: In function void* memcpy(void*, const void*, size_t), inlined from void qToUnaligned(T, void*) [with T = short unsigned int] at /home/ablasche/dev/qt/qt59/qtbase/include/QtCore/../../src/corelib/global/qendian.h:82:5, inlined from void qToLittleEndian(T, void*) [with T = short unsigned int] at /home/ablasche/dev/qt/qt59/qtbase/include/QtCore/../../src/corelib/global/qendian.h:227:3, inlined from void putBtData(T, void*) [with T = short unsigned int] at bluez/bluez_data_p.h:196:5, inlined from void QLowEnergyControllerPrivate::readServiceValuesByOffset(uint, quint16, bool) at qlowenergycontroller_bluez.cpp:1692:34: /usr/include/x86_64-linux-gnu/bits/string3.h:53:71: warning: call to void* __builtin___memcpy_chk(void*, const void*, long unsigned int, long unsigned int) will always overflow destination buffer return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); Change-Id: I5b8d7781b78ea3e07e30b9b830a4d8885bb8c989 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qlowenergycontroller_bluez.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 1649fe8c..9dadab91 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -1665,9 +1665,9 @@ void QLowEnergyControllerPrivate::readServiceValuesByOffset( { const QLowEnergyHandle charHandle = (handleData & 0xffff); const QLowEnergyHandle descriptorHandle = ((handleData >> 16) & 0xffff); - quint8 packet[READ_REQUEST_HEADER_SIZE]; - packet[0] = ATT_OP_READ_BLOB_REQUEST; + QByteArray data(READ_BLOB_REQUEST_HEADER_SIZE, Qt::Uninitialized); + data[0] = ATT_OP_READ_BLOB_REQUEST; QLowEnergyHandle handleToRead = charHandle; if (descriptorHandle) { @@ -1688,11 +1688,8 @@ void QLowEnergyControllerPrivate::readServiceValuesByOffset( } } - putBtData(handleToRead, &packet[1]); - putBtData(offset, &packet[3]); - - QByteArray data(READ_BLOB_REQUEST_HEADER_SIZE, Qt::Uninitialized); - memcpy(data.data(), packet, READ_BLOB_REQUEST_HEADER_SIZE); + putBtData(handleToRead, data.data() + 1); + putBtData(offset, data.data() + 3); Request request; request.payload = data; -- cgit v1.2.3 From f11ad085133aa43f3ea390e7b7b4a596d9ec3ae8 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 13 Jun 2017 09:58:39 +0200 Subject: Remove last qdoc warning from qtconnectivity src/bluetooth/android/devicediscoverybroadcastreceiver.cpp:240: warning: Cannot tie this documentation to anything [I found a /*! ... */ comment, but there was no topic command (e.g., '\fn', '\page') in the comment and no function definition following the comment.] The file referenced in the warning does not contribute to the QtBluetooth documentation. The patch removes qdoc annotation from the file. Change-Id: Ie5699d79a12e5fc1851a924adbf50ebcb5059454 Reviewed-by: Timur Pocheptsov --- src/bluetooth/android/devicediscoverybroadcastreceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp index 9c9c0409..5acf761d 100644 --- a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp +++ b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp @@ -237,7 +237,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { Q_NULLPTR, 0 }, // index 64 & separator }; -/*! Advertising Data Type (AD type) for LE scan records, as defined in Bluetooth CSS v6. */ +/* Advertising Data Type (AD type) for LE scan records, as defined in Bluetooth CSS v6. */ enum ADType { ADType16BitUuidIncomplete = 0x02, ADType16BitUuidComplete = 0x03, -- cgit v1.2.3 From cdfd123e35c721e8062152783a661afbff4359fe Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 14 Jun 2017 08:34:13 +0200 Subject: Only do Classic device discovery inside QBluetoothServiceDiscoveryAgent QBluetoothServiceDiscoveryAgent performs SDP based Bluetooth service discovery. There is no need to do a BTLE discovery for the purpose of triggering an SDP service discovery. Change-Id: I16448b603e80e778b71ee397c0db14d0502d3acf Reviewed-by: Denis Shienkov Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothservicediscoveryagent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 8998d608..7daab4b7 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -442,7 +442,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery() setDiscoveryState(DeviceDiscovery); - deviceDiscoveryAgent->start(); + deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod); } /*! -- cgit v1.2.3 From dcf4f947455afae2d07a2cec02990581523afd3e Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 14 Jun 2017 10:06:29 +0200 Subject: Apple: Do Classic dev discovery inside QBluetoothServiceDiscoveryAgent This was missed when doing the same change for the non-Apple platforms. Change-Id: Ib1ef55acc82d98def4e1fc1ca228dabe6a13f241 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothservicediscoveryagent_osx.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm index 4a52b379..25bb2447 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm @@ -141,7 +141,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery() state = DeviceDiscovery; setupDeviceDiscoveryAgent(); - deviceDiscoveryAgent->start(); + deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod); } void QBluetoothServiceDiscoveryAgentPrivate::stopDeviceDiscovery() -- cgit v1.2.3 From ffa9e1978bfd168e961bc86301f10aad0f5aa6d6 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 13 Jun 2017 13:07:44 +0200 Subject: Android: Remove QBluetoothSocket fallback when Android SDK 23+ The private BluetoothDevice.getServiceChannel() is no longer available since Android release 6.0+ (v23+). We silently skip it on those platforms. Change-Id: Ia924f1c2fe81ccfb50b8abcfb682c350e9ce49ff Reviewed-by: Christian Stromme --- src/bluetooth/qbluetoothsocket_android.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 56d4f77b..85b69882 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -46,6 +46,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -329,7 +330,8 @@ bool QBluetoothSocketPrivate::fallBackConnect(QAndroidJniObject uuid, int channe * 3. if threaded connect succeeds call socketConnectSuccess() via signals * -> done * 4. if threaded connect fails call defaultSocketConnectFailed() via signals - * 5. call fallBackConnect() + * 5. call fallBackConnect() if Android version 22 or below + * -> Android 23+ complete failure of entire connectToService() * 6. if threaded connect on fallback channel succeeds call socketConnectSuccess() * via signals * -> done @@ -489,7 +491,9 @@ void QBluetoothSocketPrivate::defaultSocketConnectFailed( if (socket != socketObject) return; - bool success = fallBackConnect(targetUuid, FALLBACK_CHANNEL); + bool success = false; + if (QtAndroid::androidSdkVersion() <= 22) + success = fallBackConnect(targetUuid, FALLBACK_CHANNEL); if (!success) { errorString = QBluetoothSocket::tr("Connection to service failed"); socketObject = remoteDevice = QAndroidJniObject(); -- cgit v1.2.3 From 2acddda12f98a5022613d05bd62a3133c7de212b Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 13 Jun 2017 15:24:55 +0200 Subject: Workaround for Android SDP discovery bug Due to an Android platform bug, SDP discovery may return the wrong uuid for the remote service. This bug was introduced by Android 6.0.1 and tracked by https://issuetracker.google.com/issues/37076498. The returned UUID is byte swapped. To increase the QBluetoothSocket::connectToService() convenience QBluetoothSocket uses a fallback which attempts to connect to the remote service assuming the uuid was byte swapped. This will only happen if the uuid is not derived from the official Bluetooth base UUID (aka the given UUID is truly custom). There is the slight chance that the reversed UUID is a different service but that chance is very marginal when considering the amount of possible custom UUIDs. Task-number: QTBUG-61392 Change-Id: Ia41d670ab8d0666628f067e174965b698d0f26b0 Reviewed-by: Christian Stromme --- src/bluetooth/qbluetoothsocket_android.cpp | 113 ++++++++++++++++++++++++++--- src/bluetooth/qbluetoothsocket_p.h | 13 +++- 2 files changed, 114 insertions(+), 12 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 85b69882..87c9ffc8 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -57,6 +57,7 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID) Q_DECLARE_METATYPE(QAndroidJniObject) +Q_BLUETOOTH_EXPORT bool useReverseUuidWorkAroundConnect = true; /* BluetoothSocket.connect() can block up to 10s. Therefore it must be * in a separate thread. Unfortunately if BluetoothSocket.close() is @@ -79,10 +80,12 @@ class SocketConnectWorker : public QObject Q_OBJECT public: SocketConnectWorker(const QAndroidJniObject& socket, - const QAndroidJniObject& targetUuid) + const QAndroidJniObject& targetUuid, + const QBluetoothUuid& qtTargetUuid) : QObject(), mSocketObject(socket), - mTargetUuid(targetUuid) + mTargetUuid(targetUuid), + mQtTargetUuid(qtTargetUuid) { static int t = qRegisterMetaType(); Q_UNUSED(t); @@ -91,7 +94,8 @@ public: signals: void socketConnectDone(const QAndroidJniObject &socket); void socketConnectFailed(const QAndroidJniObject &socket, - const QAndroidJniObject &targetUuid); + const QAndroidJniObject &targetUuid, + const QBluetoothUuid &qtUuid); public slots: void connectSocket() { @@ -103,7 +107,7 @@ public slots: env->ExceptionDescribe(); env->ExceptionClear(); - emit socketConnectFailed(mSocketObject, mTargetUuid); + emit socketConnectFailed(mSocketObject, mTargetUuid, mQtTargetUuid); QThread::currentThread()->quit(); return; } @@ -131,6 +135,8 @@ public slots: private: QAndroidJniObject mSocketObject; QAndroidJniObject mTargetUuid; + // same as mTargetUuid above - just the Qt C++ version rather than jni uuid + QBluetoothUuid mQtTargetUuid; }; class WorkerThread: public QThread @@ -144,10 +150,11 @@ public: // Runs in same thread as QBluetoothSocketPrivate void setupWorker(QBluetoothSocketPrivate* d_ptr, const QAndroidJniObject& socketObject, - const QAndroidJniObject& uuidObject, bool useFallback) + const QAndroidJniObject& uuidObject, bool useFallback, + const QBluetoothUuid& qtUuid = QBluetoothUuid()) { SocketConnectWorker* worker = new SocketConnectWorker( - socketObject, uuidObject); + socketObject, uuidObject, qtUuid); worker->moveToThread(this); connect(this, &QThread::finished, worker, &QObject::deleteLater); @@ -173,6 +180,30 @@ private: QPointer workerPointer; }; +/* + * This function is part of a workaround for QTBUG-61392 + * + * Returns null uuid if the given \a serviceUuid is not a uuid + * derived from the Bluetooth base uuid. + */ +static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid) +{ + if (serviceUuid.isNull()) + return QBluetoothUuid(); + + bool isBaseUuid = false; + serviceUuid.toUInt32(&isBaseUuid); + if (isBaseUuid) + return QBluetoothUuid(); + + const quint128 original = serviceUuid.toUInt128(); + quint128 reversed; + for (int i = 0; i < 16; i++) + reversed.data[15-i] = original.data[i]; + + return QBluetoothUuid(reversed); +} + QBluetoothSocketPrivate::QBluetoothSocketPrivate() : socket(-1), socketType(QBluetoothServiceInfo::UnknownProtocol), @@ -207,7 +238,7 @@ bool QBluetoothSocketPrivate::ensureNativeSocket(QBluetoothServiceInfo::Protocol bool QBluetoothSocketPrivate::fallBackConnect(QAndroidJniObject uuid, int channel) { - qCWarning(QT_BT_ANDROID) << "Falling back to workaround."; + qCWarning(QT_BT_ANDROID) << "Falling back to getServiceChannel() workaround."; QAndroidJniEnvironment env; @@ -321,6 +352,60 @@ bool QBluetoothSocketPrivate::fallBackConnect(QAndroidJniObject uuid, int channe return true; } +/* + * Workaround for QTBUG-61392 + */ +bool QBluetoothSocketPrivate::fallBackReversedConnect(const QBluetoothUuid &uuid) +{ + Q_Q(QBluetoothSocket); + + qCWarning(QT_BT_ANDROID) << "Falling back to reverse uuid workaround."; + const QBluetoothUuid reverse = reverseUuid(uuid); + if (reverse.isNull()) + return false; + + //cut leading { and trailing } {xxx-xxx} + QString tempUuid = reverse.toString(); + tempUuid.chop(1); //remove trailing '}' + tempUuid.remove(0, 1); //remove first '{' + + QAndroidJniEnvironment env; + const QAndroidJniObject inputString = QAndroidJniObject::fromString(tempUuid); + const QAndroidJniObject uuidObject = QAndroidJniObject::callStaticObjectMethod("java/util/UUID", "fromString", + "(Ljava/lang/String;)Ljava/util/UUID;", + inputString.object()); + + if (secFlags == QBluetooth::NoSecurity) { + qCDebug(QT_BT_ANDROID) << "Connnecting via insecure rfcomm"; + socketObject = remoteDevice.callObjectMethod("createInsecureRfcommSocketToServiceRecord", + "(Ljava/util/UUID;)Landroid/bluetooth/BluetoothSocket;", + uuidObject.object()); + } else { + qCDebug(QT_BT_ANDROID) << "Connnecting via secure rfcomm"; + socketObject = remoteDevice.callObjectMethod("createRfcommSocketToServiceRecord", + "(Ljava/util/UUID;)Landroid/bluetooth/BluetoothSocket;", + uuidObject.object()); + } + + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + + socketObject = remoteDevice = QAndroidJniObject(); + errorString = QBluetoothSocket::tr("Cannot connect to %1", + "%1 = uuid").arg(reverse.toString()); + q->setSocketError(QBluetoothSocket::ServiceNotFoundError); + q->setSocketState(QBluetoothSocket::UnconnectedState); + return false; + } + + WorkerThread *workerThread = new WorkerThread(); + workerThread->setupWorker(this, socketObject, uuidObject, USE_FALLBACK); + workerThread->start(); + emit connectJavaSocket(); + + return true; +} /* * The call order during a connectToService() is as follows: @@ -332,10 +417,12 @@ bool QBluetoothSocketPrivate::fallBackConnect(QAndroidJniObject uuid, int channe * 4. if threaded connect fails call defaultSocketConnectFailed() via signals * 5. call fallBackConnect() if Android version 22 or below * -> Android 23+ complete failure of entire connectToService() - * 6. if threaded connect on fallback channel succeeds call socketConnectSuccess() + * 6. call fallBackReversedConnect() if Android version 23 or above + * -> if failure entire connectToService() fails + * 7. if threaded connect on one of above fallbacks succeeds call socketConnectSuccess() * via signals * -> done - * 7. if threaded connect on fallback channel fails call fallbackSocketConnectFailed() + * 8. if threaded connect on fallback channel fails call fallbackSocketConnectFailed() * -> complete failure of entire connectToService() * */ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, @@ -416,7 +503,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, } WorkerThread *workerThread = new WorkerThread(); - workerThread->setupWorker(this, socketObject, uuidObject, !USE_FALLBACK); + workerThread->setupWorker(this, socketObject, uuidObject, !USE_FALLBACK, uuid); workerThread->start(); emit connectJavaSocket(); } @@ -482,7 +569,8 @@ void QBluetoothSocketPrivate::socketConnectSuccess(const QAndroidJniObject &sock } void QBluetoothSocketPrivate::defaultSocketConnectFailed( - const QAndroidJniObject &socket, const QAndroidJniObject &targetUuid) + const QAndroidJniObject &socket, const QAndroidJniObject &targetUuid, + const QBluetoothUuid &qtTargetUuid) { Q_Q(QBluetoothSocket); @@ -494,6 +582,9 @@ void QBluetoothSocketPrivate::defaultSocketConnectFailed( bool success = false; if (QtAndroid::androidSdkVersion() <= 22) success = fallBackConnect(targetUuid, FALLBACK_CHANNEL); + else if (useReverseUuidWorkAroundConnect) // version 23+ has Android bug (see QTBUG-61392) + success = fallBackReversedConnect(qtTargetUuid); + if (!success) { errorString = QBluetoothSocket::tr("Connection to service failed"); socketObject = remoteDevice = QAndroidJniObject(); diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h index 956f8f02..c1af9471 100644 --- a/src/bluetooth/qbluetoothsocket_p.h +++ b/src/bluetooth/qbluetoothsocket_p.h @@ -127,6 +127,7 @@ public: #endif #ifdef QT_ANDROID_BLUETOOTH bool fallBackConnect(QAndroidJniObject uuid, int channel); + bool fallBackReversedConnect(const QBluetoothUuid &uuid); #endif @@ -197,7 +198,8 @@ public: public slots: void socketConnectSuccess(const QAndroidJniObject &socket); void defaultSocketConnectFailed(const QAndroidJniObject & socket, - const QAndroidJniObject &targetUuid); + const QAndroidJniObject &targetUuid, + const QBluetoothUuid &qtTargetUuid); void fallbackSocketConnectFailed(const QAndroidJniObject &socket, const QAndroidJniObject &targetUuid); void inputThreadError(int errorCode); @@ -286,6 +288,15 @@ static inline quint64 convertAddress(quint8 (&from)[6], quint64 *to = 0) return result; } +#ifdef Q_OS_ANDROID +// QTBUG-61392 related +// Private API to disable the silent behavior to reverse a remote service's +// UUID. In rare cases the workaround behavior might not be desirable as +// it may lead to connects to incorrect services. +extern bool useReverseUuidWorkAroundConnect; + +#endif + QT_END_NAMESPACE -- cgit v1.2.3 From cba4c454543ab83797b44946b132323687a198dc Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 19 May 2017 16:44:06 +0200 Subject: Obtain random bt address flag via Bluetooth Mgmt API DBus does not expose this information. The Bluetooth Management API advertises the information but requires CAP_NET_ADMIN. The Management class monitors DEVICE FOUND events and records the random bit flag of each new device. QBluetoothDeviceDiscoveryAgent can subsequently add this information to the internal data set. Ultimately this makes QLowEnergyController::setRemoteAddressType obsolete. This function was only ever required on Linux. Task-number: QTBUG-46776 Change-Id: If10df86d332dfc7cc98b7c783eb28487c3fa9045 Reviewed-by: Kai Koehne --- src/bluetooth/bluez/bluetoothmanagement.cpp | 314 +++++++++++++++++++++ src/bluetooth/bluez/bluetoothmanagement_p.h | 98 +++++++ src/bluetooth/bluez/bluez.pri | 6 +- src/bluetooth/bluez/bluez_data_p.h | 7 +- .../qbluetoothdevicediscoveryagent_bluez.cpp | 3 + src/bluetooth/qbluetoothsocket_p.h | 4 +- src/bluetooth/qlowenergycontroller.cpp | 15 +- src/bluetooth/qlowenergycontroller_bluez.cpp | 19 +- 8 files changed, 455 insertions(+), 11 deletions(-) create mode 100644 src/bluetooth/bluez/bluetoothmanagement.cpp create mode 100644 src/bluetooth/bluez/bluetoothmanagement_p.h (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/bluetoothmanagement.cpp b/src/bluetooth/bluez/bluetoothmanagement.cpp new file mode 100644 index 00000000..9df74b34 --- /dev/null +++ b/src/bluetooth/bluez/bluetoothmanagement.cpp @@ -0,0 +1,314 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "bluetoothmanagement_p.h" +#include "bluez_data_p.h" +#include "../qbluetoothsocket_p.h" + +#include +#include +#include +#include +#include + + +QT_BEGIN_NAMESPACE + +// Packet data structures for Mgmt API bluez.git/doc/mgmt-api.txt + +enum class EventCode { + DeviceFound = 0x0012, +}; + +struct MgmtHdr { + quint16 cmdCode; + quint16 controllerIndex; + quint16 length; +} __attribute__((packed)); + +struct MgmtEventDeviceFound { + bdaddr_t bdaddr; + quint8 type; + quint8 rssi; + quint32 flags; + quint16 eirLength; + quint8 eirData[0]; +} __attribute__((packed)); + + +/* + * This class encapsulates access to the Bluetooth Management API as introduced by + * Linux kernel 3.4. Some Bluetooth information is not exposed via the usual DBus + * API (e.g. the random/public address type info). In those cases we have to fall back + * to this mgmt API. + * + * Note that opening such a Bluetooth mgmt socket requires CAP_NET_ADMIN (root) capability. + * + * Documentation can be found in bluez-git/doc/mgmt-api.txt + */ + +Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ) + +// These structs and defines come straight from linux/capability.h. +// To avoid missing definitions we re-define them if not existing. +// In addition, we don't want to pull in a libcap2 dependency +struct capHdr { + quint32 version; + int pid; +}; + +struct capData { + quint32 effective; + quint32 permitted; + quint32 inheritable; +}; + +#ifndef _LINUX_CAPABILITY_VERSION_3 +#define _LINUX_CAPABILITY_VERSION_3 0x20080522 +#endif + +#ifndef _LINUX_CAPABILITY_U32S_3 +#define _LINUX_CAPABILITY_U32S_3 2 +#endif + +#ifndef CAP_NET_ADMIN +#define CAP_NET_ADMIN 12 +#endif + +#ifndef CAP_TO_INDEX +#define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */ +#endif + +#ifndef CAP_TO_MASK +#define CAP_TO_MASK(x) (1 << ((x) & 31)) /* mask for indexed __u32 */ +#endif + +const int msecInADay = 1000*60*60*24; + +inline uint qHash(const QBluetoothAddress& address) +{ + return qHash(address.toUInt64()); +} + +static int sysCallCapGet(capHdr *header, capData *data) +{ + return syscall(__NR_capget, header, data); +} + +/*! + * Checks that the current process has the effective CAP_NET_ADMIN permission. + */ +static bool hasBtMgmtPermission() +{ + // We only care for cap version 3 introduced by kernel 2.6.26 + // because the new BlueZ management API only exists since kernel 3.4. + + struct capHdr header = {}; + struct capData data[_LINUX_CAPABILITY_U32S_3] = {{}}; + header.version = _LINUX_CAPABILITY_VERSION_3; + header.pid = getpid(); + + if (sysCallCapGet(&header, data) < 0) { + qCWarning(QT_BT_BLUEZ, "BluetoothManangement: getCap failed with %s", + qPrintable(qt_error_string(errno))); + return false; + } + + return (data[CAP_TO_INDEX(CAP_NET_ADMIN)].effective & CAP_TO_MASK(CAP_NET_ADMIN)); +} + +BluetoothManagement::BluetoothManagement(QObject *parent) : QObject(parent) +{ + bool hasPermission = hasBtMgmtPermission(); + if (!hasPermission) { + qCInfo(QT_BT_BLUEZ, "Missing CAP_NET_ADMIN permission. Cannot determine whether " + "a found address is of random or public type."); + return; + } + + sockaddr_hci hciAddr; + + fd = ::socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, BTPROTO_HCI); + if (fd < 0) { + qCWarning(QT_BT_BLUEZ, "Cannot open Bluetooth Management socket: %s", + qPrintable(qt_error_string(errno))); + return; + } + + memset(&hciAddr, 0, sizeof(hciAddr)); + hciAddr.hci_dev = HCI_DEV_NONE; + hciAddr.hci_channel = HCI_CHANNEL_CONTROL; + hciAddr.hci_family = AF_BLUETOOTH; + + if (::bind(fd, (struct sockaddr *)(&hciAddr), sizeof(hciAddr)) < 0) { + qCWarning(QT_BT_BLUEZ, "Cannot bind Bluetooth Management socket: %s", + qPrintable(qt_error_string(errno))); + ::close(fd); + fd = -1; + return; + } + + notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); + connect(notifier, &QSocketNotifier::activated, this, &BluetoothManagement::_q_readNotifier); + + // ensure cache is regularly cleaned (once every 24h) + QTimer* timer = new QTimer(this); + timer->setInterval(msecInADay); + timer->setTimerType(Qt::VeryCoarseTimer); + connect(timer, &QTimer::timeout, this, &BluetoothManagement::cleanupOldAddressFlags); + timer->start(); +} + +Q_GLOBAL_STATIC(BluetoothManagement, bluetoothKernelManager) + +BluetoothManagement *BluetoothManagement::instance() +{ + return bluetoothKernelManager(); +} + +void BluetoothManagement::_q_readNotifier() +{ + char *dst = buffer.reserve(QPRIVATELINEARBUFFER_BUFFERSIZE); + int readCount = ::read(fd, dst, QPRIVATELINEARBUFFER_BUFFERSIZE); + buffer.chop(QPRIVATELINEARBUFFER_BUFFERSIZE - (readCount < 0 ? 0 : readCount)); + if (readCount < 0) { + qCWarning(QT_BT_BLUEZ, "Management Control read error %s", qPrintable(qt_error_string(errno))); + return; + } + + // do we have at least one complete mgmt header? + if ((uint)buffer.size() < sizeof(MgmtHdr)) + return; + + QByteArray data = buffer.readAll(); + + while (true) { + if ((uint)data.size() < sizeof(MgmtHdr)) + break; + + const MgmtHdr *hdr = reinterpret_cast(data.constData()); + const int nextPackageSize = qFromLittleEndian(hdr->length) + sizeof(MgmtHdr); + const int remainingPackageSize = data.length() - nextPackageSize; + + if (data.length() < nextPackageSize) + break; // not a complete event header -> wait for next notifier + + switch (static_cast(qFromLittleEndian(hdr->cmdCode))) { + case EventCode::DeviceFound: + { + const MgmtEventDeviceFound *event = reinterpret_cast + (data.constData() + sizeof(MgmtHdr)); + + if (event->type == BDADDR_LE_RANDOM) { + const bdaddr_t address = event->bdaddr; + quint64 bdaddr; + + convertAddress(address.b, &bdaddr); + const QBluetoothAddress qtAddress(bdaddr); + qCDebug(QT_BT_BLUEZ) << "BluetoothManagement: found random device" + << qtAddress; + processRandomAddressFlagInformation(qtAddress); + } + + break; + } + default: + qCDebug(QT_BT_BLUEZ) << "BluetoothManagement: Ignored event:" + << hex << qFromLittleEndian(hdr->cmdCode); + break; + } + + if (data.length() > nextPackageSize) + data = data.right(remainingPackageSize); + else + data.clear(); + + if (data.isEmpty()) + break; + } + + if (!data.isEmpty()) + buffer.ungetBlock(data.constData(), data.size()); +} + +void BluetoothManagement::processRandomAddressFlagInformation(const QBluetoothAddress &address) +{ + // insert or update + QMutexLocker locker(&accessLock); + privateFlagAddresses[address] = QDateTime::currentDateTimeUtc(); +} + +/* + * Ensure that private address cache is not older than 24h. + */ +void BluetoothManagement::cleanupOldAddressFlags() +{ + const auto cutOffTime = QDateTime::currentDateTimeUtc().addDays(-1); + + QMutexLocker locker(&accessLock); + + auto i = privateFlagAddresses.begin(); + while (i != privateFlagAddresses.end()) { + if (i.value() < cutOffTime) + i = privateFlagAddresses.erase(i); + else + i++; + } +} + +bool BluetoothManagement::isAddressRandom(const QBluetoothAddress &address) const +{ + if (fd == -1 || address.isNull()) + return false; + + QMutexLocker locker(&accessLock); + return privateFlagAddresses.contains(address); +} + +bool BluetoothManagement::isMonitoringEnabled() const +{ + return (fd == -1) ? false : true; +} + + +QT_END_NAMESPACE diff --git a/src/bluetooth/bluez/bluetoothmanagement_p.h b/src/bluetooth/bluez/bluetoothmanagement_p.h new file mode 100644 index 00000000..954f6e03 --- /dev/null +++ b/src/bluetooth/bluez/bluetoothmanagement_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BLUETOOTHMANAGEMENT_P_H +#define BLUETOOTHMANAGEMENT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + +#include + +#ifndef QPRIVATELINEARBUFFER_BUFFERSIZE +#define QPRIVATELINEARBUFFER_BUFFERSIZE Q_INT64_C(16384) +#endif +#include "../qprivatelinearbuffer_p.h" + +QT_BEGIN_NAMESPACE + +class QSocketNotifier; + +class BluetoothManagement : public QObject +{ + Q_OBJECT + +public: + explicit BluetoothManagement(QObject *parent = nullptr); + static BluetoothManagement *instance(); + + bool isAddressRandom(const QBluetoothAddress &address) const; + bool isMonitoringEnabled() const; + +private slots: + void _q_readNotifier(); + void processRandomAddressFlagInformation(const QBluetoothAddress &address); + void cleanupOldAddressFlags(); + +private: + void readyRead(); + + int fd = -1; + QSocketNotifier* notifier; + QPrivateLinearBuffer buffer; + QHash privateFlagAddresses; + mutable QMutex accessLock; +}; + + +QT_END_NAMESPACE + +#endif // BLUETOOTHMANAGEMENT_P_H diff --git a/src/bluetooth/bluez/bluez.pri b/src/bluetooth/bluez/bluez.pri index 3ff2e9d8..b99f2712 100644 --- a/src/bluetooth/bluez/bluez.pri +++ b/src/bluetooth/bluez/bluez.pri @@ -19,7 +19,8 @@ HEADERS += bluez/manager_p.h \ bluez/obex_transfer1_bluez5_p.h \ bluez/bluez_data_p.h \ bluez/hcimanager_p.h \ - bluez/remotedevicemanager_p.h + bluez/remotedevicemanager_p.h \ + bluez/bluetoothmanagement_p.h SOURCES += bluez/manager.cpp \ bluez/adapter.cpp \ @@ -41,4 +42,5 @@ SOURCES += bluez/manager.cpp \ bluez/obex_objectpush1_bluez5.cpp \ bluez/obex_transfer1_bluez5.cpp \ bluez/hcimanager.cpp \ - bluez/remotedevicemanager.cpp + bluez/remotedevicemanager.cpp \ + bluez/bluetoothmanagement.cpp diff --git a/src/bluetooth/bluez/bluez_data_p.h b/src/bluetooth/bluez/bluez_data_p.h index 25edc661..684cd5b8 100644 --- a/src/bluetooth/bluez/bluez_data_p.h +++ b/src/bluetooth/bluez/bluez_data_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtBluetooth module of the Qt Toolkit. @@ -204,7 +204,10 @@ template<> inline void putBtData(quint128 src, void *dst) // HCI related -#define HCI_MAX_DEV 16 +#define HCI_MAX_DEV 16 +#define HCI_DEV_NONE 0xffff + +#define HCI_CHANNEL_CONTROL 0x3 #define HCI_MAX_EVENT_SIZE 260 diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 5288eaf8..b913bde4 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -51,6 +51,7 @@ #include "bluez/adapter1_bluez5_p.h" #include "bluez/device1_bluez5_p.h" #include "bluez/properties_p.h" +#include "bluez/bluetoothmanagement_p.h" QT_BEGIN_NAMESPACE @@ -82,6 +83,8 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)), q, SLOT(_q_InterfacesAdded(QDBusObjectPath,InterfaceList))); + // start private address monitoring + BluetoothManagement::instance(); } else { manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"), QDBusConnection::systemBus(), parent); diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h index c1af9471..177f154a 100644 --- a/src/bluetooth/qbluetoothsocket_p.h +++ b/src/bluetooth/qbluetoothsocket_p.h @@ -265,7 +265,7 @@ public slots: #endif // QT_OSX_BLUETOOTH -static inline void convertAddress(quint64 from, quint8 (&to)[6]) +static inline void convertAddress(const quint64 from, quint8 (&to)[6]) { to[0] = (from >> 0) & 0xff; to[1] = (from >> 8) & 0xff; @@ -275,7 +275,7 @@ static inline void convertAddress(quint64 from, quint8 (&to)[6]) to[5] = (from >> 40) & 0xff; } -static inline quint64 convertAddress(quint8 (&from)[6], quint64 *to = 0) +static inline quint64 convertAddress(const quint8 (&from)[6], quint64 *to = 0) { const quint64 result = (quint64(from[0]) << 0) | (quint64(from[1]) << 8) | diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index a3aad282..2337268d 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtBluetooth module of the Qt Toolkit. @@ -691,6 +691,19 @@ QLowEnergyController::RemoteAddressType QLowEnergyController::remoteAddressType( /*! Sets the remote address \a type. The type is required to connect to the remote Bluetooth Low Energy device. + + This attribute is only required to be set on Linux/BlueZ systems with older + Linux kernels (v3.3 or lower), or if CAP_NET_ADMIN is not set for the executable. + The default value of the attribute is \l RandomAddress. + + \note All other platforms handle this flag transparently and therefore applications + can ignore it entirely. On Linux, the address type flag is not directly exposed + by BlueZ although some use cases do require this information. The only way to detect + the flag is via the Linux kernel's Bluetooth Management API (kernel + version 3.4+ required). This API requires CAP_NET_ADMIN capabilities though. If the + local QtBluetooth process has this capability set QtBluetooth will use the API. This + assumes that \l QBluetoothDeviceDiscoveryAgent was used prior to calling + \l QLowEnergyController::connectToDevice(). */ void QLowEnergyController::setRemoteAddressType( QLowEnergyController::RemoteAddressType type) diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 9dadab91..583c0e27 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -46,6 +46,7 @@ #include "bluez/hcimanager_p.h" #include "bluez/remotedevicemanager_p.h" #include "bluez/bluez5_helper_p.h" +#include "bluez/bluetoothmanagement_p.h" #include #include @@ -598,10 +599,20 @@ void QLowEnergyControllerPrivate::establishL2cpClientSocket() this, SLOT(l2cpErrorChanged(QBluetoothSocket::SocketError))); connect(l2cpSocket, SIGNAL(readyRead()), this, SLOT(l2cpReadyRead())); - if (addressType == QLowEnergyController::PublicAddress) - l2cpSocket->d_ptr->lowEnergySocketType = BDADDR_LE_PUBLIC; - else if (addressType == QLowEnergyController::RandomAddress) - l2cpSocket->d_ptr->lowEnergySocketType = BDADDR_LE_RANDOM; + quint32 addressTypeToUse = (addressType == QLowEnergyController::PublicAddress) + ? BDADDR_LE_PUBLIC : BDADDR_LE_RANDOM; + if (BluetoothManagement::instance()->isMonitoringEnabled()) { + // if monitoring is possible and it's private then we force it to the relevant option + if (BluetoothManagement::instance()->isAddressRandom(remoteDevice)) { + addressTypeToUse = BDADDR_LE_RANDOM; + } + } + + qCDebug(QT_BT_BLUEZ) << "addresstypeToUse:" + << (addressTypeToUse == BDADDR_LE_RANDOM + ? QStringLiteral("Random") : QStringLiteral("Public")); + + l2cpSocket->d_ptr->lowEnergySocketType = addressTypeToUse; int sockfd = l2cpSocket->socketDescriptor(); if (sockfd < 0) { -- cgit v1.2.3 From 1ed8390e17831afc5624bc7519b667eb8eea05a7 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 15 Jun 2017 14:47:33 +0200 Subject: Android: Don't miss services if the last device discovery failed Android collects the SDP information for all devices and puts them into an sdp cache. Only when the discovery finishes the sdp cache is evaluated and the serviceDiscovered() signal is sent. The evaluation is triggerd by _q_fetchUuidsTimeout(). If it is not possible to retrieve uuids or an address for the last discovered device, the old code never triggered _q_fetchUuidsTimeout(). As a consequence QBluetoothServiceDiscoveryAgent appeared to never find any service. This patch ensures that if the last SDP discovery failed we still trigger the final UUID evaluation and subsequent serviceDiscovered() signal emissions. Change-Id: I8454dc3f7cf3688110e6c86af324d797351b5b33 Reviewed-by: Christian Stromme --- src/bluetooth/qbluetoothservicediscoveryagent_android.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp index ba5bcb0a..51db091e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp @@ -244,6 +244,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids( //could not find any service for the current address/device -> go to next one if (address.isNull() || uuids.isEmpty()) { + if (discoveredDevices.count() == 1) { + Q_Q(QBluetoothServiceDiscoveryAgent); + QTimer::singleShot(4000, q, SLOT(_q_fetchUuidsTimeout())); + } _q_serviceDiscoveryFinished(); return; } -- cgit v1.2.3 From 1b59c2f715d04ab1aae18dcdd74ecd2a890608a5 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 15 May 2014 15:18:26 +0200 Subject: Update DBus interface generation script for Bluez 5 Task-number: QTBUG-32085 Change-Id: I74df2d89a5f8f0d2c58aaa1fea248d26cb0683dd Reviewed-by: Aaron McCarthy Reviewed-by: Fabian Bumberger --- src/bluetooth/bluez/generate | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/generate b/src/bluetooth/bluez/generate index 14bcaea8..cdba18c4 100755 --- a/src/bluetooth/bluez/generate +++ b/src/bluetooth/bluez/generate @@ -1,5 +1,6 @@ #!/bin/sh +#Bluez 4 qdbusxml2cpp -p manager_p.h:manager.cpp org.bluez.Manager.xml org.bluez.Manager qdbusxml2cpp -p adapter_p.h:adapter.cpp org.bluez.all.xml org.bluez.Adapter qdbusxml2cpp -i servicemap_p.h -p device_p.h:device.cpp org.bluez.Device.xml org.bluez.Device @@ -9,8 +10,13 @@ qdbusxml2cpp -p obex_manager_p.h:obex_manager.cpp org.openobex.all.xml org.openo qdbusxml2cpp -p obex_client_p.h:obex_client.cpp org.openobex.client.xml org.openobex.Client qdbusxml2cpp -p obex_transfer_p.h:obex_transfer.cpp org.openobex.transfer.xml org.openobex.Transfer qdbusxml2cpp -a obex_agent_p.h:obex_agent.cpp org.openobex.agent.xml org.openobex.Agent -#qdbusxml2cpp -p serialproxymanager_p.h:serialproxymanager.cpp org.bluez.all.xml org.bluez.SerialProxyManager -#qdbusxml2cpp -p networkpeer_p.h:networkpeer.cpp org.bluez.all.xml org.bluez.NetworkPeer -#qdbusxml2cpp -p networkhub_p.h:networkhub.cpp org.bluez.all.xml org.bluez.NetworkHub -#qdbusxml2cpp -p networkrouter_p.h:networkrouter.cpp org.bluez.all.xml org.bluez.NetworkRouter +#Bluez 5 +qdbusxml2cpp -p adapter1_bluez5_p.h:adapter1_bluez5.cpp org.bluez.Adapter1.xml +qdbusxml2cpp -p device1_bluez5_p.h:device1_bluez5.cpp org.bluez.Device1.xml +qdbusxml2cpp -p profile1_p.h:profile1.cpp org.bluez.ProfileManager1.xml +qdbusxml2cpp -p objectmanager_p.h:objectmanager.cpp org.freedesktop.dbus.objectmanager.xml +qdbusxml2cpp -p properties_p.h:properties.cpp org.freedesktop.dbus.properties.xml +qdbusxml2cpp -p obex_client1_bluez5_p.h:obex_client1_bluez5_p.h org.bluez.Client1.xml +qdbusxml2cpp -p obex_objectpush1_bluez5_p.h:obex_objectpush1_bluez5.cpp org.bluez.obex.ObjectPush1.xml +qdbusxml2cpp -p obex_transfer1_bluez5_p.h:obex_transfer1_bluez5_p.h org.bluez.obex.Transfer1.xml -- cgit v1.2.3 From 240be1579d3c9ab8c7eeec9402b5a7ed0fae7abd Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 20 Jun 2017 16:25:00 +0200 Subject: Add Qt6 TODO for QBLuetoothDeviceInfo::DataCompleteness The enum has very little use. Change-Id: I4767f59b9603fb46a18364a502696ceaa50376c3 Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothdeviceinfo.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h index 751c8384..5ff17e1c 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.h +++ b/src/bluetooth/qbluetoothdeviceinfo.h @@ -189,6 +189,7 @@ public: }; Q_DECLARE_FLAGS(ServiceClasses, ServiceClass) + //TODO Qt6 Remove DataCompleteness -> it serves no purpose enum DataCompleteness { DataComplete, DataIncomplete, -- cgit v1.2.3 From 3222f7b7a6115891515e6340aec62b2d045d1bba Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 20 Jun 2017 16:49:03 +0200 Subject: Improve detection of lowenergy devices Bluez DBus API does not expose a flag indicating whether a given device is BTLE or not. For BTLE only cases the device class is still a fairly good indicator. However more and more devices are hybrids. This patch takes a closer look at the advertised service uuids and matches them against the known 0x1800 BTLE service uuids. Change-Id: Iaad747ff8a7b17be5ee17e51e2f4e329604a708c Reviewed-by: Oliver Wolff --- .../qbluetoothdevicediscoveryagent_bluez.cpp | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 5288eaf8..cda1bd17 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -400,18 +400,34 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString& dev // read information QBluetoothDeviceInfo deviceInfo(btAddress, btName, btClass); - - if (!btClass) - deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::LowEnergyCoreConfiguration); - else - deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration); - deviceInfo.setRssi(device.rSSI()); + QList uuids; - foreach (const QString &u, device.uUIDs()) - uuids.append(QBluetoothUuid(u)); + bool foundLikelyLowEnergyUuid = false; + for (const auto &u: device.uUIDs()) { + const QBluetoothUuid id(u); + if (id.isNull()) + continue; + + if (!foundLikelyLowEnergyUuid) { + //once we found one BTLE service we are done + bool ok = false; + quint16 shortId = id.toUInt16(&ok); + if (ok && ((shortId & QBluetoothUuid::GenericAccess) == QBluetoothUuid::GenericAccess)) + foundLikelyLowEnergyUuid = true; + } + uuids.append(id); + } deviceInfo.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete); + if (!btClass) { + deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::LowEnergyCoreConfiguration); + } else { + deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration); + if (foundLikelyLowEnergyUuid) + deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration); + } + for (int i = 0; i < discoveredDevices.size(); i++) { if (discoveredDevices[i].address() == deviceInfo.address()) { if (discoveredDevices[i] == deviceInfo) { -- cgit v1.2.3 From 57b51b9830adb1c2428c21d674709943a7f85e2d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 21 Jun 2017 08:32:48 +0200 Subject: Remove obsolete define and related comments This define was used a while ago. The code that used the define is long gone but the define was forgotten. Change-Id: Ieebe4ef4f95bbd730c2929083e87a0ee439deda8 Reviewed-by: Oliver Wolff --- src/bluetooth/bluez/objectmanager_p.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/objectmanager_p.h b/src/bluetooth/bluez/objectmanager_p.h index 823badeb..74f5ab43 100644 --- a/src/bluetooth/bluez/objectmanager_p.h +++ b/src/bluetooth/bluez/objectmanager_p.h @@ -20,10 +20,6 @@ #include #include -/* Temporary hack to merge branches until Bluez headers are removed - * from bluez5_helpers_p.h. - */ -#define NO_BLUEZ_INCLUDES #include "bluez5_helper_p.h" /* -- cgit v1.2.3 From 9ecd4d7bb7eb17babdb85762a197968f0f85a5e7 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 20 Jun 2017 16:04:42 +0200 Subject: Add new Bluez Device1 properties to QtBLuetooth The org.bluez.Device1 interface got a few new properties which this patch makes accessible to QtBluetooth. The new properties will be used later on to enable new use cases and streamline existing code. Change-Id: I8bd28b7df7ead5e46b70f6b7b387ab378f45e7a7 Reviewed-by: Oliver Wolff --- src/bluetooth/bluez/bluez5_helper.cpp | 1 + src/bluetooth/bluez/bluez5_helper_p.h | 2 ++ src/bluetooth/bluez/device1_bluez5.cpp | 3 +-- src/bluetooth/bluez/device1_bluez5_p.h | 38 ++++++++++++++++++++++--------- src/bluetooth/bluez/org.bluez.Device1.xml | 10 ++++++++ 5 files changed, 41 insertions(+), 13 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index 8871a872..de41003f 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -69,6 +69,7 @@ bool isBluez5() qDBusRegisterMetaType(); qDBusRegisterMetaType(); + qDBusRegisterMetaType(); QDBusPendingReply reply = manager.GetManagedObjects(); reply.waitForFinished(); diff --git a/src/bluetooth/bluez/bluez5_helper_p.h b/src/bluetooth/bluez/bluez5_helper_p.h index a46810fc..2d72caf1 100644 --- a/src/bluetooth/bluez/bluez5_helper_p.h +++ b/src/bluetooth/bluez/bluez5_helper_p.h @@ -57,8 +57,10 @@ typedef QMap InterfaceList; typedef QMap ManagedObjectList; +typedef QMap ManufacturerDataList; Q_DECLARE_METATYPE(InterfaceList) +Q_DECLARE_METATYPE(ManufacturerDataList) Q_DECLARE_METATYPE(ManagedObjectList) QT_BEGIN_NAMESPACE diff --git a/src/bluetooth/bluez/device1_bluez5.cpp b/src/bluetooth/bluez/device1_bluez5.cpp index a4c01d3f..491a365d 100644 --- a/src/bluetooth/bluez/device1_bluez5.cpp +++ b/src/bluetooth/bluez/device1_bluez5.cpp @@ -1,8 +1,7 @@ /* * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -p device1_bluez5 -v org.bluez.Device1.xml * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd. * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments diff --git a/src/bluetooth/bluez/device1_bluez5_p.h b/src/bluetooth/bluez/device1_bluez5_p.h index d6181b34..4feb5318 100644 --- a/src/bluetooth/bluez/device1_bluez5_p.h +++ b/src/bluetooth/bluez/device1_bluez5_p.h @@ -1,15 +1,14 @@ /* * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -p device1_bluez5 -v org.bluez.Device1.xml * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd. * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ -#ifndef DEVICE1_BLUEZ5_H_1396951960 -#define DEVICE1_BLUEZ5_H_1396951960 +#ifndef DEVICE1_BLUEZ5_P_H +#define DEVICE1_BLUEZ5_P_H #include #include @@ -19,6 +18,7 @@ #include #include #include +#include "bluez5_helper_p.h" /* * Proxy class for interface org.bluez.Device1 @@ -31,7 +31,7 @@ public: { return "org.bluez.Device1"; } public: - OrgBluezDevice1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + OrgBluezDevice1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); ~OrgBluezDevice1Interface(); @@ -75,6 +75,10 @@ public: inline bool legacyPairing() const { return qvariant_cast< bool >(property("LegacyPairing")); } + Q_PROPERTY(ManufacturerDataList ManufacturerData READ manufacturerData) + inline ManufacturerDataList manufacturerData() const + { return qvariant_cast< ManufacturerDataList >(property("ManufacturerData")); } + Q_PROPERTY(QString Modalias READ modalias) inline QString modalias() const { return qvariant_cast< QString >(property("Modalias")); } @@ -91,12 +95,24 @@ public: inline short rSSI() const { return qvariant_cast< short >(property("RSSI")); } + Q_PROPERTY(QVariantMap ServiceData READ serviceData) + inline QVariantMap serviceData() const + { return qvariant_cast< QVariantMap >(property("ServiceData")); } + + Q_PROPERTY(bool ServicesResolved READ servicesResolved) + inline bool servicesResolved() const + { return qvariant_cast< bool >(property("ServicesResolved")); } + Q_PROPERTY(bool Trusted READ trusted WRITE setTrusted) inline bool trusted() const { return qvariant_cast< bool >(property("Trusted")); } inline void setTrusted(bool value) { setProperty("Trusted", QVariant::fromValue(value)); } + Q_PROPERTY(short TxPower READ txPower) + inline short txPower() const + { return qvariant_cast< short >(property("TxPower")); } + Q_PROPERTY(QStringList UUIDs READ uUIDs) inline QStringList uUIDs() const { return qvariant_cast< QStringList >(property("UUIDs")); } @@ -105,39 +121,39 @@ public Q_SLOTS: // METHODS inline QDBusPendingReply<> CancelPairing() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("CancelPairing"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("CancelPairing"), argumentList); } inline QDBusPendingReply<> Connect() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("Connect"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("Connect"), argumentList); } inline QDBusPendingReply<> ConnectProfile(const QString &UUID) { QList argumentList; argumentList << QVariant::fromValue(UUID); - return asyncCallWithArgumentList(QLatin1String("ConnectProfile"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("ConnectProfile"), argumentList); } inline QDBusPendingReply<> Disconnect() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("Disconnect"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("Disconnect"), argumentList); } inline QDBusPendingReply<> DisconnectProfile(const QString &UUID) { QList argumentList; argumentList << QVariant::fromValue(UUID); - return asyncCallWithArgumentList(QLatin1String("DisconnectProfile"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("DisconnectProfile"), argumentList); } inline QDBusPendingReply<> Pair() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("Pair"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("Pair"), argumentList); } Q_SIGNALS: // SIGNALS diff --git a/src/bluetooth/bluez/org.bluez.Device1.xml b/src/bluetooth/bluez/org.bluez.Device1.xml index 1f8fd2c1..554d0b53 100644 --- a/src/bluetooth/bluez/org.bluez.Device1.xml +++ b/src/bluetooth/bluez/org.bluez.Device1.xml @@ -27,5 +27,15 @@ + + + + + + + + + + -- cgit v1.2.3 From 0b475c565843e6c0901558d6342a02722d57acbc Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 21 Jun 2017 15:45:26 +0200 Subject: Provide a way to define GAP/GATT services for central roles Some devices require the Generic Access (GAP) and Generic Attribute (GATT) services to be defined. Otherwise they refuse a proper interaction. This is done implicitly by Android and BlueZ. The reason why BlueZ does not do this for QtBluetooth is because QtBluetooth sets up its own GATT infrastructure. Normally a QLEController in central role cannot do that via public API as the QLEController::addService() function blocks on peripheral use cases. This patch sets the profiles up. In the future the feature really requires a better form of API (beyond the above env variable) or should be enabled by default but since we need this earlier than Qt 5.10 a more subtle approach was chosen. For now the feature can only be enabled if the QT_DEFAULT_CENTRAL_SERVICES was set. Another limitation is that the characteristics of the added services are completely static. Task-number: QTBUG-61554 Change-Id: Id03bddb2e54cc4f0869838e13ddf281311ad3a26 Reviewed-by: Christian Kandeler Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycontroller.cpp | 37 +++++++++------ src/bluetooth/qlowenergycontroller_bluez.cpp | 68 ++++++++++++++++++++++++++++ src/bluetooth/qlowenergycontroller_p.h | 3 ++ 3 files changed, 95 insertions(+), 13 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index 2337268d..053ca980 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -931,13 +931,24 @@ QLowEnergyService *QLowEnergyController::addService(const QLowEnergyServiceData return nullptr; } + Q_D(QLowEnergyController); + QLowEnergyService *newService = d->addServiceHelper(service); + if (newService) + newService->setParent(parent); + + return newService; +} + +QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( + const QLowEnergyServiceData &service) +{ // Spec says services "should" be grouped by uuid length (16-bit first, then 128-bit). // Since this is not mandatory, we ignore it here and let the caller take responsibility // for it. const auto servicePrivate = QSharedPointer::create(); servicePrivate->state = QLowEnergyService::LocalService; - servicePrivate->setController(d_ptr); + servicePrivate->setController(this); servicePrivate->uuid = service.uuid(); servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; @@ -947,13 +958,13 @@ QLowEnergyService *QLowEnergyController::addService(const QLowEnergyServiceData } // Spec v4.2, Vol 3, Part G, Section 3. - const QLowEnergyHandle oldLastHandle = d_ptr->lastLocalHandle; - servicePrivate->startHandle = ++d_ptr->lastLocalHandle; // Service declaration. - d_ptr->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. + const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; + servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. + this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { - const QLowEnergyHandle declHandle = ++d_ptr->lastLocalHandle; + const QLowEnergyHandle declHandle = ++this->lastLocalHandle; QLowEnergyServicePrivate::CharData charData; - charData.valueHandle = ++d_ptr->lastLocalHandle; + charData.valueHandle = ++this->lastLocalHandle; charData.uuid = cd.uuid(); charData.properties = cd.properties(); charData.value = cd.value(); @@ -961,21 +972,21 @@ QLowEnergyService *QLowEnergyController::addService(const QLowEnergyServiceData QLowEnergyServicePrivate::DescData descData; descData.uuid = dd.uuid(); descData.value = dd.value(); - charData.descriptorList.insert(++d_ptr->lastLocalHandle, descData); + charData.descriptorList.insert(++this->lastLocalHandle, descData); } servicePrivate->characteristicList.insert(declHandle, charData); } - servicePrivate->endHandle = d_ptr->lastLocalHandle; - const bool handleOverflow = d_ptr->lastLocalHandle <= oldLastHandle; + servicePrivate->endHandle = this->lastLocalHandle; + const bool handleOverflow = this->lastLocalHandle <= oldLastHandle; if (handleOverflow) { qCWarning(QT_BT) << "Not enough attribute handles left to create this service"; - d_ptr->lastLocalHandle = oldLastHandle; + this->lastLocalHandle = oldLastHandle; return nullptr; } - d_ptr->localServices.insert(servicePrivate->uuid, servicePrivate); - d_ptr->addToGenericAttributeList(service, servicePrivate->startHandle); - return new QLowEnergyService(servicePrivate, parent); + this->localServices.insert(servicePrivate->uuid, servicePrivate); + this->addToGenericAttributeList(service, servicePrivate->startHandle); + return new QLowEnergyService(servicePrivate); } /*! diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 583c0e27..0744bcc4 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -530,6 +530,8 @@ void QLowEnergyControllerPrivate::connectToDevice() if (l2cpSocket) delete l2cpSocket; + createServicesForCentralIfRequired(); + // check for active running connections // BlueZ 5.37+ (maybe even earlier versions) can have pending BTLE connections // Only one active L2CP socket to CID 0x4 possible at a time @@ -644,6 +646,72 @@ void QLowEnergyControllerPrivate::establishL2cpClientSocket() loadSigningDataIfNecessary(LocalSigningKey); } +void QLowEnergyControllerPrivate::createServicesForCentralIfRequired() +{ + //only enable when requested + //for now we use env variable to activate the feature + if (Q_LIKELY(!qEnvironmentVariableIsSet("QT_DEFAULT_CENTRAL_SERVICES"))) + return; //nothing to do + + //do not add the services each time we start a connection + if (localServices.contains(QBluetoothUuid(QBluetoothUuid::GenericAccess))) + return; + + qCDebug(QT_BT_BLUEZ) << "Creating default GAP/GATT services"; + + //populate Generic Access service + //for now the values are static + QLowEnergyServiceData gapServiceData; + gapServiceData.setType(QLowEnergyServiceData::ServiceTypePrimary); + gapServiceData.setUuid(QBluetoothUuid::GenericAccess); + + QLowEnergyCharacteristicData gapDeviceName; + gapDeviceName.setUuid(QBluetoothUuid::DeviceName); + gapDeviceName.setProperties(QLowEnergyCharacteristic::Read); + + QBluetoothLocalDevice mainAdapter; + gapDeviceName.setValue(mainAdapter.name().toLatin1()); //static name + + QLowEnergyCharacteristicData gapAppearance; + gapAppearance.setUuid(QBluetoothUuid::Appearance); + gapAppearance.setProperties(QLowEnergyCharacteristic::Read); + gapAppearance.setValue(QByteArray::fromHex("80")); // Generic Computer (0x80) + + QLowEnergyCharacteristicData gapPrivacyFlag; + gapPrivacyFlag.setUuid(QBluetoothUuid::PeripheralPrivacyFlag); + gapPrivacyFlag.setProperties(QLowEnergyCharacteristic::Read); + gapPrivacyFlag.setValue(QByteArray::fromHex("00")); // disable privacy + + gapServiceData.addCharacteristic(gapDeviceName); + gapServiceData.addCharacteristic(gapAppearance); + gapServiceData.addCharacteristic(gapPrivacyFlag); + + Q_Q(QLowEnergyController); + QLowEnergyService *service = addServiceHelper(gapServiceData); + if (service) + service->setParent(q); + + QLowEnergyServiceData gattServiceData; + gattServiceData.setType(QLowEnergyServiceData::ServiceTypePrimary); + gattServiceData.setUuid(QBluetoothUuid::GenericAttribute); + + QLowEnergyCharacteristicData serviceChangedChar; + serviceChangedChar.setUuid(QBluetoothUuid::ServiceChanged); + serviceChangedChar.setProperties(QLowEnergyCharacteristic::Indicate); + //arbitrary range of 2 bit handle range (1-4 + serviceChangedChar.setValue(QByteArray::fromHex("0104")); + + const QLowEnergyDescriptorData clientConfig( + QBluetoothUuid::ClientCharacteristicConfiguration, + QByteArray(2, 0)); + serviceChangedChar.addDescriptor(clientConfig); + gattServiceData.addCharacteristic(serviceChangedChar); + + service = addServiceHelper(gattServiceData); + if (service) + service->setParent(q); +} + void QLowEnergyControllerPrivate::l2cpConnected() { Q_Q(QLowEnergyController); diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index 5811376b..5c680c3b 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -147,6 +147,8 @@ public: QLowEnergyHandle handle); QLowEnergyDescriptor descriptorForHandle( QLowEnergyHandle handle); + QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service); + quint16 updateValueOfCharacteristic(QLowEnergyHandle charHandle, const QByteArray &value, @@ -416,6 +418,7 @@ private: void restartRequestTimer(); void establishL2cpClientSocket(); + void createServicesForCentralIfRequired(); private slots: void l2cpConnected(); -- cgit v1.2.3 From b93dc2756d9947236deb955634b499b27aaaa414 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 28 Jun 2017 16:21:01 +0200 Subject: Fix concurrent access to QBluetoothSocket::canReadLine() on Android On Android, the socket's read buffer is managed in the Java thread. QBluetoothSocket::canReadLine() is public API (most likely) being called by in the main Qt thread though. The function directly called into the Java buffer instance without proper locking. This can create race conditions. Starting with this patch canReadLine() calls another QBluetoothSocketPrivate indirection to allow a platform specific implementation. This affects WinRT, BlueZ and the dummy backend too. This is not an issue on macOS as its implementation of QBluetoothSocket is separate and does not have to deal with multiple QBluetoothSocketPrivate implementations. Task-number: QTBUG-58190 Task-number: QTBUG-60830 Change-Id: Idae19f1aee6f809699d36519b01a3c68ad9c563d Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff --- src/bluetooth/android/inputstreamthread.cpp | 6 ++++++ src/bluetooth/android/inputstreamthread_p.h | 1 + src/bluetooth/qbluetoothsocket.cpp | 2 +- src/bluetooth/qbluetoothsocket_android.cpp | 9 +++++++++ src/bluetooth/qbluetoothsocket_bluez.cpp | 5 +++++ src/bluetooth/qbluetoothsocket_p.cpp | 5 +++++ src/bluetooth/qbluetoothsocket_p.h | 1 + src/bluetooth/qbluetoothsocket_winrt.cpp | 5 +++++ 8 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/android/inputstreamthread.cpp b/src/bluetooth/android/inputstreamthread.cpp index ecd9218e..982c477b 100644 --- a/src/bluetooth/android/inputstreamthread.cpp +++ b/src/bluetooth/android/inputstreamthread.cpp @@ -77,6 +77,12 @@ qint64 InputStreamThread::bytesAvailable() const return m_socket_p->buffer.size(); } +bool InputStreamThread::canReadLine() const +{ + QMutexLocker locker(&m_mutex); + return m_socket_p->buffer.canReadLine(); +} + qint64 InputStreamThread::readData(char *data, qint64 maxSize) { QMutexLocker locker(&m_mutex); diff --git a/src/bluetooth/android/inputstreamthread_p.h b/src/bluetooth/android/inputstreamthread_p.h index 741333ac..a6ee0655 100644 --- a/src/bluetooth/android/inputstreamthread_p.h +++ b/src/bluetooth/android/inputstreamthread_p.h @@ -68,6 +68,7 @@ public: explicit InputStreamThread(QBluetoothSocketPrivate *socket_p); qint64 bytesAvailable() const; + bool canReadLine() const; bool run(); qint64 readData(char *data, qint64 maxSize); diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 3e961142..57dd3aa0 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -624,7 +624,7 @@ void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state) bool QBluetoothSocket::canReadLine() const { Q_D(const QBluetoothSocket); - return d->buffer.canReadLine() || QIODevice::canReadLine(); + return d->canReadLine(); } /*! diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 87c9ffc8..c2fc96f2 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -879,6 +879,15 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return 0; } +bool QBluetoothSocketPrivate::canReadLine() const +{ + // We cannot access buffer directly as it is part of different thread + if (inputThread) + return inputThread->canReadLine(); + + return false; +} + QT_END_NAMESPACE #include diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index 42c5503b..dca1bc3b 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -592,4 +592,9 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return buffer.size(); } +bool QBluetoothSocketPrivate::canReadLine() const +{ + return buffer.canReadLine(); +} + QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothsocket_p.cpp b/src/bluetooth/qbluetoothsocket_p.cpp index 6007b924..dc14e97b 100644 --- a/src/bluetooth/qbluetoothsocket_p.cpp +++ b/src/bluetooth/qbluetoothsocket_p.cpp @@ -158,4 +158,9 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return 0; } +bool QBluetoothSocketPrivate::canReadLine() const +{ + return false; +} + QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h index 177f154a..cfa342bb 100644 --- a/src/bluetooth/qbluetoothsocket_p.h +++ b/src/bluetooth/qbluetoothsocket_p.h @@ -166,6 +166,7 @@ public: QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite); qint64 bytesAvailable() const; + bool canReadLine() const; public: QPrivateLinearBuffer buffer; diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 1f4e6233..a56e10fa 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -569,6 +569,11 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return buffer.size(); } +bool QBluetoothSocketPrivate::canReadLine() const +{ + return buffer.canReadLine(); +} + void QBluetoothSocketPrivate::handleNewData(const QVector &data) { // Defer putting the data into the list until the next event loop iteration -- cgit v1.2.3 From 31990acd549f3f811b60caefa6371ec8fc09bb4b Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 29 Jun 2017 11:01:08 +0200 Subject: Add indirection for QBluetoothSocket::bytesToWrite() Not all platforms use txbuffer for writes. Fortunately those platforms who do not use it do not use any buffering at all. Hence bytesToWrite() returned the correct value as txbuffer always had size zero. Therefore this patch is effectively a NOP. Nevertheless this patch encourages the right implementation across the platform. This does not affect macOS as it has a separate implementation for QBluetoothSocket::bytesToWrite(). Task-number: QTBUG-58190 Change-Id: Ic05f4358b079f612ee7e0e4dbb7fb9aa78fd6556 Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 2 +- src/bluetooth/qbluetoothsocket_android.cpp | 5 +++++ src/bluetooth/qbluetoothsocket_bluez.cpp | 5 +++++ src/bluetooth/qbluetoothsocket_p.cpp | 5 +++++ src/bluetooth/qbluetoothsocket_p.h | 1 + src/bluetooth/qbluetoothsocket_winrt.cpp | 5 +++++ 6 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 57dd3aa0..2f38ed04 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -300,7 +300,7 @@ qint64 QBluetoothSocket::bytesAvailable() const qint64 QBluetoothSocket::bytesToWrite() const { Q_D(const QBluetoothSocket); - return d->txBuffer.size(); + return d->bytesToWrite(); } /*! diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index c2fc96f2..6a92f29a 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -879,6 +879,11 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return 0; } +qint64 QBluetoothSocketPrivate::bytesToWrite() const +{ + return 0; // nothing because always unbuffered +} + bool QBluetoothSocketPrivate::canReadLine() const { // We cannot access buffer directly as it is part of different thread diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index dca1bc3b..6aef811a 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -592,6 +592,11 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return buffer.size(); } +qint64 QBluetoothSocketPrivate::bytesToWrite() const +{ + return txBuffer.size(); +} + bool QBluetoothSocketPrivate::canReadLine() const { return buffer.canReadLine(); diff --git a/src/bluetooth/qbluetoothsocket_p.cpp b/src/bluetooth/qbluetoothsocket_p.cpp index dc14e97b..39d483d6 100644 --- a/src/bluetooth/qbluetoothsocket_p.cpp +++ b/src/bluetooth/qbluetoothsocket_p.cpp @@ -163,4 +163,9 @@ bool QBluetoothSocketPrivate::canReadLine() const return false; } +qint64 QBluetoothSocketPrivate::bytesToWrite() const +{ + return 0; +} + QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h index cfa342bb..9aabf660 100644 --- a/src/bluetooth/qbluetoothsocket_p.h +++ b/src/bluetooth/qbluetoothsocket_p.h @@ -167,6 +167,7 @@ public: qint64 bytesAvailable() const; bool canReadLine() const; + qint64 bytesToWrite() const; public: QPrivateLinearBuffer buffer; diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index a56e10fa..4a9d1b93 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -569,6 +569,11 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return buffer.size(); } +qint64 QBluetoothSocketPrivate::bytesToWrite() const +{ + return 0; // nothing because always unbuffered +} + bool QBluetoothSocketPrivate::canReadLine() const { return buffer.canReadLine(); -- cgit v1.2.3 From b827a21be00f5161b4b42ddaf3f8a46477d39054 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 29 Jun 2017 11:15:15 +0200 Subject: Android: Do not emit QBluetoothSocket::bytesWritten() if write() failed QBluetoothSocket::write() emits the bytesWritten(int) signal when the write was successful. java.io.OutputStream.write() returns an exception when it fails. We should not emit bytesWritten() if such an exception occurred. Change-Id: I76e7a85188102e8227d586450c3e733c046e9957 Reviewed-by: Christian Stromme Reviewed-by: Oliver Wolff --- 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 6a92f29a..d0b901ae 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -722,7 +722,6 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) env->SetByteArrayRegion(nativeData, 0, (qint32)maxSize, reinterpret_cast(data)); outputStream.callMethod("write", "([BII)V", nativeData, 0, (qint32)maxSize); env->DeleteLocalRef(nativeData); - emit q->bytesWritten(maxSize); if (env->ExceptionCheck()) { qCWarning(QT_BT_ANDROID) << "Error while writing"; @@ -733,6 +732,7 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) return -1; } + emit q->bytesWritten(maxSize); return maxSize; } -- cgit v1.2.3 From 0148c476bbc407c00d40f65f9e166226043ec5cf Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 29 Jun 2017 13:10:42 +0200 Subject: Continuously emit deviceDiscovered() signal during never-ending dev discovery If the user chooses to do a BTLE device discovery with QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout being set to 0, we should continuously emit the deviceDiscovered() signal and not only once per device. This patch checks the timeout value before triggering the duplication detection for deviceDiscovered() signals. Task-number: QTBUG-57847 Change-Id: I0e43b779a89b918640fe3d812d2500ed0a016cc3 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp | 2 +- src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index e76ddff7..ed6507f3 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -304,7 +304,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices( for (int i = 0; i < discoveredDevices.size(); i++) { if (discoveredDevices[i].address() == info.address()) { - if (discoveredDevices[i] == info) { + if (discoveredDevices[i] == info && lowEnergySearchTimeout > 0) { qCDebug(QT_BT_ANDROID) << "Duplicate: " << info.address() << "isLeScanResult:" << isLeResult; return; diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index b913bde4..5c70f1c1 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -417,7 +417,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString& dev for (int i = 0; i < discoveredDevices.size(); i++) { if (discoveredDevices[i].address() == deviceInfo.address()) { - if (discoveredDevices[i] == deviceInfo) { + if (discoveredDevices[i] == deviceInfo && lowEnergySearchTimeout > 0) { qCDebug(QT_BT_BLUEZ) << "Duplicate: " << btAddress.toString(); return; } -- cgit v1.2.3 From 29b98ef4a4a34497cfcb6091554809673024340e Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 29 Jun 2017 14:08:42 +0200 Subject: Device discovery (CoreBluetooth): report duplicates in case LE scan has timeout 0 If we have a never-ending LE scan, we should report even complete duplicates. The original bug-report has a scenario with a long-running application, that records a data from BTLE scales once a day. Task-number: QTBUG-57847 Change-Id: If5e4828f119d5f4e4418cfe60fa518b583210a14 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index b308f7cc..9e3f6a57 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -525,7 +525,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(const QBluetoothDeviceIn for (int i = 0, e = discoveredDevices.size(); i < e; ++i) { if (isLE ? discoveredDevices[i].deviceUuid() == newDeviceInfo.deviceUuid(): discoveredDevices[i].address() == newDeviceInfo.address()) { - if (discoveredDevices[i] == newDeviceInfo) + if (discoveredDevices[i] == newDeviceInfo && (!isLE || lowEnergySearchTimeout > 0)) return; discoveredDevices.replace(i, newDeviceInfo); -- cgit v1.2.3 From 225ba9d013073b27b6c4d2b3eee3720b09f5a379 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 29 Jun 2017 15:12:42 +0200 Subject: Update doc for QBluetoothDeviceDiscoveryAgent::deviceDiscovered() lowEnergyDiscoveryTimeout affects the emission behavior of deviceDiscovered(). This behavior change should be explicitly documented. Task-number: QTBUG-57847 Change-Id: I94bd7cb36935b376c34ba90f5de4e3084e87e883 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothdevicediscoveryagent.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index b033ae3c..02ea30d1 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -143,7 +143,15 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT) information via \l discoveredDevices() once the discovery has finished. This will yield the most recent RSSI information. - \sa QBluetoothDeviceInfo::rssi() + If \l lowEnergyDiscoveryTimeout() is larger than 0 the signal is only ever + emitted when at least one attribute of \a info changes. This reflects the desire to + receive updates as more precise information becomes available. The exception to this + behavior is the case when \l lowEnergyDiscoveryTimeout is set to \c 0. A timeout of \c 0 + expresses the desire to monitor the appearance and disappearance of Low Energy devices + over time. Under this condition the \l deviceDiscovered() signal is emitted even if + \a info has not changed since the last signal emission. + + \sa QBluetoothDeviceInfo::rssi(), lowEnergyDiscoveryTimeout() */ /*! -- cgit v1.2.3 From 7761bb88000c19d2f5bfb1182f5c5ddf7dae6c5a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 12 Jun 2017 14:34:58 -0700 Subject: Use QRandomGenerator instead of q?rand Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf Reviewed-by: Lars Knoll --- src/bluetooth/android/lowenergynotificationhub.cpp | 5 ++--- src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp index 53f2d6cc..9f90e3de 100644 --- a/src/bluetooth/android/lowenergynotificationhub.cpp +++ b/src/bluetooth/android/lowenergynotificationhub.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include QT_BEGIN_NAMESPACE @@ -81,11 +81,10 @@ LowEnergyNotificationHub::LowEnergyNotificationHub(const QBluetoothAddress &remo } // register C++ class pointer in Java - qsrand(QTime::currentTime().msec()); lock.lockForWrite(); while (true) { - javaToCtoken = qrand(); + javaToCtoken = QRandomGenerator::get32(); if (!hubMap()->contains(javaToCtoken)) break; } diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index c8c5ffbf..0982573e 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include +#include #include #include "qbluetoothlocaldevice.h" @@ -798,9 +799,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), SLOT(PropertyChanged(QString, QDBusVariant))); - qsrand(QTime::currentTime().msec()); agent_path = agentPath; - agent_path.append(QString::fromLatin1("/%1").arg(qrand())); + agent_path.append(QString::fromLatin1("/%1").arg(QRandomGenerator::get32())); } } @@ -1164,7 +1164,7 @@ QString QBluetoothLocalDevicePrivate::RequestPinCode(const QDBusObjectPath &in0) Q_Q(QBluetoothLocalDevice); qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << in0.path(); // seeded in constructor, 6 digit pin - QString pin = QString::fromLatin1("%1").arg(qrand() % 1000000); + QString pin = QString::fromLatin1("%1").arg(QRandomGenerator::bounded(1000000)); pin = QString::fromLatin1("%1").arg(pin, 6, QLatin1Char('0')); emit q->pairingDisplayPinCode(address, pin); @@ -1276,7 +1276,7 @@ uint QBluetoothLocalDevicePrivate::RequestPasskey(const QDBusObjectPath &in0) { Q_UNUSED(in0); qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO; - return (qrand() % 1000000); + return (QRandomGenerator::bounded(1000000)); } // Bluez 4 -- cgit v1.2.3 From b0089abb05e6f60cc252068be1ba40be32e29bd3 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 4 Jul 2017 08:16:34 +0200 Subject: winrt: Do not emit canceled in timeout case in device discovery canceled should only be emitted if stop was used to abort a running device discovery. A timeout happening has to cause a normal finished. Change-Id: I1072c14a44b84da0cb93420cf7344b8bc56b523e Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent_p.h | 1 - src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 17 +---------------- 2 files changed, 1 insertion(+), 17 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index 45764c1a..7b57abb2 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -163,7 +163,6 @@ private: private slots: void registerDevice(const QBluetoothDeviceInfo &info); void onScanFinished(); - void onScanCanceled(); private: void disconnectAndClearWorker(); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index d8d68d4b..1aaaf0a4 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -109,7 +109,6 @@ public slots: Q_SIGNALS: void deviceFound(const QBluetoothDeviceInfo &info); void scanFinished(); - void scanCanceled(); public: quint8 requestedModes; @@ -250,10 +249,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() void QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout() { - if (m_pendingPairedDevices == 0) - emit scanFinished(); - else - emit scanCanceled(); + emit scanFinished(); deleteLater(); } @@ -552,8 +548,6 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent this, &QBluetoothDeviceDiscoveryAgentPrivate::registerDevice); connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanFinished, this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished); - connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanCanceled, - this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanCanceled); worker->start(); if (lowEnergySearchTimeout > 0 && methods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod) { // otherwise no timeout and stop() required @@ -613,21 +607,12 @@ void QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished() emit q->finished(); } -void QBluetoothDeviceDiscoveryAgentPrivate::onScanCanceled() -{ - Q_Q(QBluetoothDeviceDiscoveryAgent); - disconnectAndClearWorker(); - emit q->canceled(); -} - void QBluetoothDeviceDiscoveryAgentPrivate::disconnectAndClearWorker() { Q_Q(QBluetoothDeviceDiscoveryAgent); if (!worker) return; - disconnect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanCanceled, - this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanCanceled); disconnect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanFinished, this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished); disconnect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::deviceFound, -- cgit v1.2.3 From ccd1e69e83144781aabb3d1b3f7d33abb797521c Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 7 Apr 2017 19:39:42 +0300 Subject: QLowEnergyController: introduce ConnectionClosedError Unlike ConnectionError, this shall be used to mention errors occurred due to the remote device's intent (term, power loss, etc) Change-Id: I6918879e3918a5131841f012b2824c30b99e472d Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov Reviewed-by: Konstantin Ritt --- src/bluetooth/qlowenergycontroller.cpp | 5 +++++ src/bluetooth/qlowenergycontroller.h | 1 + 2 files changed, 6 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index 053ca980..004ee3be 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -138,6 +138,8 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT) This value was introduced by Qt 5.5. \value AdvertisingError The attempt to start advertising failed. This value was introduced by Qt 5.7. + \value RemoteHostClosedError The remote device closed the connection. + This value was introduced by Qt 5.10. */ /*! @@ -299,6 +301,9 @@ void QLowEnergyControllerPrivate::setError( case QLowEnergyController::AdvertisingError: errorString = QLowEnergyController::tr("Error occurred trying to start advertising"); break; + case QLowEnergyController::RemoteHostClosedError: + errorString = QLowEnergyController::tr("Remote device closed the connection"); + break; case QLowEnergyController::NoError: return; default: diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h index 1c4fa83f..1a84b05b 100644 --- a/src/bluetooth/qlowenergycontroller.h +++ b/src/bluetooth/qlowenergycontroller.h @@ -66,6 +66,7 @@ public: InvalidBluetoothAdapterError, ConnectionError, AdvertisingError, + RemoteHostClosedError }; Q_ENUM(Error) -- cgit v1.2.3 From b80ed337cb3a145038ad6384df3bfcce8134a0e7 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 6 Jul 2017 12:37:28 +0200 Subject: Add error flag for use case when the remote peer closes the connection [ChangeLog][QtBluetooth][QBluetoothSocket] Added QBluetoothSocket::RemoteHostClosedError. Change-Id: Ic9d27f9188f66be0fad309e55f2904eaed2cf61a Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket.cpp | 5 +++++ src/bluetooth/qbluetoothsocket.h | 1 + src/bluetooth/qbluetoothsocket_osx.mm | 3 +++ 3 files changed, 9 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 2f38ed04..f8aa8ddf 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -112,6 +112,8 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT) supported on this platform. \value OperationError An operation was attempted while the socket was in a state that did not permit it. + \value RemoteHostClosedError The remote host closed the connection. This value was + introduced by Qt 5.10. */ /*! @@ -854,6 +856,9 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error) case QBluetoothSocket::HostNotFoundError: debug << "QBluetoothSocket::HostNotFoundError"; break; + case QBluetoothSocket::RemoteHostClosedError: + debug << "QBluetoothSocket::RemoteHostClosedError"; + break; case QBluetoothSocket::ServiceNotFoundError: debug << "QBluetoothSocket::ServiceNotFoundError"; break; diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h index 97b6685b..2b1bd3cf 100644 --- a/src/bluetooth/qbluetoothsocket.h +++ b/src/bluetooth/qbluetoothsocket.h @@ -79,6 +79,7 @@ public: enum SocketError { NoSocketError = -2, UnknownSocketError = QAbstractSocket::UnknownSocketError, //-1 + RemoteHostClosedError = QAbstractSocket::RemoteHostClosedError, //1 HostNotFoundError = QAbstractSocket::HostNotFoundError, //2 ServiceNotFoundError = QAbstractSocket::SocketAddressNotAvailableError, //9 NetworkError = QAbstractSocket::NetworkError, //7 diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm index 75712868..cde98720 100644 --- a/src/bluetooth/qbluetoothsocket_osx.mm +++ b/src/bluetooth/qbluetoothsocket_osx.mm @@ -761,6 +761,9 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error) case QBluetoothSocket::HostNotFoundError: debug << "QBluetoothSocket::HostNotFoundError"; break; + case QBluetoothSocket::RemoteHostClosedError: + debug << "QBluetoothSocket::RemoteHostClosedError"; + break; case QBluetoothSocket::ServiceNotFoundError: debug << "QBluetoothSocket::ServiceNotFoundError"; break; -- cgit v1.2.3 From e93517592f6a1e08d3019c0e425fbf47df4dab25 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 6 Jul 2017 12:47:22 +0200 Subject: Add debug output for QBluetoothSocket::UnsupportedProtocolError Change-Id: Ia68da10c26ed0baff95a1f696b5a248595d23b1d Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov Reviewed-by: Konstantin Ritt --- src/bluetooth/qbluetoothsocket.cpp | 3 +++ src/bluetooth/qbluetoothsocket_osx.mm | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index f8aa8ddf..a35863b4 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -865,6 +865,9 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error) case QBluetoothSocket::NetworkError: debug << "QBluetoothSocket::NetworkError"; break; + case QBluetoothSocket::UnsupportedProtocolError: + debug << "QBluetoothSocket::UnsupportedProtocolError"; + break; default: debug << "QBluetoothSocket::SocketError(" << (int)error << ")"; } diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm index cde98720..71e249fe 100644 --- a/src/bluetooth/qbluetoothsocket_osx.mm +++ b/src/bluetooth/qbluetoothsocket_osx.mm @@ -770,6 +770,9 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error) case QBluetoothSocket::NetworkError: debug << "QBluetoothSocket::NetworkError"; break; + case QBluetoothSocket::UnsupportedProtocolError: + debug << "QBluetoothSocket::UnsupportedProtocolError"; + break; default: debug << "QBluetoothSocket::SocketError(" << (int)error << ")"; } -- cgit v1.2.3 From 1a6a18b9132e8b82d3b91f9ccbd7405599003fe3 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 7 Jul 2017 11:07:36 +0200 Subject: Add support for QBluetoothSocket::RemoteHostClosedError on Win UWP Change-Id: I6503377cd99d403ff31a2eae8109476294cbebac Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket_winrt.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 4a9d1b93..4e2bc11c 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -223,7 +223,7 @@ public: // the closing of the socket won't be communicated to the caller. So only the error is set. The // actual socket close happens inside of read. if (!bufferLength) { - emit socketErrorOccured(QBluetoothSocket::NetworkError); + emit socketErrorOccured(QBluetoothSocket::RemoteHostClosedError); return S_OK; } @@ -594,6 +594,9 @@ void QBluetoothSocketPrivate::handleError(QBluetoothSocket::SocketError error) case QBluetoothSocket::NetworkError: errorString = QBluetoothSocket::tr("Network error"); break; + case QBluetoothSocket::RemoteHostClosedError: + errorString = QBluetoothSocket::tr("Remote host closed connection"); + break; default: errorString = QBluetoothSocket::tr("Unknown socket error"); } -- cgit v1.2.3 From 0c3cc5374d2703fde6a99d301fcff974122d057d Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 11 Jul 2017 14:49:41 +0200 Subject: BTLE (CoreBluetooth) - prospective fix The type of manage.state has changed on macOS (like on iOS before), making an declataion invalid. Change-Id: I55caa32fa9f0a85090506cfbd788c1a80d41e8ce Reviewed-by: Jake Petroules --- src/bluetooth/osx/osxbtcentralmanager.mm | 7 +------ src/bluetooth/osx/osxbtledeviceinquiry.mm | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index c8eee733..15354f80 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -1030,12 +1030,7 @@ QT_END_NAMESPACE { using namespace OSXBluetooth; -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) - const CBManagerState state = central.state; -#else - const CBCentralManagerState state = central.state; -#endif - + const auto state = central.state; #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) if (state == CBManagerStateUnknown || state == CBManagerStateResetting) { diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index 3ce66d49..05b20167 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -233,11 +233,10 @@ QT_USE_NAMESPACE dispatch_queue_t leQueue(qt_LE_queue()); Q_ASSERT(leQueue); + const auto state = central.state; #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) - const CBManagerState state(central.state); if (state == CBManagerStatePoweredOn) { #else - const CBCentralManagerState state(central.state); if (state == CBCentralManagerStatePoweredOn) { #endif if (internalState == InquiryStarting) { -- cgit v1.2.3 From be5af68f8194ab0c59ca3f4a5bcafd3c71100b52 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 7 Jul 2017 10:47:21 +0200 Subject: Add support for QBluetoothSocket::RemoteHostClosedError on BlueZ Change-Id: I88ff16001280dea4967887ae711c463304c7ec7d Reviewed-by: Timur Pocheptsov Reviewed-by: Christian Kandeler --- src/bluetooth/qbluetoothsocket_bluez.cpp | 4 +++- src/bluetooth/qlowenergycontroller_bluez.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index 6aef811a..17b8e738 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -290,7 +290,9 @@ void QBluetoothSocketPrivate::_q_readNotify() qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << socket << "error:" << readFromDevice << errorString; if (errsv == EHOSTDOWN) q->setSocketError(QBluetoothSocket::HostNotFoundError); - else if (errsv != ECONNRESET) // The other side closing the connection is not an error. + else if (errsv == ECONNRESET) + q->setSocketError(QBluetoothSocket::RemoteHostClosedError); + else q->setSocketError(QBluetoothSocket::UnknownSocketError); q->disconnectFromService(); diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 0744bcc4..8eee2ab2 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -753,6 +753,10 @@ void QLowEnergyControllerPrivate::l2cpErrorChanged(QBluetoothSocket::SocketError setError(QLowEnergyController::NetworkError); qCDebug(QT_BT_BLUEZ) << "Network IO error while talking to LE device"; break; + case QBluetoothSocket::RemoteHostClosedError: + setError(QLowEnergyController::RemoteHostClosedError); + qCDebug(QT_BT_BLUEZ) << "Remote host closed the connection"; + break; case QBluetoothSocket::UnknownSocketError: case QBluetoothSocket::UnsupportedProtocolError: case QBluetoothSocket::OperationError: -- cgit v1.2.3 From 746187ad9ef1f8c9a3d797879bb3771377ae4bca Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 11 Jul 2017 14:49:41 +0200 Subject: BTLE (CoreBluetooth) - prospective fix The type of manage.state has changed on macOS (like on iOS before), making an declataion invalid. (cherry-picked from qtconnectivity/0c3cc5374d2703fde6a99d301fcff974122d057d) Change-Id: I55caa32fa9f0a85090506cfbd788c1a80d41e8ce Reviewed-by: Timur Pocheptsov --- src/bluetooth/osx/osxbtcentralmanager.mm | 7 +------ src/bluetooth/osx/osxbtledeviceinquiry.mm | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index f7218ca6..9e5128c4 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -1032,12 +1032,7 @@ QT_END_NAMESPACE { using namespace OSXBluetooth; -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) - const CBManagerState state = central.state; -#else - const CBCentralManagerState state = central.state; -#endif - + const auto state = central.state; #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) if (state == CBManagerStateUnknown || state == CBManagerStateResetting) { diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index 3ce66d49..05b20167 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -233,11 +233,10 @@ QT_USE_NAMESPACE dispatch_queue_t leQueue(qt_LE_queue()); Q_ASSERT(leQueue); + const auto state = central.state; #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) - const CBManagerState state(central.state); if (state == CBManagerStatePoweredOn) { #else - const CBCentralManagerState state(central.state); if (state == CBCentralManagerStatePoweredOn) { #endif if (internalState == InquiryStarting) { -- cgit v1.2.3 From 497a3c7ddadf5776b76e5369d2e452966c2bad15 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 18 Jul 2017 13:02:01 +0200 Subject: iOS: Do not include qlowenergycontroller_p.cpp if not needed Change-Id: Icdd0c9421f4894a7f84b69d31d4de440900f3d39 Reviewed-by: Timur Pocheptsov --- src/bluetooth/bluetooth.pro | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 40b14a84..233cdb3b 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -183,11 +183,9 @@ qtConfig(bluez) { qbluetoothserviceinfo_p.cpp \ qbluetoothservicediscoveryagent_p.cpp \ qbluetoothsocket_p.cpp \ - qbluetoothserver_p.cpp \ - qlowenergycontroller_p.cpp + qbluetoothserver_p.cpp SOURCES -= qbluetoothdevicediscoveryagent.cpp - SOURCES -= qlowenergycontroller_p.cpp SOURCES -= qlowenergyservice.cpp SOURCES -= qlowenergycontroller.cpp } else:winrt { -- cgit v1.2.3 From d206d1e4182f6e1a79c05bd1c11a5acf5ec80c22 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 18 Jul 2017 17:15:51 +0200 Subject: Enable default services for all central use cases on BlueZ Qt 5.9 introduced this behavior change as part of a bug fix. Qt 5.10 will force the new behavior unless otherwise requested by the user. Task-number: QTBUG-61554 Change-Id: I75a2107c64e0eaaf03490658669c9a23ac7dcf63 Reviewed-by: Timur Pocheptsov Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluez.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 8eee2ab2..ca3f7760 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -648,9 +648,9 @@ void QLowEnergyControllerPrivate::establishL2cpClientSocket() void QLowEnergyControllerPrivate::createServicesForCentralIfRequired() { - //only enable when requested - //for now we use env variable to activate the feature - if (Q_LIKELY(!qEnvironmentVariableIsSet("QT_DEFAULT_CENTRAL_SERVICES"))) + bool ok = false; + int value = qEnvironmentVariableIntValue("QT_DEFAULT_CENTRAL_SERVICES", &ok); + if (Q_UNLIKELY(ok && value == 0)) return; //nothing to do //do not add the services each time we start a connection -- cgit v1.2.3 From e1537a4677722e55c790c8fd7b424c0620afb710 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 12 Jul 2017 16:03:04 +0200 Subject: Provide means to select the Bluetooth discovery type on BlueZ This is an addition since BlueZ 5.30. Task-number: QTBUG-57575 Change-Id: Ib24702ac91ee55e5e0511d93cd9bd43937c0edb1 Reviewed-by: Timur Pocheptsov Reviewed-by: Oliver Wolff --- src/bluetooth/bluez/adapter1_bluez5.cpp | 4 ++-- src/bluetooth/bluez/adapter1_bluez5_p.h | 23 +++++++++++++++-------- src/bluetooth/bluez/org.bluez.Adapter1.xml | 4 ++++ 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluez/adapter1_bluez5.cpp b/src/bluetooth/bluez/adapter1_bluez5.cpp index 0f1e0acd..b1aefc8d 100644 --- a/src/bluetooth/bluez/adapter1_bluez5.cpp +++ b/src/bluetooth/bluez/adapter1_bluez5.cpp @@ -1,8 +1,8 @@ /* * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -p adapter1 -v org.bluez.Adapter1.xml + * Command line was: qdbusxml2cpp -p adapter1_bluez5_p.h:adapter1_bluez5.cpp org.bluez.Adapter1.xml * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd. * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments diff --git a/src/bluetooth/bluez/adapter1_bluez5_p.h b/src/bluetooth/bluez/adapter1_bluez5_p.h index 5568da4c..ce108ad0 100644 --- a/src/bluetooth/bluez/adapter1_bluez5_p.h +++ b/src/bluetooth/bluez/adapter1_bluez5_p.h @@ -1,15 +1,15 @@ /* * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -p adapter1 -v org.bluez.Adapter1.xml + * Command line was: qdbusxml2cpp -p adapter1_bluez5_p.h:adapter1_bluez5.cpp org.bluez.Adapter1.xml * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd. * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ -#ifndef ADAPTER1_H_1396951555 -#define ADAPTER1_H_1396951555 +#ifndef ADAPTER1_BLUEZ5_P_H +#define ADAPTER1_BLUEZ5_P_H #include #include @@ -31,7 +31,7 @@ public: { return "org.bluez.Adapter1"; } public: - OrgBluezAdapter1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + OrgBluezAdapter1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); ~OrgBluezAdapter1Interface(); @@ -100,19 +100,26 @@ public Q_SLOTS: // METHODS { QList argumentList; argumentList << QVariant::fromValue(device); - return asyncCallWithArgumentList(QLatin1String("RemoveDevice"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("RemoveDevice"), argumentList); + } + + inline QDBusPendingReply<> SetDiscoveryFilter(const QVariantMap &properties) + { + QList argumentList; + argumentList << QVariant::fromValue(properties); + return asyncCallWithArgumentList(QStringLiteral("SetDiscoveryFilter"), argumentList); } inline QDBusPendingReply<> StartDiscovery() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("StartDiscovery"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("StartDiscovery"), argumentList); } inline QDBusPendingReply<> StopDiscovery() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("StopDiscovery"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("StopDiscovery"), argumentList); } Q_SIGNALS: // SIGNALS diff --git a/src/bluetooth/bluez/org.bluez.Adapter1.xml b/src/bluetooth/bluez/org.bluez.Adapter1.xml index a1e6babe..121c277e 100644 --- a/src/bluetooth/bluez/org.bluez.Adapter1.xml +++ b/src/bluetooth/bluez/org.bluez.Adapter1.xml @@ -7,6 +7,10 @@ + + + + -- cgit v1.2.3 From 892d50020da29807d328b07d7568990e803c36f0 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 21 Jul 2017 14:37:23 +0200 Subject: Use Bluez's SetDiscoveryFilter to control the device discovery method Task-number: QTBUG-57575 Change-Id: Ia289bcb1e0172e74bbda7f4b2dbc904ca1f5a856 Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothdevicediscoveryagent.cpp | 8 ++++- .../qbluetoothdevicediscoveryagent_bluez.cpp | 34 +++++++++++++++++++--- src/bluetooth/qbluetoothdevicediscoveryagent_p.h | 2 +- 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index 02ea30d1..5f142f1a 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -333,13 +333,19 @@ void QBluetoothDeviceDiscoveryAgent::start() } /*! - Start Bluetooth device discovery, if it is not already started and the provided + Starts Bluetooth device discovery, if it is not already started and the provided \a methods are supported. The discovery \a methods limit the scope of the device search. For example, if the target service or device is a Bluetooth Low Energy device, this function could be used to limit the search to Bluetooth Low Energy devices and thereby reduces the discovery time significantly. + \note \a methods only determines the type of discovery and does not imply + the filtering of the results. For example, the search may still contain classic bluetooth devices + despite \a methods being set to \l {QBluetoothDeviceDiscoveryAgent::LowEnergyMethod} + {LowEnergyMethod} only. This may happen due to previously cached search results + which may be incorporated into the search results. + \since 5.8 */ void QBluetoothDeviceDiscoveryAgent::start(DiscoveryMethods methods) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index f2ca4233..3cc3354a 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -125,7 +125,7 @@ QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent: return (ClassicMethod | LowEnergyMethod); } -void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods /*methods*/) +void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods) { // Currently both BlueZ backends do not distinguish discovery methods. // The DBus API's always return both device types. Therefore we ignore @@ -139,7 +139,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent discoveredDevices.clear(); if (managerBluez5) { - startBluez5(); + startBluez5(methods); return; } @@ -228,11 +228,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent } } -void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5() +void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods) { Q_Q(QBluetoothDeviceDiscoveryAgent); - bool ok = false; const QString adapterPath = findAdapterForAddress(m_adapterAddress, &ok); if (!ok || adapterPath.isEmpty()) { @@ -257,6 +256,33 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5() return; } + QVariantMap map; + if (methods == (QBluetoothDeviceDiscoveryAgent::LowEnergyMethod|QBluetoothDeviceDiscoveryAgent::ClassicMethod)) + map.insert(QStringLiteral("Transport"), QStringLiteral("auto")); + else if (methods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod) + map.insert(QStringLiteral("Transport"), QStringLiteral("le")); + else + map.insert(QStringLiteral("Transport"), QStringLiteral("bredr")); + + // older BlueZ 5.x versions don't have this function + // filterReply returns UnknownMethod which we ignore + QDBusPendingReply<> filterReply = adapterBluez5->SetDiscoveryFilter(map); + filterReply.waitForFinished(); + if (filterReply.isError()) { + if (filterReply.error().type() == QDBusError::Other + && filterReply.error().name() == QStringLiteral("org.bluez.Error.Failed")) { + qCDebug(QT_BT_BLUEZ) << "Discovery method" << methods << "not supported"; + lastError = QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod; + errorString = QBluetoothDeviceDiscoveryAgent::tr("One or more device discovery methods " + "are not supported on this platform"); + delete adapterBluez5; + adapterBluez5 = 0; + emit q->error(lastError); + return; + } else if (filterReply.error().type() != QDBusError::UnknownMethod) { + qCDebug(QT_BT_BLUEZ) << "SetDiscoveryFilter failed:" << filterReply.error(); + } + } QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path()); QObject::connect(QtBluezDiscoveryManager::instance(), SIGNAL(discoveryInterrupted(QString)), diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index 7b57abb2..13d85a94 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -153,7 +153,7 @@ private: QList propertyMonitors; void deviceFoundBluez5(const QString& devicePath); - void startBluez5(); + void startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods); bool useExtendedDiscovery; QTimer extendedDiscoveryTimer; -- cgit v1.2.3 From 96590b7d608ef25c21a2025d368b50b56b958364 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 25 Jul 2017 14:56:45 +0200 Subject: Windows: Fix namespaced build Change-Id: I9f6a7c3884c2d7c9b0856a0e9a689ad88cca59fe Reviewed-by: Maurice Kalinowski --- src/bluetooth/qbluetoothdevicediscoveryagent_p.h | 4 ++-- src/bluetooth/qbluetoothservicediscoveryagent_p.h | 8 ++++---- src/bluetooth/qbluetoothsocket_p.h | 6 ++++-- src/bluetooth/qlowenergycontroller_p.h | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index 7b57abb2..44834024 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -78,12 +78,12 @@ class QDBusVariant; QT_END_NAMESPACE #endif +QT_BEGIN_NAMESPACE + #ifdef QT_WINRT_BLUETOOTH class QWinRTBluetoothDeviceDiscoveryWorker; #endif -QT_BEGIN_NAMESPACE - class QBluetoothDeviceDiscoveryAgentPrivate #if defined(QT_ANDROID_BLUETOOTH) || defined(QT_WINRT_BLUETOOTH) : public QObject diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.h b/src/bluetooth/qbluetoothservicediscoveryagent_p.h index 9a8da5e3..c4ea20a9 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.h @@ -72,10 +72,6 @@ class QXmlStreamReader; QT_END_NAMESPACE #endif -#ifdef QT_WINRT_BLUETOOTH -class QWinRTBluetoothServiceDiscoveryWorker; -#endif - QT_BEGIN_NAMESPACE class QBluetoothDeviceDiscoveryAgent; @@ -86,6 +82,10 @@ class LocalDeviceBroadcastReceiver; #include #endif +#ifdef QT_WINRT_BLUETOOTH +class QWinRTBluetoothServiceDiscoveryWorker; +#endif + class QBluetoothServiceDiscoveryAgentPrivate #if defined QT_WINRT_BLUETOOTH : public QObject diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h index 9aabf660..907acbe2 100644 --- a/src/bluetooth/qbluetoothsocket_p.h +++ b/src/bluetooth/qbluetoothsocket_p.h @@ -77,8 +77,6 @@ namespace ABI { } } } - -class SocketWorker; #endif // QT_WINRT_BLUETOOTH #ifndef QPRIVATELINEARBUFFER_BUFFERSIZE @@ -92,6 +90,10 @@ QT_FORWARD_DECLARE_CLASS(QSocketNotifier) QT_BEGIN_NAMESPACE +#ifdef QT_WINRT_BLUETOOTH +class SocketWorker; +#endif + class QBluetoothServiceDiscoveryAgent; class QSocketServerPrivate diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index 5c680c3b..b92716e9 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -85,8 +85,6 @@ QT_END_NAMESPACE #elif defined(QT_WINRT_BLUETOOTH) #include #include - -class QWinRTLowEnergyServiceHandler; #endif #include @@ -103,6 +101,8 @@ class QSocketNotifier; class RemoteDeviceManager; #elif defined(QT_ANDROID_BLUETOOTH) class LowEnergyNotificationHub; +#elif defined(QT_WINRT_BLUETOOTH) +class QWinRTLowEnergyServiceHandler; #endif extern void registerQLowEnergyControllerMetaType(); -- cgit v1.2.3 From 8646dd8a830225b1697dc1cafff32bba0ade84c5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 21 Jul 2017 12:16:53 +0200 Subject: Use QSharedPointer::create() more This is the result of running the (experimental) clang-tidy check qt-modernize-qsharedpointer-create Discarded changes: none. Change-Id: I58a0f230516e836df62b40cf8ec38a6b3d7122db Reviewed-by: Thiago Macieira Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserviceinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp index d2920d78..e4e5d1ed 100644 --- a/src/bluetooth/qbluetoothserviceinfo.cpp +++ b/src/bluetooth/qbluetoothserviceinfo.cpp @@ -342,7 +342,7 @@ bool QBluetoothServiceInfo::unregisterService() Construct a new invalid QBluetoothServiceInfo; */ QBluetoothServiceInfo::QBluetoothServiceInfo() - : d_ptr(QSharedPointer(new QBluetoothServiceInfoPrivate)) + : d_ptr(QSharedPointer::create()) { } -- cgit v1.2.3 From e9cb913a37318284353790f46edc648a630d758f Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 1 Aug 2017 15:44:13 +0200 Subject: winrt: Check for valid m_socketObject before accessing socket information If the socket was created without giving the socket type, ensureNativeSocket was not called and thus m_socketObject is 0. Calling localName and friends caused a crash because they accesses the object unconditionally. Change-Id: I442e3d1492458161fb8660f1b2f17d52b37a2935 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket_winrt.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 4a9d1b93..501ffd74 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -422,6 +422,9 @@ QString QBluetoothSocketPrivate::localName() const QBluetoothAddress QBluetoothSocketPrivate::localAddress() const { + if (!m_socketObject) + return QBluetoothAddress(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -437,6 +440,9 @@ QBluetoothAddress QBluetoothSocketPrivate::localAddress() const quint16 QBluetoothSocketPrivate::localPort() const { + if (!m_socketObject) + return 0; + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -449,6 +455,9 @@ quint16 QBluetoothSocketPrivate::localPort() const QString QBluetoothSocketPrivate::peerName() const { + if (!m_socketObject) + return QString(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -464,6 +473,9 @@ QString QBluetoothSocketPrivate::peerName() const QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const { + if (!m_socketObject) + return QBluetoothAddress(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -479,6 +491,9 @@ QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const quint16 QBluetoothSocketPrivate::peerPort() const { + if (!m_socketObject) + return 0; + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); -- cgit v1.2.3 From aeeae7bc92f19778a73fb10a09b8949b2c384d39 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Fri, 7 Jul 2017 13:15:51 +0200 Subject: winrt: Ensure that QLowEnergyController::RemoteHostClosedError is emitted As there is no Windows API to disconnect from a BTLE device, we just set the internal state in QLowEnergyController::disconnectFromDevice. By removing the callback registration in disconnectFromDevice we can be sure, that every state change from connected to disconnected is caused by the remote host closing the connection and thus implement RemoteHostClosedError. Change-Id: I7dcacaffce68784cb297b02df2e9f9356bf14d9d Reviewed-by: Maurice Kalinowski --- src/bluetooth/qlowenergycontroller_winrt.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index d6fc4952..8d3d85d8 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -338,6 +338,7 @@ void QLowEnergyControllerPrivate::connectToDevice() emit q->connected(); } else if (state == QLowEnergyController::ConnectedState && status == BluetoothConnectionStatus::BluetoothConnectionStatus_Disconnected) { + setError(QLowEnergyController::RemoteHostClosedError); setState(QLowEnergyController::UnconnectedState); emit q->disconnected(); } @@ -419,6 +420,10 @@ void QLowEnergyControllerPrivate::disconnectFromDevice() Q_Q(QLowEnergyController); setState(QLowEnergyController::UnconnectedState); emit q->disconnected(); + if (mDevice && mStatusChangedToken.value) { + mDevice->remove_ConnectionStatusChanged(mStatusChangedToken); + mStatusChangedToken.value = 0; + } } ComPtr QLowEnergyControllerPrivate::getNativeService(const QBluetoothUuid &serviceUuid) -- cgit v1.2.3 From d1d06bf7ad2f0c02165f17904d219fc535477f25 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 3 Aug 2017 11:15:11 +0200 Subject: winrt: Fix crash in QBluetoothServer::nextPendingConnection If there are no pending connections, the call should not make the application crash but just return nullptr. Change-Id: I33c2ec9b47bbb72abc99ad22035f794724b295ef Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserver_winrt.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothserver_winrt.cpp b/src/bluetooth/qbluetoothserver_winrt.cpp index 61134c1f..ddd71c21 100644 --- a/src/bluetooth/qbluetoothserver_winrt.cpp +++ b/src/bluetooth/qbluetoothserver_winrt.cpp @@ -217,6 +217,8 @@ bool QBluetoothServer::hasPendingConnections() const QBluetoothSocket *QBluetoothServer::nextPendingConnection() { Q_D(QBluetoothServer); + if (d->pendingConnections.count() == 0) + return nullptr; ComPtr socket = d->pendingConnections.takeFirst(); -- cgit v1.2.3 From 687ec9eb370e9538264280b58bed4d3b1c889579 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 2 Aug 2017 11:53:54 +0200 Subject: Avoid recursion during QBluetoothDeviceDiscoveryAgent::stop() QBluetoothDeviceDiscoveryAgent (DDA) is deleted by QBluetoothServiceDiscoveryAgent (SDA) once it receives an error or SDA is instructed to stop() the discovery process. Currently, this triggers at least two calls to the DDA's stop() function. In addition, if stop() generates an error the error call itself will call back to DDA:stop(). Therefore it create an endless loop back. This is at least true for the Android devices mentioned in the related bug report. This patch ensures that the main logic of Android's DDA::stop() is not called more than once. Further more SDA disconnects from DDA's signals to avoid a potential endless loop. Any error in DDA is not of relevance to the surrounding SDA instance anymore. Task-number: QTBUG-60131 Change-Id: I1df16f2b0896928833aa2ced75c43d4642b4fba3 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp | 3 +++ src/bluetooth/qbluetoothservicediscoveryagent.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index ed6507f3..7e8e4236 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -225,6 +225,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop() return; if (m_active == SDPScanActive) { + if (pendingCancel) + return; + pendingCancel = true; pendingStart = false; bool success = adapter.callMethod("cancelDiscovery"); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 7daab4b7..d6163f0e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -450,6 +450,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery() */ void QBluetoothServiceDiscoveryAgentPrivate::stopDeviceDiscovery() { + // disconnect to avoid recursion during stop() - QTBUG-60131 + // we don't care about a potential signals from device discovery agent anymore + deviceDiscoveryAgent->disconnect(); + deviceDiscoveryAgent->stop(); delete deviceDiscoveryAgent; deviceDiscoveryAgent = 0; @@ -497,6 +501,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryError(QBluetoothD error = static_cast(newError); errorString = deviceDiscoveryAgent->errorString(); + // disconnect to avoid recursion during stop() - QTBUG-60131 + // we don't care about a potential signals from device discovery agent anymore + deviceDiscoveryAgent->disconnect(); + deviceDiscoveryAgent->stop(); delete deviceDiscoveryAgent; deviceDiscoveryAgent = 0; -- cgit v1.2.3 From 94cc2b914a027fbcb7a1eb6cb34af45d0c07d2a4 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 17 Aug 2017 15:26:24 +0200 Subject: winrt: Make sure that "finished" is emitted for device discovery If we do not scan for low energy devices, the timeout will never be triggered. In this case the discovery is finished as soon as every paired device has been handled by the worker. Change-Id: I59772e706ac0fbf62c560a54d650bef9815118b6 Reviewed-by: Maurice Kalinowski --- src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 1aaaf0a4..17726660 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -104,7 +104,7 @@ private: HRESULT onBluetoothLEDeviceFound(ComPtr device, PairingCheck pairingCheck = CheckForPairing); public slots: - void handleLeTimeout(); + void finishDiscovery(); Q_SIGNALS: void deviceFound(const QBluetoothDeviceInfo &info); @@ -247,7 +247,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() Q_ASSERT_SUCCEEDED(hr); } -void QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout() +void QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery() { emit scanFinished(); deleteLater(); @@ -263,6 +263,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync HRESULT hr = m_deviceStatics->FromIdAsync(deviceId, &deviceFromIdOperation); if (FAILED(hr)) { --m_pendingPairedDevices; + if (!m_pendingPairedDevices + && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) + finishDiscovery(); qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id"; return S_OK; } @@ -271,6 +274,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync (this, &QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoundAsync).Get()); if (FAILED(hr)) { --m_pendingPairedDevices; + if (!m_pendingPairedDevices + && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) + finishDiscovery(); qCWarning(QT_BT_WINRT) << "Could not register device found callback"; return S_OK; } @@ -386,6 +392,8 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoun QMetaObject::invokeMethod(this, "deviceFound", Qt::AutoConnection, Q_ARG(QBluetoothDeviceInfo, info)); + if (!m_pendingPairedDevices && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) + finishDiscovery(); return S_OK; } @@ -556,7 +564,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent leScanTimer->setSingleShot(true); } connect(leScanTimer, &QTimer::timeout, - worker, &QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout); + worker, &QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery); leScanTimer->setInterval(lowEnergySearchTimeout); leScanTimer->start(); } @@ -619,7 +627,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::disconnectAndClearWorker() q, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered); if (leScanTimer) { disconnect(leScanTimer, &QTimer::timeout, - worker, &QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout); + worker, &QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery); } worker.clear(); } -- cgit v1.2.3 From dbd70341ea47122239ec90304f1d6c66c34a4acd Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 1 Aug 2017 09:27:22 +0200 Subject: Add configure test to detect presence of winrt API Instead of checking for a certain Windows version, we should check whether the API is actually available [ChangeLog][QtBluetooth][Windows] Enabled UWP backend for desktop Windows versions that support the API Task-number: QTBUG-61566 Change-Id: I8384119c70cc2c4bdcdbe6b297cfcf5fb3e3f534 Reviewed-by: Oswald Buddenhagen Reviewed-by: Maurice Kalinowski --- src/bluetooth/bluetooth.pro | 19 ++++++-- src/bluetooth/configure.json | 13 ++++- .../qbluetoothdevicediscoveryagent_winrt.cpp | 4 ++ src/bluetooth/qbluetoothserver_winrt.cpp | 3 ++ .../qbluetoothservicediscoveryagent_winrt.cpp | 3 ++ src/bluetooth/qbluetoothserviceinfo_winrt.cpp | 3 ++ src/bluetooth/qbluetoothsocket_winrt.cpp | 3 ++ src/bluetooth/qbluetoothutils_win.cpp | 56 ++++++++++++++++++++++ src/bluetooth/qlowenergycontroller_winrt.cpp | 3 ++ 9 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 src/bluetooth/qbluetoothutils_win.cpp (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 233cdb3b..b0e78d39 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -77,6 +77,11 @@ SOURCES += \ qlowenergycontroller.cpp \ qlowenergyserviceprivate.cpp +win32 { + WINDOWS_SDK_VERSION_STRING = $$(WindowsSDKVersion) + WINDOWS_SDK_VERSION = $$member($$list($$split(WINDOWS_SDK_VERSION_STRING, .)), 2) +} + qtConfig(bluez) { QT_PRIVATE = concurrent QT_FOR_PRIVATE += dbus @@ -188,8 +193,14 @@ qtConfig(bluez) { SOURCES -= qbluetoothdevicediscoveryagent.cpp SOURCES -= qlowenergyservice.cpp SOURCES -= qlowenergycontroller.cpp -} else:winrt { +} else: qtConfig(winrt_bt) { DEFINES += QT_WINRT_BLUETOOTH + !winrt { + SOURCES += qbluetoothutils_win.cpp + DEFINES += CLASSIC_APP_BUILD + LIBS += runtimeobject.lib + } + QT += core-private SOURCES += \ @@ -201,11 +212,9 @@ qtConfig(bluez) { qbluetoothsocket_winrt.cpp \ qlowenergycontroller_winrt.cpp - WINRT_SDK_VERSION_STRING = $$(UCRTVersion) - WINRT_SDK_VERSION = $$member($$list($$split(WINRT_SDK_VERSION_STRING, .)), 2) - lessThan(WINRT_SDK_VERSION, 14393) { + lessThan(WINDOWS_SDK_VERSION, 14393) { DEFINES += QT_WINRT_LIMITED_SERVICEDISCOVERY - DEFINES += QT_UCRTVERSION=$$WINRT_SDK_VERSION + DEFINES += QT_UCRTVERSION=$$WINDOWS_SDK_VERSION } } else { message("Unsupported Bluetooth platform, will not build a working QtBluetooth library.") diff --git a/src/bluetooth/configure.json b/src/bluetooth/configure.json index a1e65000..3153aca6 100644 --- a/src/bluetooth/configure.json +++ b/src/bluetooth/configure.json @@ -23,6 +23,11 @@ "label": "Linux Crypto API", "type": "compile", "test": "linux_crypto_api" + }, + "winrt_bt": { + "label": "WinRT Bluetooth API", + "type": "compile", + "test": "winrt_bt" } }, @@ -41,6 +46,11 @@ "label": "Linux Crypto API", "condition": "features.bluez_le && tests.linux_crypto_api", "output": [ "privateFeature" ] + }, + "winrt_bt": { + "label": "WinRT Bluetooth API (desktop & UWP)", + "condition": "config.win32 && tests.winrt_bt", + "output": [ "privateFeature" ] } }, @@ -64,7 +74,8 @@ Only classic Bluetooth will be available." "entries": [ "bluez", "bluez_le", - "linux_crypto_api" + "linux_crypto_api", + "winrt_bt" ] } ] diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 1aaaf0a4..363bc438 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -41,6 +41,10 @@ #include "qbluetoothdevicediscoveryagent_p.h" #include "qbluetoothaddress.h" #include "qbluetoothuuid.h" + +#ifdef CLASSIC_APP_BUILD +#define Q_OS_WINRT +#endif #include "qfunctions_winrt.h" #include diff --git a/src/bluetooth/qbluetoothserver_winrt.cpp b/src/bluetooth/qbluetoothserver_winrt.cpp index ddd71c21..f478dc93 100644 --- a/src/bluetooth/qbluetoothserver_winrt.cpp +++ b/src/bluetooth/qbluetoothserver_winrt.cpp @@ -44,6 +44,9 @@ #include #include +#ifdef CLASSIC_APP_BUILD +#define Q_OS_WINRT +#endif #include #include diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp index 29ccb290..77310d01 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp @@ -40,6 +40,9 @@ #include "qbluetoothservicediscoveryagent.h" #include "qbluetoothservicediscoveryagent_p.h" +#ifdef CLASSIC_APP_BUILD +#define Q_OS_WINRT +#endif #include #include #include diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp index d72056b7..975a3f4a 100644 --- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp @@ -42,6 +42,9 @@ #include "qbluetoothserver_p.h" #include +#ifdef CLASSIC_APP_BUILD +#define Q_OS_WINRT +#endif #include #include diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 365fe046..ec511974 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -40,6 +40,9 @@ #include "qbluetoothsocket.h" #include "qbluetoothsocket_p.h" +#ifdef CLASSIC_APP_BUILD +#define Q_OS_WINRT +#endif #include #include diff --git a/src/bluetooth/qbluetoothutils_win.cpp b/src/bluetooth/qbluetoothutils_win.cpp new file mode 100644 index 00000000..d561dcef --- /dev/null +++ b/src/bluetooth/qbluetoothutils_win.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#define Q_OS_WINRT +#include + +QT_BEGIN_NAMESPACE + +#pragma warning (push) +#pragma warning (disable: 4273) +HRESULT QEventDispatcherWinRT::runOnXamlThread(const std::function &delegate, bool waitForRun) +{ + Q_UNUSED(waitForRun) + return delegate(); +} +#pragma warning (pop) + +QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index 8d3d85d8..62b8a9d3 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -39,6 +39,9 @@ #include "qlowenergycontroller_p.h" +#ifdef CLASSIC_APP_BUILD +#define Q_OS_WINRT +#endif #include #include #include -- cgit v1.2.3 From 8f1bd6c6c017a0e28160c5325d1c5c86a3e16384 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 7 Aug 2017 13:25:45 +0200 Subject: windows: Make sure everything is properly CoInitialized on desktop use Task-number: QTBUG-61566 Change-Id: I5f8ff2c3e8a841ab8c5a3fb465d0be4b003d7a2b Reviewed-by: Friedemann Kleint Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 6 ++++++ src/bluetooth/qbluetoothserver_winrt.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 363bc438..e9641344 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -133,6 +133,9 @@ QWinRTBluetoothDeviceDiscoveryWorker::QWinRTBluetoothDeviceDiscoveryWorker(QBlue { qRegisterMetaType(); +#ifdef CLASSIC_APP_BUILD + CoInitialize(NULL); +#endif HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothDevice).Get(), &m_deviceStatics); Q_ASSERT_SUCCEEDED(hr); hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothLEDevice).Get(), &m_leDeviceStatics); @@ -142,6 +145,9 @@ QWinRTBluetoothDeviceDiscoveryWorker::QWinRTBluetoothDeviceDiscoveryWorker(QBlue QWinRTBluetoothDeviceDiscoveryWorker::~QWinRTBluetoothDeviceDiscoveryWorker() { stop(); +#ifdef CLASSIC_APP_BUILD + CoUninitialize(); +#endif } void QWinRTBluetoothDeviceDiscoveryWorker::start() diff --git a/src/bluetooth/qbluetoothserver_winrt.cpp b/src/bluetooth/qbluetoothserver_winrt.cpp index f478dc93..08aa45b4 100644 --- a/src/bluetooth/qbluetoothserver_winrt.cpp +++ b/src/bluetooth/qbluetoothserver_winrt.cpp @@ -73,6 +73,9 @@ QHash __fakeServerPorts; QBluetoothServerPrivate::QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol sType) : maxPendingConnections(1), serverType(sType), m_lastError(QBluetoothServer::NoError), socket(0) { +#ifdef CLASSIC_APP_BUILD + CoInitialize(NULL); +#endif socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); } @@ -82,6 +85,12 @@ QBluetoothServerPrivate::~QBluetoothServerPrivate() __fakeServerPorts.remove(this); if (socket) delete socket; +#ifdef CLASSIC_APP_BUILD + // If we do not reset that pointer, socketListener will go out of scope after CoUninitialize was + // called, which will lead to a crash. + socketListener = nullptr; + CoUninitialize(); +#endif } bool QBluetoothServerPrivate::isListening() const -- cgit v1.2.3 From 36997810d9fec492635152be89efaa55208e224a Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 21 Aug 2017 14:20:25 +0200 Subject: Rename qbluetoothglobal.h to qtbluetoothglobal.h ... and deprecate the former. By doing so we get the header file in line with other modules - see qtnetworkglobal.h for example. The include is not used in the examples so it is removed there. Change-Id: Ie6267738d4a45e45a0350d458a40654d8a952f4a Reviewed-by: Oswald Buddenhagen Reviewed-by: Alex Blasche --- src/bluetooth/android/jni_android.cpp | 2 +- src/bluetooth/bluetooth.pro | 2 +- src/bluetooth/qbluetooth.h | 2 +- src/bluetooth/qbluetoothaddress.h | 2 +- src/bluetooth/qbluetoothdevicediscoveryagent.h | 2 +- src/bluetooth/qbluetoothdeviceinfo.h | 2 +- src/bluetooth/qbluetoothglobal.h | 59 ------------------------- src/bluetooth/qbluetoothhostinfo.h | 2 +- src/bluetooth/qbluetoothlocaldevice.h | 2 +- src/bluetooth/qbluetoothlocaldevice_p.h | 2 +- src/bluetooth/qbluetoothserver.h | 2 +- src/bluetooth/qbluetoothservicediscoveryagent.h | 2 +- src/bluetooth/qbluetoothserviceinfo.h | 2 +- src/bluetooth/qbluetoothsocket.h | 2 +- src/bluetooth/qbluetoothtransfermanager.h | 2 +- src/bluetooth/qbluetoothtransferrequest.h | 2 +- src/bluetooth/qbluetoothtransferrequest_p.h | 2 +- src/bluetooth/qbluetoothuuid.h | 2 +- src/bluetooth/qlowenergyadvertisingdata.h | 2 +- src/bluetooth/qlowenergyadvertisingparameters.h | 2 +- src/bluetooth/qlowenergyconnectionparameters.h | 2 +- src/bluetooth/qlowenergyservicedata.h | 2 +- src/bluetooth/qtbluetoothglobal.h | 59 +++++++++++++++++++++++++ 23 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 src/bluetooth/qbluetoothglobal.h create mode 100644 src/bluetooth/qtbluetoothglobal.h (limited to 'src/bluetooth') diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp index 68e291e5..176416c8 100644 --- a/src/bluetooth/android/jni_android.cpp +++ b/src/bluetooth/android/jni_android.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include "android/jni_android_p.h" #include "android/androidbroadcastreceiver_p.h" #include "android/serveracceptancethread_p.h" diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index b0e78d39..8dd748c7 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -6,7 +6,7 @@ QMAKE_DOCS = $$PWD/doc/qtbluetooth.qdocconf OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator PUBLIC_HEADERS += \ - qbluetoothglobal.h \ + qtbluetoothglobal.h \ qbluetoothaddress.h\ qbluetoothhostinfo.h \ qbluetoothuuid.h\ diff --git a/src/bluetooth/qbluetooth.h b/src/bluetooth/qbluetooth.h index 82136eca..df763147 100644 --- a/src/bluetooth/qbluetooth.h +++ b/src/bluetooth/qbluetooth.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTH_H #define QBLUETOOTH_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/bluetooth/qbluetoothaddress.h b/src/bluetooth/qbluetoothaddress.h index de2d4240..e3750d21 100644 --- a/src/bluetooth/qbluetoothaddress.h +++ b/src/bluetooth/qbluetoothaddress.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHADDRESS_H #define QBLUETOOTHADDRESS_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h index 17827656..62050282 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHDEVICEDISCOVERYAGENT_H #define QBLUETOOTHDEVICEDISCOVERYAGENT_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h index 5ff17e1c..33cd40b7 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.h +++ b/src/bluetooth/qbluetoothdeviceinfo.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHDEVICEINFO_H #define QBLUETOOTHDEVICEINFO_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothglobal.h b/src/bluetooth/qbluetoothglobal.h deleted file mode 100644 index 45867e94..00000000 --- a/src/bluetooth/qbluetoothglobal.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtBluetooth module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QTBLUETOOTH_H -#define QTBLUETOOTH_H - -#include -#include // for feature detection - -QT_BEGIN_NAMESPACE - -#ifndef QT_STATIC -# if defined(QT_BUILD_BLUETOOTH_LIB) -# define Q_BLUETOOTH_EXPORT Q_DECL_EXPORT -# else -# define Q_BLUETOOTH_EXPORT Q_DECL_IMPORT -# endif -#else -# define Q_BLUETOOTH_EXPORT -#endif - -QT_END_NAMESPACE - -#endif // QTBLUETOOTH_H diff --git a/src/bluetooth/qbluetoothhostinfo.h b/src/bluetooth/qbluetoothhostinfo.h index e92bdb5c..42dfcaab 100644 --- a/src/bluetooth/qbluetoothhostinfo.h +++ b/src/bluetooth/qbluetoothhostinfo.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHHOSTINFO_H #define QBLUETOOTHHOSTINFO_H -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/bluetooth/qbluetoothlocaldevice.h b/src/bluetooth/qbluetoothlocaldevice.h index 49de25ae..9363a116 100644 --- a/src/bluetooth/qbluetoothlocaldevice.h +++ b/src/bluetooth/qbluetoothlocaldevice.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHLOCALDEVICE_H #define QBLUETOOTHLOCALDEVICE_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h index acd88083..a52b683c 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.h +++ b/src/bluetooth/qbluetoothlocaldevice_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include +#include #include "qbluetoothlocaldevice.h" diff --git a/src/bluetooth/qbluetoothserver.h b/src/bluetooth/qbluetoothserver.h index 568ca3d9..e6e4a68f 100644 --- a/src/bluetooth/qbluetoothserver.h +++ b/src/bluetooth/qbluetoothserver.h @@ -41,7 +41,7 @@ #ifndef QBLUETOOTHSERVER_H #define QBLUETOOTHSERVER_H -#include +#include #include diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h index ba0b91b8..12df37a8 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.h +++ b/src/bluetooth/qbluetoothservicediscoveryagent.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHSERVICEDISCOVERYAGENT_H #define QBLUETOOTHSERVICEDISCOVERYAGENT_H -#include +#include #include diff --git a/src/bluetooth/qbluetoothserviceinfo.h b/src/bluetooth/qbluetoothserviceinfo.h index 38cddfb6..cc4041e2 100644 --- a/src/bluetooth/qbluetoothserviceinfo.h +++ b/src/bluetooth/qbluetoothserviceinfo.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHSERVICEINFO_H #define QBLUETOOTHSERVICEINFO_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h index 2b1bd3cf..bbcecbf4 100644 --- a/src/bluetooth/qbluetoothsocket.h +++ b/src/bluetooth/qbluetoothsocket.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHSOCKET_H #define QBLUETOOTHSOCKET_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothtransfermanager.h b/src/bluetooth/qbluetoothtransfermanager.h index d1171588..756fe54f 100644 --- a/src/bluetooth/qbluetoothtransfermanager.h +++ b/src/bluetooth/qbluetoothtransfermanager.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHTRANSFERMANAGER_H #define QBLUETOOTHTRANSFERMANAGER_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothtransferrequest.h b/src/bluetooth/qbluetoothtransferrequest.h index 006f1ced..5485a0d9 100644 --- a/src/bluetooth/qbluetoothtransferrequest.h +++ b/src/bluetooth/qbluetoothtransferrequest.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHTRANSFERREQUEST_H #define QBLUETOOTHTRANSFERREQUEST_H -#include +#include #include #include diff --git a/src/bluetooth/qbluetoothtransferrequest_p.h b/src/bluetooth/qbluetoothtransferrequest_p.h index d8b2e55d..410a9709 100644 --- a/src/bluetooth/qbluetoothtransferrequest_p.h +++ b/src/bluetooth/qbluetoothtransferrequest_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include +#include #include "qbluetoothtransferrequest.h" QT_BEGIN_NAMESPACE diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h index fb301c37..2a2ce138 100644 --- a/src/bluetooth/qbluetoothuuid.h +++ b/src/bluetooth/qbluetoothuuid.h @@ -40,7 +40,7 @@ #ifndef QBLUETOOTHUUID_H #define QBLUETOOTHUUID_H -#include +#include #include #include diff --git a/src/bluetooth/qlowenergyadvertisingdata.h b/src/bluetooth/qlowenergyadvertisingdata.h index 904c5c2b..0fc55adb 100644 --- a/src/bluetooth/qlowenergyadvertisingdata.h +++ b/src/bluetooth/qlowenergyadvertisingdata.h @@ -40,7 +40,7 @@ #ifndef QLOWENERGYADVERTISINGDATA_H #define QLOWENERGYADVERTISINGDATA_H -#include +#include #include #include diff --git a/src/bluetooth/qlowenergyadvertisingparameters.h b/src/bluetooth/qlowenergyadvertisingparameters.h index 547e5798..055026e6 100644 --- a/src/bluetooth/qlowenergyadvertisingparameters.h +++ b/src/bluetooth/qlowenergyadvertisingparameters.h @@ -40,7 +40,7 @@ #ifndef QLOWENERGYADVERTISINGPARAMETERS_H #define QLOWENERGYADVERTISINGPARAMETERS_H -#include +#include #include #include #include diff --git a/src/bluetooth/qlowenergyconnectionparameters.h b/src/bluetooth/qlowenergyconnectionparameters.h index 9a3896c3..c765763f 100644 --- a/src/bluetooth/qlowenergyconnectionparameters.h +++ b/src/bluetooth/qlowenergyconnectionparameters.h @@ -40,7 +40,7 @@ #ifndef QLOWENERGYCONNECTIONPARAMETERS_H #define QLOWENERGYCONNECTIONPARAMETERS_H -#include +#include #include #include diff --git a/src/bluetooth/qlowenergyservicedata.h b/src/bluetooth/qlowenergyservicedata.h index 48f7fe89..4d553267 100644 --- a/src/bluetooth/qlowenergyservicedata.h +++ b/src/bluetooth/qlowenergyservicedata.h @@ -40,7 +40,7 @@ #ifndef QLOWENERGYSERVICEDATA_H #define QLOWENERGYSERVICEDATA_H -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/bluetooth/qtbluetoothglobal.h b/src/bluetooth/qtbluetoothglobal.h new file mode 100644 index 00000000..40b6d3d2 --- /dev/null +++ b/src/bluetooth/qtbluetoothglobal.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QTBLUETOOTH_H +#define QTBLUETOOTH_H + +#include +#include // for feature detection + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_BLUETOOTH_LIB) +# define Q_BLUETOOTH_EXPORT Q_DECL_EXPORT +# else +# define Q_BLUETOOTH_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_BLUETOOTH_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QTBLUETOOTH_H -- cgit v1.2.3 From 17ee18f99ef8e6cd39d48e089e6e8ca4e01073cd Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 21 Aug 2017 14:35:36 +0200 Subject: Add missing qtbluetoothglobal_p.h Change-Id: I6d1d5b5e8084afdb0dd5082c344975dda5e66d1a Reviewed-by: Oswald Buddenhagen Reviewed-by: Alex Blasche --- src/bluetooth/bluetooth.pro | 1 + src/bluetooth/qtbluetoothglobal_p.h | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/bluetooth/qtbluetoothglobal_p.h (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 8dd748c7..5f415341 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -33,6 +33,7 @@ PUBLIC_HEADERS += \ qlowenergycontroller.h PRIVATE_HEADERS += \ + qtbluetoothglobal_p.h \ qbluetoothaddress_p.h\ qbluetoothhostinfo_p.h \ qbluetoothdeviceinfo_p.h\ diff --git a/src/bluetooth/qtbluetoothglobal_p.h b/src/bluetooth/qtbluetoothglobal_p.h new file mode 100644 index 00000000..ffbfc4fe --- /dev/null +++ b/src/bluetooth/qtbluetoothglobal_p.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTBLUETOOTHGLOBAL_P_H +#define QTBLUETOOTHGLOBAL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include +#include + +#endif // QTBLUETOOTHGLOBAL_P_H -- cgit v1.2.3 From ed5a1134d50f6dbed3fc568c799a39f4e2338056 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Fri, 30 Jun 2017 12:13:36 +0200 Subject: Bail out early if Bluetooth is used on an unsupported Windows version Task-number: QTBUG-61566 Change-Id: Ie40762dbb07e9f29d862e75eba2bc05da088a34c Reviewed-by: Alex Blasche --- src/bluetooth/bluetooth.pro | 2 +- src/bluetooth/qbluetoothutils_win.cpp | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 5f415341..b45da961 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -199,7 +199,7 @@ qtConfig(bluez) { !winrt { SOURCES += qbluetoothutils_win.cpp DEFINES += CLASSIC_APP_BUILD - LIBS += runtimeobject.lib + LIBS += runtimeobject.lib user32.lib } QT += core-private diff --git a/src/bluetooth/qbluetoothutils_win.cpp b/src/bluetooth/qbluetoothutils_win.cpp index d561dcef..fa3127cb 100644 --- a/src/bluetooth/qbluetoothutils_win.cpp +++ b/src/bluetooth/qbluetoothutils_win.cpp @@ -42,6 +42,14 @@ #define Q_OS_WINRT #include +#include +#include + +using namespace Microsoft::WRL; +using namespace Microsoft::WRL::Wrappers; +using namespace ABI::Windows::Devices::Bluetooth; +using namespace ABI::Windows::Foundation; + QT_BEGIN_NAMESPACE #pragma warning (push) @@ -53,4 +61,34 @@ HRESULT QEventDispatcherWinRT::runOnXamlThread(const std::function &d } #pragma warning (pop) +extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: { + // Check if we are running on a recent enough Windows + HRESULT hr = OleInitialize(NULL); + if (FAILED(hr)) { + MessageBox(NULL, (LPCWSTR)L"OleInitialize failed.", (LPCWSTR)L"Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); + exit(-1); + } + ComPtr deviceStatics; + hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothDevice).Get(), &deviceStatics); + if (hr == REGDB_E_CLASSNOTREG) { + QString error ("This Windows version (" + QSysInfo::kernelVersion() + ") does not " + "support the required Bluetooth API. Consider updating to a more recent Windows " + "(10.0.10586 or above)."); + MessageBox(NULL, (LPCWSTR)error.constData(), (LPCWSTR)L"Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); + CoUninitialize(); + exit(-1); + } + break; + } + case DLL_PROCESS_DETACH: + CoUninitialize(); + } + + return TRUE; +} + QT_END_NAMESPACE -- cgit v1.2.3 From 19e6a952d9b736ae9e052d094f908946b4abebe3 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 31 Aug 2017 10:53:34 +0200 Subject: Enable macOS 10.13 in QtBluetooth A similar change was done earlier for iOS already. This is due to deprecated API. Task-number: QTBUG-62658 Change-Id: If1d4a0eae382e46e3224a6bd4a6e75309ff87cac Reviewed-by: Timur Pocheptsov --- src/bluetooth/osx/osxbtcentralmanager.mm | 8 ++++---- src/bluetooth/osx/osxbtledeviceinquiry.mm | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 9e5128c4..ec046d1b 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -1033,7 +1033,7 @@ QT_END_NAMESPACE using namespace OSXBluetooth; const auto state = central.state; -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (state == CBManagerStateUnknown || state == CBManagerStateResetting) { #else @@ -1049,7 +1049,7 @@ QT_END_NAMESPACE } // Let's check some states we do not like first: -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (state == CBManagerStateUnsupported || state == CBManagerStateUnauthorized) { #else if (state == CBCentralManagerStateUnsupported || state == CBCentralManagerStateUnauthorized) { @@ -1069,7 +1069,7 @@ QT_END_NAMESPACE return; } -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (state == CBManagerStatePoweredOff) { #else if (state == CBCentralManagerStatePoweredOff) { @@ -1088,7 +1088,7 @@ QT_END_NAMESPACE return; } -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (state == CBManagerStatePoweredOn) { #else if (state == CBCentralManagerStatePoweredOn) { diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index 05b20167..7a516dd4 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -234,7 +234,7 @@ QT_USE_NAMESPACE Q_ASSERT(leQueue); const auto state = central.state; -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (state == CBManagerStatePoweredOn) { #else if (state == CBCentralManagerStatePoweredOn) { @@ -259,7 +259,7 @@ QT_USE_NAMESPACE [manager scanForPeripheralsWithServices:nil options:nil]; } // Else we ignore. -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) } else if (state == CBManagerStateUnsupported || state == CBManagerStateUnauthorized) { #else } else if (state == CBCentralManagerStateUnsupported || state == CBCentralManagerStateUnauthorized) { @@ -276,7 +276,7 @@ QT_USE_NAMESPACE } [manager setDelegate:nil]; -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) } else if (state == CBManagerStatePoweredOff) { #else } else if (state == CBCentralManagerStatePoweredOff) { -- cgit v1.2.3 From eea38b6cfa7b0723f5b89b1d0a4b6cedddc6df12 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 1 Sep 2017 13:14:28 -0700 Subject: Remove 10.9 SDK workaround Qt can no longer be built with the 10.9 SDK. Change-Id: I51da5a48b9985255bb1015c2b401906100d497bd Reviewed-by: Timur Pocheptsov --- src/bluetooth/osx/osxbluetooth_p.h | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbluetooth_p.h b/src/bluetooth/osx/osxbluetooth_p.h index 93842e77..1c6ac761 100644 --- a/src/bluetooth/osx/osxbluetooth_p.h +++ b/src/bluetooth/osx/osxbluetooth_p.h @@ -67,33 +67,9 @@ #else -// CoreBluetooth with SDK 10.9 seems to be broken: the class CBPeripheralManager is enabled on macOS -// but some of its declarations are using a disabled enum CBPeripheralAuthorizationStatus -// (disabled using __attribute__ syntax and NS_ENUM_AVAILABLE macro). -// This + -std=c++11 ends with a compilation error. For the SDK 10.9 we can: -// 1. either undefine NS_ENUM_AVAILABLE macro (it works somehow) and redefine it as an empty sequence -// of pp-tokens or -// 2. define __attribute__ as an empty sequence. Both solutions look quite ugly. - -#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) && !QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10) - -// Must be included BEFORE CoreBluetooth.h: -#include - -#define CB_ERROR_WORKAROUND_REQUIRED -#undef NS_ENUM_AVAILABLE -#define NS_ENUM_AVAILABLE(_mac, _ios) - -#endif // SDK version == 10.9 - // In SDK below 10.12 IOBluetooth.h includes CoreBluetooth.h. #include -#ifdef CB_ERROR_WORKAROUND_REQUIRED -#undef __attribute__ -#undef CB_ERROR_WORKAROUND_REQUIRED -#endif // WORKAROUND - #endif // SDK #endif // QT_OSX_BLUETOOTH -- cgit v1.2.3 From f554300e1f2b69c77e7bbb5054231c2fc5c78928 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 1 Sep 2017 13:26:30 -0700 Subject: Simplify system frameworks includes The previous version was doing exactly this, but in a far more complicated manner. Change-Id: Ia8f6a418a7fc6eab03207ced099288b8d4e5f3a7 Reviewed-by: Timur Pocheptsov --- src/bluetooth/osx/osxbluetooth_p.h | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbluetooth_p.h b/src/bluetooth/osx/osxbluetooth_p.h index 1c6ac761..ea1b388f 100644 --- a/src/bluetooth/osx/osxbluetooth_p.h +++ b/src/bluetooth/osx/osxbluetooth_p.h @@ -54,23 +54,10 @@ #include -#ifndef QT_OSX_BLUETOOTH - -#include - -#else - -#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12) - #include -#include -#else - -// In SDK below 10.12 IOBluetooth.h includes CoreBluetooth.h. +#ifdef Q_OS_MACOS #include +#endif -#endif // SDK - -#endif // QT_OSX_BLUETOOTH #endif // OSXBLUETOOTH_P_H -- cgit v1.2.3 From ae21b2574c0000aac6e3b10f7e11ebd1da567ffd Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 5 Sep 2017 13:28:53 +0200 Subject: CoreBluetooth - use the right enumerators/constants with SDK 10.13 Like it was done for central manager - use the correct enumerators (types) - with 10.13 SDK they also use 'generic' CBManagerXXX constants on macOS instead of CBCentral/PeripheralManagerXXX constants. Task-number: QTBUG-62658 Change-Id: I4b4de239930f5e731dc4977ff3353512290ff3b2 Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtperipheralmanager.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtperipheralmanager.mm b/src/bluetooth/osx/osxbtperipheralmanager.mm index 9c443cf6..64c8cd90 100644 --- a/src/bluetooth/osx/osxbtperipheralmanager.mm +++ b/src/bluetooth/osx/osxbtperipheralmanager.mm @@ -391,7 +391,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data) if (peripheral != manager || !notifier) return; -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (peripheral.state == CBManagerStatePoweredOn) { #else if (peripheral.state == CBPeripheralManagerStatePoweredOn) { @@ -426,7 +426,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data) explicitly added again." */ -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) +#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) if (peripheral.state == CBManagerStateUnauthorized || peripheral.state == CBManagerStateUnsupported) { #else -- cgit v1.2.3 From dbb8f97bf3e3a50c6841ab79bbf4b5d6294b8d65 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 4 Sep 2017 22:09:04 -0700 Subject: Android: remove support for local/debug deployment This removes the pre-dexed JAR files activated by the absence of the bundled_jar_file CONFIG option, as versions of Android >= 5 no longer support this deployment mechanism. Now, the "bundled" JARs simply become normal JARs containing class files, and are neither activated by a bundled_jar_file CONFIG entry nor do they have a -bundled suffix in the file's base name. Task-number: QTBUG-62995 Change-Id: Ifc13542ff71844da7e80cefe9ff51e3d7cdfc830 Reviewed-by: Oswald Buddenhagen Reviewed-by: BogDan Vatra --- src/bluetooth/bluetooth.pro | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index b45da961..1ef7406b 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -126,8 +126,6 @@ qtConfig(bluez) { android.permission.BLUETOOTH_ADMIN \ android.permission.ACCESS_COARSE_LOCATION # since Android 6.0 (API lvl 23) ANDROID_BUNDLED_JAR_DEPENDENCIES = \ - jar/QtAndroidBluetooth-bundled.jar:org.qtproject.qt5.android.bluetooth.QtBluetoothBroadcastReceiver - ANDROID_JAR_DEPENDENCIES = \ jar/QtAndroidBluetooth.jar:org.qtproject.qt5.android.bluetooth.QtBluetoothBroadcastReceiver SOURCES += \ -- cgit v1.2.3 From 38e561011bb248ae9b803084eb66824588c7b22a Mon Sep 17 00:00:00 2001 From: Kevin Funk Date: Wed, 20 Sep 2017 20:57:38 +0200 Subject: Replace Q_DECL_OVERRIDE with override Change-Id: I1c1f2c3cf273cde5030d54901db554cb52e66557 Reviewed-by: Lars Knoll Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm | 8 ++++---- src/bluetooth/qbluetoothlocaldevice_osx.mm | 16 ++++++++-------- src/bluetooth/qbluetoothserver_osx_p.h | 4 ++-- src/bluetooth/qbluetoothservicediscoveryagent_osx.mm | 4 ++-- src/bluetooth/qbluetoothsocket_osx_p.h | 12 ++++++------ src/bluetooth/qbluetoothtransferreply_osx.mm | 12 ++++++------ src/bluetooth/qbluetoothtransferreply_osx_p.h | 8 ++++---- 7 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index 9e3f6a57..1318d768 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -90,7 +90,7 @@ public: QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress & address, QBluetoothDeviceDiscoveryAgent *q); - ~QBluetoothDeviceDiscoveryAgentPrivate() Q_DECL_OVERRIDE; + ~QBluetoothDeviceDiscoveryAgentPrivate() override; bool isValid() const; bool isActive() const; @@ -108,9 +108,9 @@ private: }; // DeviceInquiryDelegate: - void inquiryFinished(IOBluetoothDeviceInquiry *inq) Q_DECL_OVERRIDE; - void error(IOBluetoothDeviceInquiry *inq, IOReturn error) Q_DECL_OVERRIDE; - void deviceFound(IOBluetoothDeviceInquiry *inq, IOBluetoothDevice *device) Q_DECL_OVERRIDE; + void inquiryFinished(IOBluetoothDeviceInquiry *inq) override; + void error(IOBluetoothDeviceInquiry *inq, IOReturn error) override; + void deviceFound(IOBluetoothDeviceInquiry *inq, IOBluetoothDevice *device) override; void LEinquiryFinished(); void LEinquiryError(QBluetoothDeviceDiscoveryAgent::Error error); diff --git a/src/bluetooth/qbluetoothlocaldevice_osx.mm b/src/bluetooth/qbluetoothlocaldevice_osx.mm index 45fa310a..8b22f809 100644 --- a/src/bluetooth/qbluetoothlocaldevice_osx.mm +++ b/src/bluetooth/qbluetoothlocaldevice_osx.mm @@ -74,18 +74,18 @@ public: private: // PairingDelegate: - void connecting(ObjCPairingRequest *pair) Q_DECL_OVERRIDE; - void requestPIN(ObjCPairingRequest *pair) Q_DECL_OVERRIDE; + void connecting(ObjCPairingRequest *pair) override; + void requestPIN(ObjCPairingRequest *pair) override; void requestUserConfirmation(ObjCPairingRequest *pair, - BluetoothNumericValue) Q_DECL_OVERRIDE; + BluetoothNumericValue) override; void passkeyNotification(ObjCPairingRequest *pair, - BluetoothPasskey passkey) Q_DECL_OVERRIDE; - void error(ObjCPairingRequest *pair, IOReturn errorCode) Q_DECL_OVERRIDE; - void pairingFinished(ObjCPairingRequest *pair) Q_DECL_OVERRIDE; + BluetoothPasskey passkey) override; + void error(ObjCPairingRequest *pair, IOReturn errorCode) override; + void pairingFinished(ObjCPairingRequest *pair) override; // ConnectionMonitor - void deviceConnected(const QBluetoothAddress &deviceAddress) Q_DECL_OVERRIDE; - void deviceDisconnected(const QBluetoothAddress &deviceAddress) Q_DECL_OVERRIDE; + void deviceConnected(const QBluetoothAddress &deviceAddress) override; + void deviceDisconnected(const QBluetoothAddress &deviceAddress) override; void emitPairingFinished(const QBluetoothAddress &deviceAddress, Pairing pairing, bool queued); void emitError(QBluetoothLocalDevice::Error error, bool queued); diff --git a/src/bluetooth/qbluetoothserver_osx_p.h b/src/bluetooth/qbluetoothserver_osx_p.h index 63d0f314..3116ca02 100644 --- a/src/bluetooth/qbluetoothserver_osx_p.h +++ b/src/bluetooth/qbluetoothserver_osx_p.h @@ -80,8 +80,8 @@ private: void stopListener(); // SocketListener (delegate): - void openNotify(IOBluetoothRFCOMMChannel *channel) Q_DECL_OVERRIDE; - void openNotify(IOBluetoothL2CAPChannel *channel) Q_DECL_OVERRIDE; + void openNotify(IOBluetoothRFCOMMChannel *channel) override; + void openNotify(IOBluetoothL2CAPChannel *channel) override; QBluetoothServiceInfo::Protocol serverType; QBluetoothServer *q_ptr; diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm index 25bb2447..f9e4afaf 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm @@ -88,8 +88,8 @@ public: private: // SDPInquiryDelegate: - void SDPInquiryFinished(IOBluetoothDevice *device) Q_DECL_OVERRIDE; - void SDPInquiryError(IOBluetoothDevice *device, IOReturn errorCode) Q_DECL_OVERRIDE; + void SDPInquiryFinished(IOBluetoothDevice *device) override; + void SDPInquiryError(IOBluetoothDevice *device, IOReturn errorCode) override; void performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress); void setupDeviceDiscoveryAgent(); diff --git a/src/bluetooth/qbluetoothsocket_osx_p.h b/src/bluetooth/qbluetoothsocket_osx_p.h index 732d31aa..ce376702 100644 --- a/src/bluetooth/qbluetoothsocket_osx_p.h +++ b/src/bluetooth/qbluetoothsocket_osx_p.h @@ -104,7 +104,7 @@ public: quint16 peerPort() const; void _q_readNotify(); - void _q_writeNotify() Q_DECL_OVERRIDE; + void _q_writeNotify() override; private: // Create a socket from an external source (without connectToService). @@ -112,11 +112,11 @@ private: bool setChannel(IOBluetoothL2CAPChannel *channel); // L2CAP and RFCOMM delegate - void setChannelError(IOReturn errorCode) Q_DECL_OVERRIDE; - void channelOpenComplete() Q_DECL_OVERRIDE; - void channelClosed() Q_DECL_OVERRIDE; - void readChannelData(void *data, std::size_t size) Q_DECL_OVERRIDE; - void writeComplete() Q_DECL_OVERRIDE; + void setChannelError(IOReturn errorCode) override; + void channelOpenComplete() override; + void channelClosed() override; + void readChannelData(void *data, std::size_t size) override; + void writeComplete() override; qint64 writeData(const char *data, qint64 maxSize); qint64 readData(char *data, qint64 maxSize); diff --git a/src/bluetooth/qbluetoothtransferreply_osx.mm b/src/bluetooth/qbluetoothtransferreply_osx.mm index 02133860..39ec79aa 100644 --- a/src/bluetooth/qbluetoothtransferreply_osx.mm +++ b/src/bluetooth/qbluetoothtransferreply_osx.mm @@ -75,14 +75,14 @@ public: private: // OBEX session delegate: - void OBEXConnectError(OBEXError errorCode, OBEXOpCode response) Q_DECL_OVERRIDE; - void OBEXConnectSuccess() Q_DECL_OVERRIDE; + void OBEXConnectError(OBEXError errorCode, OBEXOpCode response) override; + void OBEXConnectSuccess() override; - void OBEXAbortSuccess() Q_DECL_OVERRIDE; + void OBEXAbortSuccess() override; - void OBEXPutDataSent(quint32 current, quint32 total) Q_DECL_OVERRIDE; - void OBEXPutSuccess() Q_DECL_OVERRIDE; - void OBEXPutError(OBEXError error, OBEXOpCode response) Q_DECL_OVERRIDE; + void OBEXPutDataSent(quint32 current, quint32 total) override; + void OBEXPutSuccess() override; + void OBEXPutError(OBEXError error, OBEXOpCode response) override; QBluetoothTransferReplyOSX *q_ptr; diff --git a/src/bluetooth/qbluetoothtransferreply_osx_p.h b/src/bluetooth/qbluetoothtransferreply_osx_p.h index d77d4913..e7b6f683 100644 --- a/src/bluetooth/qbluetoothtransferreply_osx_p.h +++ b/src/bluetooth/qbluetoothtransferreply_osx_p.h @@ -73,11 +73,11 @@ public: QBluetoothTransferManager *parent); ~QBluetoothTransferReplyOSX(); - TransferError error() const Q_DECL_OVERRIDE; - QString errorString() const Q_DECL_OVERRIDE; + TransferError error() const override; + QString errorString() const override; - bool isFinished() const Q_DECL_OVERRIDE; - bool isRunning() const Q_DECL_OVERRIDE; + bool isFinished() const override; + bool isRunning() const override; Q_SIGNALS: void error(QBluetoothTransferReply::TransferError lastError); -- cgit v1.2.3 From 844382001f8deaa7fcc9faac779b24188f35329b Mon Sep 17 00:00:00 2001 From: Kevin Funk Date: Sun, 24 Sep 2017 23:54:54 +0200 Subject: Replace Q_NULLPTR with nullptr Change-Id: Ica194c2568465a94d851ddeaf62ca71b33fe4464 Reviewed-by: Lars Knoll --- .../android/devicediscoverybroadcastreceiver.cpp | 28 +++++++++++----------- src/bluetooth/osx/osxbtl2capchannel.mm | 4 ++-- src/bluetooth/osx/osxbtobexsession.mm | 22 ++++++++--------- src/bluetooth/osx/osxbtrfcommchannel.mm | 4 ++-- src/bluetooth/osx/osxbtutility_p.h | 10 ++++---- src/bluetooth/qbluetoothdevicediscoveryagent.h | 4 ++-- .../qbluetoothdevicediscoveryagent_ios.mm | 2 +- .../qbluetoothdevicediscoveryagent_osx.mm | 2 +- src/bluetooth/qbluetoothdeviceinfo.h | 2 +- src/bluetooth/qbluetoothlocaldevice.h | 4 ++-- src/bluetooth/qbluetoothserver.h | 2 +- src/bluetooth/qbluetoothserver_osx.mm | 8 +++---- src/bluetooth/qbluetoothservicediscoveryagent.h | 4 ++-- .../qbluetoothservicediscoveryagent_osx.mm | 8 +++---- src/bluetooth/qbluetoothserviceinfo_osx.mm | 4 ++-- src/bluetooth/qbluetoothsocket.h | 4 ++-- src/bluetooth/qbluetoothsocket_osx.mm | 2 +- src/bluetooth/qbluetoothtransfermanager.h | 2 +- src/bluetooth/qbluetoothtransferreply.h | 2 +- src/bluetooth/qbluetoothtransferreply_osx.mm | 2 +- src/bluetooth/qbluetoothuuid.h | 4 ++-- src/bluetooth/qlowenergycontroller.cpp | 2 +- src/bluetooth/qlowenergycontroller.h | 8 +++---- src/bluetooth/qlowenergycontroller_osx.mm | 4 ++-- src/bluetooth/qlowenergyservice.cpp | 8 +++---- src/bluetooth/qlowenergyservice.h | 2 +- src/bluetooth/qlowenergyservice_osx.mm | 10 ++++---- 27 files changed, 79 insertions(+), 79 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp index 5acf761d..131fb48d 100644 --- a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp +++ b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp @@ -120,7 +120,7 @@ static const MajorClassJavaToQtMapping majorMappings[] = { { "TOY", QBluetoothDeviceInfo::ToyDevice }, { "UNCATEGORIZED", QBluetoothDeviceInfo::UncategorizedDevice }, { "WEARABLE", QBluetoothDeviceInfo::WearableDevice }, - { Q_NULLPTR, QBluetoothDeviceInfo::UncategorizedDevice } //end of list + { nullptr, QBluetoothDeviceInfo::UncategorizedDevice } //end of list }; // QBluetoothDeviceInfo::MajorDeviceClass value plus 1 matches index @@ -164,7 +164,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "AUDIO_VIDEO_VIDEO_GAMING_TOY", QBluetoothDeviceInfo::GamingDevice }, { "AUDIO_VIDEO_VIDEO_MONITOR", QBluetoothDeviceInfo::VideoMonitor }, { "AUDIO_VIDEO_WEARABLE_HEADSET", QBluetoothDeviceInfo::WearableHeadsetDevice }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // QBluetoothDevice::ComputerDevice -> 7 entries { "COMPUTER_UNCATEGORIZED", QBluetoothDeviceInfo::UncategorizedComputer }, // index 18 @@ -174,7 +174,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "COMPUTER_PALM_SIZE_PC_PDA", QBluetoothDeviceInfo::HandheldClamShellComputer }, { "COMPUTER_SERVER", QBluetoothDeviceInfo::ServerComputer }, { "COMPUTER_WEARABLE", QBluetoothDeviceInfo::WearableComputer }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // QBluetoothDevice::HealthDevice -> 8 entries { "HEALTH_BLOOD_PRESSURE", QBluetoothDeviceInfo::HealthBloodPressureMonitor }, // index 26 @@ -185,7 +185,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "HEALTH_THERMOMETER", QBluetoothDeviceInfo::HealthThermometer }, { "HEALTH_UNCATEGORIZED", QBluetoothDeviceInfo::UncategorizedHealthDevice }, { "HEALTH_WEIGHING", QBluetoothDeviceInfo::HealthWeightScale }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // QBluetoothDevice::PhoneDevice -> 6 entries { "PHONE_CELLULAR", QBluetoothDeviceInfo::CellularPhone }, // index 35 @@ -194,7 +194,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "PHONE_MODEM_OR_GATEWAY", QBluetoothDeviceInfo::WiredModemOrVoiceGatewayPhone }, { "PHONE_SMART", QBluetoothDeviceInfo::SmartPhone }, { "PHONE_UNCATEGORIZED", QBluetoothDeviceInfo::UncategorizedPhone }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // QBluetoothDevice::ToyDevice -> 6 entries { "TOY_CONTROLLER", QBluetoothDeviceInfo::ToyController }, // index 42 @@ -203,7 +203,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "TOY_ROBOT", QBluetoothDeviceInfo::ToyRobot }, { "TOY_UNCATEGORIZED", QBluetoothDeviceInfo::UncategorizedToy }, { "TOY_VEHICLE", QBluetoothDeviceInfo::ToyVehicle }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // QBluetoothDevice::WearableDevice -> 6 entries { "WEARABLE_GLASSES", QBluetoothDeviceInfo::WearableGlasses }, // index 49 @@ -212,7 +212,7 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "WEARABLE_PAGER", QBluetoothDeviceInfo::WearablePager }, { "WEARABLE_UNCATEGORIZED", QBluetoothDeviceInfo::UncategorizedWearableDevice }, { "WEARABLE_WRIST_WATCH", QBluetoothDeviceInfo::WearableWristWatch }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // QBluetoothDevice::PeripheralDevice -> 3 entries // For some reason these are not mentioned in Android docs but still exist @@ -220,21 +220,21 @@ static const MinorClassJavaToQtMapping minorMappings[] = { { "PERIPHERAL_KEYBOARD", QBluetoothDeviceInfo::KeyboardPeripheral }, { "PERIPHERAL_POINTING", QBluetoothDeviceInfo::PointingDevicePeripheral }, { "PERIPHERAL_KEYBOARD_POINTING", QBluetoothDeviceInfo::KeyboardWithPointingDevicePeripheral }, - { Q_NULLPTR, 0 }, // separator + { nullptr, 0 }, // separator // the following entries do not exist on Android // we map them to the unknown minor version case // QBluetoothDevice::Miscellaneous - { Q_NULLPTR, 0 }, // index 61 & separator + { nullptr, 0 }, // index 61 & separator // QBluetoothDevice::LANAccessDevice - { Q_NULLPTR, 0 }, // index 62 & separator + { nullptr, 0 }, // index 62 & separator // QBluetoothDevice::ImagingDevice - { Q_NULLPTR, 0 }, // index 63 & separator + { nullptr, 0 }, // index 63 & separator // QBluetoothDevice::UncategorizedDevice - { Q_NULLPTR, 0 }, // index 64 & separator + { nullptr, 0 }, // index 64 & separator }; /* Advertising Data Type (AD type) for LE scan records, as defined in Bluetooth CSS v6. */ @@ -308,7 +308,7 @@ QBluetoothDeviceInfo::MajorDeviceClass resolveAndroidMajorClass(jint javaType) int i = 0; jint fieldValue; QBluetoothDeviceInfo::MajorDeviceClass result = QBluetoothDeviceInfo::UncategorizedDevice; - while (majorMappings[i].javaFieldName != Q_NULLPTR) { + while (majorMappings[i].javaFieldName != nullptr) { fieldValue = QAndroidJniObject::getStaticField( javaBluetoothClassDeviceMajorClassName, majorMappings[i].javaFieldName); if (env->ExceptionCheck()) { @@ -359,7 +359,7 @@ void triggerCachingOfMinorsForMajor(QBluetoothDeviceInfo::MajorDeviceClass major int sizeIndex = minorIndexSizes[mappingIndex]; QAndroidJniEnvironment env; - while (minorMappings[sizeIndex].javaFieldName != Q_NULLPTR) { + while (minorMappings[sizeIndex].javaFieldName != nullptr) { jint fieldValue = QAndroidJniObject::getStaticField( javaBluetoothClassDeviceClassName, minorMappings[sizeIndex].javaFieldName); if (env->ExceptionCheck()) { // field lookup failed? skip it diff --git a/src/bluetooth/osx/osxbtl2capchannel.mm b/src/bluetooth/osx/osxbtl2capchannel.mm index 02ec4f90..474fe04b 100644 --- a/src/bluetooth/osx/osxbtl2capchannel.mm +++ b/src/bluetooth/osx/osxbtl2capchannel.mm @@ -210,7 +210,7 @@ QT_USE_NAMESPACE - (BluetoothDeviceAddress)peerAddress { const BluetoothDeviceAddress *const addr = device ? [device getAddress] - : Q_NULLPTR; + : nullptr; if (addr) return *addr; @@ -245,7 +245,7 @@ QT_USE_NAMESPACE Q_ASSERT_X(length, Q_FUNC_INFO, "invalid data size"); Q_ASSERT_X(connected && channel, Q_FUNC_INFO, "invalid L2CAP channel"); - return [channel writeAsync:data length:length refcon:Q_NULLPTR]; + return [channel writeAsync:data length:length refcon:nullptr]; } diff --git a/src/bluetooth/osx/osxbtobexsession.mm b/src/bluetooth/osx/osxbtobexsession.mm index b8e604c8..e228d6db 100644 --- a/src/bluetooth/osx/osxbtobexsession.mm +++ b/src/bluetooth/osx/osxbtobexsession.mm @@ -489,11 +489,11 @@ QT_USE_NAMESPACE const OBEXError status = [session OBEXConnect:kOBEXConnectFlagNone maxPacketLength:[QT_MANGLE_NAMESPACE(OSXBTOBEXSession) maxPacketLength] - optionalHeaders:Q_NULLPTR + optionalHeaders:nullptr optionalHeadersLength:0 eventSelector:@selector(OBEXConnectHandler:) selectorTarget:self - refCon:Q_NULLPTR]; + refCon:nullptr]; if (status != kOBEXSuccess) { currentRequest = OSXBluetooth::OBEXNoop; @@ -572,11 +572,11 @@ QT_USE_NAMESPACE return kOBEXSessionNotConnectedError; currentRequest = OBEXAbort; - const OBEXError status = [session OBEXAbort:Q_NULLPTR + const OBEXError status = [session OBEXAbort:nullptr optionalHeadersLength:0 eventSelector:@selector(OBEXAbortHandler:) selectorTarget:self - refCon:Q_NULLPTR]; + refCon:nullptr]; if (status != kOBEXSuccess) currentRequest = OBEXNoop; @@ -677,7 +677,7 @@ QT_USE_NAMESPACE bodyDataLength:[chunk length] eventSelector:@selector(OBEXPutHandler:) selectorTarget:self - refCon:Q_NULLPTR]; + refCon:nullptr]; if (status == kOBEXSuccess) { if (delegate && fileSize && !input->isSequential()) @@ -737,16 +737,16 @@ QT_USE_NAMESPACE return; } - void *dataPtr = chunk ? [chunk mutableBytes] : Q_NULLPTR; + void *dataPtr = chunk ? [chunk mutableBytes] : nullptr; const NSUInteger dataSize = chunk ? [chunk length] : 0; const OBEXError status = [session OBEXPut:lastChunk - headersData:Q_NULLPTR + headersData:nullptr headersDataLength:0 bodyData:dataPtr bodyDataLength:dataSize eventSelector:@selector(OBEXPutHandler:) selectorTarget:self - refCon:Q_NULLPTR]; + refCon:nullptr]; if (status != kOBEXSuccess) { qCWarning(QT_BT_OSX) << "failed to send the next memory chunk"; @@ -778,11 +778,11 @@ QT_USE_NAMESPACE currentRequest = OSXBluetooth::OBEXDisconnect; - [session OBEXDisconnect:Q_NULLPTR + [session OBEXDisconnect:nullptr optionalHeadersLength:0 eventSelector:@selector(OBEXDisconnectHandler:) selectorTarget:self - refCon:Q_NULLPTR]; + refCon:nullptr]; } - (void)OBEXDisconnectHandler:(const OBEXSessionEvent*)event @@ -806,7 +806,7 @@ QT_USE_NAMESPACE // Clear the delegate and reset the request, // do not try any of OBEX commands - the session will be deleted // immediately. - delegate = Q_NULLPTR; + delegate = nullptr; // This will stop any handler (callback) preventing // any read/write to potentially deleted objects. currentRequest = OSXBluetooth::OBEXNoop; diff --git a/src/bluetooth/osx/osxbtrfcommchannel.mm b/src/bluetooth/osx/osxbtrfcommchannel.mm index ea679ec8..bd87aae0 100644 --- a/src/bluetooth/osx/osxbtrfcommchannel.mm +++ b/src/bluetooth/osx/osxbtrfcommchannel.mm @@ -210,7 +210,7 @@ QT_USE_NAMESPACE - (BluetoothDeviceAddress)peerAddress { const BluetoothDeviceAddress *const addr = device ? [device getAddress] - : Q_NULLPTR; + : nullptr; if (addr) return *addr; @@ -248,7 +248,7 @@ QT_USE_NAMESPACE Q_ASSERT_X(length, Q_FUNC_INFO, "invalid data size"); Q_ASSERT_X(connected && channel, Q_FUNC_INFO, "invalid RFCOMM channel"); - return [channel writeAsync:data length:length refcon:Q_NULLPTR]; + return [channel writeAsync:data length:length refcon:nullptr]; } diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h index 148ebc0b..441d4183 100644 --- a/src/bluetooth/osx/osxbtutility_p.h +++ b/src/bluetooth/osx/osxbtutility_p.h @@ -82,7 +82,7 @@ public: // add a default ctor??? This will make the semantics more // transparent + will simplify the future transition to ARC // (if it will ever happen). - explicit ObjCScopedPointer(T *ptr = Q_NULLPTR) : QScopedPointer(ptr){} + explicit ObjCScopedPointer(T *ptr = nullptr) : QScopedPointer(ptr){} operator T*() const { return data(); @@ -196,7 +196,7 @@ template class CFStrongReference { public: CFStrongReference() - : m_ptr(Q_NULLPTR) + : m_ptr(nullptr) { } @@ -230,13 +230,13 @@ public: CFStrongReference(CFStrongReference &&xval) { m_ptr = xval.m_ptr; - xval.m_ptr = Q_NULLPTR; + xval.m_ptr = nullptr; } CFStrongReference &operator = (CFStrongReference &&xval) { m_ptr = xval.m_ptr; - xval.m_ptr = Q_NULLPTR; + xval.m_ptr = nullptr; return *this; } #endif @@ -270,7 +270,7 @@ public: T take() { T p = m_ptr; - m_ptr = Q_NULLPTR; + m_ptr = nullptr; return p; } private: diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h index 62050282..d3e41265 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h @@ -85,9 +85,9 @@ public: Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod) Q_FLAG(DiscoveryMethods) - explicit QBluetoothDeviceDiscoveryAgent(QObject *parent = Q_NULLPTR); + explicit QBluetoothDeviceDiscoveryAgent(QObject *parent = nullptr); explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, - QObject *parent = Q_NULLPTR); + QObject *parent = nullptr); ~QBluetoothDeviceDiscoveryAgent(); // TODO Remove inquiry type in Qt 6 -> not really used anywhere diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm index 3f4c6755..c50d546d 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm @@ -127,7 +127,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con Q_UNUSED(adapter); registerQDeviceDiscoveryMetaType(); - Q_ASSERT_X(q != Q_NULLPTR, Q_FUNC_INFO, "invalid q_ptr (null)"); + Q_ASSERT_X(q != nullptr, Q_FUNC_INFO, "invalid q_ptr (null)"); } QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate() diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index 1318d768..5ebc131c 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -168,7 +168,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con { registerQDeviceDiscoveryMetaType(); - Q_ASSERT_X(q != Q_NULLPTR, Q_FUNC_INFO, "invalid q_ptr (null)"); + Q_ASSERT_X(q != nullptr, Q_FUNC_INFO, "invalid q_ptr (null)"); HostController controller([[IOBluetoothHostController defaultController] retain]); if (!controller || [controller powerState] != kBluetoothHCIPowerStateON) { diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h index 33cd40b7..f2558bbf 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.h +++ b/src/bluetooth/qbluetoothdeviceinfo.h @@ -232,7 +232,7 @@ public: void setRssi(qint16 signal); void setServiceUuids(const QList &uuids, DataCompleteness completeness); - QList serviceUuids(DataCompleteness *completeness = Q_NULLPTR) const; + QList serviceUuids(DataCompleteness *completeness = nullptr) const; DataCompleteness serviceUuidsCompleteness() const; void setCoreConfigurations(QBluetoothDeviceInfo::CoreConfigurations coreConfigs); diff --git a/src/bluetooth/qbluetoothlocaldevice.h b/src/bluetooth/qbluetoothlocaldevice.h index 9363a116..9f6d1e1b 100644 --- a/src/bluetooth/qbluetoothlocaldevice.h +++ b/src/bluetooth/qbluetoothlocaldevice.h @@ -79,8 +79,8 @@ public: }; Q_ENUM(Error) - explicit QBluetoothLocalDevice(QObject *parent = Q_NULLPTR); - explicit QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = Q_NULLPTR); + explicit QBluetoothLocalDevice(QObject *parent = nullptr); + explicit QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = nullptr); virtual ~QBluetoothLocalDevice(); bool isValid() const; diff --git a/src/bluetooth/qbluetoothserver.h b/src/bluetooth/qbluetoothserver.h index e6e4a68f..193101fc 100644 --- a/src/bluetooth/qbluetoothserver.h +++ b/src/bluetooth/qbluetoothserver.h @@ -70,7 +70,7 @@ public: }; Q_ENUM(Error) - explicit QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = Q_NULLPTR); + explicit QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr); ~QBluetoothServer(); void close(); diff --git a/src/bluetooth/qbluetoothserver_osx.mm b/src/bluetooth/qbluetoothserver_osx.mm index 8896651d..c72845bb 100644 --- a/src/bluetooth/qbluetoothserver_osx.mm +++ b/src/bluetooth/qbluetoothserver_osx.mm @@ -237,7 +237,7 @@ QBluetoothServerPrivate *QBluetoothServerPrivate::registeredServer(quint16 port, qCWarning(QT_BT_OSX) << "invalid protocol"; } - return Q_NULLPTR; + return nullptr; } void QBluetoothServerPrivate::unregisterServer(QBluetoothServerPrivate *server) @@ -441,7 +441,7 @@ bool QBluetoothServer::hasPendingConnections() const QBluetoothSocket *QBluetoothServer::nextPendingConnection() { if (!d_ptr->pendingConnections.size()) - return Q_NULLPTR; + return nullptr; QScopedPointer newSocket(new QBluetoothSocket); QBluetoothServerPrivate::PendingConnection channel(d_ptr->pendingConnections.front()); @@ -451,10 +451,10 @@ QBluetoothSocket *QBluetoothServer::nextPendingConnection() if (d_ptr->serverType == QSInfo::RfcommProtocol) { if (!newSocket->d_ptr->setChannel(static_cast(channel))) - return Q_NULLPTR; + return nullptr; } else { if (!newSocket->d_ptr->setChannel(static_cast(channel))) - return Q_NULLPTR; + return nullptr; } return newSocket.take(); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h index 12df37a8..4a553c7d 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.h +++ b/src/bluetooth/qbluetoothservicediscoveryagent.h @@ -80,8 +80,8 @@ public: }; Q_ENUM(DiscoveryMode) - explicit QBluetoothServiceDiscoveryAgent(QObject *parent = Q_NULLPTR); - explicit QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = Q_NULLPTR); + explicit QBluetoothServiceDiscoveryAgent(QObject *parent = nullptr); + explicit QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = nullptr); ~QBluetoothServiceDiscoveryAgent(); bool isActive() const; diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm index f9e4afaf..e1e73a0c 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm @@ -152,7 +152,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::stopDeviceDiscovery() Q_ASSERT_X(state == DeviceDiscovery, Q_FUNC_INFO, "invalid state"); deviceDiscoveryAgent->stop(); - deviceDiscoveryAgent.reset(Q_NULLPTR); + deviceDiscoveryAgent.reset(nullptr); state = Inactive; emit q_ptr->canceled(); @@ -268,7 +268,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryError(QBluetoothD errorString = QCoreApplication::translate(DEV_DISCOVERY, DD_UNKNOWN_ERROR); deviceDiscoveryAgent->stop(); - deviceDiscoveryAgent.reset(Q_NULLPTR); + deviceDiscoveryAgent.reset(nullptr); state = QBluetoothServiceDiscoveryAgentPrivate::Inactive; emit q_ptr->error(error); @@ -283,12 +283,12 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryFinished() //Forward the device discovery error error = static_cast(deviceDiscoveryAgent->error()); errorString = deviceDiscoveryAgent->errorString(); - deviceDiscoveryAgent.reset(Q_NULLPTR); + deviceDiscoveryAgent.reset(nullptr); state = Inactive; emit q_ptr->error(error); emit q_ptr->finished(); } else { - deviceDiscoveryAgent.reset(Q_NULLPTR); + deviceDiscoveryAgent.reset(nullptr); startServiceDiscovery(); } } diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm index a25653ab..6da9d7a2 100644 --- a/src/bluetooth/qbluetoothserviceinfo_osx.mm +++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm @@ -127,7 +127,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca const QSInfo::Protocol type = q_ptr->socketProtocol(); quint16 realPort = 0; - QBluetoothServerPrivate *server = Q_NULLPTR; + QBluetoothServerPrivate *server = nullptr; bool configured = false; if (type == QBluetoothServiceInfo::L2capProtocol) { @@ -179,7 +179,7 @@ bool QBluetoothServiceInfoPrivate::unregisterService() serviceRecord.reset(nil); const QSInfo::Protocol type = q_ptr->socketProtocol(); - QBluetoothServerPrivate *server = Q_NULLPTR; + QBluetoothServerPrivate *server = nullptr; const QMutexLocker lock(&QBluetoothServerPrivate::channelMapMutex()); if (type == QSInfo::RfcommProtocol) diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h index bbcecbf4..3fc2892e 100644 --- a/src/bluetooth/qbluetoothsocket.h +++ b/src/bluetooth/qbluetoothsocket.h @@ -89,8 +89,8 @@ public: }; Q_ENUM(SocketError) - explicit QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, QObject *parent = Q_NULLPTR); // create socket of type socketType - explicit QBluetoothSocket(QObject *parent = Q_NULLPTR); // create a blank socket + explicit QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, QObject *parent = nullptr); // create socket of type socketType + explicit QBluetoothSocket(QObject *parent = nullptr); // create a blank socket virtual ~QBluetoothSocket(); void abort(); diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm index 71e249fe..bf20220d 100644 --- a/src/bluetooth/qbluetoothsocket_osx.mm +++ b/src/bluetooth/qbluetoothsocket_osx.mm @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE QBluetoothSocketPrivate::QBluetoothSocketPrivate() - : q_ptr(Q_NULLPTR), + : q_ptr(nullptr), writeChunk(std::numeric_limits::max()), openMode(QIODevice::NotOpen), // That's what is set in public class' ctors. state(QBluetoothSocket::UnconnectedState), diff --git a/src/bluetooth/qbluetoothtransfermanager.h b/src/bluetooth/qbluetoothtransfermanager.h index 756fe54f..98850392 100644 --- a/src/bluetooth/qbluetoothtransfermanager.h +++ b/src/bluetooth/qbluetoothtransfermanager.h @@ -58,7 +58,7 @@ class Q_BLUETOOTH_EXPORT QBluetoothTransferManager : public QObject Q_OBJECT public: - explicit QBluetoothTransferManager(QObject *parent = Q_NULLPTR); + explicit QBluetoothTransferManager(QObject *parent = nullptr); ~QBluetoothTransferManager(); QBluetoothTransferReply *put(const QBluetoothTransferRequest &request, QIODevice *data); diff --git a/src/bluetooth/qbluetoothtransferreply.h b/src/bluetooth/qbluetoothtransferreply.h index c2b0b622..8f0679f5 100644 --- a/src/bluetooth/qbluetoothtransferreply.h +++ b/src/bluetooth/qbluetoothtransferreply.h @@ -88,7 +88,7 @@ Q_SIGNALS: void error(QBluetoothTransferReply::TransferError lastError); protected: - explicit QBluetoothTransferReply(QObject *parent = Q_NULLPTR); + explicit QBluetoothTransferReply(QObject *parent = nullptr); void setManager(QBluetoothTransferManager *manager); void setRequest(const QBluetoothTransferRequest &request); diff --git a/src/bluetooth/qbluetoothtransferreply_osx.mm b/src/bluetooth/qbluetoothtransferreply_osx.mm index 39ec79aa..65c8f82d 100644 --- a/src/bluetooth/qbluetoothtransferreply_osx.mm +++ b/src/bluetooth/qbluetoothtransferreply_osx.mm @@ -394,7 +394,7 @@ bool QBluetoothTransferReplyOSX::abort() // Reset a delegate. [osx_d_ptr->session closeSession]; // Should never be called from an OBEX callback! - osx_d_ptr->session.reset(Q_NULLPTR); + osx_d_ptr->session.reset(nullptr); // Not setReplyError, we emit finished only! osx_d_ptr->requestComplete = true; diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h index 2a2ce138..28b08583 100644 --- a/src/bluetooth/qbluetoothuuid.h +++ b/src/bluetooth/qbluetoothuuid.h @@ -383,8 +383,8 @@ public: int minimumSize() const; - quint16 toUInt16(bool *ok = Q_NULLPTR) const; - quint32 toUInt32(bool *ok = Q_NULLPTR) const; + quint16 toUInt16(bool *ok = nullptr) const; + quint32 toUInt32(bool *ok = nullptr) const; quint128 toUInt128() const; static QString serviceClassToString(ServiceClassUuid uuid); diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index 004ee3be..7cd80072 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -850,7 +850,7 @@ QLowEnergyService *QLowEnergyController::createServiceObject( { Q_D(QLowEnergyController); - QLowEnergyService *service = Q_NULLPTR; + QLowEnergyService *service = nullptr; ServiceDataMap::const_iterator it = d->serviceList.constFind(serviceUuid); if (it != d->serviceList.constEnd()) { diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h index 1a84b05b..f9e6ef5d 100644 --- a/src/bluetooth/qlowenergycontroller.h +++ b/src/bluetooth/qlowenergycontroller.h @@ -91,12 +91,12 @@ public: Q_ENUM(Role) explicit QLowEnergyController(const QBluetoothAddress &remoteDevice, - QObject *parent = Q_NULLPTR); // TODO Qt 6 remove ctor + QObject *parent = nullptr); // TODO Qt 6 remove ctor explicit QLowEnergyController(const QBluetoothDeviceInfo &remoteDevice, - QObject *parent = Q_NULLPTR); + QObject *parent = nullptr); explicit QLowEnergyController(const QBluetoothAddress &remoteDevice, const QBluetoothAddress &localDevice, - QObject *parent = Q_NULLPTR); // TODO Qt 6 remove ctor + QObject *parent = nullptr); // TODO Qt 6 remove ctor static QLowEnergyController *createCentral(const QBluetoothDeviceInfo &remoteDevice, QObject *parent = nullptr); @@ -122,7 +122,7 @@ public: void discoverServices(); QList services() const; - QLowEnergyService *createServiceObject(const QBluetoothUuid &service, QObject *parent = Q_NULLPTR); + QLowEnergyService *createServiceObject(const QBluetoothUuid &service, QObject *parent = nullptr); void startAdvertising(const QLowEnergyAdvertisingParameters ¶meters, const QLowEnergyAdvertisingData &advertisingData, diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm index a2923d81..1206ef42 100644 --- a/src/bluetooth/qlowenergycontroller_osx.mm +++ b/src/bluetooth/qlowenergycontroller_osx.mm @@ -962,7 +962,7 @@ void QLowEnergyControllerPrivateOSX::setErrorDescription(QLowEnergyController::E void QLowEnergyControllerPrivateOSX::invalidateServices() { foreach (const QSharedPointer service, discoveredServices.values()) { - service->setController(Q_NULLPTR); + service->setController(nullptr); service->setState(QLowEnergyService::InvalidService); } @@ -1228,7 +1228,7 @@ QLowEnergyService *QLowEnergyController::createServiceObject(const QBluetoothUui { OSX_D_PTR; - QLowEnergyService *service = Q_NULLPTR; + QLowEnergyService *service = nullptr; QLowEnergyControllerPrivateOSX::ServiceMap::const_iterator it = osx_d_ptr->discoveredServices.constFind(serviceUuid); if (it != osx_d_ptr->discoveredServices.constEnd()) { diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 9d3129fd..35a3a7d0 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -632,7 +632,7 @@ void QLowEnergyService::readCharacteristic( { Q_D(QLowEnergyService); - if (d->controller == Q_NULLPTR || state() != ServiceDiscovered || !contains(characteristic)) { + if (d->controller == nullptr || state() != ServiceDiscovered || !contains(characteristic)) { d->setError(QLowEnergyService::OperationError); return; } @@ -703,7 +703,7 @@ void QLowEnergyService::writeCharacteristic( //TODO check behavior when writing to WriteSigned characteristic Q_D(QLowEnergyService); - if (d->controller == Q_NULLPTR + if (d->controller == nullptr || (d->controller->role == QLowEnergyController::CentralRole && state() != ServiceDiscovered) || !contains(characteristic)) { @@ -762,7 +762,7 @@ void QLowEnergyService::readDescriptor( { Q_D(QLowEnergyService); - if (d->controller == Q_NULLPTR || state() != ServiceDiscovered || !contains(descriptor)) { + if (d->controller == nullptr || state() != ServiceDiscovered || !contains(descriptor)) { d->setError(QLowEnergyService::OperationError); return; } @@ -804,7 +804,7 @@ void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor, { Q_D(QLowEnergyService); - if (d->controller == Q_NULLPTR + if (d->controller == nullptr || (d->controller->role == QLowEnergyController::CentralRole && state() != ServiceDiscovered) || !contains(descriptor)) { diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h index f138459f..3f6cfd88 100644 --- a/src/bluetooth/qlowenergyservice.h +++ b/src/bluetooth/qlowenergyservice.h @@ -136,7 +136,7 @@ private: friend class QLowEnergyController; friend class QLowEnergyControllerPrivate; QLowEnergyService(QSharedPointer p, - QObject *parent = Q_NULLPTR); + QObject *parent = nullptr); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QLowEnergyService::ServiceTypes) diff --git a/src/bluetooth/qlowenergyservice_osx.mm b/src/bluetooth/qlowenergyservice_osx.mm index 52c2ac87..4423887a 100644 --- a/src/bluetooth/qlowenergyservice_osx.mm +++ b/src/bluetooth/qlowenergyservice_osx.mm @@ -58,7 +58,7 @@ namespace { QLowEnergyControllerPrivateOSX *qt_mac_le_controller(QSharedPointer d_ptr) { if (d_ptr.isNull()) - return Q_NULLPTR; + return nullptr; return static_cast(d_ptr->controller.data()); } @@ -195,7 +195,7 @@ bool QLowEnergyService::contains(const QLowEnergyCharacteristic &characteristic) void QLowEnergyService::readCharacteristic(const QLowEnergyCharacteristic &characteristic) { QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (controller == Q_NULLPTR || state() != ServiceDiscovered || !contains(characteristic)) { + if (controller == nullptr || state() != ServiceDiscovered || !contains(characteristic)) { d_ptr->setError(OperationError); return; } @@ -208,7 +208,7 @@ void QLowEnergyService::writeCharacteristic(const QLowEnergyCharacteristic &ch, WriteMode mode) { QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (controller == Q_NULLPTR || + if (controller == nullptr || (controller->role == QLowEnergyController::CentralRole && state() != ServiceDiscovered) || !contains(ch)) { d_ptr->setError(QLowEnergyService::OperationError); @@ -239,7 +239,7 @@ bool QLowEnergyService::contains(const QLowEnergyDescriptor &descriptor) const void QLowEnergyService::readDescriptor(const QLowEnergyDescriptor &descriptor) { QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (controller == Q_NULLPTR || state() != ServiceDiscovered || !contains(descriptor)) { + if (controller == nullptr || state() != ServiceDiscovered || !contains(descriptor)) { d_ptr->setError(OperationError); return; } @@ -251,7 +251,7 @@ void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue) { QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (controller == Q_NULLPTR || state() != ServiceDiscovered || !contains(descriptor)) { + if (controller == nullptr || state() != ServiceDiscovered || !contains(descriptor)) { // This operation error also includes LE controller in the peripheral role: // on iOS/OS X - descriptors are immutable. d_ptr->setError(OperationError); -- cgit v1.2.3 From 18af3226765b62312acc8f801cc531fde0d9822b Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 2 Oct 2017 13:27:13 +0200 Subject: CoreBluetooth - fix compilation errors for 10.13 SDK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple broke source code compatibility by moving 'identifier' properties from CBPeripheral and CBCentral classes into the new CBPeer class and marking it as "since 10.13". As a result we have compilation errors in the code that was valid since 10.7. To workaround this issue, we introduce a category with 'identifier' property declarations for SDK >= 10.13 and target < 10.13. Change-Id: Id7c9d33a9c8ae7627a06b4c1930e70cede1e5b07 Reviewed-by: Tor Arne Vestbø --- src/bluetooth/osx/osxbtutility_p.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h index 148ebc0b..5d90a54e 100644 --- a/src/bluetooth/osx/osxbtutility_p.h +++ b/src/bluetooth/osx/osxbtutility_p.h @@ -313,4 +313,23 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_OSX) QT_END_NAMESPACE +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(101300) && QT_MACOS_DEPLOYMENT_TARGET_BELOW(101300) + + // In the macOS 10.13 SDK, the identifier property was moved from the CBPeripheral + // and CBCentral classes to a new CBPeer base class. Because CBPeer is only available + // on macOS 10.13 and above, the same is true for -[CBPeer identifier]. However, + // since we know that the derived classes have always had this property, + // we'll explicitly mark its availability here. This will not adversely affect + // using the identifier through the CBPeer base class, which will still require macOS 10.13. + +@interface CBPeripheral (UnguardedWorkaround) +@property (readonly, nonatomic) NSUUID *identifier NS_AVAILABLE(10_7, 5_0); +@end + +@interface CBCentral (UnguardedWorkaround) +@property (readonly, nonatomic) NSUUID *identifier NS_AVAILABLE(10_7, 5_0); +@end + +#endif + #endif -- cgit v1.2.3 From 4bce1481c5cfbd402973c2a488b36499ed44af2e Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 11 Oct 2017 10:10:27 +0200 Subject: IOBluetooth: warn about incorrent thread/runloop IOBluetooth is heavily based on CFRunLoops. An attempt to use it on a thread, that does not properly run CFRunLoop results in callbacks never firing and thus QBluetooth classes never finishing their jobs, including: - device discovery - service discovery - RFCOMM/LCAP2 - Bluetooth server - Bluetooth socket etc. While we cannot fix the core problem until we have a properly working CoreFoundation event dispatcher, we can at least issue a warning so that people do not waste their time debugging this well-known limitation. Task-number: QTBUG-63630 Change-Id: Iefa4d675ea0962167bdfede640d2087dbdf37b18 Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtutility.mm | 15 ++++++++++++++- src/bluetooth/osx/osxbtutility_p.h | 3 ++- src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm | 2 ++ src/bluetooth/qbluetoothlocaldevice_osx.mm | 2 ++ src/bluetooth/qbluetoothserver_osx.mm | 2 ++ src/bluetooth/qbluetoothservicediscoveryagent_osx.mm | 2 ++ src/bluetooth/qbluetoothsocket_osx.mm | 8 ++++++++ 7 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/osx/osxbtutility.mm b/src/bluetooth/osx/osxbtutility.mm index 1508c89f..e17006de 100644 --- a/src/bluetooth/osx/osxbtutility.mm +++ b/src/bluetooth/osx/osxbtutility.mm @@ -48,6 +48,7 @@ #ifndef QT_IOS_BLUETOOTH #import +#import #if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12, __IPHONE_NA) #import #endif @@ -164,7 +165,19 @@ QString qt_error_string(IOReturn errorCode) } } -#endif +void qt_test_iobluetooth_runloop() +{ + // IOBluetooth heavily relies on a CFRunLoop machinery in a way it dispatches + // its callbacks. Technically, having a QThread with CFRunLoop-based event + // dispatcher would suffice. At the moment of writing we do not have such + // event dispatcher, so we only can work on the main thread. + if (CFRunLoopGetMain() != CFRunLoopGetCurrent()) { + qCWarning(QT_BT_OSX) << "IOBluetooth works only on the main thread or a" + << "thread with a running CFRunLoop"; + } +} + +#endif // !QT_IOS_BLUETOOTH // Apple has: CBUUID, NSUUID, CFUUID, IOBluetoothSDPUUID diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h index 148ebc0b..5ded5e7f 100644 --- a/src/bluetooth/osx/osxbtutility_p.h +++ b/src/bluetooth/osx/osxbtutility_p.h @@ -287,8 +287,9 @@ BluetoothDeviceAddress iobluetooth_address(const QBluetoothAddress &address); ObjCStrongReference iobluetooth_uuid(const QBluetoothUuid &uuid); QBluetoothUuid qt_uuid(IOBluetoothSDPUUID *uuid); QString qt_error_string(IOReturn errorCode); +void qt_test_iobluetooth_runloop(); -#endif +#endif // !QT_IOS_BLUETOOTH QBluetoothUuid qt_uuid(CBUUID *uuid); CFStrongReference cf_uuid(const QBluetoothUuid &qtUuid); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index 9e3f6a57..7f037596 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -245,6 +245,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startClassic() Q_ASSERT(requestedMethods & QBluetoothDeviceDiscoveryAgent::ClassicMethod); Q_ASSERT(agentState == NonActive); + OSXBluetooth::qt_test_iobluetooth_runloop(); + if (!inquiry) { // The first Classic scan for this DDA. inquiry.reset([[DeviceInquiryObjC alloc]initWithDelegate:this]); diff --git a/src/bluetooth/qbluetoothlocaldevice_osx.mm b/src/bluetooth/qbluetoothlocaldevice_osx.mm index 45fa310a..cb5625d6 100644 --- a/src/bluetooth/qbluetoothlocaldevice_osx.mm +++ b/src/bluetooth/qbluetoothlocaldevice_osx.mm @@ -464,6 +464,8 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai return; } + OSXBluetooth::qt_test_iobluetooth_runloop(); + return d_ptr->requestPairing(address, pairing); } diff --git a/src/bluetooth/qbluetoothserver_osx.mm b/src/bluetooth/qbluetoothserver_osx.mm index 8896651d..8d7eeb29 100644 --- a/src/bluetooth/qbluetoothserver_osx.mm +++ b/src/bluetooth/qbluetoothserver_osx.mm @@ -291,6 +291,8 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port) { typedef QBluetoothServerPrivate::ObjCListener ObjCListener; + OSXBluetooth::qt_test_iobluetooth_runloop(); + if (d_ptr->listener) { qCWarning(QT_BT_OSX) << "already in listen mode, close server first"; return false; diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm index 25bb2447..0b2f593d 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm @@ -526,6 +526,8 @@ QBluetoothAddress QBluetoothServiceDiscoveryAgent::remoteAddress() const void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode) { + OSXBluetooth::qt_test_iobluetooth_runloop(); + if (d_ptr->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive && d_ptr->error != InvalidBluetoothAdapterError) { diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm index 75712868..59fb66f2 100644 --- a/src/bluetooth/qbluetoothsocket_osx.mm +++ b/src/bluetooth/qbluetoothsocket_osx.mm @@ -443,6 +443,8 @@ qint64 QBluetoothSocket::bytesToWrite() const void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, OpenMode openMode) { + OSXBluetooth::qt_test_iobluetooth_runloop(); + // Report this problem early, potentially avoid device discovery: if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type"; @@ -480,6 +482,8 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode) { + OSXBluetooth::qt_test_iobluetooth_runloop(); + // Report this problem early, avoid device discovery: if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type"; @@ -505,6 +509,8 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const void QBluetoothSocket::connectToService(const QBluetoothAddress &address, quint16 port, OpenMode openMode) { + OSXBluetooth::qt_test_iobluetooth_runloop(); + if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type"; d_ptr->errorString = QCoreApplication::translate(SOCKET, SOC_NETWORK_ERROR); @@ -571,6 +577,8 @@ void QBluetoothSocket::setSocketError(QBluetoothSocket::SocketError socketError) void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, OpenMode openMode) { + OSXBluetooth::qt_test_iobluetooth_runloop(); + setSocketState(ServiceLookupState); if (d_ptr->discoveryAgent) -- cgit v1.2.3 From 80d85141aa496583c5cfa6dd0f62d5eb4a8ba660 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 28 Sep 2017 15:52:52 +0200 Subject: Fix outdated FDL license header Change-Id: Ia26b0bf499f8a0b6040e82bc1d460bee688bfbf6 Reviewed-by: Alex Blasche --- src/bluetooth/doc/src/bluetooth-cpp.qdoc | 10 +++++----- src/bluetooth/doc/src/bluetooth-index.qdoc | 10 +++++----- src/bluetooth/doc/src/bluetooth-le-overview.qdoc | 10 +++++----- src/bluetooth/doc/src/bluetooth-overview.qdoc | 10 +++++----- src/bluetooth/doc/src/bluetooth-qml.qdoc | 10 +++++----- src/bluetooth/doc/src/examples.qdoc | 10 +++++----- 6 files changed, 30 insertions(+), 30 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/doc/src/bluetooth-cpp.qdoc b/src/bluetooth/doc/src/bluetooth-cpp.qdoc index ae39772f..26cd060b 100644 --- a/src/bluetooth/doc/src/bluetooth-cpp.qdoc +++ b/src/bluetooth/doc/src/bluetooth-cpp.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt local connectivty modules. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/bluetooth/doc/src/bluetooth-index.qdoc b/src/bluetooth/doc/src/bluetooth-index.qdoc index d2db7aa3..9cb5f3b2 100644 --- a/src/bluetooth/doc/src/bluetooth-index.qdoc +++ b/src/bluetooth/doc/src/bluetooth-index.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc index a29f88d0..60181240 100644 --- a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc +++ b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt local connectivty modules. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/bluetooth/doc/src/bluetooth-overview.qdoc b/src/bluetooth/doc/src/bluetooth-overview.qdoc index 1b712f23..8138e937 100644 --- a/src/bluetooth/doc/src/bluetooth-overview.qdoc +++ b/src/bluetooth/doc/src/bluetooth-overview.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt local connectivty modules. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/bluetooth/doc/src/bluetooth-qml.qdoc b/src/bluetooth/doc/src/bluetooth-qml.qdoc index 2fb64f45..51aa5a25 100644 --- a/src/bluetooth/doc/src/bluetooth-qml.qdoc +++ b/src/bluetooth/doc/src/bluetooth-qml.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt local connectivty modules. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/bluetooth/doc/src/examples.qdoc b/src/bluetooth/doc/src/examples.qdoc index 32152c84..e33ae4d8 100644 --- a/src/bluetooth/doc/src/examples.qdoc +++ b/src/bluetooth/doc/src/examples.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ -- cgit v1.2.3