summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-01-05 14:20:42 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2016-01-05 14:23:14 +0100
commit302fc3cbda9a68c8d606e31702beac75cb5021d3 (patch)
treeb88604342ecd8c4b069db7e20576f2fb061c8213
parenta3e2b199366c7a8f71842369cf266107a3b38490 (diff)
parenta3cf9d99b303baaca0d1b0fbaa1b1923c06d18cc (diff)
Merge remote-tracking branch 'gerrit/dev' into neard
Conflicts: src/bluetooth/qlowenergycontroller.cpp Change-Id: I28b116deb3fa87169432eb2d94b70894359a9057
-rw-r--r--src/bluetooth/bluetooth.pro3
-rw-r--r--src/bluetooth/bluez/bluez5_helper.cpp22
-rw-r--r--src/bluetooth/bluez/bluez5_helper_p.h2
-rw-r--r--src/bluetooth/osx/osxbtcentralmanager.mm5
-rw-r--r--src/bluetooth/osx/osxbtutility_p.h3
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_bluez.cpp2
-rw-r--r--src/bluetooth/qbluetoothsocket_osx_p.h2
-rw-r--r--src/bluetooth/qbluetoothtransferreply_bluez.cpp2
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp5
-rw-r--r--src/bluetooth/qlowenergycontroller_android.cpp8
-rw-r--r--src/bluetooth/qlowenergycontroller_osx.mm18
-rw-r--r--src/bluetooth/qlowenergycontroller_osx_p.h6
-rw-r--r--src/nfc/qnearfieldtarget.cpp2
-rw-r--r--tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp6
14 files changed, 52 insertions, 34 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 9f2a109e..920fbe9a 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -166,7 +166,7 @@ config_bluez:qtHaveModule(dbus) {
SOURCES -= qlowenergyservice.cpp
SOURCES -= qlowenergycontroller.cpp
SOURCES -= qlowenergycontroller_p.cpp
-} else:ios {
+} else:ios|tvos {
DEFINES += QT_IOS_BLUETOOTH
LIBS += -framework Foundation -framework CoreBluetooth
@@ -209,4 +209,3 @@ config_bluez:qtHaveModule(dbus) {
OTHER_FILES +=
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
-
diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp
index 384b9979..14e064e1 100644
--- a/src/bluetooth/bluez/bluez5_helper.cpp
+++ b/src/bluetooth/bluez/bluez5_helper.cpp
@@ -339,4 +339,26 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok =
return QString(); // nothing matching found
}
+/*
+ Removes every character that cannot be used in QDbusObjectPath
+
+ See QDbusUtil::isValidObjectPath(QString) for more details.
+ */
+QString sanitizeNameForDBus(const QString &text)
+{
+ QString appName = text;
+ for (int i = 0; i < appName.length(); i++) {
+ ushort us = appName[i].unicode();
+ bool valid = (us >= 'a' && us <= 'z')
+ || (us >= 'A' && us <= 'Z')
+ || (us >= '0' && us <= '9')
+ || (us == '_');
+
+ if (!valid)
+ appName[i] = QLatin1Char('_');
+ }
+
+ return appName;
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/bluez/bluez5_helper_p.h b/src/bluetooth/bluez/bluez5_helper_p.h
index a3f164b0..019fe635 100644
--- a/src/bluetooth/bluez/bluez5_helper_p.h
+++ b/src/bluetooth/bluez/bluez5_helper_p.h
@@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE
bool isBluez5();
+QString sanitizeNameForDBus(const QString& text);
+
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok);
class QtBluezDiscoveryManagerPrivate;
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm
index 2f881f79..21ba1b81 100644
--- a/src/bluetooth/osx/osxbtcentralmanager.mm
+++ b/src/bluetooth/osx/osxbtcentralmanager.mm
@@ -43,12 +43,12 @@
#include <algorithm>
#include <limits>
-QT_BEGIN_NAMESPACE
-
Q_DECLARE_METATYPE(QLowEnergyCharacteristic)
Q_DECLARE_METATYPE(QLowEnergyDescriptor)
Q_DECLARE_METATYPE(QLowEnergyHandle)
+QT_BEGIN_NAMESPACE
+
namespace OSXBluetooth {
NSUInteger qt_countGATTEntries(CBService *service)
@@ -80,7 +80,6 @@ NSUInteger qt_countGATTEntries(CBService *service)
QT_END_NAMESPACE
-QT_USE_NAMESPACE
@interface QT_MANGLE_NAMESPACE(OSXBTCentralManager) (PrivateAPI)
diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h
index 3506b0d1..8816d6f3 100644
--- a/src/bluetooth/osx/osxbtutility_p.h
+++ b/src/bluetooth/osx/osxbtutility_p.h
@@ -94,8 +94,7 @@ public:
}
};
-typedef ObjCScopedPointer<NSAutoreleasePool> AutoreleasePool;
-#define QT_BT_MAC_AUTORELEASEPOOL const OSXBluetooth::AutoreleasePool pool([[NSAutoreleasePool alloc] init])
+#define QT_BT_MAC_AUTORELEASEPOOL const QMacAutoReleasePool pool;
template<class T>
class ObjCStrongReference {
diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
index e3fa81d1..d18f4bb1 100644
--- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
@@ -294,7 +294,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
// create path
profilePath = profilePathTemplate;
profilePath.append(QString::fromLatin1("/%1%2/%3").
- arg(QCoreApplication::applicationName()).
+ arg(sanitizeNameForDBus(QCoreApplication::applicationName())).
arg(QCoreApplication::applicationPid()).
arg(pathCounter.fetchAndAddOrdered(1)));
diff --git a/src/bluetooth/qbluetoothsocket_osx_p.h b/src/bluetooth/qbluetoothsocket_osx_p.h
index cfd653d3..969dcef6 100644
--- a/src/bluetooth/qbluetoothsocket_osx_p.h
+++ b/src/bluetooth/qbluetoothsocket_osx_p.h
@@ -98,7 +98,7 @@ public:
quint16 peerPort() const;
void _q_readNotify();
- void _q_writeNotify();
+ void _q_writeNotify() Q_DECL_OVERRIDE;
private:
// Create a socket from an external source (without connectToService).
diff --git a/src/bluetooth/qbluetoothtransferreply_bluez.cpp b/src/bluetooth/qbluetoothtransferreply_bluez.cpp
index f7f72873..3362b2c1 100644
--- a/src/bluetooth/qbluetoothtransferreply_bluez.cpp
+++ b/src/bluetooth/qbluetoothtransferreply_bluez.cpp
@@ -91,7 +91,7 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con
m_agent_path = agentPath;
m_agent_path.append(QStringLiteral("/%1%2/%3").
- arg(QCoreApplication::applicationName()).
+ arg(sanitizeNameForDBus(QCoreApplication::applicationName())).
arg(QCoreApplication::applicationPid()).
arg(agentPathCounter.fetchAndAddOrdered(1)));
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index d4d41d69..8a6a2e1d 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -271,11 +271,12 @@ void QLowEnergyControllerPrivate::setError(
case QLowEnergyController::AdvertisingError:
errorString = QLowEnergyController::tr("Error occurred trying to start advertising");
break;
+ case QLowEnergyController::NoError:
+ return;
+ default:
case QLowEnergyController::UnknownError:
errorString = QLowEnergyController::tr("Unknown Error");
break;
- case QLowEnergyController::NoError:
- return;
}
emit q->error(newError);
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index 1ad57a8f..3e3ea830 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -326,6 +326,14 @@ void QLowEnergyControllerPrivate::connectionUpdated(
if (newState == QLowEnergyController::UnconnectedState
&& !(oldState == QLowEnergyController::UnconnectedState
|| oldState == QLowEnergyController::ConnectingState)) {
+
+ // Invalidate the services if the disconnect came from the remote end.
+ // Qtherwise we disconnected via QLowEnergyController::disconnectDevice() which
+ // triggered invalidation already
+ if (!serviceList.isEmpty()) {
+ Q_ASSERT(oldState != QLowEnergyController::ClosingState);
+ invalidateServices();
+ }
emit q->disconnected();
} else if (newState == QLowEnergyController::ConnectedState
&& oldState != QLowEnergyController::ConnectedState ) {
diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm
index 975c03c4..7ca0d9ac 100644
--- a/src/bluetooth/qlowenergycontroller_osx.mm
+++ b/src/bluetooth/qlowenergycontroller_osx.mm
@@ -132,7 +132,6 @@ UUIDList qt_servicesUuids(NSArray *services)
QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyController *q)
: q_ptr(q),
- isConnecting(false),
lastError(QLowEnergyController::NoError),
controllerState(QLowEnergyController::UnconnectedState),
addressType(QLowEnergyController::PublicAddress)
@@ -165,7 +164,6 @@ QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyControl
: q_ptr(q),
deviceUuid(deviceInfo.deviceUuid()),
deviceName(deviceInfo.name()),
- isConnecting(false),
lastError(QLowEnergyController::NoError),
controllerState(QLowEnergyController::UnconnectedState),
addressType(QLowEnergyController::PublicAddress)
@@ -214,20 +212,18 @@ void QLowEnergyControllerPrivateOSX::_q_connected()
controllerState = QLowEnergyController::ConnectedState;
- if (!isConnecting) {
- emit q_ptr->stateChanged(QLowEnergyController::ConnectedState);
- emit q_ptr->connected();
- }
+ emit q_ptr->stateChanged(QLowEnergyController::ConnectedState);
+ emit q_ptr->connected();
}
void QLowEnergyControllerPrivateOSX::_q_disconnected()
{
controllerState = QLowEnergyController::UnconnectedState;
- if (!isConnecting) {
- emit q_ptr->stateChanged(QLowEnergyController::UnconnectedState);
- emit q_ptr->disconnected();
- }
+ invalidateServices();
+ emit q_ptr->stateChanged(QLowEnergyController::UnconnectedState);
+ emit q_ptr->disconnected();
+
}
void QLowEnergyControllerPrivateOSX::_q_serviceDiscoveryFinished()
@@ -512,8 +508,6 @@ void QLowEnergyControllerPrivateOSX::connectToDevice()
Q_FUNC_INFO, "invalid state");
Q_ASSERT_X(!deviceUuid.isNull(), Q_FUNC_INFO,
"invalid private controller (no device uuid)");
- Q_ASSERT_X(!isConnecting, Q_FUNC_INFO,
- "recursive connectToDevice call");
dispatch_queue_t leQueue(OSXBluetooth::qt_LE_queue());
if (!leQueue) {
diff --git a/src/bluetooth/qlowenergycontroller_osx_p.h b/src/bluetooth/qlowenergycontroller_osx_p.h
index 58804243..190f2ac5 100644
--- a/src/bluetooth/qlowenergycontroller_osx_p.h
+++ b/src/bluetooth/qlowenergycontroller_osx_p.h
@@ -148,12 +148,6 @@ private:
QLowEnergyController *q_ptr;
QBluetoothUuid deviceUuid;
QString deviceName;
- // To be sure we set controller's state correctly
- // (Connecting or Connected) we have to know if we're
- // still inside connectToDevice - this is important,
- // if a peripheral is _already_ connected from Core Bluetooth's
- // point of view.
- bool isConnecting;
QString errorString;
QLowEnergyController::Error lastError;
diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp
index 0d57e5f3..1cb8d30c 100644
--- a/src/nfc/qnearfieldtarget.cpp
+++ b/src/nfc/qnearfieldtarget.cpp
@@ -135,7 +135,7 @@ static const quint16 crc_tbl[16] = {
*/
quint16 qNfcChecksum(const char *data, uint len)
{
- register quint16 crc = 0x6363;
+ quint16 crc = 0x6363;
uchar c;
const uchar *p = reinterpret_cast<const uchar *>(data);
while (len--) {
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
index 8c924925..1386f75c 100644
--- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
+++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
@@ -189,7 +189,7 @@ void tst_QLowEnergyController::initTestCase()
*/
void tst_QLowEnergyController::init()
{
-#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
+#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_TVOS)
/*
* Add a delay to give Android/iOS stack time to catch up in between
* the multiple connect/disconnects within each test function.
@@ -249,7 +249,7 @@ void tst_QLowEnergyController::tst_connect()
{
QList<QBluetoothHostInfo> localAdapters = QBluetoothLocalDevice::allDevices();
-#ifdef Q_OS_IOS
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
if (remoteDeviceInfo.isValid())
#else
if (localAdapters.isEmpty() || !remoteDeviceInfo.isValid())
@@ -265,7 +265,7 @@ void tst_QLowEnergyController::tst_connect()
else
QCOMPARE(control.remoteName(), remoteDeviceInfo.name());
-#ifndef Q_OS_IOS
+#if !defined(Q_OS_IOS) && !defined(Q_OS_TVOS)
const QBluetoothAddress localAdapter = localAdapters.at(0).address();
QCOMPARE(control.localAddress(), localAdapter);
QVERIFY(!control.localAddress().isNull());