aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-09-21 03:17:03 +0200
committerSven Gothel <[email protected]>2021-09-21 03:17:03 +0200
commitf9b92984621258b1f75f1ddbedae05b06747ad09 (patch)
tree81474244f6896444f51241c507d0ba76c0e6103a
parentcf14e88fae8ed3dc5678ca550fa93c57197c3da6 (diff)
Refine initAdapter() in exampled: Remove listener on start[Discovery/Advertising]() failure.
Examples dbt_scanner10.cpp/DBTScanner10.java and dbt_peripheral00.cpp/DBTPeripheral00.java
-rw-r--r--examples/direct_bt_peripheral00/dbt_peripheral00.cpp4
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp4
-rw-r--r--examples/java/DBTPeripheral00.java4
-rw-r--r--examples/java/DBTScanner10.java4
4 files changed, 12 insertions, 4 deletions
diff --git a/examples/direct_bt_peripheral00/dbt_peripheral00.cpp b/examples/direct_bt_peripheral00/dbt_peripheral00.cpp
index ed47d1ae..a722df4e 100644
--- a/examples/direct_bt_peripheral00/dbt_peripheral00.cpp
+++ b/examples/direct_bt_peripheral00/dbt_peripheral00.cpp
@@ -242,12 +242,14 @@ static bool initAdapter(std::shared_ptr<BTAdapter>& adapter) {
return false;
}
// adapter is powered-on
- adapter->addStatusListener(std::shared_ptr<AdapterStatusListener>(new MyAdapterStatusListener()));
+ std::shared_ptr<AdapterStatusListener> asl(new MyAdapterStatusListener());
+ adapter->addStatusListener( asl );
// Flush discovered devices after registering our status listener.
// This avoids discovered devices before we have registered!
adapter->removeDiscoveredDevices();
if( !startAdvertising(adapter.get(), "initAdapter") ) {
+ adapter->removeStatusListener( asl );
return false;
}
return true;
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index 8e487ed6..1e1c2ea3 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -671,7 +671,8 @@ static bool initAdapter(std::shared_ptr<BTAdapter>& adapter) {
return false;
}
// adapter is powered-on
- adapter->addStatusListener(std::shared_ptr<AdapterStatusListener>(new MyAdapterStatusListener()));
+ std::shared_ptr<AdapterStatusListener> asl(new MyAdapterStatusListener());
+ adapter->addStatusListener( asl );
// Flush discovered devices after registering our status listener.
// This avoids discovered devices before we have registered!
adapter->removeDiscoveredDevices();
@@ -683,6 +684,7 @@ static bool initAdapter(std::shared_ptr<BTAdapter>& adapter) {
}
} else {
if( !startDiscovery(adapter.get(), "initAdapter") ) {
+ adapter->removeStatusListener( asl );
return false;
}
}
diff --git a/examples/java/DBTPeripheral00.java b/examples/java/DBTPeripheral00.java
index b15a8986..93c2e006 100644
--- a/examples/java/DBTPeripheral00.java
+++ b/examples/java/DBTPeripheral00.java
@@ -260,12 +260,14 @@ public class DBTPeripheral00 {
return false;
}
// adapter is powered-on
- adapter.addStatusListener(new MyAdapterStatusListener() );
+ final AdapterStatusListener asl = new MyAdapterStatusListener();
+ adapter.addStatusListener( asl );
// Flush discovered devices after registering our status listener.
// This avoids discovered devices before we have registered!
adapter.removeDiscoveredDevices();
if( !startAdvertising(adapter, "initAdapter") ) {
+ adapter.removeStatusListener( asl );
return false;
}
return true;
diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java
index 65b99fe1..b07f4865 100644
--- a/examples/java/DBTScanner10.java
+++ b/examples/java/DBTScanner10.java
@@ -670,7 +670,8 @@ public class DBTScanner10 {
return false;
}
// adapter is powered-on
- adapter.addStatusListener(new MyAdapterStatusListener() );
+ final AdapterStatusListener asl = new MyAdapterStatusListener();
+ adapter.addStatusListener( asl );
// Flush discovered devices after registering our status listener.
// This avoids discovered devices before we have registered!
adapter.removeDiscoveredDevices();
@@ -683,6 +684,7 @@ public class DBTScanner10 {
}
} else {
if( !startDiscovery(adapter, "initAdapter") ) {
+ adapter.removeStatusListener( asl );
return false;
}
}