From 2e58b250a382e05f0f4cb8d9520097afe07b91cd Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 7 Jun 2020 19:28:36 +0200 Subject: Relax GATTHandler == nullptr for disable and listener-removal operations, it's OK to have a NOP here when GATTHandler has been shutdown. --- java/jni/direct_bt/DBTDevice.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'java/jni') diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx index a392fadc..6349c180 100644 --- a/java/jni/direct_bt/DBTDevice.cxx +++ b/java/jni/direct_bt/DBTDevice.cxx @@ -213,7 +213,9 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_removeCharacteristicListener(JNIEnv *en JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); std::shared_ptr gatt = device->getGATTHandler(); if( nullptr == gatt ) { - throw IllegalStateException("Characteristic's device GATTHandle not connected: "+ device->toString(), E_FILE_LINE); + // OK to have GATTHandler being shutdown @ disable + DBG_PRINT("Characteristic's device GATTHandle not connected: %s", device->toString().c_str()); + return false; } if( ! gatt->removeCharacteristicListener(pre) ) { @@ -233,9 +235,10 @@ jint Java_direct_1bt_tinyb_DBTDevice_removeAllCharacteristicListener(JNIEnv *env JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); std::shared_ptr gatt = device->getGATTHandler(); if( nullptr == gatt ) { - throw IllegalStateException("Characteristic's device GATTHandle not connected: "+ device->toString(), E_FILE_LINE); + // OK to have GATTHandler being shutdown @ disable + DBG_PRINT("Characteristic's device GATTHandle not connected: %s", device->toString().c_str()); + return 0; } - return gatt->removeAllCharacteristicListener(); } catch(...) { rethrow_and_raise_java_exception(env); -- cgit v1.2.3