From 74d41274760a9087c7a8c57e145fe531b035baae Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 26 Jul 2020 05:38:36 +0200 Subject: Shutdown: Drop special case, working on robustness --- java/direct_bt/tinyb/DBTAdapter.java | 46 ++++++++++++------------------------ java/direct_bt/tinyb/DBTDevice.java | 42 ++++++++++++++------------------ java/direct_bt/tinyb/DBTManager.java | 2 +- 3 files changed, 34 insertions(+), 56 deletions(-) (limited to 'java') diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java index 46879a67..2580172f 100644 --- a/java/direct_bt/tinyb/DBTAdapter.java +++ b/java/direct_bt/tinyb/DBTAdapter.java @@ -87,41 +87,25 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter @Override public synchronized void close() { - close(false); - } - - /* pp */ synchronized void close(final boolean isShutdown) { if( !isValid() ) { return; } - if( !isShutdown ) { // avoid all interaction @ JVM shutdown, native dtor (deleteImpl) cleans up. - - // mute all listener first - removeAllStatusListener(); - disableDiscoverableNotifications(); - disableDiscoveringNotifications(); - disablePairableNotifications(); - disablePoweredNotifications(); - - stopDiscovery(); - - final List devices = getDevices(); - for(final Iterator id = devices.iterator(); id.hasNext(); ) { - final DBTDevice d = (DBTDevice) id.next(); - d.close( false ); - } - - // done in native dtor: removeDevicesImpl(); - - } else { - - final List devices = getDevices(); - for(final Iterator id = devices.iterator(); id.hasNext(); ) { - final DBTDevice d = (DBTDevice) id.next(); - d.close( true ); - } - + // mute all listener first + removeAllStatusListener(); + disableDiscoverableNotifications(); + disableDiscoveringNotifications(); + disablePairableNotifications(); + disablePoweredNotifications(); + + stopDiscovery(); + + final List devices = getDevices(); + for(final Iterator id = devices.iterator(); id.hasNext(); ) { + final DBTDevice d = (DBTDevice) id.next(); + d.close(); } + + // done in native dtor: removeDevicesImpl(); discoveredDevices.clear(); super.close(); diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java index fa47a6ff..6b1bdd0e 100644 --- a/java/direct_bt/tinyb/DBTDevice.java +++ b/java/direct_bt/tinyb/DBTDevice.java @@ -233,37 +233,31 @@ public class DBTDevice extends DBTObject implements BluetoothDevice @Override public synchronized void close() { - close(false); - } - - /* pp */ synchronized void close(final boolean isShutdown) { if( !isValid() ) { return; } - if( !isShutdown ) { // avoid all interaction @ JVM shutdown, native dtor (deleteImpl) cleans up. - // implicit via disconnect, gatt.disconnect(): GATTHandler::removeAllCharacteristicListener(); - disconnectImpl(); // make sure, regardless of isConnected state + // GATTHandler::removeAllCharacteristicListener(): implicit via device.disconnect -> gatt.disconnect + disconnectImpl(); // make sure, regardless of isConnected state - disableConnectedNotifications(); - disableRSSINotifications(); - disableManufacturerDataNotifications(); - disableServicesResolvedNotifications(); + disableConnectedNotifications(); + disableRSSINotifications(); + disableManufacturerDataNotifications(); + disableServicesResolvedNotifications(); - disableBlockedNotifications(); - disableBlockedNotificationsImpl(); - disablePairedNotifications(); - disablePairedNotificationsImpl(); - disableServiceDataNotifications(); - disableTrustedNotifications(); - // FIXME disableTrustedNotificationsImpl(); + disableBlockedNotifications(); + disableBlockedNotificationsImpl(); + disablePairedNotifications(); + disablePairedNotificationsImpl(); + disableServiceDataNotifications(); + disableTrustedNotifications(); + // FIXME disableTrustedNotificationsImpl(); - clearServiceCache(); + clearServiceCache(); - final DBTAdapter a = getAdapter(); - if( null != a ) { - a.removeStatusListener(statusListener); - a.removeDiscoveredDevice(this); - } + final DBTAdapter a = getAdapter(); + if( null != a ) { + a.removeStatusListener(statusListener); + a.removeDiscoveredDevice(this); } super.close(); } diff --git a/java/direct_bt/tinyb/DBTManager.java b/java/direct_bt/tinyb/DBTManager.java index 45faed64..d4dcd70f 100644 --- a/java/direct_bt/tinyb/DBTManager.java +++ b/java/direct_bt/tinyb/DBTManager.java @@ -316,7 +316,7 @@ public class DBTManager implements BluetoothManager public void shutdown() { for(final Iterator ia= adapters.iterator(); ia.hasNext(); ) { final DBTAdapter a = (DBTAdapter)ia.next(); - a.close( true ); + a.close(); } adapters.clear(); deleteImpl(nativeInstance); -- cgit v1.2.3