summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-01-18 09:14:19 +0100
committerAlex Blasche <alexander.blasche@qt.io>2017-01-24 14:49:21 +0000
commit2e60c570b46e69599861969fc949551a058e902d (patch)
tree13fb3cb6f33af3f63f173f155056626ebba1ea20 /src/bluetooth/android
parent6b0595b64ea46554a8a63f026c15ab07ea804285 (diff)
Android: Implement QLEService::descriptorWritten() signals for peripheral
Change-Id: I60e5bdce4256804754909c2538aebe581897e1e9 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/bluetooth/android')
-rw-r--r--src/bluetooth/android/jni_android.cpp2
-rw-r--r--src/bluetooth/android/lowenergynotificationhub.cpp22
-rw-r--r--src/bluetooth/android/lowenergynotificationhub_p.h3
3 files changed, 27 insertions, 0 deletions
diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp
index 7f08ea85..68e291e5 100644
--- a/src/bluetooth/android/jni_android.cpp
+++ b/src/bluetooth/android/jni_android.cpp
@@ -234,6 +234,8 @@ static JNINativeMethod methods_leServer[] = {
(void *) LowEnergyNotificationHub::lowEnergy_advertisementError},
{"leServerCharacteristicChanged", "(JLandroid/bluetooth/BluetoothGattCharacteristic;[B)V",
(void *) LowEnergyNotificationHub::lowEnergy_serverCharacteristicChanged},
+ {"leServerDescriptorWritten", "(JLandroid/bluetooth/BluetoothGattDescriptor;[B)V",
+ (void *) LowEnergyNotificationHub::lowEnergy_serverDescriptorWritten},
};
static JNINativeMethod methods_server[] = {
diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp
index b0d8b0a2..53f2d6cc 100644
--- a/src/bluetooth/android/lowenergynotificationhub.cpp
+++ b/src/bluetooth/android/lowenergynotificationhub.cpp
@@ -273,6 +273,28 @@ void LowEnergyNotificationHub::lowEnergy_descriptorWritten(
(QLowEnergyService::ServiceError)errorCode));
}
+void LowEnergyNotificationHub::lowEnergy_serverDescriptorWritten(
+ JNIEnv *env, jobject, jlong qtObject, jobject descriptor, jbyteArray newValue)
+{
+ lock.lockForRead();
+ LowEnergyNotificationHub *hub = hubMap()->value(qtObject);
+ lock.unlock();
+ if (!hub)
+ return;
+
+ QByteArray payload;
+ if (newValue) { //empty Java byte array is 0x0
+ jsize length = env->GetArrayLength(newValue);
+ payload.resize(length);
+ env->GetByteArrayRegion(newValue, 0, length,
+ reinterpret_cast<signed char*>(payload.data()));
+ }
+
+ QMetaObject::invokeMethod(hub, "serverDescriptorWritten", Qt::QueuedConnection,
+ Q_ARG(QAndroidJniObject, descriptor),
+ Q_ARG(QByteArray, payload));
+}
+
void LowEnergyNotificationHub::lowEnergy_characteristicChanged(
JNIEnv *env, jobject, jlong qtObject, jint charHandle, jbyteArray data)
{
diff --git a/src/bluetooth/android/lowenergynotificationhub_p.h b/src/bluetooth/android/lowenergynotificationhub_p.h
index b3962190..7a328204 100644
--- a/src/bluetooth/android/lowenergynotificationhub_p.h
+++ b/src/bluetooth/android/lowenergynotificationhub_p.h
@@ -91,6 +91,8 @@ public:
static void lowEnergy_descriptorWritten(JNIEnv *, jobject, jlong qtObject,
jint descHandle, jbyteArray data,
jint errorCode);
+ static void lowEnergy_serverDescriptorWritten(JNIEnv *, jobject, jlong qtObject,
+ jobject descriptor, jbyteArray newValue);
static void lowEnergy_characteristicChanged(JNIEnv *, jobject, jlong qtObject,
jint charHandle, jbyteArray data);
static void lowEnergy_serverCharacteristicChanged(JNIEnv *, jobject, jlong qtObject,
@@ -120,6 +122,7 @@ signals:
QLowEnergyService::ServiceError errorCode);
void descriptorWritten(int descHandle, const QByteArray &data,
QLowEnergyService::ServiceError errorCode);
+ void serverDescriptorWritten(const QAndroidJniObject &descriptor, const QByteArray newValue);
void characteristicChanged(int charHandle, const QByteArray &data);
void serverCharacteristicChanged(const QAndroidJniObject& characteristic, const QByteArray& newValue);
void serviceError(int attributeHandle, QLowEnergyService::ServiceError errorCode);