diff options
author | Sven Gothel <[email protected]> | 2022-05-15 01:04:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-05-15 01:04:36 +0200 |
commit | 919cf46dd36e7c97a5784d86b5313f024212a756 (patch) | |
tree | 7d25ca70a5771c5ec1b179caad21fe2ad0faa0bf | |
parent | 313b27cfcf5aa6ea6c16eaec0e6a8452e998d481 (diff) |
noexcept: BTGattHandler::send*(): JNI: Return the boolean result of actual native send[Notification|Indication]() method.
-rw-r--r-- | examples/dbt_peripheral00.cpp | 20 | ||||
-rw-r--r-- | examples/java/DBTPeripheral00.java | 20 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTDevice.cxx | 6 |
3 files changed, 22 insertions, 24 deletions
diff --git a/examples/dbt_peripheral00.cpp b/examples/dbt_peripheral00.cpp index 4fb75315..3f962efe 100644 --- a/examples/dbt_peripheral00.cpp +++ b/examples/dbt_peripheral00.cpp @@ -380,12 +380,12 @@ class MyGATTServerListener : public DBGattServer::Listener { jau::POctets v(data.size()+1, jau::endian::little); v.put_string_nc(0, data, v.size(), true /* includeEOS */); if( 0 != handlePulseDataNotify ) { - fprintf_td(stderr, "****** GATT::sendNotification: PULSE to %s\n", connectedDevice_->toString().c_str()); - connectedDevice_->sendNotification(handlePulseDataNotify, v); + const bool res = connectedDevice_->sendNotification(handlePulseDataNotify, v); + fprintf_td(stderr, "****** GATT::sendNotification: PULSE (res %d) to %s\n", res, connectedDevice_->toString().c_str()); } if( 0 != handlePulseDataIndicate ) { - fprintf_td(stderr, "****** GATT::sendIndication: PULSE to %s\n", connectedDevice_->toString().c_str()); - connectedDevice_->sendIndication(handlePulseDataIndicate, v); + const bool res = connectedDevice_->sendIndication(handlePulseDataIndicate, v); + fprintf_td(stderr, "****** GATT::sendIndication: PULSE (res %d) to %s\n", res, connectedDevice_->toString().c_str()); } } } @@ -405,14 +405,14 @@ class MyGATTServerListener : public DBGattServer::Listener { if( nullptr != connectedDevice_ && connectedDevice_->getConnected() ) { if( 0 != handleResponseDataNotify || 0 != handleResponseDataIndicate ) { if( 0 != handleResponseDataNotify ) { - fprintf_td(stderr, "****** GATT::sendNotification: %s to %s\n", - data.toString().c_str(), connectedDevice_->toString().c_str()); - connectedDevice_->sendNotification(handleResponseDataNotify, data); + const bool res = connectedDevice_->sendNotification(handleResponseDataNotify, data); + fprintf_td(stderr, "****** GATT::sendNotification (res %d): %s to %s\n", + res, data.toString().c_str(), connectedDevice_->toString().c_str()); } if( 0 != handleResponseDataIndicate ) { - fprintf_td(stderr, "****** GATT::sendIndication: %s to %s\n", - data.toString().c_str(), connectedDevice_->toString().c_str()); - connectedDevice_->sendIndication(handleResponseDataIndicate, data); + const bool res = connectedDevice_->sendIndication(handleResponseDataIndicate, data); + fprintf_td(stderr, "****** GATT::sendIndication (res %d): %s to %s\n", + res, data.toString().c_str(), connectedDevice_->toString().c_str()); } } } diff --git a/examples/java/DBTPeripheral00.java b/examples/java/DBTPeripheral00.java index 00b3f7ad..a1859e47 100644 --- a/examples/java/DBTPeripheral00.java +++ b/examples/java/DBTPeripheral00.java @@ -393,12 +393,12 @@ public class DBTPeripheral00 { final String data = String.format("Dynamic Data Example. Elapsed Milliseconds: %,9d", BTUtils.elapsedTimeMillis()); final byte[] v = data.getBytes(StandardCharsets.UTF_8); if( 0 != handlePulseDataNotify ) { - BTUtils.fprintf_td(System.err, "****** GATT::sendNotification: PULSE to %s\n", connectedDevice_.toString()); - connectedDevice_.sendNotification(handlePulseDataNotify, v); + final boolean res = connectedDevice_.sendNotification(handlePulseDataNotify, v); + BTUtils.fprintf_td(System.err, "****** GATT::sendNotification: PULSE (res %b) to %s\n", res, connectedDevice_.toString()); } if( 0 != handlePulseDataIndicate ) { - BTUtils.fprintf_td(System.err, "****** GATT::sendIndication: PULSE to %s\n", connectedDevice_.toString()); - connectedDevice_.sendIndication(handlePulseDataIndicate, v); + final boolean res = connectedDevice_.sendIndication(handlePulseDataIndicate, v); + BTUtils.fprintf_td(System.err, "****** GATT::sendIndication: PULSE (res %b) to %s\n", res, connectedDevice_.toString()); } } } @@ -417,14 +417,14 @@ public class DBTPeripheral00 { if( null != connectedDevice_ && connectedDevice_.getConnected() ) { if( 0 != handleResponseDataNotify || 0 != handleResponseDataIndicate ) { if( 0 != handleResponseDataNotify ) { - BTUtils.fprintf_td(System.err, "****** GATT::sendNotification: %s to %s\n", - BTUtils.bytesHexString(data, 0, data.length, true /* lsb */), connectedDevice_.toString()); - connectedDevice_.sendNotification(handleResponseDataNotify, data); + final boolean res = connectedDevice_.sendNotification(handleResponseDataNotify, data); + BTUtils.fprintf_td(System.err, "****** GATT::sendNotification (res %b): %s to %s\n", + res, BTUtils.bytesHexString(data, 0, data.length, true /* lsb */), connectedDevice_.toString()); } if( 0 != handleResponseDataIndicate ) { - BTUtils.fprintf_td(System.err, "****** GATT::sendIndication: %s to %s\n", - BTUtils.bytesHexString(data, 0, data.length, true /* lsb */), connectedDevice_.toString()); - connectedDevice_.sendIndication(handleResponseDataIndicate, data); + final boolean res = connectedDevice_.sendIndication(handleResponseDataIndicate, data); + BTUtils.fprintf_td(System.err, "****** GATT::sendIndication (res %b): %s to %s\n", + res, BTUtils.bytesHexString(data, 0, data.length, true /* lsb */), connectedDevice_.toString()); } } } diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx index dcd73336..f054b4af 100644 --- a/java/jni/direct_bt/DBTDevice.cxx +++ b/java/jni/direct_bt/DBTDevice.cxx @@ -957,8 +957,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_sendNotification(JNIEnv *env, jobject obj 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; + return device->sendNotification(char_value_handle, value) ? JNI_TRUE : JNI_FALSE; } catch(...) { rethrow_and_raise_java_exception(env); } @@ -984,8 +983,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_sendIndication(JNIEnv *env, jobject obj, 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; + return device->sendIndication(char_value_handle, value) ? JNI_TRUE : JNI_FALSE; } catch(...) { rethrow_and_raise_java_exception(env); } |