aboutsummaryrefslogtreecommitdiffstats
path: root/java/org/tinyb
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-23 09:44:33 +0200
committerSven Gothel <[email protected]>2020-10-23 09:44:33 +0200
commit65e706721ed1ffa3800d8d2eb1d34f779cf55b85 (patch)
tree346324df2158949f951ac18922a16505d3ed80cf /java/org/tinyb
parent39de6a7097abb12d1f60fdc9142b79d2a3ba456e (diff)
BluetoothUtils.java: Shorten *Milliseconds* functions; Reuse C++ environment::startupTimeMilliseconds for startupTimeMillis(), aligning timing.
Diffstat (limited to 'java/org/tinyb')
-rw-r--r--java/org/tinyb/AdapterStatusListener.java12
-rw-r--r--java/org/tinyb/BluetoothDevice.java6
-rw-r--r--java/org/tinyb/BluetoothFactory.java5
-rw-r--r--java/org/tinyb/BluetoothUtils.java19
-rw-r--r--java/org/tinyb/GATTCharacteristicListener.java4
5 files changed, 22 insertions, 24 deletions
diff --git a/java/org/tinyb/AdapterStatusListener.java b/java/org/tinyb/AdapterStatusListener.java
index 78c307a6..23e6f421 100644
--- a/java/org/tinyb/AdapterStatusListener.java
+++ b/java/org/tinyb/AdapterStatusListener.java
@@ -63,7 +63,7 @@ public abstract class AdapterStatusListener {
* see {@link BluetoothAdapter#addStatusListener(AdapterStatusListener, BluetoothDevice) addStatusListener(..)}.
* @param newmask the new settings mask
* @param changedmask the changes settings mask
- * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#getCurrentMilliseconds()}.
+ * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}.
*/
public void adapterSettingsChanged(final BluetoothAdapter adapter,
final AdapterSettings oldmask, final AdapterSettings newmask,
@@ -76,14 +76,14 @@ public abstract class AdapterStatusListener {
* @param changedType denotes the changed {@link ScanType}
* @param changedEnabled denotes whether the changed {@link ScanType} has been enabled or disabled
* @param keepAlive if {@code true}, the denoted changed {@link ScanType} will be re-enabled if disabled by the underlying Bluetooth implementation.
- * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#getCurrentMilliseconds()}.
+ * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}.
*/
public void discoveringChanged(final BluetoothAdapter adapter, final ScanType currentMeta, final ScanType changedType, final boolean changedEnabled, final boolean keepAlive, final long timestamp) { }
/**
* A {@link BluetoothDevice} has been newly discovered.
* @param device the found device
- * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#getCurrentMilliseconds()}.
+ * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}.
*/
public void deviceFound(final BluetoothDevice device, final long timestamp) { }
@@ -91,7 +91,7 @@ public abstract class AdapterStatusListener {
* An already discovered {@link BluetoothDevice} has been updated.
* @param device the updated device
* @param updateMask the update mask of changed data
- * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#getCurrentMilliseconds()}.
+ * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}.
*/
public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) { }
@@ -99,7 +99,7 @@ public abstract class AdapterStatusListener {
* {@link BluetoothDevice} got connected.
* @param device the device which has been connected, holding the new connection handle.
* @param handle the new connection handle, which has been assigned to the device already
- * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#getCurrentMilliseconds()}.
+ * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}.
*/
public void deviceConnected(final BluetoothDevice device, final short handle, final long timestamp) { }
@@ -108,7 +108,7 @@ public abstract class AdapterStatusListener {
* @param device the device which has been disconnected with zeroed connection handle.
* @param reason the {@link HCIStatusCode} reason for disconnection
* @param handle the disconnected connection handle, which has been unassigned from the device already
- * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#getCurrentMilliseconds()}.
+ * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}.
*/
public void deviceDisconnected(final BluetoothDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { }
};
diff --git a/java/org/tinyb/BluetoothDevice.java b/java/org/tinyb/BluetoothDevice.java
index 989852c4..36535d7b 100644
--- a/java/org/tinyb/BluetoothDevice.java
+++ b/java/org/tinyb/BluetoothDevice.java
@@ -294,7 +294,7 @@ public interface BluetoothDevice extends BluetoothObject
* Returns the timestamp in monotonic milliseconds when this device instance has been created,
* either via its initial discovery or its initial direct connection.
*
- * @see BluetoothUtils#getCurrentMilliseconds()
+ * @see BluetoothUtils#currentTimeMillis()
* @since 2.0.0
*/
long getCreationTimestamp();
@@ -303,7 +303,7 @@ public interface BluetoothDevice extends BluetoothObject
* Returns the timestamp in monotonic milliseconds when this device instance has
* discovered or connected directly the last time.
*
- * @see BluetoothUtils#getCurrentMilliseconds()
+ * @see BluetoothUtils#currentTimeMillis()
* @since 2.0.0
* @implNote not implemented in tinyb.dbus, returns {@link #getCreationTimestamp()}
*/
@@ -313,7 +313,7 @@ public interface BluetoothDevice extends BluetoothObject
* Returns the timestamp in monotonic milliseconds when this device instance underlying data
* has been updated the last time.
*
- * @see BluetoothUtils#getCurrentMilliseconds()
+ * @see BluetoothUtils#currentTimeMillis()
* @since 2.0.0
* @implNote not implemented in tinyb.dbus, returns {@link #getCreationTimestamp()}
*/
diff --git a/java/org/tinyb/BluetoothFactory.java b/java/org/tinyb/BluetoothFactory.java
index 9dc5e3f9..1cb03c96 100644
--- a/java/org/tinyb/BluetoothFactory.java
+++ b/java/org/tinyb/BluetoothFactory.java
@@ -186,7 +186,6 @@ public class BluetoothFactory {
}
private static ImplementationIdentifier initializedID = null;
- private static long t0;
public static synchronized void checkInitialized() {
if( null == initializedID ) {
@@ -273,8 +272,6 @@ public class BluetoothFactory {
}
initializedID = id; // initialized!
- t0 = BluetoothUtils.getCurrentMilliseconds();
-
APIVersion = JAPIVersion;
ImplVersion = null != mfAttributes ? mfAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION) : null;
if( VERBOSE ) {
@@ -504,8 +501,6 @@ public class BluetoothFactory {
private native static String getNativeAPIVersion();
private native static void setenv(String name, String value, boolean overwrite);
-
- /* pp */ static long getStartupTimeMilliseconds() { return t0; }
}
/** \example DBTScanner10.java
diff --git a/java/org/tinyb/BluetoothUtils.java b/java/org/tinyb/BluetoothUtils.java
index 6be03eb0..37048306 100644
--- a/java/org/tinyb/BluetoothUtils.java
+++ b/java/org/tinyb/BluetoothUtils.java
@@ -25,23 +25,26 @@
package org.tinyb;
public class BluetoothUtils {
+ private static long t0;
+ static {
+ t0 = startupTimeMillisImpl();
+ }
+ private static native long startupTimeMillisImpl();
/**
- * Returns module startup time t0 in monotonic time in milliseconds.
+ * Returns current monotonic time in milliseconds.
*/
- public static long getStartupTimeMilliseconds() { return BluetoothFactory.getStartupTimeMilliseconds(); }
+ public static native long currentTimeMillis();
/**
- * Returns current monotonic time in milliseconds.
+ * Returns the startup time in monotonic time in milliseconds of the native module.
*/
- public static native long getCurrentMilliseconds();
+ public static long startupTimeMillis() { return t0; }
/**
- * Returns current elapsed monotonic time in milliseconds since module startup, see {@link #getStartupTimeMilliseconds()}.
+ * Returns current elapsed monotonic time in milliseconds since module startup, see {@link #startupTimeMillis()}.
*/
- public static long getElapsedMillisecond() {
- return getCurrentMilliseconds() - BluetoothFactory.getStartupTimeMilliseconds();
- }
+ public static long elapsedTimeMillis() { return currentTimeMillis() - t0; }
/**
* Returns a hex string representation
diff --git a/java/org/tinyb/GATTCharacteristicListener.java b/java/org/tinyb/GATTCharacteristicListener.java
index f47e17d3..96114e07 100644
--- a/java/org/tinyb/GATTCharacteristicListener.java
+++ b/java/org/tinyb/GATTCharacteristicListener.java
@@ -88,7 +88,7 @@ public abstract class GATTCharacteristicListener {
* with the given {@link BluetoothGattCharacteristic}.
* @param charDecl {@link BluetoothGattCharacteristic} related to this notification
* @param value the notification value
- * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#getCurrentMilliseconds()}
+ * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#currentTimeMillis()}
*/
public void notificationReceived(final BluetoothGattCharacteristic charDecl,
final byte[] value, final long timestamp) {
@@ -99,7 +99,7 @@ public abstract class GATTCharacteristicListener {
* with the given {@link BluetoothGattCharacteristic}.
* @param charDecl {@link BluetoothGattCharacteristic} related to this indication
* @param value the indication value
- * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#getCurrentMilliseconds()}
+ * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#currentTimeMillis()}
* @param confirmationSent if true, the native stack has sent the confirmation, otherwise user is required to do so.
*/
public void indicationReceived(final BluetoothGattCharacteristic charDecl,