diff options
author | Sven Gothel <[email protected]> | 2020-10-23 09:44:33 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-10-23 09:44:33 +0200 |
commit | 65e706721ed1ffa3800d8d2eb1d34f779cf55b85 (patch) | |
tree | 346324df2158949f951ac18922a16505d3ed80cf /java | |
parent | 39de6a7097abb12d1f60fdc9142b79d2a3ba456e (diff) |
BluetoothUtils.java: Shorten *Milliseconds* functions; Reuse C++ environment::startupTimeMilliseconds for startupTimeMillis(), aligning timing.
Diffstat (limited to 'java')
-rw-r--r-- | java/jni/BluetoothUtils.cxx | 11 | ||||
-rw-r--r-- | java/org/tinyb/AdapterStatusListener.java | 12 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothDevice.java | 6 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothFactory.java | 5 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothUtils.java | 19 | ||||
-rw-r--r-- | java/org/tinyb/GATTCharacteristicListener.java | 4 | ||||
-rw-r--r-- | java/tinyb/dbus/DBusDevice.java | 2 |
7 files changed, 33 insertions, 26 deletions
diff --git a/java/jni/BluetoothUtils.cxx b/java/jni/BluetoothUtils.cxx index 84c18bcb..945afff1 100644 --- a/java/jni/BluetoothUtils.cxx +++ b/java/jni/BluetoothUtils.cxx @@ -31,9 +31,11 @@ #include <time.h> #include <jau/dfa_utf8_decode.hpp> +#include <jau/environment.hpp> #include "helper_base.hpp" + static const int64_t NanoPerMilli = 1000000L; static const int64_t MilliPerOne = 1000L; @@ -45,7 +47,7 @@ static const int64_t MilliPerOne = 1000L; * clock_gettime seems to be well supported at least on kernel >= 4.4. * Only bfin and sh are missing, while ia64 seems to be complicated. */ -jlong Java_org_tinyb_BluetoothUtils_getCurrentMilliseconds(JNIEnv *env, jclass clazz) { +jlong Java_org_tinyb_BluetoothUtils_currentTimeMillis(JNIEnv *env, jclass clazz) { (void)env; (void)clazz; @@ -55,6 +57,13 @@ jlong Java_org_tinyb_BluetoothUtils_getCurrentMilliseconds(JNIEnv *env, jclass c return (jlong)res; } +jlong Java_org_tinyb_BluetoothUtils_startupTimeMillisImpl(JNIEnv *env, jclass clazz) { + (void)env; + (void)clazz; + + return jau::environment::startupTimeMilliseconds; +} + jstring Java_org_tinyb_BluetoothUtils_decodeUTF8String(JNIEnv *env, jclass clazz, jbyteArray jbuffer, jint offset, jint size) { (void)clazz; 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, diff --git a/java/tinyb/dbus/DBusDevice.java b/java/tinyb/dbus/DBusDevice.java index 474466c9..070e71d3 100644 --- a/java/tinyb/dbus/DBusDevice.java +++ b/java/tinyb/dbus/DBusDevice.java @@ -283,7 +283,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice private DBusDevice(final long instance) { super(instance); - ts_creation = BluetoothUtils.getCurrentMilliseconds(); + ts_creation = BluetoothUtils.currentTimeMillis(); } final long ts_creation; |