summaryrefslogtreecommitdiffstats
path: root/java/direct_bt/tinyb
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-31 18:18:01 +0200
committerSven Gothel <[email protected]>2020-05-31 18:18:01 +0200
commitc4454638931dd66bf80ae0132b80d85fbf01932c (patch)
treef27b1bf76c59eb820cb2927c4bf9800de306f2e3 /java/direct_bt/tinyb
parent18bfd4108c06669256c7d52d961fe6197eceb202 (diff)
AdapterStatusListener(C++/Java): Expose 'HCIErrorCode reason' on disconnect (split deviceConnectionChanged up), align args of deviceUpdated
The 'HCIErrorCode reason' gives us valuable information of the disconnect reason, hence we shall expose it to the user level on the C++ and Java side.
Diffstat (limited to 'java/direct_bt/tinyb')
-rw-r--r--java/direct_bt/tinyb/DBTAdapter.java14
-rw-r--r--java/direct_bt/tinyb/DBTDevice.java30
2 files changed, 35 insertions, 9 deletions
diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java
index c667a92a..e0d9aa02 100644
--- a/java/direct_bt/tinyb/DBTAdapter.java
+++ b/java/direct_bt/tinyb/DBTAdapter.java
@@ -41,6 +41,7 @@ import org.tinyb.BluetoothManager;
import org.tinyb.BluetoothNotification;
import org.tinyb.BluetoothType;
import org.tinyb.EIRDataTypeSet;
+import org.tinyb.HCIErrorCode;
import org.tinyb.HCIWhitelistConnectType;
import org.tinyb.AdapterStatusListener;
import org.tinyb.TransportType;
@@ -417,7 +418,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
}
@Override
- public void deviceUpdated(final BluetoothDevice device, final long timestamp, final EIRDataTypeSet updateMask) {
+ public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) {
if( DEBUG ) {
System.err.println("Adapter.StatusListener.UPDATED: "+updateMask+" of "+device+" on "+device.getAdapter());
}
@@ -425,9 +426,16 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
}
@Override
- public void deviceConnectionChanged(final BluetoothDevice device, final boolean connected, final long timestamp) {
+ public void deviceConnected(final BluetoothDevice device, final long timestamp) {
if( DEBUG ) {
- System.err.println("Adapter.StatusListener.CONNECTION: connected "+connected+": "+device+" on "+device.getAdapter());
+ System.err.println("Adapter.StatusListener.CONNECTED: "+device+" on "+device.getAdapter());
+ }
+ }
+
+ @Override
+ public void deviceDisconnected(final BluetoothDevice device, final HCIErrorCode reason, final long timestamp) {
+ if( DEBUG ) {
+ System.err.println("Adapter.StatusListener.DISCONNECTED: Reason "+reason+": "+device+" on "+device.getAdapter());
}
}
};
diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java
index da0ddd5d..fa749afe 100644
--- a/java/direct_bt/tinyb/DBTDevice.java
+++ b/java/direct_bt/tinyb/DBTDevice.java
@@ -39,6 +39,7 @@ import org.tinyb.BluetoothNotification;
import org.tinyb.BluetoothType;
import org.tinyb.EIRDataTypeSet;
import org.tinyb.GATTCharacteristicListener;
+import org.tinyb.HCIErrorCode;
public class DBTDevice extends DBTObject implements BluetoothDevice
{
@@ -61,7 +62,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
final AdapterStatusListener statusListener = new AdapterStatusListener() {
@Override
- public void deviceUpdated(final BluetoothDevice device, final long timestamp, final EIRDataTypeSet updateMask) {
+ public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) {
synchronized(userCallbackLock) {
if( updateMask.isSet( EIRDataTypeSet.DataType.RSSI ) && null != userRSSINotificationsCB ) {
userRSSINotificationsCB.run(getRSSI());
@@ -72,14 +73,14 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
}
}
@Override
- public void deviceConnectionChanged(final BluetoothDevice device, final boolean connected, final long timestamp) {
- if( DBTDevice.this.connected != connected ) {
- DBTDevice.this.connected = connected;
+ public void deviceConnected(final BluetoothDevice device, final long timestamp) {
+ if( !connected ) {
+ connected = true;
synchronized(userCallbackLock) {
if( null != userConnectedNotificationsCB ) {
- userConnectedNotificationsCB.run(connected);
+ userConnectedNotificationsCB.run(Boolean.TRUE);
}
- if( connected && !servicesResolved ) {
+ if( !servicesResolved ) {
servicesResolved = true;
if( null != userServicesResolvedNotificationsCB ) {
userServicesResolvedNotificationsCB.run(Boolean.TRUE);
@@ -88,6 +89,23 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
}
}
}
+ @Override
+ public void deviceDisconnected(final BluetoothDevice device, final HCIErrorCode reason, final long timestamp) {
+ if( connected ) {
+ connected = false;
+ synchronized(userCallbackLock) {
+ if( servicesResolved ) {
+ servicesResolved = false;
+ if( null != userServicesResolvedNotificationsCB ) {
+ userServicesResolvedNotificationsCB.run(Boolean.FALSE);
+ }
+ }
+ if( null != userConnectedNotificationsCB ) {
+ userConnectedNotificationsCB.run(Boolean.FALSE);
+ }
+ }
+ }
+ }
};