aboutsummaryrefslogtreecommitdiffstats
path: root/java/direct_bt/tinyb/DBTAdapter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-25 02:57:31 +0100
committerSven Gothel <[email protected]>2020-10-25 02:57:31 +0100
commite878104ae9950d7cbc44841e6c5c5f0b9c131304 (patch)
tree4113a6af50db87dcbc32a4e5dd58a5b5e1a253bd /java/direct_bt/tinyb/DBTAdapter.java
parent305a92e8f295298bc4dd3cb12f4b32b68d7bf0ae (diff)
Support Adapter removal and add @ runtime: Handle INDEX_ADDED and INDEX_REMOVED Mgmt events
C++ DBTManager detects INDEX_ADDED and INDEX_REMOVED Mgmt events @INDEX_ADDED reception in the event reader, a new processAdapterAdded() thread is spawned initializing the adapter as usual and maintaining adding its AdapterInfo artifact. Then all user INDEX_ADDED callbacks are called from this thread, after the new AdapterInfo entry has been added. @INDEX_REMOVED here the matching AdapterInfo entry is simply removed DBTAdapter naturally also listens to INDEX_REMOVED, simply closing its instance and hence rendering it isValid() = false. +++ On close(), Java's DBTAdapter will remove itself from the DBTManager's adapter list. This removal will happen automatically, if INDEX_REMOVED is received - see below. On the Java side, DBTManager listens to: @INDEX_REMOVED here the matching adapter instance is simply removed @INDEX_ADDED and @NEW_SETTINGS(POWERED) checks whether the matching adapter instance exists and creates a new one added to the adapters list if necessary. @NEW_SETTINGS(POWERED) has been added here as well, since a user could chose to close the adapter if POWERED off and hence removing itself from the DBTManager adapter list. Hence NEW_SETTINGS(POWERED) will add a new adapter instance, if none exists. +++ Due to this new concurrent use-case of the adapter list, the list is now a CopyOnWriteArrayList instance supporting lock-free fast reads. Mutations of the list occur rarely, hopefully ;-). On the C++, the AdapterInfo is a jau::cow_vector and the callbacks are store in a jau::cow_vector as well (MgmtAdapterEventCallbackList). Hence both share the same properties w/ the Java side: Fast lock-free reads.
Diffstat (limited to 'java/direct_bt/tinyb/DBTAdapter.java')
-rw-r--r--java/direct_bt/tinyb/DBTAdapter.java3
1 files changed, 3 insertions, 0 deletions
diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java
index 62e92930..594760cd 100644
--- a/java/direct_bt/tinyb/DBTAdapter.java
+++ b/java/direct_bt/tinyb/DBTAdapter.java
@@ -121,6 +121,9 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
poweredOff();
+ // notify manager that this instance is gone for good
+ ((DBTManager)DBTManager.getManager()).removeAdapterCB(dev_id, 0x0100 /* custom opc */);
+
super.close();
}