summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_android.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-12 10:39:04 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-14 08:46:04 +0100
commit26b5e44ffc7c33b258e6c3eb6bce340d51a4a377 (patch)
tree757fbd89fad2fc363ef3f4c991e4b00c10d07a08 /src/bluetooth/qlowenergycontroller_android.cpp
parentcc94fad463e50f0f4ec110bacc098f4c4d4818d8 (diff)
Support for QLEService::writeDescriptor() on Android
Change-Id: I1c7f0491506c6f0512d097a419660c5f5e7fb144 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.cpp61
1 files changed, 57 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index 3891bb5b..582e83a6 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -76,6 +76,8 @@ void QLowEnergyControllerPrivate::connectToDevice()
this, &QLowEnergyControllerPrivate::descriptorRead);
connect(hub, &LowEnergyNotificationHub::characteristicWritten,
this, &QLowEnergyControllerPrivate::characteristicWritten);
+ connect(hub, &LowEnergyNotificationHub::descriptorWritten,
+ this, &QLowEnergyControllerPrivate::descriptorWritten);
}
if (!hub->javaObject().isValid()) {
@@ -186,12 +188,37 @@ void QLowEnergyControllerPrivate::writeCharacteristic(
}
void QLowEnergyControllerPrivate::writeDescriptor(
- const QSharedPointer<QLowEnergyServicePrivate> /*service*/,
+ const QSharedPointer<QLowEnergyServicePrivate> service,
const QLowEnergyHandle /*charHandle*/,
- const QLowEnergyHandle /*descriptorHandle*/,
- const QByteArray &/*newValue*/)
+ const QLowEnergyHandle descHandle,
+ const QByteArray &newValue)
{
+ Q_ASSERT(!service.isNull());
+
+ QAndroidJniEnvironment env;
+ jbyteArray payload;
+ payload = env->NewByteArray(newValue.size());
+ env->SetByteArrayRegion(payload, 0, newValue.size(),
+ (jbyte *)newValue.constData());
+
+ bool result = false;
+ if (hub) {
+ qCDebug(QT_BT_ANDROID) << "Write descriptor with handle " << descHandle
+ << newValue.toHex() << "(service:" << service->uuid << ")";
+ result = hub->javaObject().callMethod<jboolean>("writeDescriptor", "(I[B)Z",
+ descHandle, payload);
+ }
+
+ if (env->ExceptionOccurred()) {
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ result = false;
+ }
+ env->DeleteLocalRef(payload);
+
+ if (!result)
+ service->setError(QLowEnergyService::DescriptorWriteError);
}
void QLowEnergyControllerPrivate::connectionUpdated(
@@ -340,7 +367,6 @@ void QLowEnergyControllerPrivate::characteristicWritten(
if (service.isNull())
return;
-
qCDebug(QT_BT_ANDROID) << "Characteristic write confirmation" << service->uuid
<< charHandle << data.toHex() << errorCode;
@@ -359,4 +385,31 @@ void QLowEnergyControllerPrivate::characteristicWritten(
emit service->characteristicWritten(characteristic, data);
}
+void QLowEnergyControllerPrivate::descriptorWritten(
+ int descHandle, const QByteArray &data, QLowEnergyService::ServiceError errorCode)
+{
+ QSharedPointer<QLowEnergyServicePrivate> service =
+ serviceForHandle(descHandle);
+ if (service.isNull())
+ return;
+
+ qCDebug(QT_BT_ANDROID) << "Descriptor write confirmation" << service->uuid
+ << descHandle << data.toHex() << errorCode;
+
+ if (errorCode != QLowEnergyService::NoError) {
+ service->setError(errorCode);
+ return;
+ }
+
+ QLowEnergyDescriptor descriptor = descriptorForHandle(descHandle);
+ if (!descriptor.isValid()) {
+ qCWarning(QT_BT_ANDROID) << "descriptorWritten: Cannot find descriptor";
+ return;
+ }
+
+ updateValueOfDescriptor(descriptor.characteristicHandle(),
+ descHandle, data, false);
+ emit service->descriptorWritten(descriptor, data);
+}
+
QT_END_NAMESPACE