From 32623c4686d069305c8f7e046038cfcc5817052a Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 3 Nov 2017 12:24:31 +0100 Subject: Convert most old-style QObject::connect() to pointer syntax The remaining cases (e.g. in QBluetoothServiceDiscoveryAgent) are connected to Q_PRIVATE_SLOT usage which requires a redesign. Change-Id: I9227b5459b81228a7aa2660193d5b984c036b74f Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index a35863b4..6c14cffc 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -662,8 +662,10 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O //qDebug() << "Got agent"; - connect(d->discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); - connect(d->discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); + connect(d->discoveryAgent, &QBluetoothServiceDiscoveryAgent::serviceDiscovered, + this, &QBluetoothSocket::serviceDiscovered); + connect(d->discoveryAgent, &QBluetoothServiceDiscoveryAgent::finished, + this, &QBluetoothSocket::discoveryFinished); d->openMode = openMode; -- cgit v1.2.1 From e8d9bd63b05b33b22ff5d19fb31ad55b1e409256 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 3 Jan 2018 13:34:48 +0100 Subject: Improve documentation about missing iOS support in QtBluetooth Task-number: QTBUG-65547 Change-Id: I472b354621db89a921eec01b1459d46dbaa15ac0 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothsocket.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index a35863b4..06b0668c 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -81,6 +81,9 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT) \note QBluetoothSocket does not support synchronous read and write operations. Functions such as \l waitForReadyRead() and \l waitForBytesWritten() are not implemented. I/O operations should be performed using \l readyRead(), \l read() and \l write(). + + On iOS, this class cannot be used because the platform does not expose + an API which may permit access to QBluetoothSocket related features. */ /*! -- cgit v1.2.1 From da4273723f42bb53827124101d91afa97d14b984 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 24 Jan 2018 14:04:03 +0100 Subject: Avoid wrong implicit cast leading to wrong connectToService() call Prior to this change passing a QBluetoothUuid::ServiceClassUuid to connectToService() caused the port overload to be called rather than the QBluetoothUuid version. This patch introduces a ServiceClassUuid overload that avoids relying on implicit type conversion. There is a remote chance that this patch breaks existing code if the remote port was in the same range as the ServiceClassUuid range. In general the Bluetooth ports are below 100 though. Task-number: QTBUG-65831 Change-Id: I6574291ae6fee284466d84ecb91f21e3be89f6b2 Reviewed-by: Simon Hausmann Reviewed-by: Karsten Heimrich --- src/bluetooth/qbluetoothsocket.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 18567f34..ddc6469f 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -386,6 +386,14 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op #endif } +/*! + \fn void QBluetoothSocket::connectToService(const QBluetoothAddress &address, QBluetoothUuid::ServiceClassUuid uuid, OpenMode openMode = ReadWrite) + + \internal + + Exists to avoid QTBUG-65831. +*/ + /*! Attempts to make a connection to the service identified by \a uuid on the device with address \a address. -- cgit v1.2.1 From 279a6968a7550b59e41ff8ffa70a5ca705780d4b Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 20 Mar 2018 15:45:12 +0100 Subject: Fix shadow warning qbluetoothsocket.h: In member function 'void QBluetoothSocket::connectToService( const QBluetoothAddress&, QBluetoothUuid::ServiceClassUuid, QIODevice::OpenMode)': qbluetoothsocket.h:111:5: error: declaration of 'openMode' shadows a member of 'this' [-Werror=shadow] Change-Id: Ib9478027799b287430721d99bebee4002a1e5896 Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index ddc6469f..c5b0f7d3 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -387,7 +387,7 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op } /*! - \fn void QBluetoothSocket::connectToService(const QBluetoothAddress &address, QBluetoothUuid::ServiceClassUuid uuid, OpenMode openMode = ReadWrite) + \fn void QBluetoothSocket::connectToService(const QBluetoothAddress &address, QBluetoothUuid::ServiceClassUuid uuid, OpenMode mode = ReadWrite) \internal -- cgit v1.2.1 From db58c8691d9a0d6f9ee9226658b0fd6508a52c12 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 26 Apr 2018 08:59:00 +0200 Subject: Add missing emission of readChannelFinished() This fixes the problem for all supported platforms. Task-number: QTBUG-67672 Change-Id: I9cecfbe8a73df46070293eba1870ea3bee738b7b Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothsocket.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index c5b0f7d3..1ad3ffc2 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -742,6 +742,7 @@ void QBluetoothSocket::abort() #ifndef QT_ANDROID_BLUETOOTH //Android closes when the Java event loop comes around setSocketState(QBluetoothSocket::UnconnectedState); + emit readChannelFinished(); emit disconnected(); #endif } @@ -827,6 +828,7 @@ void QBluetoothSocket::close() #ifndef QT_ANDROID_BLUETOOTH //Android closes when the Java event loop comes around setSocketState(UnconnectedState); + emit readChannelFinished(); emit disconnected(); #endif } -- cgit v1.2.1 From 1036b09c0e613f01c48cc5e25ca51c0faddaacb4 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 23 Jul 2018 10:29:58 +0200 Subject: QBluetoothSocket - fix info message (IOBluetooth) Change-Id: If84041384b09a73c1da0277fef571f3ac37155e2 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 1ad3ffc2..214201b9 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -661,7 +661,7 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O Q_D(QBluetoothSocket); setSocketState(QBluetoothSocket::ServiceLookupState); - qCDebug(QT_BT) << "Starting Bluetooth Socket discovery"; + qCDebug(QT_BT) << "Starting Bluetooth service discovery"; if(d->discoveryAgent) { d->discoveryAgent->stop(); -- cgit v1.2.1 From 28eeb7afc27e99deeb52eefe10cdd458c7621698 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 18 Jul 2018 11:03:53 +0200 Subject: Add runtime polymorphism for QBluetoothSocketPrivate This patch introduces a generic interface towards QBluetoothSocketPrivate. Later on, the QBluetoothSocketPrivate class will be split into platform specific overloads/interfaces. Ultimately, this will be needed to support runtime selection of the QBluetootSocket d-pointer on Linux. The Linux Bluez5 implementation is significantly different from the Bluez4 (raw socket) implementation. Since recent Bluez5 releases the raw socket implementation is no longer functional and/or the user has to have root permission and enable bluetooth --compat mode. Therefore a second QBluetoothSocket for the dbus socket API is needed. QBLuetoothSocket has to choose at runtime (during its instanciation) which implementation to use. Task-number: QTBUG-68550 Change-Id: I5d0b8e24b8acd1b149b897f52f0d82eade7f3823 Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov Reviewed-by: Lubomir I. Ivanov --- src/bluetooth/qbluetoothsocket.cpp | 66 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 214201b9..6a5178db 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -250,11 +250,12 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT) Constructs a Bluetooth socket of \a socketType type, with \a parent. */ QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, QObject *parent) -: QIODevice(parent), d_ptr(new QBluetoothSocketPrivate) +: QIODevice(parent) { + d_ptr = new QBluetoothSocketPrivate(); d_ptr->q_ptr = this; - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); d->ensureNativeSocket(socketType); setOpenMode(QIODevice::NotOpen); @@ -264,8 +265,9 @@ QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, Q Constructs a Bluetooth socket with \a parent. */ QBluetoothSocket::QBluetoothSocket(QObject *parent) - : QIODevice(parent), d_ptr(new QBluetoothSocketPrivate) + : QIODevice(parent) { + d_ptr = new QBluetoothSocketPrivate(); d_ptr->q_ptr = this; setOpenMode(QIODevice::NotOpen); } @@ -294,7 +296,7 @@ bool QBluetoothSocket::isSequential() const */ qint64 QBluetoothSocket::bytesAvailable() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return QIODevice::bytesAvailable() + d->bytesAvailable(); } @@ -304,7 +306,7 @@ qint64 QBluetoothSocket::bytesAvailable() const */ qint64 QBluetoothSocket::bytesToWrite() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->bytesToWrite(); } @@ -327,7 +329,7 @@ qint64 QBluetoothSocket::bytesToWrite() const */ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, OpenMode openMode) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); if (state() != QBluetoothSocket::UnconnectedState && state() != QBluetoothSocket::ServiceLookupState) { qCWarning(QT_BT) << "QBluetoothSocket::connectToService called on busy socket"; @@ -419,7 +421,7 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op */ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); if (state() != QBluetoothSocket::UnconnectedState) { qCWarning(QT_BT) << "QBluetoothSocket::connectToService called on busy socket"; @@ -480,7 +482,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const */ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, quint16 port, OpenMode openMode) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); #if defined(QT_ANDROID_BLUETOOTH) Q_UNUSED(port); Q_UNUSED(openMode); @@ -526,7 +528,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, quint1 */ QBluetoothServiceInfo::Protocol QBluetoothSocket::socketType() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->socketType; } @@ -535,7 +537,7 @@ QBluetoothServiceInfo::Protocol QBluetoothSocket::socketType() const */ QBluetoothSocket::SocketState QBluetoothSocket::state() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->state; } @@ -544,7 +546,7 @@ QBluetoothSocket::SocketState QBluetoothSocket::state() const */ QBluetoothSocket::SocketError QBluetoothSocket::error() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->socketError; } @@ -553,7 +555,7 @@ QBluetoothSocket::SocketError QBluetoothSocket::error() const */ QString QBluetoothSocket::errorString() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->errorString; } @@ -586,7 +588,7 @@ QString QBluetoothSocket::errorString() const */ void QBluetoothSocket::setPreferredSecurityFlags(QBluetooth::SecurityFlags flags) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); if (d->secFlags != flags) d->secFlags = flags; } @@ -607,7 +609,7 @@ void QBluetoothSocket::setPreferredSecurityFlags(QBluetooth::SecurityFlags flags */ QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->secFlags; } @@ -616,7 +618,7 @@ QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const */ void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); SocketState old = d->state; d->state = state; if(old != d->state) @@ -636,7 +638,7 @@ void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state) bool QBluetoothSocket::canReadLine() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->canReadLine(); } @@ -645,7 +647,7 @@ bool QBluetoothSocket::canReadLine() const */ void QBluetoothSocket::setSocketError(QBluetoothSocket::SocketError error_) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); d->socketError = error_; emit error(error_); } @@ -658,7 +660,7 @@ void QBluetoothSocket::setSocketError(QBluetoothSocket::SocketError error_) void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, OpenMode openMode) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); setSocketState(QBluetoothSocket::ServiceLookupState); qCDebug(QT_BT) << "Starting Bluetooth service discovery"; @@ -697,7 +699,7 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O void QBluetoothSocket::serviceDiscovered(const QBluetoothServiceInfo &service) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); qCDebug(QT_BT) << "FOUND SERVICE!" << service; if (service.protocolServiceMultiplexer() > 0 || service.serverChannel() > 0) { connectToService(service, d->openMode); @@ -711,7 +713,7 @@ void QBluetoothSocket::serviceDiscovered(const QBluetoothServiceInfo &service) void QBluetoothSocket::discoveryFinished() { qCDebug(QT_BT) << "Socket discovery finished"; - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); if (d->discoveryAgent){ qCDebug(QT_BT) << "Didn't find any"; d->errorString = tr("Service cannot be found"); @@ -727,7 +729,7 @@ void QBluetoothSocket::abort() if (state() == UnconnectedState) return; - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); setOpenMode(QIODevice::NotOpen); if (state() == ServiceLookupState && d->discoveryAgent) { @@ -754,43 +756,43 @@ void QBluetoothSocket::disconnectFromService() QString QBluetoothSocket::localName() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->localName(); } QBluetoothAddress QBluetoothSocket::localAddress() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->localAddress(); } quint16 QBluetoothSocket::localPort() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->localPort(); } QString QBluetoothSocket::peerName() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->peerName(); } QBluetoothAddress QBluetoothSocket::peerAddress() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->peerAddress(); } quint16 QBluetoothSocket::peerPort() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->peerPort(); } qint64 QBluetoothSocket::writeData(const char *data, qint64 maxSize) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); if (!data || maxSize <= 0) { d_ptr->errorString = tr("Invalid data/data size"); @@ -803,7 +805,7 @@ qint64 QBluetoothSocket::writeData(const char *data, qint64 maxSize) qint64 QBluetoothSocket::readData(char *data, qint64 maxSize) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); return d->readData(data, maxSize); } @@ -812,7 +814,7 @@ void QBluetoothSocket::close() if (state() == UnconnectedState) return; - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); setOpenMode(QIODevice::NotOpen); if (state() == ServiceLookupState && d->discoveryAgent) { @@ -844,7 +846,7 @@ void QBluetoothSocket::close() bool QBluetoothSocket::setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, SocketState socketState, OpenMode openMode) { - Q_D(QBluetoothSocket); + Q_D(QBluetoothSocketBase); return d->setSocketDescriptor(socketDescriptor, socketType, socketState, openMode); } @@ -855,7 +857,7 @@ bool QBluetoothSocket::setSocketDescriptor(int socketDescriptor, QBluetoothServi int QBluetoothSocket::socketDescriptor() const { - Q_D(const QBluetoothSocket); + Q_D(const QBluetoothSocketBase); return d->socket; } -- cgit v1.2.1 From b20db00c080ff87c5b2a4d1fff2eac7cd694539c Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 19 Jul 2018 12:53:30 +0200 Subject: Add separate interfaces for QBluetoothSocketPrivate on Linux Uses the new QBluetoothSocketBasePrivate interface to separate the Linux implementations from other platforms. On Linux, there will be the existing raw socket implementation and a BlueZ5 DBus implementation. The DBus implementation is required for very recent Bluez5 deployments (v5.4x+) which restrict access to traditional SDP discovery means like sdptool. For now the DBus implementation is non-existing/dysfunctional. Task-number: QTBUG-68550 Change-Id: Idd248ecdb2a443a95cde521ced929218d40df3fe Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 6a5178db..1b187f4f 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -39,7 +39,11 @@ ****************************************************************************/ #include "qbluetoothsocket.h" +#if QT_CONFIG(bluez) +#include "qbluetoothsocket_bluez_p.h" +#else #include "qbluetoothsocket_p.h" +#endif #include "qbluetoothdeviceinfo.h" #include "qbluetoothserviceinfo.h" @@ -252,7 +256,11 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT) QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, QObject *parent) : QIODevice(parent) { +#if QT_CONFIG(bluez) + d_ptr = new QBluetoothSocketPrivateBluez(); +#else d_ptr = new QBluetoothSocketPrivate(); +#endif d_ptr->q_ptr = this; Q_D(QBluetoothSocketBase); @@ -267,7 +275,11 @@ QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, Q QBluetoothSocket::QBluetoothSocket(QObject *parent) : QIODevice(parent) { +#if QT_CONFIG(bluez) + d_ptr = new QBluetoothSocketPrivateBluez(); +#else d_ptr = new QBluetoothSocketPrivate(); +#endif d_ptr->q_ptr = this; setOpenMode(QIODevice::NotOpen); } -- cgit v1.2.1 From 40beb226dfe8c23f290d554d5449806e91227f7e Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 19 Jul 2018 17:37:40 +0200 Subject: Add QBluetoothSocketPrivate interface for Android Task-number: QTBUG-68550 Change-Id: Iac05cccd4f6e1b44a30568fb9b6c9171204b53fd Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 1b187f4f..d59b2adb 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -41,6 +41,8 @@ #include "qbluetoothsocket.h" #if QT_CONFIG(bluez) #include "qbluetoothsocket_bluez_p.h" +#elif defined(QT_ANDROID_BLUETOOTH) +#include "qbluetoothsocket_android_p.h" #else #include "qbluetoothsocket_p.h" #endif @@ -258,6 +260,8 @@ QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, Q { #if QT_CONFIG(bluez) d_ptr = new QBluetoothSocketPrivateBluez(); +#elif defined(QT_ANDROID_BLUETOOTH) + d_ptr = new QBluetoothSocketPrivateAndroid(); #else d_ptr = new QBluetoothSocketPrivate(); #endif @@ -277,6 +281,8 @@ QBluetoothSocket::QBluetoothSocket(QObject *parent) { #if QT_CONFIG(bluez) d_ptr = new QBluetoothSocketPrivateBluez(); +#elif defined(QT_ANDROID_BLUETOOTH) + d_ptr = new QBluetoothSocketPrivateAndroid(); #else d_ptr = new QBluetoothSocketPrivate(); #endif -- cgit v1.2.1 From 4aa30934473380793fb7bce38c9c8f6f235c9e4a Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 20 Jul 2018 12:15:55 +0200 Subject: Add QBluetoothSocketPrivate interface for WinRT Task-number: QTBUG-68550 Change-Id: I14fe43fcbbbdd6950f05feda900643f6899daa24 Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index d59b2adb..feb52684 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -43,6 +43,8 @@ #include "qbluetoothsocket_bluez_p.h" #elif defined(QT_ANDROID_BLUETOOTH) #include "qbluetoothsocket_android_p.h" +#elif defined(QT_WINRT_BLUETOOTH) +#include "qbluetoothsocket_winrt_p.h" #else #include "qbluetoothsocket_p.h" #endif @@ -262,6 +264,8 @@ QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, Q d_ptr = new QBluetoothSocketPrivateBluez(); #elif defined(QT_ANDROID_BLUETOOTH) d_ptr = new QBluetoothSocketPrivateAndroid(); +#elif defined(QT_WINRT_BLUETOOTH) + d_ptr = new QBluetoothSocketPrivateWinRT(); #else d_ptr = new QBluetoothSocketPrivate(); #endif @@ -283,6 +287,8 @@ QBluetoothSocket::QBluetoothSocket(QObject *parent) d_ptr = new QBluetoothSocketPrivateBluez(); #elif defined(QT_ANDROID_BLUETOOTH) d_ptr = new QBluetoothSocketPrivateAndroid(); +#elif defined(QT_WINRT_BLUETOOTH) + d_ptr = new QBluetoothSocketPrivateWinRT(); #else d_ptr = new QBluetoothSocketPrivate(); #endif -- cgit v1.2.1 From e452269d918655c3aaf0d5759cf2143478661af5 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 20 Jul 2018 12:38:10 +0200 Subject: Rename the final interface for the QBluetoothSocketPrivate dummy At the same time we reshuffle the inclusion of qbluetoothsocket_p.h in bluetooth.pro based on usage pattern. Task-number: QTBUG-68550 Change-Id: I3ae3f61c65e71a57d238f5c67289720ff63a1b0f Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index feb52684..9516a0c4 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -267,7 +267,7 @@ QBluetoothSocket::QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, Q #elif defined(QT_WINRT_BLUETOOTH) d_ptr = new QBluetoothSocketPrivateWinRT(); #else - d_ptr = new QBluetoothSocketPrivate(); + d_ptr = new QBluetoothSocketPrivateDummy(); #endif d_ptr->q_ptr = this; @@ -290,7 +290,7 @@ QBluetoothSocket::QBluetoothSocket(QObject *parent) #elif defined(QT_WINRT_BLUETOOTH) d_ptr = new QBluetoothSocketPrivateWinRT(); #else - d_ptr = new QBluetoothSocketPrivate(); + d_ptr = new QBluetoothSocketPrivateDummy(); #endif d_ptr->q_ptr = this; setOpenMode(QIODevice::NotOpen); -- cgit v1.2.1 From 81de083e4f9fdee7f1ef7d2fffc7d2147ddbc1b0 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 20 Jul 2018 16:19:13 +0200 Subject: Rename QBluetoothSocketBasePrivate::connectToService() The goal is to move the various QBluetoothSocket::connectoService() implementations into the private classes. Common parts can be split into QBluetoothSocketBasePrivate and the platform specific code. The code becomes cleaner and has less ifdefs. However this creates a symbol clash with the currently existing private implementation as it has a function with the same signature but different purpose. This rename provides the foundation for future changes. Task-number: QTBUG-68550 Change-Id: I121f08d93e00790c1619c0449629f47bca8a964d Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 9516a0c4..1849844e 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -367,7 +367,7 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op setSocketError(QBluetoothSocket::UnsupportedProtocolError); return; } - d->connectToService(service.device().address(), service.serviceUuid(), openMode); + d->connectToServiceHelper(service.device().address(), service.serviceUuid(), openMode); #else #if defined(QT_WINRT_BLUETOOTH) // Report these problems early: @@ -391,14 +391,14 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op setSocketError(UnknownSocketError); return; } - d->connectToService(service.device().address(), service.protocolServiceMultiplexer(), openMode); + d->connectToServiceHelper(service.device().address(), service.protocolServiceMultiplexer(), openMode); } else if (service.serverChannel() > 0) { if (!d->ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) { d->errorString = tr("Unknown socket error"); setSocketError(UnknownSocketError); return; } - d->connectToService(service.device().address(), service.serverChannel(), openMode); + d->connectToServiceHelper(service.device().address(), service.serverChannel(), openMode); } else { // try doing service discovery to see if we can find the socket if (service.serviceUuid().isNull() @@ -460,7 +460,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const setSocketError(QBluetoothSocket::UnsupportedProtocolError); return; } - d->connectToService(address, uuid, openMode); + d->connectToServiceHelper(address, uuid, openMode); #else #if defined(QT_WINRT_BLUETOOTH) // Report these problems early, prevent device discovery: @@ -539,7 +539,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, quint1 } setOpenMode(openMode); - d->connectToService(address, port, openMode); + d->connectToServiceHelper(address, port, openMode); #endif } -- cgit v1.2.1 From e84d9f24cbb7c686535cbe7e13f28a1c0baaa48d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 23 Jul 2018 13:13:49 +0200 Subject: Move QBluetoothSocket::connectToService() to private implementations This permits each platform to customize the implementations without the need for ifdefs. Upcoming changes such as the BLuez DBuS addition will increase the platform differences. Task-number: QTBUG-68550 Change-Id: I8fc9a74d3ce704466f0bf2c16287e32f222c4376 Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket.cpp | 140 ++----------------------------------- 1 file changed, 6 insertions(+), 134 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 1849844e..5f54da12 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -49,11 +49,8 @@ #include "qbluetoothsocket_p.h" #endif -#include "qbluetoothdeviceinfo.h" -#include "qbluetoothserviceinfo.h" #include "qbluetoothservicediscoveryagent.h" - #include #include @@ -354,62 +351,7 @@ qint64 QBluetoothSocket::bytesToWrite() const void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, OpenMode openMode) { Q_D(QBluetoothSocketBase); - - if (state() != QBluetoothSocket::UnconnectedState && state() != QBluetoothSocket::ServiceLookupState) { - qCWarning(QT_BT) << "QBluetoothSocket::connectToService called on busy socket"; - d->errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress"); - setSocketError(QBluetoothSocket::OperationError); - return; - } -#if defined(QT_ANDROID_BLUETOOTH) - if (!d->ensureNativeSocket(service.socketProtocol())) { - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } - d->connectToServiceHelper(service.device().address(), service.serviceUuid(), openMode); -#else -#if defined(QT_WINRT_BLUETOOTH) - // Report these problems early: - if (socketType() != QBluetoothServiceInfo::RfcommProtocol) { - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } -#endif // QT_WINRT_BLUETOOTH - if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { - qCWarning(QT_BT) << "QBluetoothSocket::connectToService cannot " - "connect with 'UnknownProtocol' type"; - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } - - if (service.protocolServiceMultiplexer() > 0) { - if (!d->ensureNativeSocket(QBluetoothServiceInfo::L2capProtocol)) { - d->errorString = tr("Unknown socket error"); - setSocketError(UnknownSocketError); - return; - } - d->connectToServiceHelper(service.device().address(), service.protocolServiceMultiplexer(), openMode); - } else if (service.serverChannel() > 0) { - if (!d->ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) { - d->errorString = tr("Unknown socket error"); - setSocketError(UnknownSocketError); - return; - } - d->connectToServiceHelper(service.device().address(), service.serverChannel(), openMode); - } else { - // try doing service discovery to see if we can find the socket - if (service.serviceUuid().isNull() - && !service.serviceClassUuids().contains(QBluetoothUuid::SerialPort)) { - qCWarning(QT_BT) << "No port, no PSM, and no UUID provided, unable to connect"; - return; - } - qCDebug(QT_BT) << "Need a port/psm, doing discovery"; - doDeviceDiscovery(service, openMode); - } -#endif + d->connectToService(service, openMode); } /*! @@ -429,10 +371,10 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op For BlueZ, the socket first enters the \l ServiceLookupState and queries the connection parameters for \a uuid. If the service parameters are successfully retrieved the socket enters ConnectingState, and attempts to connect to \a address. If a connection is established, - QBluetoothSocket enters Connected State and emits connected(). + QBluetoothSocket enters \l ConnectedState and emits connected(). On Android, the service connection can directly be established - using the UUID of the remote service. Therefore the platforms does not require + using the UUID of the remote service. Therefore the platform does not require the \l ServiceLookupState and \l socketType() is always set to \l QBluetoothServiceInfo::RfcommProtocol. @@ -446,44 +388,7 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode) { Q_D(QBluetoothSocketBase); - - if (state() != QBluetoothSocket::UnconnectedState) { - qCWarning(QT_BT) << "QBluetoothSocket::connectToService called on busy socket"; - d->errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress"); - setSocketError(QBluetoothSocket::OperationError); - return; - } - -#if defined(QT_ANDROID_BLUETOOTH) - if (!d->ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) { - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } - d->connectToServiceHelper(address, uuid, openMode); -#else -#if defined(QT_WINRT_BLUETOOTH) - // Report these problems early, prevent device discovery: - if (socketType() != QBluetoothServiceInfo::RfcommProtocol) { - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } -#endif // QT_WINRT_BLUETOOTH - if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { - qCWarning(QT_BT) << "QBluetoothSocket::connectToService cannot " - "connect with 'UnknownProtocol' type"; - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } - - QBluetoothServiceInfo service; - QBluetoothDeviceInfo device(address, QString(), QBluetoothDeviceInfo::MiscellaneousDevice); - service.setDevice(device); - service.setServiceUuid(uuid); - doDeviceDiscovery(service, openMode); -#endif + d->connectToService(address, uuid, openMode); } /*! @@ -497,7 +402,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const At any point, the socket can emit error() to signal that an error occurred. On Android, a connection to a service can not be established using a port. Calling this function - will emit a \l {QBluetoothSocket::ServiceNotFoundError}{ServiceNotFoundError} + will emit a \l {QBluetoothSocket::ServiceNotFoundError}{ServiceNotFoundError}. Note that most platforms require a pairing prior to connecting to the remote device. Otherwise the connection process may fail. @@ -507,40 +412,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const void QBluetoothSocket::connectToService(const QBluetoothAddress &address, quint16 port, OpenMode openMode) { Q_D(QBluetoothSocketBase); -#if defined(QT_ANDROID_BLUETOOTH) - Q_UNUSED(port); - Q_UNUSED(openMode); - Q_UNUSED(address); - d->errorString = tr("Connecting to port is not supported"); - setSocketError(QBluetoothSocket::ServiceNotFoundError); - qCWarning(QT_BT) << "Connecting to port is not supported"; -#else -#if defined(QT_WINRT_BLUETOOTH) - // Report these problems early - if (socketType() != QBluetoothServiceInfo::RfcommProtocol) { - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } -#endif // QT_WINRT_BLUETOOTH - if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { - qCWarning(QT_BT) << "QBluetoothSocket::connectToService cannot " - "connect with 'UnknownProtocol' type"; - d->errorString = tr("Socket type not supported"); - setSocketError(QBluetoothSocket::UnsupportedProtocolError); - return; - } - - if (state() != QBluetoothSocket::UnconnectedState) { - qCWarning(QT_BT) << "QBluetoothSocket::connectToService called on busy socket"; - d->errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress"); - setSocketError(QBluetoothSocket::OperationError); - return; - } - - setOpenMode(openMode); - d->connectToServiceHelper(address, port, openMode); -#endif + d->connectToService(address, port, openMode); } /*! -- cgit v1.2.1 From b19148f9a0f820630bd83432d96117e9598c315d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 24 Jul 2018 12:56:55 +0200 Subject: Rename qbluetoothsocket_p files to qbluetoothsocket_dummy The new name fits the class better. Task-number: QTBUG-68550 Change-Id: I7445f48134f8a9fe8b6b6291184f404b3b2faa89 Reviewed-by: Timur Pocheptsov Reviewed-by: Lubomir I. Ivanov --- src/bluetooth/qbluetoothsocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 5f54da12..dae844d7 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -46,7 +46,7 @@ #elif defined(QT_WINRT_BLUETOOTH) #include "qbluetoothsocket_winrt_p.h" #else -#include "qbluetoothsocket_p.h" +#include "qbluetoothsocket_dummy_p.h" #endif #include "qbluetoothservicediscoveryagent.h" -- cgit v1.2.1