aboutsummaryrefslogtreecommitdiffstats
path: root/java/org
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-04 15:20:37 +0200
committerSven Gothel <[email protected]>2020-05-04 15:20:37 +0200
commit640e4f15f6fd7f44b49a606515f3778574b18db7 (patch)
treeb7846e9327bbc630cd283699ac9b2665c7f4bb5f /java/org
parentd3e86e6a934af213f014b06f6469cfc97c0f5f83 (diff)
Extend BluetoothDeviceStatusListener -> BluetoothAdapterStatusListener; Enum bit field mask: Add AdapterSettings , fix EIRDataType -> EIRDataTypeSet
Extend Java BluetoothDeviceStatusListener -> BluetoothAdapterStatusListener and C++ DBTDeviceStatusListener -> DBTAdapterStatusListener - BluetoothAdapterStatusListener shall be (ab)used for anything adapter event related, user may utilize it (optional) - Added callback method adapterSettingsChanged(..) in DBTAdapterStatusListener - An internal listener further produces more detailed callbacks, used on the Java side. +++ Java enum bit field mask: Add AdapterSettings , fix EIRDataType -> EIRDataTypeSet - In Java, we cannot have an indivudual enum instance (like in C++) ;-) - Hence 'enum EIRDataType' -> EIRDataTypeSet.DataType and having the 'bit mask' implemented in EIRDataTypeSet. - Adding similar AdapterSettings bit field, utilized in DBTAdapter's internal BluetoothAdapterStatusListener to produce fine grained callbacks.
Diffstat (limited to 'java/org')
-rw-r--r--java/org/tinyb/AdapterSettings.java138
-rw-r--r--java/org/tinyb/BluetoothAdapter.java6
-rw-r--r--java/org/tinyb/BluetoothAdapterStatusListener.java (renamed from java/org/tinyb/BluetoothDeviceStatusListener.java)13
-rw-r--r--java/org/tinyb/EIRDataType.java124
-rw-r--r--java/org/tinyb/EIRDataTypeSet.java128
5 files changed, 278 insertions, 131 deletions
diff --git a/java/org/tinyb/AdapterSettings.java b/java/org/tinyb/AdapterSettings.java
new file mode 100644
index 00000000..0fab7fd5
--- /dev/null
+++ b/java/org/tinyb/AdapterSettings.java
@@ -0,0 +1,138 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package org.tinyb;
+
+public class AdapterSettings {
+
+ public enum SettingType {
+ NONE ( 0),
+ POWERED (0x00000001),
+ CONNECTABLE (0x00000002),
+ FAST_CONNECTABLE (0x00000004),
+ DISCOVERABLE (0x00000008),
+ BONDABLE (0x00000010),
+ LINK_SECURITY (0x00000020),
+ SSP (0x00000040),
+ BREDR (0x00000080),
+ HS (0x00000100),
+ LE (0x00000200),
+ ADVERTISING (0x00000400),
+ SECURE_CONN (0x00000800),
+ DEBUG_KEYS (0x00001000),
+ PRIVACY (0x00002000),
+ CONFIGURATION (0x00004000),
+ STATIC_ADDRESS (0x00008000),
+ PHY_CONFIGURATION (0x00010000);
+
+ SettingType(final int v) { value = v; }
+ public final int value;
+ }
+
+ public int mask;
+
+ public AdapterSettings(final int v) {
+ mask = v;
+ }
+
+ public boolean isSet(final SettingType bit) { return 0 != ( mask & bit.value ); }
+ public void set(final SettingType bit) { mask = mask | bit.value; }
+
+ public String toString() {
+ int count = 0;
+ final StringBuilder out = new StringBuilder();
+ if( isSet(SettingType.POWERED) ) {
+ out.append(SettingType.POWERED.name()); count++;
+ }
+ if( isSet(SettingType.CONNECTABLE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.CONNECTABLE.name()); count++;
+ }
+ if( isSet(SettingType.FAST_CONNECTABLE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.FAST_CONNECTABLE.name()); count++;
+ }
+ if( isSet(SettingType.DISCOVERABLE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.DISCOVERABLE.name()); count++;
+ }
+ if( isSet(SettingType.BONDABLE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.BONDABLE.name()); count++;
+ }
+ if( isSet(SettingType.LINK_SECURITY) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.LINK_SECURITY.name()); count++;
+ }
+ if( isSet(SettingType.SSP) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.SSP.name()); count++;
+ }
+ if( isSet(SettingType.BREDR) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.BREDR.name()); count++;
+ }
+ if( isSet(SettingType.HS) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.HS.name()); count++;
+ }
+ if( isSet(SettingType.LE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.LE.name()); count++;
+ }
+ if( isSet(SettingType.ADVERTISING) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.ADVERTISING.name()); count++;
+ }
+ if( isSet(SettingType.SECURE_CONN) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.SECURE_CONN.name()); count++;
+ }
+ if( isSet(SettingType.DEBUG_KEYS) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.DEBUG_KEYS.name()); count++;
+ }
+ if( isSet(SettingType.PRIVACY) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.PRIVACY.name()); count++;
+ }
+ if( isSet(SettingType.CONFIGURATION) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.CONFIGURATION.name()); count++;
+ }
+ if( isSet(SettingType.STATIC_ADDRESS) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.STATIC_ADDRESS.name()); count++;
+ }
+ if( isSet(SettingType.PHY_CONFIGURATION) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(SettingType.PHY_CONFIGURATION.name()); count++;
+ }
+ if( 1 < count ) {
+ out.insert(0, "[");
+ out.append("]");
+ }
+ return out.toString();
+ }
+}
diff --git a/java/org/tinyb/BluetoothAdapter.java b/java/org/tinyb/BluetoothAdapter.java
index 4a989500..bf608e90 100644
--- a/java/org/tinyb/BluetoothAdapter.java
+++ b/java/org/tinyb/BluetoothAdapter.java
@@ -242,10 +242,10 @@ public interface BluetoothAdapter extends BluetoothObject
public boolean getDiscovering();
/**
- * Sets the {@link BluetoothDeviceStatusListener} for the respective device status events.
- * @param listener A {@link BluetoothDeviceStatusListener} instance, or {@code null} to disable notifications.
+ * Sets the {@link BluetoothAdapterStatusListener} for the respective device status events.
+ * @param listener A {@link BluetoothAdapterStatusListener} instance, or {@code null} to disable notifications.
*/
- public void setDeviceStatusListener(final BluetoothDeviceStatusListener listener);
+ public void setStatusListener(final BluetoothAdapterStatusListener listener);
/**
* Enables notifications for the discovering property and calls run function of the
diff --git a/java/org/tinyb/BluetoothDeviceStatusListener.java b/java/org/tinyb/BluetoothAdapterStatusListener.java
index 3220d106..b6262a1e 100644
--- a/java/org/tinyb/BluetoothDeviceStatusListener.java
+++ b/java/org/tinyb/BluetoothAdapterStatusListener.java
@@ -26,17 +26,22 @@
package org.tinyb;
/**
- * {@link BluetoothDevice} listener for the respective {@link BluetoothDevice} discovery events: Added, updated and removed.
+ * {@link BluetoothAdapter} status listener for {@link BluetoothDevice} discovery events: Added, updated and removed;
+ * as well as for certain {@link BluetoothAdapter} events.
* <p>
* A listener instance may be attached to a {@link BluetoothAdapter} via
- * {@link BluetoothAdapter#setDeviceStatusListener(BluetoothDeviceDiscoveryListener)}.
+ * {@link BluetoothAdapter#setStatusListener(BluetoothDeviceDiscoveryListener)}.
* </p>
*/
-public interface BluetoothDeviceStatusListener {
+public interface BluetoothAdapterStatusListener {
+ /** A {@link BluetoothAdapter} setting has been changed. */
+ public void adapterSettingsChanged(final BluetoothAdapter adapter,
+ final AdapterSettings oldmask, final AdapterSettings newmask,
+ final AdapterSettings changedmask, final long timestamp);
/** A {@link BluetoothDevice} has been newly discovered. */
public void deviceFound(final BluetoothAdapter adapter, final BluetoothDevice device, final long timestamp);
/** An already discovered {@link BluetoothDevice} has been updated. */
- public void deviceUpdated(final BluetoothAdapter adapter, final BluetoothDevice device, final long timestamp, final EIRDataType updateMask);
+ public void deviceUpdated(final BluetoothAdapter adapter, final BluetoothDevice device, final long timestamp, final EIRDataTypeSet updateMask);
/** {@link BluetoothDevice} has been connected. */
public void deviceConnected(final BluetoothAdapter adapter, final BluetoothDevice device, final long timestamp);
/** {@link BluetoothDevice} has been disconnected. */
diff --git a/java/org/tinyb/EIRDataType.java b/java/org/tinyb/EIRDataType.java
deleted file mode 100644
index 8134b20e..00000000
--- a/java/org/tinyb/EIRDataType.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Author: Sven Gothel <[email protected]>
- * Copyright (c) 2020 Gothel Software e.K.
- * Copyright (c) 2020 ZAFENA AB
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package org.tinyb;
-
-public enum EIRDataType {
- NONE ( 0),
- EVT_TYPE (1 << 0),
- BDADDR_TYPE (1 << 1),
- BDADDR (1 << 2),
- FLAGS (1 << 3),
- NAME (1 << 4),
- NAME_SHORT (1 << 5),
- RSSI (1 << 6),
- TX_POWER (1 << 7),
- MANUF_DATA (1 << 8),
- DEVICE_CLASS (1 << 9),
- APPEARANCE (1 << 10),
- HASH (1 << 11),
- RANDOMIZER (1 << 12),
- DEVICE_ID (1 << 13),
- SERVICE_UUID (1 << 30);
-
- EIRDataType(final int v) { mask = v; }
- public static EIRDataType create(final int v) {
- final EIRDataType r = NONE;
- r.mask = v;
- return r;
- }
-
- public int mask;
- public boolean isSet(final EIRDataType bit) { return 0 != ( mask & bit.mask ); }
- public void set(final EIRDataType bit) { mask = mask | bit.mask; }
-
- public String toString() {
- int count = 0;
- final StringBuilder out = new StringBuilder();
- if( isSet(EVT_TYPE) ) {
- out.append(EVT_TYPE.name()); count++;
- }
- if( isSet(BDADDR_TYPE) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(BDADDR_TYPE.name()); count++;
- }
- if( isSet(BDADDR) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(BDADDR.name()); count++;
- }
- if( isSet(FLAGS) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(FLAGS.name()); count++;
- }
- if( isSet(NAME) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(NAME.name()); count++;
- }
- if( isSet(NAME_SHORT) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(NAME_SHORT.name()); count++;
- }
- if( isSet(RSSI) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(RSSI.name()); count++;
- }
- if( isSet(TX_POWER) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(TX_POWER.name()); count++;
- }
- if( isSet(MANUF_DATA) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(MANUF_DATA.name()); count++;
- }
- if( isSet(DEVICE_CLASS) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(DEVICE_CLASS.name()); count++;
- }
- if( isSet(APPEARANCE) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(APPEARANCE.name()); count++;
- }
- if( isSet(HASH) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(HASH.name()); count++;
- }
- if( isSet(RANDOMIZER) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(RANDOMIZER.name()); count++;
- }
- if( isSet(DEVICE_ID) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(DEVICE_ID.name()); count++;
- }
- if( isSet(SERVICE_UUID) ) {
- if( 0 < count ) { out.append(", "); }
- out.append(SERVICE_UUID.name()); count++;
- }
- if( 1 < count ) {
- out.insert(0, "[");
- out.append("]");
- }
- return out.toString();
- }
-}
diff --git a/java/org/tinyb/EIRDataTypeSet.java b/java/org/tinyb/EIRDataTypeSet.java
new file mode 100644
index 00000000..258066d8
--- /dev/null
+++ b/java/org/tinyb/EIRDataTypeSet.java
@@ -0,0 +1,128 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package org.tinyb;
+
+public class EIRDataTypeSet {
+
+ public enum DataType {
+ NONE ( 0),
+ EVT_TYPE (1 << 0),
+ BDADDR_TYPE (1 << 1),
+ BDADDR (1 << 2),
+ FLAGS (1 << 3),
+ NAME (1 << 4),
+ NAME_SHORT (1 << 5),
+ RSSI (1 << 6),
+ TX_POWER (1 << 7),
+ MANUF_DATA (1 << 8),
+ DEVICE_CLASS (1 << 9),
+ APPEARANCE (1 << 10),
+ HASH (1 << 11),
+ RANDOMIZER (1 << 12),
+ DEVICE_ID (1 << 13),
+ SERVICE_UUID (1 << 30);
+
+ DataType(final int v) { value = v; }
+ public final int value;
+ }
+
+ public int mask;
+
+ public EIRDataTypeSet(final int v) {
+ mask = v;
+ }
+
+ public boolean isSet(final DataType bit) { return 0 != ( mask & bit.value ); }
+ public void set(final DataType bit) { mask = mask | bit.value; }
+
+ public String toString() {
+ int count = 0;
+ final StringBuilder out = new StringBuilder();
+ if( isSet(DataType.EVT_TYPE) ) {
+ out.append(DataType.EVT_TYPE.name()); count++;
+ }
+ if( isSet(DataType.BDADDR_TYPE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.BDADDR_TYPE.name()); count++;
+ }
+ if( isSet(DataType.BDADDR) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.BDADDR.name()); count++;
+ }
+ if( isSet(DataType.FLAGS) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.FLAGS.name()); count++;
+ }
+ if( isSet(DataType.NAME) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.NAME.name()); count++;
+ }
+ if( isSet(DataType.NAME_SHORT) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.NAME_SHORT.name()); count++;
+ }
+ if( isSet(DataType.RSSI) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.RSSI.name()); count++;
+ }
+ if( isSet(DataType.TX_POWER) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.TX_POWER.name()); count++;
+ }
+ if( isSet(DataType.MANUF_DATA) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.MANUF_DATA.name()); count++;
+ }
+ if( isSet(DataType.DEVICE_CLASS) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.DEVICE_CLASS.name()); count++;
+ }
+ if( isSet(DataType.APPEARANCE) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.APPEARANCE.name()); count++;
+ }
+ if( isSet(DataType.HASH) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.HASH.name()); count++;
+ }
+ if( isSet(DataType.RANDOMIZER) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.RANDOMIZER.name()); count++;
+ }
+ if( isSet(DataType.DEVICE_ID) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.DEVICE_ID.name()); count++;
+ }
+ if( isSet(DataType.SERVICE_UUID) ) {
+ if( 0 < count ) { out.append(", "); }
+ out.append(DataType.SERVICE_UUID.name()); count++;
+ }
+ if( 1 < count ) {
+ out.insert(0, "[");
+ out.append("]");
+ }
+ return out.toString();
+ }
+}