diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-10-29 16:20:13 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-11-04 14:41:04 +0100 |
commit | 1688bbf5c7d4d24018688ee640494c842572d683 (patch) | |
tree | c0192722b59e9b9bc852b3b65a60157430ded2a3 /src/bluetooth/qlowenergycontroller_android.cpp | |
parent | cc5a370e2daad34e05dde7c9c0854ea3bf4eb3fc (diff) |
Discover BTLE services on remote device on Android
Change-Id: Ia39e2ad21b0e84cb16a355337370ba82a11b75d0
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_android.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 95f6fa27..134a21b7 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -66,6 +66,8 @@ void QLowEnergyControllerPrivate::connectToDevice() hub = new LowEnergyNotificationHub(remoteDevice, this); connect(hub, &LowEnergyNotificationHub::connectionUpdated, this, &QLowEnergyControllerPrivate::connectionUpdated); + connect(hub, &LowEnergyNotificationHub::servicesDiscovered, + this, &QLowEnergyControllerPrivate::servicesDiscovered); } if (!hub->javaObject().isValid()) { @@ -86,13 +88,19 @@ void QLowEnergyControllerPrivate::connectToDevice() void QLowEnergyControllerPrivate::disconnectFromDevice() { setState(QLowEnergyController::ClosingState); - - hub->javaObject().callMethod<void>("disconnect"); + if (hub) + hub->javaObject().callMethod<void>("disconnect"); } void QLowEnergyControllerPrivate::discoverServices() { - + if (hub && hub->javaObject().callMethod<jboolean>("discoverServices")) { + qCDebug(QT_BT_ANDROID) << "Service discovery initiated"; + } else { + //revert to connected state + setError(QLowEnergyController::NetworkError); + setState(QLowEnergyController::ConnectedState); + } } void QLowEnergyControllerPrivate::discoverServiceDetails(const QBluetoothUuid &/*service*/) @@ -145,4 +153,24 @@ void QLowEnergyControllerPrivate::connectionUpdated( } } +void QLowEnergyControllerPrivate::servicesDiscovered( + QLowEnergyController::Error errorCode, const QString &foundServices) +{ + Q_Q(QLowEnergyController); + + if (errorCode == QLowEnergyController::NoError) { + //Android delivers all services in one go + const QStringList list = foundServices.split(QStringLiteral(" "), QString::SkipEmptyParts); + foreach (const QString &entry, list) { + emit q->serviceDiscovered(QBluetoothUuid(entry)); + } + + setState(QLowEnergyController::DiscoveredState); + emit q->discoveryFinished(); + } else { + setError(errorCode); + setState(QLowEnergyController::ConnectedState); + } +} + QT_END_NAMESPACE |