summaryrefslogtreecommitdiffstats
path: root/java/direct_bt/tinyb
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-04-21 13:05:53 +0200
committerSven Gothel <[email protected]>2020-04-21 13:05:53 +0200
commit2bacdad45d6c7a315937c4c3723fba54fb83b631 (patch)
tree912cc4c8440a00aee8ab5cbe8a8c1d5c6e07a2cb /java/direct_bt/tinyb
parentd123b2363692d4e95340aa63bf5246cd293b4f30 (diff)
Refine: DBT API, HCISession/DBTAdapter lifecycle, API doc and C++ and C++/JNI exception handling
- HCISession: Handle multiple connections - DBTDevice holds le_conn_handle and provides the le_disconnect as well - HCISession maintains a vector of connected devices - HCISession/DBTAdapter: Cleanup shutdown and refine lifecycle - DBTDevice/DBTAdapter: Drop explicit HCISession argument, simply use the attached HCISession of DBTAdapter. - Refine API doc in general +++ - Device Java/JNI: Add a few more methods to test connect/disconnect. +++ Refine C++ and C++/JNI exception handling: - Use new java_exception_check_and_throw(..): Throw C++ exception on pending Java exception, retrieving toString() message. - Use new java_exception_check(..): Return immediately from JNI on pending Java exception. - Replace macro CATCH_EXCEPTION_AND_RAISE_JAVA(..) with new rethrow_and_raise_java_exception(..), re-trhowing exception and raising detailed Java exception.
Diffstat (limited to 'java/direct_bt/tinyb')
-rw-r--r--java/direct_bt/tinyb/DBTDevice.java54
1 files changed, 43 insertions, 11 deletions
diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java
index 2946f532..e2ef4d70 100644
--- a/java/direct_bt/tinyb/DBTDevice.java
+++ b/java/direct_bt/tinyb/DBTDevice.java
@@ -120,13 +120,48 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
private native void initImpl();
- /* D-Bus method calls: */
+ /* DBT method calls: Connection */
@Override
- public native boolean disconnect() throws BluetoothException;
+ public final void enableConnectedNotifications(final BluetoothNotification<Boolean> callback) {
+ connectedNotifications = callback;
+ }
+ private BluetoothNotification<Boolean> connectedNotifications = null;
+ private boolean connected = false;
@Override
- public native boolean connect() throws BluetoothException;
+ public final boolean getConnected() { return connected; }
+ // private native boolean getConnectedImpl();
+
+ @Override
+ public final boolean disconnect() throws BluetoothException {
+ boolean res = false;
+ if( connected ) {
+ res = disconnectImpl();
+ if( res ) {
+ connectedNotifications.run(Boolean.FALSE);
+ connected = false;
+ }
+ }
+ return res;
+ }
+ private native boolean disconnectImpl() throws BluetoothException;
+
+ @Override
+ public final boolean connect() throws BluetoothException {
+ boolean res = false;
+ if( !connected ) {
+ res = connectImpl();
+ if( res ) {
+ connectedNotifications.run(Boolean.TRUE);
+ connected = true;
+ }
+ }
+ return res;
+ }
+ private native boolean connectImpl() throws BluetoothException;
+
+ /* DBT method calls: */
@Override
public native boolean connectProfile(String arg_UUID) throws BluetoothException;
@@ -148,7 +183,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
@Override
public native List<BluetoothGattService> getServices();
- /* D-Bus property accessors: */
+ /* property accessors: */
@Override
public String getAlias() { return null; } // FIXME
@@ -211,12 +246,6 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
@Override
public native void disableRSSINotifications();
- @Override
- public native boolean getConnected();
-
- @Override
- public native void enableConnectedNotifications(BluetoothNotification<Boolean> callback);
-
@Override
public native void disableConnectedNotifications();
@@ -255,7 +284,10 @@ public class DBTDevice extends DBTObject implements BluetoothDevice
public native boolean getServicesResolved ();
@Override
- public native void enableServicesResolvedNotifications(BluetoothNotification<Boolean> callback);
+ public final void enableServicesResolvedNotifications(final BluetoothNotification<Boolean> callback) {
+ servicesResolvedNotifications = callback;
+ }
+ private BluetoothNotification<Boolean> servicesResolvedNotifications = null;
@Override
public native void disableServicesResolvedNotifications();