diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-11-06 15:46:03 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-11-10 08:38:10 +0100 |
commit | 9277a04640e488916b79a0dcbf818c7f1aa1510d (patch) | |
tree | b534a9f55da305c50bdda8cb9e29bb6831d324a1 /src/bluetooth/qlowenergycontroller_android.cpp | |
parent | 311eef287d658a376c80047aef942dfbf43eb889 (diff) |
Majority of service detail discovery code on Android
Primarily the change adds the required data structures and interfaces
on the Java side. What is missing is the reporting of the discovery
details back to Qt.
Change-Id: I37f2e17bb0f87b4c526f1b43a933b9b09b22be72
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_android.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 134a21b7..3a7ca98d 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -68,6 +68,8 @@ void QLowEnergyControllerPrivate::connectToDevice() this, &QLowEnergyControllerPrivate::connectionUpdated); connect(hub, &LowEnergyNotificationHub::servicesDiscovered, this, &QLowEnergyControllerPrivate::servicesDiscovered); + connect(hub, &LowEnergyNotificationHub::serviceDetailsDiscoveryFinished, + this, &QLowEnergyControllerPrivate::serviceDetailsDiscoveryFinished); } if (!hub->javaObject().isValid()) { @@ -103,9 +105,39 @@ void QLowEnergyControllerPrivate::discoverServices() } } -void QLowEnergyControllerPrivate::discoverServiceDetails(const QBluetoothUuid &/*service*/) +void QLowEnergyControllerPrivate::discoverServiceDetails(const QBluetoothUuid &service) { + if (!serviceList.contains(service)) { + qCWarning(QT_BT_ANDROID) << "Discovery of unknown service" << service.toString() + << "not possible"; + return; + } + if (!hub) + return; + + //cut leading { and trailing } {xxx-xxx} + QString tempUuid = service.toString(); + tempUuid.chop(1); //remove trailing '}' + tempUuid.remove(0, 1); //remove first '{' + + QAndroidJniEnvironment env; + QAndroidJniObject uuid = QAndroidJniObject::fromString(tempUuid); + bool result = hub->javaObject().callMethod<jboolean>("discoverServiceDetails", + "(Ljava/lang/String;)Z", + uuid.object<jstring>()); + if (!result || true) { + QSharedPointer<QLowEnergyServicePrivate> servicePrivate = + serviceList.value(service); + if (!servicePrivate.isNull()) { + servicePrivate->setError(QLowEnergyService::UnknownError); + servicePrivate->setState(QLowEnergyService::DiscoveryRequired); + } + qCWarning(QT_BT_ANDROID) << "Cannot discover details for" << service.toString(); + return; + } + + qCDebug(QT_BT_ANDROID) << "Discovery of" << service << "started"; } void QLowEnergyControllerPrivate::writeCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> /*service*/, @@ -113,7 +145,6 @@ void QLowEnergyControllerPrivate::writeCharacteristic(const QSharedPointer<QLowE const QByteArray &/*newValue*/, bool /*writeWithResponse*/) { - } void QLowEnergyControllerPrivate::writeDescriptor( @@ -162,6 +193,17 @@ void QLowEnergyControllerPrivate::servicesDiscovered( //Android delivers all services in one go const QStringList list = foundServices.split(QStringLiteral(" "), QString::SkipEmptyParts); foreach (const QString &entry, list) { + const QBluetoothUuid service(entry); + if (service.isNull()) + return; + + QLowEnergyServicePrivate *priv = new QLowEnergyServicePrivate(); + priv->uuid = service; + priv->setController(this); + + QSharedPointer<QLowEnergyServicePrivate> pointer(priv); + serviceList.insert(service, pointer); + emit q->serviceDiscovered(QBluetoothUuid(entry)); } @@ -173,4 +215,19 @@ void QLowEnergyControllerPrivate::servicesDiscovered( } } +void QLowEnergyControllerPrivate::serviceDetailsDiscoveryFinished( + const QString &serviceUuid) +{ + const QBluetoothUuid service(serviceUuid); + if (!serviceList.contains(service)) { + qCWarning(QT_BT_ANDROID) << "Discovery done of unknown service:" + << service.toString(); + return; + } + + QSharedPointer<QLowEnergyServicePrivate> pointer = + serviceList.value(service); + pointer->setState(QLowEnergyService::ServiceDiscovered); +} + QT_END_NAMESPACE |