aboutsummaryrefslogtreecommitdiffstats
path: root/examples/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-09-18 22:54:03 +0200
committerSven Gothel <[email protected]>2021-09-18 22:54:03 +0200
commitfa733201d719ca64d203d7adccd6b127f4fa73d5 (patch)
treeee53519b86e5875db9b29e9c7993767ec41171bf /examples/java
parent1480355ba4c81057f702130d6f4b7c5315d9e0c8 (diff)
Add BTAdapter::isInitialized(): Allow to avoid re-initialization of an adapter.
Diffstat (limited to 'examples/java')
-rw-r--r--examples/java/DBTPeripheral00.java34
-rw-r--r--examples/java/DBTScanner10.java2
2 files changed, 19 insertions, 17 deletions
diff --git a/examples/java/DBTPeripheral00.java b/examples/java/DBTPeripheral00.java
index 527b69d5..b0ff329f 100644
--- a/examples/java/DBTPeripheral00.java
+++ b/examples/java/DBTPeripheral00.java
@@ -234,24 +234,26 @@ public class DBTPeripheral00 {
BTUtils.fprintf_td(System.err, "initAdapter: Adapter not selected: %s\n", adapter.toString());
return false;
}
- // setName(..) ..
- if( adapter.setPowered(false) ) {
- final HCIStatusCode status = adapter.setName(adapter_name, adapter_short_name);
- if( HCIStatusCode.SUCCESS == status ) {
- BTUtils.fprintf_td(System.err, "initAdapter: setLocalName OK: %s\n", adapter.toString());
+ if( !adapter.isInitialized() ) {
+ // setName(..) ..
+ if( adapter.setPowered(false) ) {
+ final HCIStatusCode status = adapter.setName(adapter_name, adapter_short_name);
+ if( HCIStatusCode.SUCCESS == status ) {
+ BTUtils.fprintf_td(System.err, "initAdapter: setLocalName OK: %s\n", adapter.toString());
+ } else {
+ BTUtils.fprintf_td(System.err, "initAdapter: setLocalName failed: %s\n", adapter.toString());
+ }
} else {
- BTUtils.fprintf_td(System.err, "initAdapter: setLocalName failed: %s\n", adapter.toString());
+ BTUtils.fprintf_td(System.err, "initAdapter: setPowered failed: %s\n", adapter.toString());
}
- } else {
- BTUtils.fprintf_td(System.err, "initAdapter: setPowered failed: %s\n", adapter.toString());
- }
- // Initialize with defaults and power-on
- {
- final HCIStatusCode status = adapter.initialize( btMode );
- if( HCIStatusCode.SUCCESS != status ) {
- BTUtils.fprintf_td(System.err, "initAdapter: Adapter initialization failed: %s: %s\n",
- status.toString(), adapter.toString());
- return false;
+ // Initialize with defaults and power-on
+ {
+ final HCIStatusCode status = adapter.initialize( btMode );
+ if( HCIStatusCode.SUCCESS != status ) {
+ BTUtils.fprintf_td(System.err, "initAdapter: Adapter initialization failed: %s: %s\n",
+ status.toString(), adapter.toString());
+ return false;
+ }
}
}
// Even if adapter is not yet powered, listen to it and act when it gets powered-on
diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java
index 184309d1..605a90a3 100644
--- a/examples/java/DBTScanner10.java
+++ b/examples/java/DBTScanner10.java
@@ -657,7 +657,7 @@ public class DBTScanner10 {
return false;
}
// Initialize with defaults and power-on
- {
+ if( !adapter.isInitialized() ) {
final HCIStatusCode status = adapter.initialize( btMode );
if( HCIStatusCode.SUCCESS != status ) {
BTUtils.fprintf_td(System.err, "initAdapter: Adapter initialization failed: %s: %s\n",