summaryrefslogtreecommitdiffstats
path: root/java/jau/direct_bt/DBTManager.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-05-14 04:45:20 +0200
committerSven Gothel <[email protected]>2022-05-14 04:45:20 +0200
commit313b27cfcf5aa6ea6c16eaec0e6a8452e998d481 (patch)
treee7f57f495f384f8a55a81ae19437a84a24d70088 /java/jau/direct_bt/DBTManager.java
parent044c55d46de095721104ed8d511f70c47ee3d008 (diff)
C++/JNI Lifecycle Fix: BTManager must be passed as shared_ptr<> and hold as such in BTAdapter, ... (API CHANGE)
BTAdapter removes itself from BTManager, hence needs to ensure BTManager is not yet destructed. This goes well along with our new JNI mapping, holding the shared_ptr reference in nativeInstance.
Diffstat (limited to 'java/jau/direct_bt/DBTManager.java')
-rw-r--r--java/jau/direct_bt/DBTManager.java16
1 files changed, 12 insertions, 4 deletions
diff --git a/java/jau/direct_bt/DBTManager.java b/java/jau/direct_bt/DBTManager.java
index dfc332f9..243d52af 100644
--- a/java/jau/direct_bt/DBTManager.java
+++ b/java/jau/direct_bt/DBTManager.java
@@ -279,11 +279,11 @@ public class DBTManager implements BTManager
}
}
- private native void initImpl() throws BTException;
- private native void deleteImpl(long nativeInstance);
+ private native long ctorImpl() throws BTException;
+ private native void dtorImpl(long nativeInstance);
private DBTManager()
{
- initImpl();
+ nativeInstance = ctorImpl();
try {
adapters.addAll(getAdapterListImpl());
} catch (final BTException be) {
@@ -314,6 +314,14 @@ public class DBTManager implements BTManager
a.close();
}
adapters.clear();
- deleteImpl(nativeInstance);
+
+ final long handle;
+ synchronized( this ) {
+ handle = nativeInstance;
+ nativeInstance = 0;
+ }
+ if( 0 != handle ) {
+ dtorImpl(handle);
+ }
}
}