aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-11-09 22:35:15 +0100
committerSven Gothel <[email protected]>2021-11-09 22:35:15 +0100
commitadb516575e7c336450b807de000851593d18a38b (patch)
tree37c6c329bc478ba7f125de0074b8aff50b86e569 /java/jni
parent8e712c4c6868a34de29a9e84f26d03f0e627a5a1 (diff)
Add BTDevice::send[Indication|Notification]() (Java); Note: Sending zero length -> Skip sending and return true
Diffstat (limited to 'java/jni')
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 472e3bfe..4bcf6492 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -901,6 +901,58 @@ jobject Java_jau_direct_1bt_DBTDevice_getGattServicesImpl(JNIEnv *env, jobject o
return nullptr;
}
+jboolean Java_jau_direct_1bt_DBTDevice_sendNotification(JNIEnv *env, jobject obj, jshort char_value_handle, jbyteArray jval) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ if( nullptr == jval ) {
+ throw IllegalArgumentException("byte array null", E_FILE_LINE);
+ }
+ const size_t value_size = env->GetArrayLength(jval);
+ if( 0 >= value_size ) {
+ return JNI_TRUE; // no data is OK
+ }
+ JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
+ uint8_t * value_ptr = criticalArray.get(jval, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
+ if( NULL == value_ptr ) {
+ throw InternalError("GetPrimitiveArrayCritical(byte array) is null", E_FILE_LINE);
+ }
+ const jau::TROOctets value(value_ptr, value_size, endian::little);
+ device->sendNotification(char_value_handle, value);
+ return JNI_TRUE;
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return JNI_FALSE;
+}
+
+jboolean Java_jau_direct_1bt_DBTDevice_sendIndication(JNIEnv *env, jobject obj, jshort char_value_handle, jbyteArray jval) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ if( nullptr == jval ) {
+ throw IllegalArgumentException("byte array null", E_FILE_LINE);
+ }
+ const size_t value_size = env->GetArrayLength(jval);
+ if( 0 >= value_size ) {
+ return JNI_TRUE; // no data is OK
+ }
+ JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
+ uint8_t * value_ptr = criticalArray.get(jval, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
+ if( NULL == value_ptr ) {
+ throw InternalError("GetPrimitiveArrayCritical(byte array) is null", E_FILE_LINE);
+ }
+ const jau::TROOctets value(value_ptr, value_size, endian::little);
+ device->sendIndication(char_value_handle, value);
+ return JNI_TRUE;
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return JNI_FALSE;
+}
+
jboolean Java_jau_direct_1bt_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj)
{
try {