summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2019-01-21 15:08:57 +0100
committerAlex Blasche <alexander.blasche@qt.io>2019-02-11 07:19:22 +0000
commit8af2bea29a4aec10d68f022520d4abca7320ebb1 (patch)
treea88a7993959b3d44c7a253f3165875451d4ca152 /src
parentcd2f90d9157199ebadcf182a471f264a619fd521 (diff)
Add QLowEnergyController::createCentral() with localDevice overload
The QLowEnergyController ctor with localDevice overload was obsoleted but the new API did not provide an equivalent createCentral() overload. This patch fixes the problem. Fixes: QTBUG-63019 Change-Id: I4c5a249bbf20c78da5507fecc874daa67e3dce46 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp23
-rw-r--r--src/bluetooth/qlowenergycontroller.h5
-rw-r--r--src/bluetooth/qlowenergycontroller_bluezdbus.cpp10
3 files changed, 34 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index 8fc044fb..d8aa00d7 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -432,6 +432,29 @@ QLowEnergyController *QLowEnergyController::createCentral(const QBluetoothDevice
return new QLowEnergyController(remoteDevice, parent);
}
+/*!
+ Returns a new instance of this class with \a parent.
+
+ The \a remoteDevice must contain the address of the remote Bluetooth Low
+ Energy device to which this object should attempt to connect later on.
+
+ The connection is established via \a localDevice. If \a localDevice is invalid,
+ the local default device is automatically selected. If \a localDevice specifies
+ a local device that is not a local Bluetooth adapter, \l error() is set to
+ \l InvalidBluetoothAdapterError once \l connectToDevice() is called.
+
+ Note that specifying the local device to be used for the connection is only
+ possible when using BlueZ. All other platforms do not support this feature.
+
+ \since 5.13
+ */
+QLowEnergyController *QLowEnergyController::createCentral(const QBluetoothAddress &remoteDevice,
+ const QBluetoothAddress &localDevice,
+ QObject *parent)
+{
+ return new QLowEnergyController(remoteDevice, localDevice, parent);
+}
+
/*!
Returns a new object of this class that is in the \l PeripheralRole and has the
diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h
index 9fe46fe5..5498d4a5 100644
--- a/src/bluetooth/qlowenergycontroller.h
+++ b/src/bluetooth/qlowenergycontroller.h
@@ -93,13 +93,16 @@ public:
explicit QLowEnergyController(const QBluetoothAddress &remoteDevice,
QObject *parent = nullptr); // TODO Qt 6 remove ctor
explicit QLowEnergyController(const QBluetoothDeviceInfo &remoteDevice,
- QObject *parent = nullptr);
+ QObject *parent = nullptr); // TODO Qt 6 make private
explicit QLowEnergyController(const QBluetoothAddress &remoteDevice,
const QBluetoothAddress &localDevice,
QObject *parent = nullptr); // TODO Qt 6 remove ctor
static QLowEnergyController *createCentral(const QBluetoothDeviceInfo &remoteDevice,
QObject *parent = nullptr);
+ static QLowEnergyController *createCentral(const QBluetoothAddress &remoteDevice,
+ const QBluetoothAddress &localDevice,
+ QObject *parent = nullptr);
static QLowEnergyController *createPeripheral(QObject *parent = nullptr);
// TODO: Allow to set connection timeout (disconnect when no data has been exchanged for n seconds).
diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus.cpp b/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
index 441eca6b..88ae0320 100644
--- a/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
@@ -268,9 +268,13 @@ void QLowEnergyControllerPrivateBluezDBus::connectToDeviceHelper()
const QVariantMap &ifaceValues = jt.value();
if (iface == QStringLiteral("org.bluez.Device1")) {
- if (remoteDevice.toString() == ifaceValues.value(QStringLiteral("Address")).toString()) {
- devicePath = it.key().path();
- break;
+ if (remoteDevice.toString() == ifaceValues.value(QStringLiteral("Address")).toString())
+ {
+ const QVariant adapterForCurrentDevice = ifaceValues.value(QStringLiteral("Adapter"));
+ if (qvariant_cast<QDBusObjectPath>(adapterForCurrentDevice).path() == hostAdapterPath) {
+ devicePath = it.key().path();
+ break;
+ }
}
}
}