summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothserver_bluez.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2018-08-16 09:16:15 +0200
committerAlex Blasche <alexander.blasche@qt.io>2018-08-16 12:54:02 +0000
commitf602d7fef2e2f067e123e5740d4b0bf16c4ec0e2 (patch)
tree4fa53bcee779c93304572dd3b46ee7fee8b57098 /src/bluetooth/qbluetoothserver_bluez.cpp
parent58a0fe8f9ab9ea3e080148f95359a355517d5cc5 (diff)
Ensure that QBluetoothServer works with new DBus based sockets
or better ensure that the DBus based socket is not used for QBluetoothServer. The server implementation will continue to use the raw socket implementation for the foreseeable future. The reason being the DBus version not yet working. convertAddress() in the server cpp was removed because it was a duplicate implementation. Including qbluetoothsocket_bluez_p.h pulls in the qbluetoothsocketbase_p.h which provides the official convertAddress() implementations. Unfortunately this requires a new ctor for QBluetoothSocket which is only specified for BlueZ builds. It is used to permit QBluetoothServer to set the correct dptr for QBluetoothSocket. Task-number: QTBUG-68550 Change-Id: I19298f75e9bc2ab93322d9f34e1816ad733ac6d9 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/bluetooth/qbluetoothserver_bluez.cpp')
-rw-r--r--src/bluetooth/qbluetoothserver_bluez.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp
index fe36a712..f67dffde 100644
--- a/src/bluetooth/qbluetoothserver_bluez.cpp
+++ b/src/bluetooth/qbluetoothserver_bluez.cpp
@@ -40,6 +40,7 @@
#include "qbluetoothserver.h"
#include "qbluetoothserver_p.h"
#include "qbluetoothsocket.h"
+#include "qbluetoothsocket_bluez_p.h"
#include "qbluetoothlocaldevice.h"
#include "bluez/bluez_data_p.h"
@@ -52,14 +53,17 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
-static inline void convertAddress(quint64 from, quint8 (&to)[6])
+QBluetoothSocket *QBluetoothServerPrivate::createSocketForServer(
+ QBluetoothServiceInfo::Protocol socketType)
{
- to[0] = (from >> 0) & 0xff;
- to[1] = (from >> 8) & 0xff;
- to[2] = (from >> 16) & 0xff;
- to[3] = (from >> 24) & 0xff;
- to[4] = (from >> 32) & 0xff;
- to[5] = (from >> 40) & 0xff;
+ // QBluetoothServer does not work with the BluetoothSocket implementation for DBus.
+ // Fall back to the raw socket implementation.
+ // Usually the private implementation is picked based on detected BlueZ version.
+
+ // ownership of these objects is taken care of inside QBluetoothSocket and QBluetoothServer
+ QBluetoothSocketPrivateBluez *rawSocketPrivate = new QBluetoothSocketPrivateBluez();
+ QBluetoothSocket *socket = new QBluetoothSocket(rawSocketPrivate, socketType);
+ return socket;
}
QBluetoothServerPrivate::QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol sType)
@@ -67,9 +71,9 @@ QBluetoothServerPrivate::QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol
m_lastError(QBluetoothServer::NoError), socketNotifier(0)
{
if (sType == QBluetoothServiceInfo::RfcommProtocol)
- socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
+ socket = createSocketForServer(QBluetoothServiceInfo::RfcommProtocol);
else
- socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol);
+ socket = createSocketForServer(QBluetoothServiceInfo::L2capProtocol);
}
QBluetoothServerPrivate::~QBluetoothServerPrivate()
@@ -185,9 +189,9 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
delete d->socket;
if (serverType() == QBluetoothServiceInfo::RfcommProtocol)
- d->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
+ d->socket = QBluetoothServerPrivate::createSocketForServer(QBluetoothServiceInfo::RfcommProtocol);
else
- d->socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol);
+ d->socket = QBluetoothServerPrivate::createSocketForServer(QBluetoothServiceInfo::L2capProtocol);
sock = d->socket->socketDescriptor();
if (sock < 0) {
@@ -294,7 +298,7 @@ QBluetoothSocket *QBluetoothServer::nextPendingConnection()
}
if (pending >= 0) {
- QBluetoothSocket *newSocket = new QBluetoothSocket;
+ QBluetoothSocket *newSocket = QBluetoothServerPrivate::createSocketForServer();
if (d->serverType == QBluetoothServiceInfo::RfcommProtocol)
newSocket->setSocketDescriptor(pending, QBluetoothServiceInfo::RfcommProtocol);
else