aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-25 00:30:09 +0200
committerSven Gothel <[email protected]>2020-06-25 00:30:09 +0200
commita1a31f0b59b9896a04973846bfad2aa0bc9e8d1f (patch)
tree782d40db1b54693d32d07d841a8cca4a3bb08573 /java
parent8693aa160c4c4f7b72c34c99e7550a224a856644 (diff)
GATTHandler/DBTDevice (incl Java): Add ping[GATT](), testing device availability via retrieval of GATT info
Issues a ping to the device, validating whether it is still reachable. This method could be periodically utilized to shorten the underlying OS disconnect period after turning the device off, which lies within 7-13s. In case the device is no more reachable, disconnect will be initiated due to the occurring IO error. +++ Implementation attempts to read the mandatory APPEARANCE CharacteristicValue of the mandatory GENERIC_ACCESS service.
Diffstat (limited to 'java')
-rw-r--r--java/direct_bt/tinyb/DBTDevice.java14
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx13
-rw-r--r--java/org/tinyb/BluetoothDevice.java15
-rw-r--r--java/tinyb/dbus/DBusDevice.java3
4 files changed, 45 insertions, 0 deletions
diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java
index e2390a51..6c1b6342 100644
--- a/java/direct_bt/tinyb/DBTDevice.java
+++ b/java/direct_bt/tinyb/DBTDevice.java
@@ -521,6 +521,20 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
}
private native List<BluetoothGattService> getServicesImpl();
+ @Override
+ public boolean pingGATT() {
+ try {
+ return pingGATTImpl();
+ } catch (final Throwable t) {
+ if(DEBUG) {
+ System.err.println("Caught "+t.getMessage()+" on thread "+Thread.currentThread().toString());
+ t.printStackTrace();
+ }
+ }
+ return false;
+ }
+ private native boolean pingGATTImpl();
+
/* property accessors: */
@Override
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 465aa87d..958fdba2 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -378,6 +378,19 @@ jobject Java_direct_1bt_tinyb_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj
return nullptr;
}
+jboolean Java_direct_1bt_tinyb_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj)
+{
+ try {
+ DBTDevice *device = getInstance<DBTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ return device->pingGATT() ? JNI_TRUE : JNI_FALSE;
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return JNI_FALSE;
+}
+
jstring Java_direct_1bt_tinyb_DBTDevice_getIcon(JNIEnv *env, jobject obj)
{
try {
diff --git a/java/org/tinyb/BluetoothDevice.java b/java/org/tinyb/BluetoothDevice.java
index c8035001..d693eb6b 100644
--- a/java/org/tinyb/BluetoothDevice.java
+++ b/java/org/tinyb/BluetoothDevice.java
@@ -140,6 +140,21 @@ public interface BluetoothDevice extends BluetoothObject
List<BluetoothGattService> getServices();
/**
+ * Issues a GATT ping to the device, validating whether it is still reachable.
+ * <p>
+ * This method could be periodically utilized to shorten the underlying OS disconnect period
+ * after turning the device off, which lies within 7-13s.
+ * </p>
+ * <p>
+ * In case the device is no more reachable, disconnect will be initiated due to the occurring IO error.
+ * </p>
+ *
+ * @return {@code true} if successful, otherwise false in case no GATT services exists etc.
+ * @since 2.0.0
+ */
+ boolean pingGATT();
+
+ /**
* Returns the timestamp in monotonic milliseconds when this device instance has been created,
* either via its initial discovery or its initial direct connection.
*
diff --git a/java/tinyb/dbus/DBusDevice.java b/java/tinyb/dbus/DBusDevice.java
index 9e523dd8..09524836 100644
--- a/java/tinyb/dbus/DBusDevice.java
+++ b/java/tinyb/dbus/DBusDevice.java
@@ -105,6 +105,9 @@ public class DBusDevice extends DBusObject implements BluetoothDevice
@Override
public native List<BluetoothGattService> getServices();
+ @Override
+ public boolean pingGATT() { return false; } // FIXME
+
/* D-Bus property accessors: */
@Override