summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-12-08 16:25:28 +0100
committerAlex Blasche <alexander.blasche@qt.io>2018-01-05 09:06:54 +0000
commit4a008da8dd7acec3ef45392e024e31552dbc3c49 (patch)
tree5082ccdc9cce4d8b55e18d856ee23bdd04033b6b /src
parentda7a013dd2aa7bed9f4a6b5122b8f9dadcb252ab (diff)
Support service discovery for BlueZ DBus backend
At the same time a typo in a comment is fixed. Task-number: QTBUG-46819 Change-Id: Ic017df4d2d52cf0d226b6e083a9ec5f28657dee0 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/bluez/bluez5_helper.cpp2
-rw-r--r--src/bluetooth/qlowenergycontroller_bluezdbus.cpp48
2 files changed, 49 insertions, 1 deletions
diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp
index 1691bd34..90b7e5e0 100644
--- a/src/bluetooth/bluez/bluez5_helper.cpp
+++ b/src/bluetooth/bluez/bluez5_helper.cpp
@@ -197,7 +197,7 @@ QVersionNumber bluetoothdVersion()
if (bluezDaemonVersion()->isNull()) {
qCDebug(QT_BT_BLUEZ) << "Detecting bluetoothd version";
//Order of matching
- // 1. Pick whatever the user decides via BLUETOOTH_BLUEZ_DBUS_LE
+ // 1. Pick whatever the user decides via BLUETOOTH_USE_BLUEZ_DBUS_LE
const QString version = qEnvironmentVariable("BLUETOOTH_USE_BLUEZ_DBUS_LE");
if (!version.isNull()) {
const QVersionNumber vn = QVersionNumber::fromString(version);
diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus.cpp b/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
index 1829f153..1464561c 100644
--- a/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
@@ -41,6 +41,7 @@
#include "bluez/adapter1_bluez5_p.h"
#include "bluez/bluez5_helper_p.h"
#include "bluez/device1_bluez5_p.h"
+#include "bluez/gattservice1_p.h"
#include "bluez/objectmanager_p.h"
#include "bluez/properties_p.h"
@@ -308,7 +309,54 @@ void QLowEnergyControllerPrivateBluezDBus::disconnectFromDevice()
void QLowEnergyControllerPrivateBluezDBus::discoverServices()
{
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez->GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ qCWarning(QT_BT_BLUEZ) << "Cannot discover services";
+ setError(QLowEnergyController::UnknownError);
+ setState(QLowEnergyController::DiscoveredState);
+ return;
+ }
+
+ Q_Q(QLowEnergyController);
+
+ const ManagedObjectList managedObjectList = reply.value();
+ const QString servicePathPrefix = device->path().append(QStringLiteral("/service"));
+ for (ManagedObjectList::const_iterator it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) {
+ const InterfaceList &ifaceList = it.value();
+ if (!it.key().path().startsWith(servicePathPrefix))
+ continue;
+
+ for (InterfaceList::const_iterator jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) {
+ const QString &iface = jt.key();
+
+ if (iface == QStringLiteral("org.bluez.GattService1")) {
+ QScopedPointer<OrgBluezGattService1Interface> service(new OrgBluezGattService1Interface(
+ QStringLiteral("org.bluez"),it.key().path(),
+ QDBusConnection::systemBus(), this));
+
+ QSharedPointer<QLowEnergyServicePrivate> priv = QSharedPointer<QLowEnergyServicePrivate>::create();
+ priv->uuid = QBluetoothUuid(service->uUID());
+
+ //no handles available
+ //priv->startHandle = start;
+ //priv->endHandle = end;
+ service->primary()
+ ? priv->type = QLowEnergyService::PrimaryService
+ : priv->type = QLowEnergyService::IncludedService;
+ priv->setController(this);
+
+ serviceList.insert(priv->uuid, priv);
+ //TODO enable once discoverServiceDetails() is implemented
+ //foundServices.insert(priv->uuid, service);
+
+ emit q->serviceDiscovered(priv->uuid);
+ }
+ }
+ }
+ setState(QLowEnergyController::DiscoveredState);
+ emit q->discoveryFinished();
}
void QLowEnergyControllerPrivateBluezDBus::discoverServiceDetails(const QBluetoothUuid &/*service*/)