diff options
author | Sven Gothel <[email protected]> | 2020-05-12 06:39:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-12 06:39:36 +0200 |
commit | d198176d2fbe5c88cf81ffb647abced753af52c2 (patch) | |
tree | 6d41698d308520adf7fd743e718724343e48292c /examples | |
parent | 604e03053942521c1e104b0c473864ff4139b939 (diff) |
Fixing multiple Java/C++ Lifecycle Issues (DBTDevice, add ShutdownHook, ..)
DBTDevice
- don't native delete @ JNI deleteImpl, adapter holds share_ptr ownership
- only create its java object 1st time @ deviceFound callback of JNI DBTAdapter
DBTAdapter::mgmtEvDeviceFoundCB
- in case of !discoveredDeviceList but sharedDeviceList,
the device shall be updated first,
then deviceFound callbacks issued, allowing listener to act and register,
then deviceUpdate callbacks issued, allowing data update on existing actors
DBTManager.java:
- Add ShutdownHook calling custom hooks and shutdown()
- shutdown() in depth shutdown:
-- iterated through all adapter issueing adapter.close()
-- Adapter.close() iterates through all discoveredDevices issuing close()
DBTDevice.java:
- adds adapter JNI proxy to removeStatusListener(..), same 'to be resolved' issue
as with addStatusListener(..).
Diffstat (limited to 'examples')
-rw-r--r-- | examples/java/ScannerTinyB01.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java index ada30693..aea70c40 100644 --- a/examples/java/ScannerTinyB01.java +++ b/examples/java/ScannerTinyB01.java @@ -45,10 +45,11 @@ public class ScannerTinyB01 { static { System.setProperty("org.tinyb.verbose", "true"); } - /** 60,000 milliseconds */ - static long TO_DISCOVER = 60000; + /** 10,000 milliseconds */ + static long TO_DISCOVER = 10000; public static void main(final String[] args) throws InterruptedException { + long t0_discovery = TO_DISCOVER; int factory = 0; int dev_id = 0; // default int mode = 0; @@ -67,6 +68,8 @@ public class ScannerTinyB01 { mode = Integer.valueOf(args[++i]).intValue(); } else if( arg.equals("-factory") && args.length > (i+1) ) { factory = Integer.valueOf(args[++i]).intValue(); + } else if( arg.equals("-t0_discovery") && args.length > (i+1) ) { + t0_discovery = Long.valueOf(args[++i]).longValue(); } else if( arg.equals("-forever") ) { forever = true; } @@ -201,14 +204,17 @@ public class ScannerTinyB01 { if( 0 == mode ) { synchronized(matchingDiscoveredDeviceBucket) { - while( null == matchingDiscoveredDeviceBucket[0] ) { - matchingDiscoveredDeviceBucket.wait(TO_DISCOVER); + boolean timeout = false; + while( !timeout && null == matchingDiscoveredDeviceBucket[0] ) { + matchingDiscoveredDeviceBucket.wait(t0_discovery); + final long tn = BluetoothUtils.getCurrentMilliseconds(); + timeout = ( tn - t0 ) > t0_discovery; } sensor = matchingDiscoveredDeviceBucket[0]; matchingDiscoveredDeviceBucket[0] = null; } } else if( 1 == mode ) { - sensor = adapter.find(null, mac, TO_DISCOVER); + sensor = adapter.find(null, mac, t0_discovery); } else { boolean timeout = false; while( null == sensor && !timeout ) { @@ -220,7 +226,7 @@ public class ScannerTinyB01 { break; } final long tn = BluetoothUtils.getCurrentMilliseconds(); - timeout = ( tn - t0 ) > TO_DISCOVER; + timeout = ( tn - t0 ) > t0_discovery; } } } |