summaryrefslogtreecommitdiffstats
path: root/java/tinyb/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'java/tinyb/dbus')
-rw-r--r--java/tinyb/dbus/DBusAdapter.java189
-rw-r--r--java/tinyb/dbus/DBusDevice.java216
-rw-r--r--java/tinyb/dbus/DBusEvent.java61
-rw-r--r--java/tinyb/dbus/DBusGattCharacteristic.java104
-rw-r--r--java/tinyb/dbus/DBusGattDescriptor.java76
-rw-r--r--java/tinyb/dbus/DBusGattService.java80
-rw-r--r--java/tinyb/dbus/DBusManager.java165
-rw-r--r--java/tinyb/dbus/DBusObject.java93
8 files changed, 984 insertions, 0 deletions
diff --git a/java/tinyb/dbus/DBusAdapter.java b/java/tinyb/dbus/DBusAdapter.java
new file mode 100644
index 00000000..695677fe
--- /dev/null
+++ b/java/tinyb/dbus/DBusAdapter.java
@@ -0,0 +1,189 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import org.tinyb.BluetoothAdapter;
+import org.tinyb.BluetoothDevice;
+import org.tinyb.BluetoothException;
+import org.tinyb.BluetoothManager;
+import org.tinyb.BluetoothNotification;
+import org.tinyb.BluetoothType;
+import org.tinyb.TransportType;
+
+public class DBusAdapter extends DBusObject implements BluetoothAdapter
+{
+ @Override
+ public native BluetoothType getBluetoothType();
+
+ @Override
+ public native BluetoothAdapter clone();
+
+ static BluetoothType class_type() { return BluetoothType.ADAPTER; }
+
+ @Override
+ public BluetoothDevice find(final String name, final String address, final long timeoutMS) {
+ final BluetoothManager manager = DBusManager.getBluetoothManager();
+ return (BluetoothDevice) manager.find(BluetoothType.DEVICE, name, address, this, timeoutMS);
+ }
+
+ @Override
+ public BluetoothDevice find(final String name, final String address) {
+ return find(name, address, 0);
+ }
+
+ /* D-Bus method calls: */
+
+ @Override
+ public native boolean startDiscovery() throws BluetoothException;
+
+ @Override
+ public native boolean stopDiscovery() throws BluetoothException;
+
+ @Override
+ public native List<BluetoothDevice> getDevices();
+
+ @Override
+ public native int removeDevices() throws BluetoothException;
+
+ /* D-Bus property accessors: */
+
+ @Override
+ public native String getAddress();
+
+ @Override
+ public native String getName();
+
+ @Override
+ public native String getAlias();
+
+ @Override
+ public native void setAlias(String value);
+
+ @Override
+ public native long getBluetoothClass();
+
+ @Override
+ public native boolean getPowered();
+
+ @Override
+ public native void enablePoweredNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disablePoweredNotifications();
+
+ @Override
+ public native void setPowered(boolean value);
+
+ @Override
+ public native boolean getDiscoverable();
+
+ @Override
+ public native void enableDiscoverableNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disableDiscoverableNotifications();
+
+ @Override
+ public native void setDiscoverable(boolean value);
+
+ @Override
+ public native long getDiscoverableTimeout();
+
+ @Override
+ public native void setDiscoverableTimout(long value);
+
+ @Override
+ public native BluetoothDevice connectDevice(String address, String addressType);
+
+ @Override
+ public native boolean getPairable();
+
+ @Override
+ public native void enablePairableNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disablePairableNotifications();
+
+ @Override
+ public native void setPairable(boolean value);
+
+ @Override
+ public native long getPairableTimeout();
+
+ @Override
+ public native void setPairableTimeout(long value);
+
+ @Override
+ public native boolean getDiscovering();
+
+ @Override
+ public native void enableDiscoveringNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disableDiscoveringNotifications();
+
+ @Override
+ public native String[] getUUIDs();
+
+ @Override
+ public native String getModalias();
+
+ @Override
+ public void setDiscoveryFilter(final List<UUID> uuids, final int rssi, final int pathloss, final TransportType transportType) {
+ final List<String> uuidsFmt = new ArrayList<>(uuids.size());
+ for (final UUID uuid : uuids) {
+ uuidsFmt.add(uuid.toString());
+ }
+ setDiscoveryFilter(uuidsFmt, rssi, pathloss, transportType.ordinal());
+ }
+
+ public void setRssiDiscoveryFilter(final int rssi) {
+ setDiscoveryFilter(Collections.EMPTY_LIST, rssi, 0, TransportType.AUTO);
+ }
+
+ @Override
+ public String getInterfaceName() {
+ final String[] path = getObjectPath().split("/");
+ return path[path.length-1];
+ }
+
+ private native void delete();
+
+ private native void setDiscoveryFilter(List<String> uuids, int rssi, int pathloss, int transportType);
+
+ private DBusAdapter(final long instance)
+ {
+ super(instance);
+ }
+}
diff --git a/java/tinyb/dbus/DBusDevice.java b/java/tinyb/dbus/DBusDevice.java
new file mode 100644
index 00000000..bb1919b9
--- /dev/null
+++ b/java/tinyb/dbus/DBusDevice.java
@@ -0,0 +1,216 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import java.util.List;
+import java.util.Map;
+
+import org.tinyb.BluetoothDevice;
+import org.tinyb.BluetoothException;
+import org.tinyb.BluetoothGattService;
+import org.tinyb.BluetoothManager;
+import org.tinyb.BluetoothNotification;
+import org.tinyb.BluetoothType;
+
+public class DBusDevice extends DBusObject implements BluetoothDevice
+{
+ @Override
+ public native BluetoothType getBluetoothType();
+ @Override
+ public native DBusDevice clone();
+
+ static BluetoothType class_type() { return BluetoothType.DEVICE; }
+
+ @Override
+ public BluetoothGattService find(final String UUID, final long timeoutMS) {
+ final BluetoothManager manager = DBusManager.getBluetoothManager();
+ return (BluetoothGattService) manager.find(BluetoothType.GATT_SERVICE,
+ null, UUID, this, timeoutMS);
+ }
+
+ @Override
+ public BluetoothGattService find(final String UUID) {
+ return find(UUID, 0);
+ }
+
+ /* D-Bus method calls: */
+
+ @Override
+ public native boolean disconnect() throws BluetoothException;
+
+ public native void connectAsyncStart() throws BluetoothException;
+
+ public native boolean connectAsyncFinish() throws BluetoothException;
+
+ @Override
+ public native boolean connect() throws BluetoothException;
+
+ @Override
+ public native boolean connectProfile(String arg_UUID) throws BluetoothException;
+
+ @Override
+ public native boolean disconnectProfile(String arg_UUID) throws BluetoothException;
+
+ @Override
+ public native boolean pair() throws BluetoothException;
+
+ @Override
+ public native boolean remove() throws BluetoothException;
+
+ @Override
+ public native boolean cancelPairing() throws BluetoothException;
+
+ @Override
+ public native List<BluetoothGattService> getServices();
+
+ /* D-Bus property accessors: */
+
+ @Override
+ public native String getAddress();
+
+ @Override
+ public native String getName();
+
+ @Override
+ public native String getAlias();
+
+ @Override
+ public native void setAlias(String value);
+
+ @Override
+ public native int getBluetoothClass();
+
+ @Override
+ public native short getAppearance();
+
+ @Override
+ public native String getIcon();
+
+ @Override
+ public native boolean getPaired();
+
+ @Override
+ public native void enablePairedNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disablePairedNotifications();
+
+ @Override
+ public native boolean getTrusted();
+
+ @Override
+ public native void enableTrustedNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disableTrustedNotifications();
+
+ @Override
+ public native void setTrusted(boolean value);
+
+ @Override
+ public native boolean getBlocked();
+
+ @Override
+ public native void enableBlockedNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disableBlockedNotifications();
+
+ @Override
+ public native void setBlocked(boolean value);
+
+ @Override
+ public native boolean getLegacyPairing();
+
+ @Override
+ public native short getRSSI();
+
+ @Override
+ public native void enableRSSINotifications(BluetoothNotification<Short> callback);
+
+ @Override
+ public native void disableRSSINotifications();
+
+ @Override
+ public native boolean getConnected();
+
+ @Override
+ public native void enableConnectedNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disableConnectedNotifications();
+
+ @Override
+ public native String[] getUUIDs();
+
+ @Override
+ public native String getModalias();
+
+ @Override
+ public native DBusAdapter getAdapter();
+
+ @Override
+ public native Map<Short, byte[]> getManufacturerData();
+
+ @Override
+ public native void enableManufacturerDataNotifications(BluetoothNotification<Map<Short, byte[]> > callback);
+
+ @Override
+ public native void disableManufacturerDataNotifications();
+
+
+ @Override
+ public native Map<String, byte[]> getServiceData();
+
+ @Override
+ public native void enableServiceDataNotifications(BluetoothNotification<Map<String, byte[]> > callback);
+
+ @Override
+ public native void disableServiceDataNotifications();
+
+ @Override
+ public native short getTxPower ();
+
+ @Override
+ public native boolean getServicesResolved ();
+
+ @Override
+ public native void enableServicesResolvedNotifications(BluetoothNotification<Boolean> callback);
+
+ @Override
+ public native void disableServicesResolvedNotifications();
+
+ private native void delete();
+
+ private DBusDevice(final long instance)
+ {
+ super(instance);
+ }
+
+}
diff --git a/java/tinyb/dbus/DBusEvent.java b/java/tinyb/dbus/DBusEvent.java
new file mode 100644
index 00000000..fe6d4c40
--- /dev/null
+++ b/java/tinyb/dbus/DBusEvent.java
@@ -0,0 +1,61 @@
+/*
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import org.tinyb.BluetoothCallback;
+import org.tinyb.BluetoothEvent;
+import org.tinyb.BluetoothType;
+
+public class DBusEvent implements BluetoothEvent
+{
+ private long nativeInstance;
+
+ @Override
+ public native BluetoothType getType();
+ @Override
+ public native String getName();
+ @Override
+ public native String getIdentifier();
+ @Override
+ public native boolean executeCallback();
+ @Override
+ public native boolean hasCallback();
+
+ private native void init(BluetoothType type, String name, String identifier,
+ DBusObject parent, BluetoothCallback cb, Object data);
+ private native void delete();
+
+ public DBusEvent(final BluetoothType type, final String name, final String identifier,
+ final DBusObject parent, final BluetoothCallback cb, final Object data)
+ {
+ init(type, name, identifier, parent, cb, data);
+ }
+
+ @Override
+ protected void finalize()
+ {
+ delete();
+ }
+}
diff --git a/java/tinyb/dbus/DBusGattCharacteristic.java b/java/tinyb/dbus/DBusGattCharacteristic.java
new file mode 100644
index 00000000..3ca5ab93
--- /dev/null
+++ b/java/tinyb/dbus/DBusGattCharacteristic.java
@@ -0,0 +1,104 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import java.util.List;
+
+import org.tinyb.BluetoothException;
+import org.tinyb.BluetoothGattCharacteristic;
+import org.tinyb.BluetoothGattDescriptor;
+import org.tinyb.BluetoothGattService;
+import org.tinyb.BluetoothManager;
+import org.tinyb.BluetoothNotification;
+import org.tinyb.BluetoothType;
+
+public class DBusGattCharacteristic extends DBusObject implements BluetoothGattCharacteristic
+{
+ @Override
+ public native BluetoothType getBluetoothType();
+ @Override
+ public native DBusGattCharacteristic clone();
+
+ static BluetoothType class_type() { return BluetoothType.GATT_CHARACTERISTIC; }
+
+ @Override
+ public BluetoothGattDescriptor find(final String UUID, final long timeoutMS) {
+ final BluetoothManager manager = DBusManager.getBluetoothManager();
+ return (BluetoothGattDescriptor) manager.find(BluetoothType.GATT_DESCRIPTOR,
+ null, UUID, this, timeoutMS);
+ }
+
+ @Override
+ public BluetoothGattDescriptor find(final String UUID) {
+ return find(UUID, 0);
+ }
+
+ /* D-Bus method calls: */
+
+ @Override
+ public native byte[] readValue() throws BluetoothException;
+
+ @Override
+ public native void enableValueNotifications(BluetoothNotification<byte[]> callback);
+
+ @Override
+ public native void disableValueNotifications();
+
+ @Override
+ public native boolean writeValue(byte[] argValue) throws BluetoothException;
+
+ /* D-Bus property accessors: */
+
+ @Override
+ public native String getUUID();
+
+ @Override
+ public native BluetoothGattService getService();
+
+ @Override
+ public native byte[] getValue();
+
+ @Override
+ public native boolean getNotifying();
+
+ @Override
+ public native String[] getFlags();
+
+ @Override
+ public native List<BluetoothGattDescriptor> getDescriptors();
+
+ private native void init(DBusGattCharacteristic obj);
+
+ private native void delete();
+
+ private DBusGattCharacteristic(final long instance)
+ {
+ super(instance);
+ }
+}
diff --git a/java/tinyb/dbus/DBusGattDescriptor.java b/java/tinyb/dbus/DBusGattDescriptor.java
new file mode 100644
index 00000000..5c59ea8c
--- /dev/null
+++ b/java/tinyb/dbus/DBusGattDescriptor.java
@@ -0,0 +1,76 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import org.tinyb.BluetoothException;
+import org.tinyb.BluetoothGattDescriptor;
+import org.tinyb.BluetoothNotification;
+import org.tinyb.BluetoothType;
+
+public class DBusGattDescriptor extends DBusObject implements BluetoothGattDescriptor
+{
+ @Override
+ public native BluetoothType getBluetoothType();
+ @Override
+ public native BluetoothGattDescriptor clone();
+
+ static BluetoothType class_type() { return BluetoothType.GATT_DESCRIPTOR; }
+
+ /* D-Bus method calls: */
+
+ @Override
+ public native byte[] readValue();
+
+ @Override
+ public native boolean writeValue(byte[] argValue) throws BluetoothException;
+
+ @Override
+ public native void enableValueNotifications(BluetoothNotification<byte[]> callback);
+
+ @Override
+ public native void disableValueNotifications();
+
+ /* D-Bus property accessors: */
+
+ @Override
+ public native String getUUID();
+
+ @Override
+ public native DBusGattCharacteristic getCharacteristic();
+
+ @Override
+ public native byte[] getValue();
+
+ private native void delete();
+
+ private DBusGattDescriptor(final long instance)
+ {
+ super(instance);
+ }
+}
diff --git a/java/tinyb/dbus/DBusGattService.java b/java/tinyb/dbus/DBusGattService.java
new file mode 100644
index 00000000..092662a8
--- /dev/null
+++ b/java/tinyb/dbus/DBusGattService.java
@@ -0,0 +1,80 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import java.util.List;
+
+import org.tinyb.BluetoothGattCharacteristic;
+import org.tinyb.BluetoothGattService;
+import org.tinyb.BluetoothManager;
+import org.tinyb.BluetoothType;
+
+public class DBusGattService extends DBusObject implements BluetoothGattService
+{
+ @Override
+ public native BluetoothType getBluetoothType();
+
+ @Override
+ public native BluetoothGattService clone();
+
+ static BluetoothType class_type() { return BluetoothType.GATT_SERVICE; }
+
+ @Override
+ public BluetoothGattCharacteristic find(final String UUID, final long timeoutMS) {
+ final BluetoothManager manager = DBusManager.getBluetoothManager();
+ return (DBusGattCharacteristic) manager.find(BluetoothType.GATT_CHARACTERISTIC,
+ null, UUID, this, timeoutMS);
+ }
+
+ @Override
+ public BluetoothGattCharacteristic find(final String UUID) {
+ return find(UUID, 0);
+ }
+
+ /* D-Bus property accessors: */
+
+ @Override
+ public native String getUUID();
+
+ @Override
+ public native DBusDevice getDevice();
+
+ @Override
+ public native boolean getPrimary();
+
+ @Override
+ public native List<BluetoothGattCharacteristic> getCharacteristics();
+
+ private native void delete();
+
+ private DBusGattService(final long instance)
+ {
+ super(instance);
+ }
+}
diff --git a/java/tinyb/dbus/DBusManager.java b/java/tinyb/dbus/DBusManager.java
new file mode 100644
index 00000000..e3e86ab6
--- /dev/null
+++ b/java/tinyb/dbus/DBusManager.java
@@ -0,0 +1,165 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import java.util.List;
+
+import org.tinyb.BluetoothAdapter;
+import org.tinyb.BluetoothDevice;
+import org.tinyb.BluetoothException;
+import org.tinyb.BluetoothGattService;
+import org.tinyb.BluetoothObject;
+import org.tinyb.BluetoothManager;
+import org.tinyb.BluetoothType;
+
+public class DBusManager implements BluetoothManager
+{
+ private long nativeInstance;
+ private static DBusManager inst;
+
+ static {
+ try {
+ System.loadLibrary("tinyb");
+ System.loadLibrary("javatinyb");
+ } catch (final UnsatisfiedLinkError e) {
+ System.err.println("Native code library failed to load.\n" + e);
+ }
+ }
+
+ private native static String getNativeAPIVersion();
+
+ public native BluetoothType getBluetoothType();
+
+ private native DBusObject find(int type, String name, String identifier, BluetoothObject parent, long milliseconds);
+
+ @Override
+ public DBusObject find(final BluetoothType type, final String name, final String identifier, final BluetoothObject parent, final long timeoutMS) {
+ return find(type.ordinal(), name, identifier, parent, timeoutMS);
+ }
+
+ @Override
+ public DBusObject find(final BluetoothType type, final String name, final String identifier, final BluetoothObject parent) {
+ return find(type, name, identifier, parent, 0);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends BluetoothObject> T find(final String name, final String identifier, final BluetoothObject parent, final long timeoutMS) {
+ return (T) find(DBusObject.class_type().ordinal(), name, identifier, parent, timeoutMS);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends BluetoothObject> T find(final String name, final String identifier, final BluetoothObject parent) {
+ return (T) find(name, identifier, parent, 0);
+ }
+
+ @Override
+ public BluetoothObject getObject(final BluetoothType type, final String name,
+ final String identifier, final BluetoothObject parent) {
+ return getObject(type.ordinal(), name, identifier, parent);
+ }
+ private native BluetoothObject getObject(int type, String name, String identifier, BluetoothObject parent);
+
+ @Override
+ public List<BluetoothObject> getObjects(final BluetoothType type, final String name,
+ final String identifier, final BluetoothObject parent) {
+ return getObjects(type.ordinal(), name, identifier, parent);
+ }
+ private native List<BluetoothObject> getObjects(int type, String name, String identifier, BluetoothObject parent);
+
+ @Override
+ public native List<BluetoothAdapter> getAdapters();
+
+ @Override
+ public native List<BluetoothDevice> getDevices();
+
+ @Override
+ public native List<BluetoothGattService> getServices();
+
+ @Override
+ public native boolean setDefaultAdapter(BluetoothAdapter adapter);
+
+ @Override
+ public native BluetoothAdapter getDefaultAdapter();
+
+ @Override
+ public native boolean startDiscovery() throws BluetoothException;
+
+ @Override
+ public native boolean stopDiscovery() throws BluetoothException;
+
+ @Override
+ public native boolean getDiscovering() throws BluetoothException;
+
+ private native void init() throws BluetoothException;
+ private native void delete();
+ private DBusManager()
+ {
+ init();
+ }
+
+ /** Returns an instance of BluetoothManager, to be used instead of constructor.
+ * @return An initialized BluetoothManager instance.
+ */
+ public static synchronized BluetoothManager getBluetoothManager() throws RuntimeException, BluetoothException
+ {
+ if (inst == null)
+ {
+ final String nativeAPIVersion = getNativeAPIVersion();
+ final String APIVersion = DBusManager.class.getPackage().getSpecificationVersion();
+ if ( null != APIVersion && APIVersion.equals(nativeAPIVersion) == false) {
+ final String[] nativeAPIVersionCode = nativeAPIVersion.split("\\D");
+ final String[] APIVersionCode = APIVersion.split("\\D");
+ if (APIVersionCode[0].equals(nativeAPIVersionCode[0]) == false) {
+ if (Integer.valueOf(APIVersionCode[0]) < Integer.valueOf(nativeAPIVersionCode[0]))
+ throw new RuntimeException("Java library is out of date. Please update the Java library.");
+ else throw new RuntimeException("Native library is out of date. Please update the native library.");
+ }
+ else if (APIVersionCode[0].equals("0") == true) {
+ if (Integer.valueOf(APIVersionCode[1]) < Integer.valueOf(nativeAPIVersionCode[1]))
+ throw new RuntimeException("Java library is out of date. Please update the Java library.");
+ else throw new RuntimeException("Native library is out of date. Please update the native library.");
+ }
+ else if (Integer.valueOf(APIVersionCode[1]) < Integer.valueOf(nativeAPIVersionCode[1]))
+ System.err.println("Java library is out of date. Please update the Java library.");
+ else System.err.println("Native library is out of date. Please update the native library.");
+ }
+ inst = new DBusManager();
+ inst.init();
+ }
+ return inst;
+ }
+
+ @Override
+ protected void finalize()
+ {
+ delete();
+ }
+}
diff --git a/java/tinyb/dbus/DBusObject.java b/java/tinyb/dbus/DBusObject.java
new file mode 100644
index 00000000..a9095d1a
--- /dev/null
+++ b/java/tinyb/dbus/DBusObject.java
@@ -0,0 +1,93 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * 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 tinyb.dbus;
+
+import org.tinyb.BluetoothObject;
+import org.tinyb.BluetoothType;
+
+public class DBusObject implements BluetoothObject
+{
+ protected long nativeInstance;
+ private boolean isValid;
+
+ static {
+ try {
+ System.loadLibrary("javatinyb");
+ } catch (final UnsatisfiedLinkError e) {
+ System.err.println("Native code library failed to load.\n" + e);
+ }
+ }
+
+ static BluetoothType class_type() { return BluetoothType.NONE; }
+
+ @Override
+ public native BluetoothType getBluetoothType();
+
+ @Override
+ public native BluetoothObject clone();
+
+ private native void delete();
+ private native boolean operatorEqual(DBusObject obj);
+
+ protected DBusObject(final long instance)
+ {
+ nativeInstance = instance;
+ isValid = true;
+ }
+
+ @Override
+ protected void finalize()
+ {
+ close();
+ }
+
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (obj == null || !(obj instanceof DBusObject))
+ return false;
+ return operatorEqual((DBusObject)obj);
+ }
+
+ protected native String getObjectPath();
+
+ @Override
+ public int hashCode() {
+ final String objectPath = getObjectPath();
+ return objectPath.hashCode();
+ }
+
+ @Override
+ public synchronized void close() {
+ if (!isValid)
+ return;
+ isValid = false;
+ delete();
+ }
+}