diff options
author | Sven Gothel <[email protected]> | 2020-05-28 06:06:46 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-28 06:06:46 +0200 |
commit | 9f91fa9a33a35a893555e68a761db5a600d96867 (patch) | |
tree | 7884010c54e9b78b2fd19196a88f83092aede945 | |
parent | 1da27ac4831a6ae64e059ec29eb186e653a1a4e5 (diff) |
DBTDevice/BluetoothDevice: Expose getCreationTimestamp() and add BluetoothAddressType getAddressType()
-rw-r--r-- | api/direct_bt/DBTDevice.hpp | 5 | ||||
-rw-r--r-- | java/direct_bt/tinyb/DBTDevice.java | 13 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTAdapter.cxx | 10 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothAddressType.java | 18 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothDevice.java | 17 | ||||
-rw-r--r-- | java/tinyb/dbus/DBusDevice.java | 11 |
6 files changed, 66 insertions, 8 deletions
diff --git a/api/direct_bt/DBTDevice.hpp b/api/direct_bt/DBTDevice.hpp index 7be4faa7..d673b23e 100644 --- a/api/direct_bt/DBTDevice.hpp +++ b/api/direct_bt/DBTDevice.hpp @@ -104,7 +104,12 @@ namespace direct_bt { /** Returns the managing adapter */ DBTAdapter & getAdapter() const { return adapter; } + /** + * Returns the timestamp in monotonic milliseconds when this device instance has been created, either via discovery or direct connection. + * @see BasicTypes::getCurrentMilliseconds() + */ uint64_t getCreationTimestamp() const { return ts_creation; } + uint64_t getUpdateTimestamp() const { return ts_update; } uint64_t getLastUpdateAge(const uint64_t ts_now) const { return ts_now - ts_update; } diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java index 18f52783..c9ea2647 100644 --- a/java/direct_bt/tinyb/DBTDevice.java +++ b/java/direct_bt/tinyb/DBTDevice.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import org.tinyb.AdapterStatusListener; +import org.tinyb.BluetoothAddressType; import org.tinyb.BluetoothDevice; import org.tinyb.BluetoothException; import org.tinyb.BluetoothGattCharacteristic; @@ -43,6 +44,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice { private final DBTAdapter adapter; private final String address; + private final BluetoothAddressType addressType; private final String name; private final long ts_creation; long ts_update; @@ -81,11 +83,14 @@ public class DBTDevice extends DBTObject implements BluetoothDevice }; - /* pp */ DBTDevice(final long nativeInstance, final DBTAdapter adptr, final String address, final String name, final long ts_creation) + /* pp */ DBTDevice(final long nativeInstance, final DBTAdapter adptr, + final String address, final int intAddressType, + final String name, final long ts_creation) { super(nativeInstance, compHash(address, name)); this.adapter = adptr; this.address = address; + this.addressType = BluetoothAddressType.get(intAddressType); this.name = name; this.ts_creation = ts_creation; ts_update = ts_creation; @@ -123,6 +128,9 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } @Override + public final long getCreationTimestamp() { return ts_creation; } + + @Override public DBTAdapter getAdapter() { return adapter; } @@ -131,6 +139,9 @@ public class DBTDevice extends DBTObject implements BluetoothDevice public String getAddress() { return address; } @Override + public BluetoothAddressType getAddressType() { return addressType; } + + @Override public String getName() { return name; } @Override diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index 73cf8534..bba2f94f 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -40,7 +40,7 @@ static const std::string _adapterSettingsClassName("org/tinyb/AdapterSettings"); static const std::string _adapterSettingsClazzCtorArgs("(I)V"); static const std::string _eirDataTypeSetClassName("org/tinyb/EIRDataTypeSet"); static const std::string _eirDataTypeSetClazzCtorArgs("(I)V"); -static const std::string _deviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTAdapter;Ljava/lang/String;Ljava/lang/String;J)V"); +static const std::string _deviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTAdapter;Ljava/lang/String;ILjava/lang/String;J)V"); static const std::string _adapterSettingsChangedMethodArgs("(Lorg/tinyb/BluetoothAdapter;Lorg/tinyb/AdapterSettings;Lorg/tinyb/AdapterSettings;Lorg/tinyb/AdapterSettings;J)V"); static const std::string _discoveringChangedMethodArgs("(Lorg/tinyb/BluetoothAdapter;ZZJ)V"); @@ -253,7 +253,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { const jstring name = from_string_to_jstring(env, device->getName()); java_exception_check_and_throw(env, E_FILE_LINE); jobject jDevice = env->NewObject(deviceClazzRef->getClass(), deviceClazzCtor, - (jlong)device.get(), JavaGlobalObj::GetObject(adapterObjRef), addr, name, (jlong)timestamp); + (jlong)device.get(), JavaGlobalObj::GetObject(adapterObjRef), addr, device->getAddressType(), name, (jlong)timestamp); java_exception_check_and_throw(env, E_FILE_LINE); JNIGlobalRef::check(jDevice, E_FILE_LINE); std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject(); @@ -401,7 +401,8 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_isDeviceWhitelisted(JNIEnv *env, jobje } return JNI_FALSE; } -jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist(JNIEnv *env, jobject obj, jstring jaddress, int jaddressType, int jctype, +jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist__Ljava_lang_String_2IISSSS(JNIEnv *env, jobject obj, + jstring jaddress, int jaddressType, int jctype, jshort min_interval, jshort max_interval, jshort latency, jshort timeout) { try { @@ -418,7 +419,8 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist(JNIEnv *env, jobj } return JNI_FALSE; } -jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist(JNIEnv *env, jobject obj, jstring jaddress, int jaddressType, int jctype) { +jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist__Ljava_lang_String_2II(JNIEnv *env, jobject obj, + jstring jaddress, int jaddressType, int jctype) { try { DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj); JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); diff --git a/java/org/tinyb/BluetoothAddressType.java b/java/org/tinyb/BluetoothAddressType.java index 3556798a..34fd2170 100644 --- a/java/org/tinyb/BluetoothAddressType.java +++ b/java/org/tinyb/BluetoothAddressType.java @@ -85,7 +85,7 @@ public enum BluetoothAddressType { * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type * as described above. */ - public static BluetoothAddressType get(final String name) { + public static BluetoothAddressType get(final String name) throws IllegalArgumentException { if( null == name || name.length() == 0 ) { return BDADDR_BREDR; } @@ -98,6 +98,22 @@ public enum BluetoothAddressType { return valueOf(name); } + /** + * Maps the specified integer value to a constant of BluetoothAddressType. + * @param value the integer value to be mapped to a constant of this enum type. + * @return the corresponding constant of this enum type. + * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type + * as described above. + */ + public static BluetoothAddressType get(final int value) throws IllegalArgumentException { + switch(value) { + case 0x00: return BDADDR_BREDR; + case 0x01: return BDADDR_LE_PUBLIC; + case 0x02: return BDADDR_LE_RANDOM; + } + throw new IllegalArgumentException("Unsupported value "+value); + } + BluetoothAddressType(final int v) { value = v; } diff --git a/java/org/tinyb/BluetoothDevice.java b/java/org/tinyb/BluetoothDevice.java index b2b4aab7..dbfb1d06 100644 --- a/java/org/tinyb/BluetoothDevice.java +++ b/java/org/tinyb/BluetoothDevice.java @@ -139,12 +139,27 @@ public interface BluetoothDevice extends BluetoothObject */ List<BluetoothGattService> getServices(); - /* D-Bus property accessors: */ + /** + * Returns the timestamp in monotonic milliseconds when this device instance has been created, either via discovery or direct connection. + * + * @see BluetoothUtils#getCurrentMilliseconds() + * @since 2.0.0 + */ + long getCreationTimestamp(); + /** Returns the hardware address of this device. * @return The hardware address of this device. */ String getAddress(); + /** + * Returns the {@link BluetoothAddressType}, + * determining whether the device is {@link BluetoothAddressType#BDADDR_BREDR} + * or an LE device, {@link BluetoothAddressType#BDADDR_LE_PUBLIC} or {@link BluetoothAddressType#BDADDR_LE_RANDOM}. + * @since 2.0.0 + */ + BluetoothAddressType getAddressType(); + /** Returns the remote friendly name of this device. * @return The remote friendly name of this device, or NULL if not set. */ diff --git a/java/tinyb/dbus/DBusDevice.java b/java/tinyb/dbus/DBusDevice.java index bc57d063..735ca79f 100644 --- a/java/tinyb/dbus/DBusDevice.java +++ b/java/tinyb/dbus/DBusDevice.java @@ -31,6 +31,7 @@ package tinyb.dbus; import java.util.List; import java.util.Map; +import org.tinyb.BluetoothAddressType; import org.tinyb.BluetoothDevice; import org.tinyb.BluetoothException; import org.tinyb.BluetoothGattCharacteristic; @@ -38,11 +39,15 @@ import org.tinyb.BluetoothGattService; import org.tinyb.BluetoothManager; import org.tinyb.BluetoothNotification; import org.tinyb.BluetoothType; +import org.tinyb.BluetoothUtils; import org.tinyb.GATTCharacteristicListener; public class DBusDevice extends DBusObject implements BluetoothDevice { @Override + public final long getCreationTimestamp() { return ts_creation; } + + @Override public native BluetoothType getBluetoothType(); @Override public native DBusDevice clone(); @@ -100,6 +105,9 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native String getAddress(); @Override + public BluetoothAddressType getAddressType() { return BluetoothAddressType.BDADDR_LE_PUBLIC; /* FIXME */} + + @Override public native String getName(); @Override @@ -231,6 +239,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice private DBusDevice(final long instance) { super(instance); + ts_creation = BluetoothUtils.getCurrentMilliseconds(); } - + final long ts_creation; } |