summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2013-09-23 13:52:35 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-25 10:37:27 +0200
commit85de7d64e85aa058f1777bc9d1a778790b1d50a6 (patch)
treea498afb7454905736cf589d3624ab68542ae04d8
parent85eac47703aa40df76e5102eb04291d8f029bfa3 (diff)
Fix peer to peer communication using two local adapters.
The code assumed to use the default adapter in a variety of places which caused wrong SDP registrations, device searches and peer names. The btchat examples was extended to cope with two local adapters. If there are more than two local adapters they will be ignored. Change-Id: I27d8bce65d943773e4e6cbd86982446fa79664a4 Reviewed-by: Fabian Bumberger <fbumberger@rim.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--examples/bluetooth/btchat/chat.cpp50
-rw-r--r--examples/bluetooth/btchat/chat.h6
-rw-r--r--examples/bluetooth/btchat/chat.ui26
-rw-r--r--examples/bluetooth/btchat/chatclient.cpp2
-rw-r--r--examples/bluetooth/btchat/chatserver.cpp14
-rw-r--r--examples/bluetooth/btchat/chatserver.h3
-rw-r--r--examples/bluetooth/btchat/remoteselector.cpp17
-rw-r--r--examples/bluetooth/btchat/remoteselector.h2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp6
-rw-r--r--src/bluetooth/qbluetoothserviceinfo.cpp16
-rw-r--r--src/bluetooth/qbluetoothserviceinfo.h5
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_bluez.cpp32
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_p.cpp9
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_p.h16
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_qnx.cpp9
-rw-r--r--src/bluetooth/qbluetoothsocket_bluez.cpp9
16 files changed, 160 insertions, 62 deletions
diff --git a/examples/bluetooth/btchat/chat.cpp b/examples/bluetooth/btchat/chat.cpp
index 37bfb85c..f3df7aa1 100644
--- a/examples/bluetooth/btchat/chat.cpp
+++ b/examples/bluetooth/btchat/chat.cpp
@@ -56,7 +56,7 @@
static const QLatin1String serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c8");
Chat::Chat(QWidget *parent)
-: QDialog(parent), ui(new Ui_Chat)
+ : QDialog(parent), currentAdapterIndex(0), ui(new Ui_Chat)
{
//! [Construct UI]
ui->setupUi(this);
@@ -66,6 +66,22 @@ Chat::Chat(QWidget *parent)
connect(ui->sendButton, SIGNAL(clicked()), this, SLOT(sendClicked()));
//! [Construct UI]
+ localAdapters = QBluetoothLocalDevice::allDevices();
+ if (localAdapters.count() < 2) {
+ ui->localAdapterBox->setVisible(false);
+ } else {
+ //we ignore more than two adapters
+ ui->localAdapterBox->setVisible(true);
+ ui->firstAdapter->setText(tr("Default (%1)", "%1 = Bluetooth address").
+ arg(localAdapters.at(0).address().toString()));
+ ui->secondAdapter->setText(localAdapters.at(1).address().toString());
+ ui->firstAdapter->setChecked(true);
+ connect(ui->firstAdapter, SIGNAL(clicked()), this, SLOT(newAdapterSelected()));
+ connect(ui->secondAdapter, SIGNAL(clicked()), this, SLOT(newAdapterSelected()));
+ QBluetoothLocalDevice adapter(localAdapters.at(0).address());
+ adapter.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
+ }
+
//! [Create Chat Server]
server = new ChatServer(this);
connect(server, SIGNAL(clientConnected(QString)), this, SLOT(clientConnected(QString)));
@@ -104,6 +120,32 @@ void Chat::connected(const QString &name)
{
ui->chat->insertPlainText(QString::fromLatin1("Joined chat with %1.\n").arg(name));
}
+
+void Chat::newAdapterSelected()
+{
+ const int newAdapterIndex = adapterFromUserSelection();
+ if (currentAdapterIndex != newAdapterIndex) {
+ server->stopServer();
+ currentAdapterIndex = newAdapterIndex;
+ const QBluetoothHostInfo info = localAdapters.at(currentAdapterIndex);
+ QBluetoothLocalDevice adapter(info.address());
+ adapter.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
+ server->startServer(info.address());
+ localName = info.name();
+ }
+}
+
+int Chat::adapterFromUserSelection() const
+{
+ int result = 0;
+ QBluetoothAddress newAdapter = localAdapters.at(0).address();
+
+ if (ui->secondAdapter->isChecked()) {
+ newAdapter = localAdapters.at(1).address();
+ result = 1;
+ }
+ return result;
+}
//! [connected]
//! [clientDisconnected]
@@ -123,7 +165,11 @@ void Chat::connectClicked()
ui->connectButton->setEnabled(false);
// scan for services
- RemoteSelector remoteSelector;
+ const QBluetoothAddress adapter = localAdapters.isEmpty() ?
+ QBluetoothAddress() :
+ localAdapters.at(currentAdapterIndex).address();
+
+ RemoteSelector remoteSelector(adapter);
remoteSelector.startDiscovery(QBluetoothUuid(serviceUuid));
if (remoteSelector.exec() == QDialog::Accepted) {
QBluetoothServiceInfo service = remoteSelector.service();
diff --git a/examples/bluetooth/btchat/chat.h b/examples/bluetooth/btchat/chat.h
index fed850f1..75d7669f 100644
--- a/examples/bluetooth/btchat/chat.h
+++ b/examples/bluetooth/btchat/chat.h
@@ -44,6 +44,7 @@
#include <qbluetoothserviceinfo.h>
#include <qbluetoothsocket.h>
+#include <qbluetoothhostinfo.h>
#include <QDebug>
@@ -75,11 +76,16 @@ private slots:
void clientDisconnected();
void connected(const QString &name);
+ void newAdapterSelected();
+
private:
+ int adapterFromUserSelection() const;
+ int currentAdapterIndex;
Ui_Chat *ui;
ChatServer *server;
QList<ChatClient *> clients;
+ QList<QBluetoothHostInfo> localAdapters;
QString localName;
};
diff --git a/examples/bluetooth/btchat/chat.ui b/examples/bluetooth/btchat/chat.ui
index acebc937..d7829294 100644
--- a/examples/bluetooth/btchat/chat.ui
+++ b/examples/bluetooth/btchat/chat.ui
@@ -15,6 +15,32 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
+ <widget class="QGroupBox" name="localAdapterBox">
+ <property name="title">
+ <string>Local Bluetooth Adapter</string>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QRadioButton" name="firstAdapter">
+ <property name="text">
+ <string>Default</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="secondAdapter">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
<widget class="QTextEdit" name="chat">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
diff --git a/examples/bluetooth/btchat/chatclient.cpp b/examples/bluetooth/btchat/chatclient.cpp
index b6ba7c52..06930145 100644
--- a/examples/bluetooth/btchat/chatclient.cpp
+++ b/examples/bluetooth/btchat/chatclient.cpp
@@ -62,7 +62,7 @@ void ChatClient::startClient(const QBluetoothServiceInfo &remoteService)
socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
qDebug() << "Create socket";
socket->connectToService(remoteService);
- qDebug() << "ConnecttoService done";
+ qDebug() << "ConnectToService done";
connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
diff --git a/examples/bluetooth/btchat/chatserver.cpp b/examples/bluetooth/btchat/chatserver.cpp
index 863078fc..8b1bf6f0 100644
--- a/examples/bluetooth/btchat/chatserver.cpp
+++ b/examples/bluetooth/btchat/chatserver.cpp
@@ -42,6 +42,7 @@
#include <qbluetoothserver.h>
#include <qbluetoothsocket.h>
+#include <qbluetoothlocaldevice.h>
//! [Service UUID]
static const QLatin1String serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c8");
@@ -57,7 +58,7 @@ ChatServer::~ChatServer()
stopServer();
}
-void ChatServer::startServer()
+void ChatServer::startServer(const QBluetoothAddress& localAdapter)
{
if (rfcommServer)
return;
@@ -65,7 +66,11 @@ void ChatServer::startServer()
//! [Create the server]
rfcommServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
connect(rfcommServer, SIGNAL(newConnection()), this, SLOT(clientConnected()));
- rfcommServer->listen();
+ bool result = rfcommServer->listen(localAdapter);
+ if (!result) {
+ qWarning() << "Cannot bind chat server to" << localAdapter.toString();
+ return;
+ }
//! [Create the server]
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010);
@@ -81,7 +86,7 @@ void ChatServer::startServer()
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Bt Chat Server"));
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription,
tr("Example bluetooth chat server"));
- serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("Nokia, QtDF"));
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("qt-project.org"));
//! [Service name, description and provider]
//! [Service UUID set]
@@ -107,7 +112,7 @@ void ChatServer::startServer()
//! [Protocol descriptor list]
//! [Register service]
- serviceInfo.registerService();
+ serviceInfo.registerService(localAdapter);
//! [Register service]
}
@@ -146,7 +151,6 @@ void ChatServer::clientConnected()
connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
clientSockets.append(socket);
-
emit clientConnected(socket->peerName());
}
//! [clientConnected]
diff --git a/examples/bluetooth/btchat/chatserver.h b/examples/bluetooth/btchat/chatserver.h
index 2a3c3503..8af21f55 100644
--- a/examples/bluetooth/btchat/chatserver.h
+++ b/examples/bluetooth/btchat/chatserver.h
@@ -42,6 +42,7 @@
#define CHATSERVER_H
#include <qbluetoothserviceinfo.h>
+#include <qbluetoothaddress.h>
#include <QtCore/QObject>
#include <QtCore/QList>
@@ -60,7 +61,7 @@ public:
explicit ChatServer(QObject *parent = 0);
~ChatServer();
- void startServer();
+ void startServer(const QBluetoothAddress &localAdapter = QBluetoothAddress());
void stopServer();
public slots:
diff --git a/examples/bluetooth/btchat/remoteselector.cpp b/examples/bluetooth/btchat/remoteselector.cpp
index f660a815..73f56a54 100644
--- a/examples/bluetooth/btchat/remoteselector.cpp
+++ b/examples/bluetooth/btchat/remoteselector.cpp
@@ -47,25 +47,12 @@
QT_USE_NAMESPACE
-RemoteSelector::RemoteSelector(QWidget *parent)
+RemoteSelector::RemoteSelector(const QBluetoothAddress &localAdapter, QWidget *parent)
: QDialog(parent), ui(new Ui::RemoteSelector)
{
ui->setupUi(this);
- //Using default Bluetooth adapter
- QBluetoothLocalDevice localDevice;
- QBluetoothAddress adapterAddress = localDevice.address();
-
- /*
- * In case of multiple Bluetooth adapters it is possible to
- * set which adapter will be used by providing MAC Address.
- * Example code:
- *
- * QBluetoothAddress adapterAddress("XX:XX:XX:XX:XX:XX");
- * m_discoveryAgent = new QBluetoothServiceDiscoveryAgent(adapterAddress);
- */
-
- m_discoveryAgent = new QBluetoothServiceDiscoveryAgent(adapterAddress);
+ m_discoveryAgent = new QBluetoothServiceDiscoveryAgent(localAdapter);
connect(m_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
diff --git a/examples/bluetooth/btchat/remoteselector.h b/examples/bluetooth/btchat/remoteselector.h
index 3f6e15c9..5b123127 100644
--- a/examples/bluetooth/btchat/remoteselector.h
+++ b/examples/bluetooth/btchat/remoteselector.h
@@ -63,7 +63,7 @@ class RemoteSelector : public QDialog
Q_OBJECT
public:
- explicit RemoteSelector(QWidget *parent = 0);
+ explicit RemoteSelector(const QBluetoothAddress &localAdapter, QWidget *parent = 0);
~RemoteSelector();
void startDiscovery(const QBluetoothUuid &uuid);
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 023ffb80..b613642c 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -329,7 +329,11 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery()
Q_Q(QBluetoothServiceDiscoveryAgent);
if (!deviceDiscoveryAgent) {
- deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent;
+#ifdef QT_BLUEZ_BLUETOOTH
+ deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(m_deviceAdapterAddress, q);
+#else
+ deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(q);
+#endif
QObject::connect(deviceDiscoveryAgent, SIGNAL(finished()),
q, SLOT(_q_deviceDiscoveryFinished()));
QObject::connect(deviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp
index 4e2c0499..0a1d9ee5 100644
--- a/src/bluetooth/qbluetoothserviceinfo.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo.cpp
@@ -152,21 +152,27 @@ bool QBluetoothServiceInfo::isRegistered() const
}
/*!
- \fn bool QBluetoothServiceInfo::registerService() const
+ \fn bool QBluetoothServiceInfo::registerService()
Registers this service with the platform's Service Discovery Protocol (SDP) implementation,
making it findable by other devices when they perform service discovery. Returns true if the
service is successfully registered, otherwise returns false. Once registered changes to the record
cannot be made. The service must be unregistered and registered again with the changes.
+
+ The \l localAdapter parameter determines the local Bluetooth adapter under which
+ the service should be registered. If \a localAdapter is \c null the default Bluetooth adapter
+ will be used. If this service info object is already registered via a local adapter
+ and this is function is called using a different local adapter, the previous registration
+ is removed and the service reregistered using the new adapter.
*/
-bool QBluetoothServiceInfo::registerService() const
+bool QBluetoothServiceInfo::registerService(const QBluetoothAddress &localAdapter)
{
- return d_ptr->registerService();
+ return d_ptr->registerService(localAdapter);
}
/*!
- \fn bool QBluetoothServiceInfo::unregisterService() const
+ \fn bool QBluetoothServiceInfo::unregisterService()
Unregisters this service with the platform's Service Discovery Protocol (SDP) implementation.
After this, the service will no longer be findable by other devices through service discovery.
@@ -174,7 +180,7 @@ bool QBluetoothServiceInfo::registerService() const
Returns true if the service is successfully unregistered, otherwise returns false.
*/
-bool QBluetoothServiceInfo::unregisterService() const
+bool QBluetoothServiceInfo::unregisterService()
{
return d_ptr->unregisterService();
}
diff --git a/src/bluetooth/qbluetoothserviceinfo.h b/src/bluetooth/qbluetoothserviceinfo.h
index 507c7c1d..0e6555c0 100644
--- a/src/bluetooth/qbluetoothserviceinfo.h
+++ b/src/bluetooth/qbluetoothserviceinfo.h
@@ -45,6 +45,7 @@
#include <QtBluetooth/qbluetoothglobal.h>
#include <QtBluetooth/QBluetoothUuid>
+#include <QtBluetooth/QBluetoothAddress>
#include <QtCore/QMetaType>
#include <QtCore/QList>
@@ -145,8 +146,8 @@ public:
QBluetoothServiceInfo &operator=(const QBluetoothServiceInfo &other);
bool isRegistered() const;
- bool registerService() const;
- bool unregisterService() const;
+ bool registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress());
+ bool unregisterService();
protected:
friend Q_BLUETOOTH_EXPORT QDebug operator<<(QDebug, const QBluetoothServiceInfo &);
diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
index a98b4a46..a24e8cea 100644
--- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp
@@ -181,12 +181,12 @@ bool QBluetoothServiceInfoPrivate::isRegistered() const
return registered;
}
-bool QBluetoothServiceInfoPrivate::unregisterService() const
+bool QBluetoothServiceInfoPrivate::unregisterService()
{
if (!registered)
return false;
- if (!ensureSdpConnection())
+ if (!ensureSdpConnection(currentLocalAdapter))
return false;
QDBusPendingReply<> reply = service->RemoveRecord(serviceRecord);
@@ -200,7 +200,7 @@ bool QBluetoothServiceInfoPrivate::unregisterService() const
return true;
}
-void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, const QVariant &value) const
+void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, const QVariant &value)
{
Q_UNUSED(attributeId);
Q_UNUSED(value);
@@ -208,35 +208,47 @@ void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, c
registerService();
}
-void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId) const
+void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId)
{
Q_UNUSED(attributeId);
registerService();
}
-bool QBluetoothServiceInfoPrivate::ensureSdpConnection() const
+bool QBluetoothServiceInfoPrivate::ensureSdpConnection(const QBluetoothAddress &localAdapter)
{
- if (service)
+ if (service && currentLocalAdapter == localAdapter)
return true;
+ delete service;
+
OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"),
QDBusConnection::systemBus());
- QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(QLatin1String("any"));
+
+ QDBusPendingReply<QDBusObjectPath> reply;
+ if (localAdapter.isNull())
+ reply = manager.DefaultAdapter();
+ else
+ reply = manager.FindAdapter(localAdapter.toString());
reply.waitForFinished();
if (reply.isError())
return false;
+ currentLocalAdapter = localAdapter;
service = new OrgBluezServiceInterface(QLatin1String("org.bluez"), reply.value().path(),
- QDBusConnection::systemBus());
+ QDBusConnection::systemBus(), this);
return true;
}
-bool QBluetoothServiceInfoPrivate::registerService() const
+bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &localAdapter)
{
- if (!ensureSdpConnection()) {
+ //if new adapter unregister previous one first
+ if (registered && localAdapter != currentLocalAdapter)
+ unregisterService();
+
+ if (!ensureSdpConnection(localAdapter)) {
qWarning() << "SDP not connected. Cannot register";
return false;
}
diff --git a/src/bluetooth/qbluetoothserviceinfo_p.cpp b/src/bluetooth/qbluetoothserviceinfo_p.cpp
index 13bc8fd5..51aeb75b 100644
--- a/src/bluetooth/qbluetoothserviceinfo_p.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_p.cpp
@@ -57,24 +57,25 @@ bool QBluetoothServiceInfoPrivate::isRegistered() const
return false;
}
-bool QBluetoothServiceInfoPrivate::registerService() const
+bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &localAdapter)
{
+ Q_UNUSED(localAdapter);
return false;
}
-bool QBluetoothServiceInfoPrivate::unregisterService() const
+bool QBluetoothServiceInfoPrivate::unregisterService()
{
return false;
}
-void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, const QVariant &value) const
+void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, const QVariant &value)
{
Q_UNUSED(attributeId);
Q_UNUSED(value);
}
-void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId) const
+void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId)
{
Q_UNUSED(attributeId);
}
diff --git a/src/bluetooth/qbluetoothserviceinfo_p.h b/src/bluetooth/qbluetoothserviceinfo_p.h
index 0e263fe6..a98cf0e9 100644
--- a/src/bluetooth/qbluetoothserviceinfo_p.h
+++ b/src/bluetooth/qbluetoothserviceinfo_p.h
@@ -43,6 +43,7 @@
#define QBLUETOOTHSERVICEINFO_P_H
#include "qbluetoothuuid.h"
+#include "qbluetoothaddress.h"
#include "qbluetoothdeviceinfo.h"
#include "qbluetoothserviceinfo.h"
@@ -63,14 +64,14 @@ public:
QBluetoothServiceInfoPrivate();
~QBluetoothServiceInfoPrivate();
- bool registerService() const;
+ bool registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress());
bool isRegistered() const;
- bool unregisterService() const;
+ bool unregisterService();
- void setRegisteredAttribute(quint16 attributeId, const QVariant &value) const;
- void removeRegisteredAttribute(quint16 attributeId) const;
+ void setRegisteredAttribute(quint16 attributeId, const QVariant &value);
+ void removeRegisteredAttribute(quint16 attributeId);
QBluetoothDeviceInfo deviceInfo;
QMap<quint16, QVariant> attributes;
@@ -78,10 +79,11 @@ public:
int serverChannel() const;
private:
#ifdef QT_BLUEZ_BLUETOOTH
- bool ensureSdpConnection() const;
+ bool ensureSdpConnection(const QBluetoothAddress &localAdapter = QBluetoothAddress());
- mutable OrgBluezServiceInterface *service;
- mutable quint32 serviceRecord;
+ OrgBluezServiceInterface *service;
+ quint32 serviceRecord;
+ QBluetoothAddress currentLocalAdapter;
#endif
mutable bool registered;
diff --git a/src/bluetooth/qbluetoothserviceinfo_qnx.cpp b/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
index cb82851c..cd1ecfef 100644
--- a/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
@@ -61,7 +61,7 @@ bool QBluetoothServiceInfoPrivate::isRegistered() const
return registered;
}
-bool QBluetoothServiceInfoPrivate::unregisterService() const
+bool QBluetoothServiceInfoPrivate::unregisterService()
{
if (!registered)
return false;
@@ -70,7 +70,7 @@ bool QBluetoothServiceInfoPrivate::unregisterService() const
}
-void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, const QVariant &value) const
+void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, const QVariant &value)
{
Q_UNUSED(attributeId);
Q_UNUSED(value);
@@ -78,7 +78,7 @@ void QBluetoothServiceInfoPrivate::setRegisteredAttribute(quint16 attributeId, c
registerService();
}
-void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId) const
+void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId)
{
Q_UNUSED(attributeId);
registered = false;
@@ -86,8 +86,9 @@ void QBluetoothServiceInfoPrivate::removeRegisteredAttribute(quint16 attributeId
extern QHash<QBluetoothServerPrivate*, int> __fakeServerPorts;
-bool QBluetoothServiceInfoPrivate::registerService() const
+bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress& localAdapter)
{
+ Q_UNUSED(localAdapter); //QNX always uses default local adapter
if (protocolDescriptor(QBluetoothUuid::Rfcomm).isEmpty()) {
qWarning() << Q_FUNC_INFO << "Only SPP services can be registered on QNX";
return false;
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index bc7dc972..c6f332e3 100644
--- a/src/bluetooth/qbluetoothsocket_bluez.cpp
+++ b/src/bluetooth/qbluetoothsocket_bluez.cpp
@@ -362,12 +362,13 @@ QString QBluetoothSocketPrivate::peerName() const
return QString();
}
- const QString address = QBluetoothAddress(bdaddr).toString();
+ const QString peerAddress = QBluetoothAddress(bdaddr).toString();
+ const QString localAdapter = localAddress().toString();
OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"),
QDBusConnection::systemBus());
- QDBusPendingReply<QDBusObjectPath> reply = manager.DefaultAdapter();
+ QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(localAdapter);
reply.waitForFinished();
if (reply.isError())
return QString();
@@ -375,13 +376,13 @@ QString QBluetoothSocketPrivate::peerName() const
OrgBluezAdapterInterface adapter(QLatin1String("org.bluez"), reply.value().path(),
QDBusConnection::systemBus());
- QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter.CreateDevice(address);
+ QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter.CreateDevice(peerAddress);
deviceObjectPath.waitForFinished();
if (deviceObjectPath.isError()) {
if (deviceObjectPath.error().name() != QLatin1String("org.bluez.Error.AlreadyExists"))
return QString();
- deviceObjectPath = adapter.FindDevice(address);
+ deviceObjectPath = adapter.FindDevice(peerAddress);
deviceObjectPath.waitForFinished();
if (deviceObjectPath.isError())
return QString();