From 4a008da8dd7acec3ef45392e024e31552dbc3c49 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 8 Dec 2017 16:25:28 +0100 Subject: 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 --- src/bluetooth/qlowenergycontroller_bluezdbus.cpp | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus.cpp') 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 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 service(new OrgBluezGattService1Interface( + QStringLiteral("org.bluez"),it.key().path(), + QDBusConnection::systemBus(), this)); + + QSharedPointer priv = QSharedPointer::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*/) -- cgit v1.2.3