diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/direct_bt/tinyb/DBTDevice.java | 25 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTDevice.cxx | 45 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothDevice.java | 24 | ||||
-rw-r--r-- | java/tinyb/dbus/DBusDevice.java | 7 |
4 files changed, 99 insertions, 2 deletions
diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java index 31146c03..18f52783 100644 --- a/java/direct_bt/tinyb/DBTDevice.java +++ b/java/direct_bt/tinyb/DBTDevice.java @@ -28,7 +28,6 @@ package direct_bt.tinyb; import java.util.List; import java.util.Map; -import org.tinyb.BluetoothAdapter; import org.tinyb.AdapterStatusListener; import org.tinyb.BluetoothDevice; import org.tinyb.BluetoothException; @@ -37,7 +36,6 @@ import org.tinyb.BluetoothGattService; import org.tinyb.BluetoothManager; import org.tinyb.BluetoothNotification; import org.tinyb.BluetoothType; -import org.tinyb.BluetoothUtils; import org.tinyb.EIRDataTypeSet; import org.tinyb.GATTCharacteristicListener; @@ -232,6 +230,29 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } private native boolean connectImpl() throws BluetoothException; + @Override + public boolean connect(final short interval, final short window, + final short min_interval, final short max_interval, + final short latency, final short timeout) { + boolean res = false; + if( !connected ) { + res = connectImpl(interval, window, min_interval, max_interval, latency, timeout); + if( res ) { + connected = true; + userConnectedNotificationsCB.run(Boolean.TRUE); + + // FIXME: Split up - may offload to other thread + // Currently service resolution performed in connectImpl()! + servicesResolved = true; + userServicesResolvedNotificationsCB.run(Boolean.TRUE); + } + } + return res; + } + private native boolean connectImpl(final short interval, final short window, + final short min_interval, final short max_interval, + final short latency, final short timeout); + /* DBT Java callbacks */ @Override diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx index f90aa6bb..073b1ee0 100644 --- a/java/jni/direct_bt/DBTDevice.cxx +++ b/java/jni/direct_bt/DBTDevice.cxx @@ -315,6 +315,51 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_connectImpl(JNIEnv *env, jobject obj) return JNI_FALSE; } +jboolean Java_direct_1bt_tinyb_DBTDevice_connectImpl(JNIEnv *env, jobject obj, + jshort interval, jshort window, + jshort min_interval, jshort max_interval, + jshort latency, jshort timeout) +{ + try { + DBTDevice *device = getInstance<DBTDevice>(env, obj); + JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); + uint16_t hciHandle; + switch( device->addressType ) { + case BDAddressType::BDADDR_LE_PUBLIC: + hciHandle = device->le_connectHCI(HCIAddressType::HCIADDR_LE_PUBLIC, HCIAddressType::HCIADDR_LE_PUBLIC, + interval, window, min_interval, max_interval, latency, timeout); + break; + case BDAddressType::BDADDR_LE_RANDOM: + hciHandle = device->le_connectHCI(HCIAddressType::HCIADDR_LE_RANDOM, HCIAddressType::HCIADDR_LE_PUBLIC, + interval, window, min_interval, max_interval, latency, timeout); + break; + default: + hciHandle = device->connectHCIDefault(); + break; + } + if( 0 == hciHandle ) { + return JNI_FALSE; + } + std::shared_ptr<GATTHandler> gatt = device->connectGATT(); + if( nullptr != gatt ) { + // FIXME: Split up - may offload to other thread + std::vector<GATTServiceRef> services = device->getGATTServices(); // implicit GATT connect and discovery if required + if( services.size() > 0 ) { + std::shared_ptr<GenericAccess> ga = device->getGATTGenericAccess(); + if( nullptr != ga ) { + env->SetShortField(obj, getField(env, obj, "appearance", "S"), static_cast<jshort>(ga->appearance)); + java_exception_check_and_throw(env, E_FILE_LINE); + DBG_PRINT("GATT connected to GenericAccess: %s", ga->toString().c_str()); + } + } + return JNI_TRUE; + } + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return JNI_FALSE; +} + // // getter // diff --git a/java/org/tinyb/BluetoothDevice.java b/java/org/tinyb/BluetoothDevice.java index aad9e233..30710fb4 100644 --- a/java/org/tinyb/BluetoothDevice.java +++ b/java/org/tinyb/BluetoothDevice.java @@ -74,9 +74,33 @@ public interface BluetoothDevice extends BluetoothObject /** A connection to this device is established, connecting each profile * flagged as auto-connectable. * @return TRUE if the device connected + * @see #connect(short, short, short, short, short, short) */ boolean connect() throws BluetoothException; + /** + * A connection to this device is established, see {@link #connect()}. + * <p> + * The given LE connection parameter will be used instead of the Bluetooth implementation defaults, + * if this device is of type {@link BluetoothAddressType#BDADDR_LE_PUBLIC} or {@link BluetoothAddressType#BDADDR_LE_RANDOM}. + * </p> + * + * @param interval default value 0x0004 + * @param window default value 0x0004 + * @param min_interval default value 0x000F + * @param max_interval default value 0x000F + * @param latency default value 0x0000 + * @param timeout default value 0x0C80 + * @return {@code true} if successful, otherwise {@code false}. + * + * @see #connect() + * @since 2.0.0 + */ + public boolean connect(final short interval, final short window, + final short min_interval, final short max_interval, + final short latency, final short timeout); + + /** Connects a specific profile available on the device, given by UUID * @param arg_UUID The UUID of the profile to be connected * @return TRUE if the profile connected successfully diff --git a/java/tinyb/dbus/DBusDevice.java b/java/tinyb/dbus/DBusDevice.java index fbbebc62..bc57d063 100644 --- a/java/tinyb/dbus/DBusDevice.java +++ b/java/tinyb/dbus/DBusDevice.java @@ -70,6 +70,13 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native boolean connect() throws BluetoothException; @Override + public boolean connect(final short interval, final short window, + final short min_interval, final short max_interval, + final short latency, final short timeout) { + return connect(); // FIXME connection params ... + } + + @Override public native boolean connectProfile(String arg_UUID) throws BluetoothException; @Override |