diff options
author | Sven Gothel <[email protected]> | 2021-01-18 18:50:31 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-01-18 18:50:31 +0100 |
commit | ac6e1b8f92ca8f84c8a3f24f370aad6d6e12b1a6 (patch) | |
tree | c36b2806e63a3835d6a568c9ec2ed2c99d4edfe2 /java/jni | |
parent | cada67fce32dfecf9f8c8709935c13681ad7bb2f (diff) |
*Adapter: Clarity [get|remove]Devices() -> [get|remove]DiscoveredDevices(); Add removeDiscoveredDevice(); Use: Flush discovered devices after adding listener.
Flushing discovered devices after adding listener to adapter.
This helps avoiding skipping deviceFound callbacks of earlier found devices
before adding the AdapterStatusListener when setting up the adapter.
Diffstat (limited to 'java/jni')
-rw-r--r-- | java/jni/direct_bt/DBTAdapter.cxx | 30 | ||||
-rw-r--r-- | java/jni/tinyb/DBusAdapter.cxx | 4 |
2 files changed, 31 insertions, 3 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index 369730f8..5e19e8e0 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -803,7 +803,7 @@ jobject Java_direct_1bt_tinyb_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, j return nullptr; } -jint Java_direct_1bt_tinyb_DBTAdapter_removeDevicesImpl(JNIEnv *env, jobject obj) +jint Java_direct_1bt_tinyb_DBTAdapter_removeDiscoveredDevicesImpl1(JNIEnv *env, jobject obj) { try { DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); @@ -814,6 +814,34 @@ jint Java_direct_1bt_tinyb_DBTAdapter_removeDevicesImpl(JNIEnv *env, jobject obj return 0; } +jboolean Java_direct_1bt_tinyb_DBTAdapter_removeDiscoveredDeviceImpl1(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) +{ + try { + DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); + + if( nullptr == jaddress ) { + throw jau::IllegalArgumentException("address null", E_FILE_LINE); + } + const size_t address_size = env->GetArrayLength(jaddress); + if( sizeof(EUI48) > address_size ) { + throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(SMPLongTermKeyInfo)), E_FILE_LINE); + } + JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release + uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE); + if( NULL == address_ptr ) { + throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE); + } + const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr); + const BDAddressAndType addressAndType(address, static_cast<BDAddressType>( jaddressType )); + + return adapter->removeDiscoveredDevice(addressAndType); + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return JNI_FALSE; +} + // // misc // diff --git a/java/jni/tinyb/DBusAdapter.cxx b/java/jni/tinyb/DBusAdapter.cxx index 2a7efc6f..531a046e 100644 --- a/java/jni/tinyb/DBusAdapter.cxx +++ b/java/jni/tinyb/DBusAdapter.cxx @@ -79,7 +79,7 @@ jboolean Java_tinyb_dbus_DBusAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj) return JNI_FALSE; } -jobject Java_tinyb_dbus_DBusAdapter_getDevices(JNIEnv *env, jobject obj) +jobject Java_tinyb_dbus_DBusAdapter_getDiscoveredDevices(JNIEnv *env, jobject obj) { try { BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj); @@ -94,7 +94,7 @@ jobject Java_tinyb_dbus_DBusAdapter_getDevices(JNIEnv *env, jobject obj) return nullptr; } -jint Java_tinyb_dbus_DBusAdapter_removeDevices(JNIEnv *env, jobject obj) +jint Java_tinyb_dbus_DBusAdapter_removeDiscoveredDevices(JNIEnv *env, jobject obj) { try { BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj); |