aboutsummaryrefslogtreecommitdiffstats
path: root/java/direct_bt/tinyb/DBTAdapter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-07-22 02:31:17 +0200
committerSven Gothel <[email protected]>2020-07-22 02:31:17 +0200
commit8b08db6177dc2e5ce6df69d6ea3589a53158b173 (patch)
tree05a361d12fa024dccd7844389d240f797983098e /java/direct_bt/tinyb/DBTAdapter.java
parent60e72dd2776dfd3649a791ad5f8dbab20c77cc1e (diff)
Java DBTAdapter + DBTDevice close @ JVM shutdown: Avoid all interaction, native dtor (deleteImpl) cleans up.
Shortcut of 'close' take-down @ JVM shutdown, avoiding any potential deadlocks. However, all device's and adapter's deleteImpl() gets issued, allowing the native adapter's destructor to be called for orderly device cleanup.
Diffstat (limited to 'java/direct_bt/tinyb/DBTAdapter.java')
-rw-r--r--java/direct_bt/tinyb/DBTAdapter.java41
1 files changed, 29 insertions, 12 deletions
diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java
index 637fec05..46879a67 100644
--- a/java/direct_bt/tinyb/DBTAdapter.java
+++ b/java/direct_bt/tinyb/DBTAdapter.java
@@ -87,24 +87,41 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
@Override
public synchronized void close() {
+ close(false);
+ }
+
+ /* pp */ synchronized void close(final boolean isShutdown) {
if( !isValid() ) {
return;
}
- stopDiscovery();
+ if( !isShutdown ) { // avoid all interaction @ JVM shutdown, native dtor (deleteImpl) cleans up.
- final List<BluetoothDevice> devices = getDevices();
- for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) {
- final BluetoothDevice d = id.next();
- d.close();
- }
+ // mute all listener first
+ removeAllStatusListener();
+ disableDiscoverableNotifications();
+ disableDiscoveringNotifications();
+ disablePairableNotifications();
+ disablePoweredNotifications();
+
+ stopDiscovery();
+
+ final List<BluetoothDevice> devices = getDevices();
+ for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) {
+ final DBTDevice d = (DBTDevice) id.next();
+ d.close( false );
+ }
+
+ // done in native dtor: removeDevicesImpl();
- removeAllStatusListener();
- disableDiscoverableNotifications();
- disableDiscoveringNotifications();
- disablePairableNotifications();
- disablePoweredNotifications();
+ } else {
- removeDevicesImpl();
+ final List<BluetoothDevice> devices = getDevices();
+ for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) {
+ final DBTDevice d = (DBTDevice) id.next();
+ d.close( true );
+ }
+
+ }
discoveredDevices.clear();
super.close();