summaryrefslogtreecommitdiffstats
path: root/java/tinyb
diff options
context:
space:
mode:
Diffstat (limited to 'java/tinyb')
-rw-r--r--java/tinyb/BluetoothAdapter.java319
-rw-r--r--java/tinyb/BluetoothCallback.java35
-rw-r--r--java/tinyb/BluetoothDevice.java361
-rw-r--r--java/tinyb/BluetoothException.java31
-rw-r--r--java/tinyb/BluetoothGattCharacteristic.java141
-rw-r--r--java/tinyb/BluetoothGattService.java99
-rw-r--r--java/tinyb/BluetoothManager.java341
-rw-r--r--java/tinyb/BluetoothNotification.java35
-rw-r--r--java/tinyb/BluetoothType.java34
-rw-r--r--java/tinyb/ObjectArgCallback.java40
-rw-r--r--java/tinyb/ObjectArrayArgCallback.java40
-rw-r--r--java/tinyb/TransportType.java19
-rw-r--r--java/tinyb/dbus/DBusAdapter.java189
-rw-r--r--java/tinyb/dbus/DBusDevice.java216
-rw-r--r--java/tinyb/dbus/DBusEvent.java (renamed from java/tinyb/BluetoothEvent.java)20
-rw-r--r--java/tinyb/dbus/DBusGattCharacteristic.java104
-rw-r--r--java/tinyb/dbus/DBusGattDescriptor.java (renamed from java/tinyb/BluetoothGattDescriptor.java)65
-rw-r--r--java/tinyb/dbus/DBusGattService.java80
-rw-r--r--java/tinyb/dbus/DBusManager.java165
-rw-r--r--java/tinyb/dbus/DBusObject.java (renamed from java/tinyb/BluetoothObject.java)42
20 files changed, 815 insertions, 1561 deletions
diff --git a/java/tinyb/BluetoothAdapter.java b/java/tinyb/BluetoothAdapter.java
deleted file mode 100644
index 8094ff23..00000000
--- a/java/tinyb/BluetoothAdapter.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * 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;
-
-import java.util.*;
-import java.time.Duration;
-
-/**
- * Provides access to Bluetooth adapters. Follows the BlueZ adapter API
- * available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt
- */
-public class BluetoothAdapter extends BluetoothObject
-{
- public native BluetoothType getBluetoothType();
- public native BluetoothAdapter clone();
-
- static BluetoothType class_type() { return BluetoothType.ADAPTER; }
-
- /** Find a BluetoothDevice. If parameters name and address are not null,
- * the returned object will have to match them.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter name optionally specify the name of the object you are
- * waiting for
- * @parameter address optionally specify the MAC address of the device you are
- * waiting for
- * @parameter timeout the function will return after timeout time, a
- * value of zero means wait forever. If object is not found during this time null will be returned.
- * @return An object matching the name and address or null if not found before
- * timeout expires.
- */
- public BluetoothDevice find(String name, String address, Duration duration) {
- BluetoothManager manager = BluetoothManager.getBluetoothManager();
- return (BluetoothDevice) manager.find(BluetoothType.DEVICE, name, address, this, duration);
- }
-
- /** Find a BluetoothDevice. If parameters name and address are not null,
- * the returned object will have to match them.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter name optionally specify the name of the object you are
- * waiting for
- * @parameter address optionally specify the MAC address of the device you are
- * waiting for
- * @return An object matching the name and address.
- */
- public BluetoothDevice find(String name, String address) {
- return find(name, address, Duration.ZERO);
- }
-
- /* D-Bus method calls: */
- /** Turns on device discovery if it is disabled.
- * @return TRUE if discovery was successfully enabled
- */
- public native boolean startDiscovery() throws BluetoothException;
-
- /** Turns off device discovery if it is enabled.
- * @return TRUE if discovery was successfully disabled
- */
- public native boolean stopDiscovery() throws BluetoothException;
-
- /** Returns a list of BluetoothDevices visible from this adapter.
- * @return A list of BluetoothDevices visible on this adapter,
- * NULL if an error occurred
- */
- public native List<BluetoothDevice> getDevices();
-
- /**
- * Remove all the known devices
- *
- * @return The number of devices removed from internal list
- * @throws BluetoothException
- */
- public native int removeDevices() throws BluetoothException;
-
- /* D-Bus property accessors: */
- /** Returns the hardware address of this adapter.
- * @return The hardware address of this adapter.
- */
- public native String getAddress();
-
- /** Returns the system name of this adapter.
- * @return The system name of this adapter.
- */
- public native String getName();
-
- /** Returns the friendly name of this adapter.
- * @return The friendly name of this adapter, or NULL if not set.
- */
- public native String getAlias();
-
- /** Sets the friendly name of this adapter.
- */
- public native void setAlias(String value);
-
- /** Returns the Bluetooth class of the adapter.
- * @return The Bluetooth class of the adapter.
- */
- public native long getBluetoothClass();
-
- /** Returns the power state the adapter.
- * @return The power state of the adapter.
- */
- public native boolean getPowered();
-
- /**
- * Enables notifications for the powered property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the powered
- * property.
- */
- public native void enablePoweredNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the powered property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disablePoweredNotifications();
-
- /** Sets the power state the adapter.
- */
- public native void setPowered(boolean value);
-
- /** Returns the discoverable state the adapter.
- * @return The discoverable state of the adapter.
- */
- public native boolean getDiscoverable();
-
- /**
- * Enables notifications for the discoverable property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the discoverable
- * property.
- */
- public native void enableDiscoverableNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the discoverable property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableDiscoverableNotifications();
-
- /** Sets the discoverable state the adapter.
- */
- public native void setDiscoverable(boolean value);
-
- /** Returns the discoverable timeout the adapter.
- * @return The discoverable timeout of the adapter.
- */
- public native long getDiscoverableTimeout();
-
- /** Sets the discoverable timeout the adapter. A value of 0 disables
- * the timeout.
- */
- public native void setDiscoverableTimout(long value);
-
- /**
- * This method connects to device without need of
- * performing General Discovery. Connection mechanism is
- * similar to Connect method from Device1 interface with
- * exception that this method returns success when physical
- * connection is established. After this method returns,
- * services discovery will continue and any supported
- * profile will be connected. There is no need for calling
- * Connect on Device1 after this call. If connection was
- * successful this method returns object path to created
- * device object.
- *
- * @param address The Bluetooth device address of the remote
- * device. This parameter is mandatory.
- * @param addressType The Bluetooth device Address Type. This is
- * address type that should be used for initial
- * connection. If this parameter is not present
- * BR/EDR device is created.
- * Possible values:
- * <ul>
- * <li>{@code public} - Public address</li>
- * <li>{@code random} - Random address</li>
- * </ul>
- */
- public native BluetoothDevice connectDevice(String address, String addressType);
-
- /** Returns the pairable state the adapter.
- * @return The pairable state of the adapter.
- */
- public native boolean getPairable();
-
- /**
- * Enables notifications for the pairable property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the pairable
- * property.
- */
- public native void enablePairableNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the pairable property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disablePairableNotifications();
-
- /** Sets the discoverable state the adapter.
- */
- public native void setPairable(boolean value);
-
- /** Returns the timeout in seconds after which pairable state turns off
- * automatically, 0 means never.
- * @return The pairable timeout of the adapter.
- */
- public native long getPairableTimeout();
-
- /** Sets the timeout after which pairable state turns off automatically, 0 means never.
- */
- public native void setPairableTimeout(long value);
-
- /** Returns the discovering state the adapter. It can be modified through
- * start_discovery/stop_discovery functions.
- * @return The discovering state of the adapter.
- */
- public native boolean getDiscovering();
-
- /**
- * Enables notifications for the discovering property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the discovering
- * property.
- */
- public native void enableDiscoveringNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the discovering property and unregisters the discovering
- * object passed through the corresponding enable method.
- */
- public native void disableDiscoveringNotifications();
-
- /** Returns the UUIDs of the adapter.
- * @return Array containing the UUIDs of the adapter, ends with NULL.
- */
- public native String[] getUUIDs();
-
- /** Returns the local ID of the adapter.
- * @return The local ID of the adapter.
- */
- public native String getModalias();
-
- /** This method sets the device discovery filter for the caller. When this method is called
- * with no filter parameter, filter is removed.
- * <p>
- * When a remote device is found that advertises any UUID from UUIDs, it will be reported if:
- * <ul><li>Pathloss and RSSI are both empty.</li>
- * <li>only Pathloss param is set, device advertise TX pwer, and computed pathloss is less than Pathloss param.</li>
- * <li>only RSSI param is set, and received RSSI is higher than RSSI param.</li>
- * </ul>
- * <p>
- * If one or more discovery filters have been set, the RSSI delta-threshold,
- * that is imposed by StartDiscovery by default, will not be applied.
- * <p>
- * If "auto" transport is requested, scan will use LE, BREDR, or both, depending on what's
- * currently enabled on the controller.
- *
- * @param uuids a list of device UUIDs
- * @param rssi a rssi value
- * @param pathloss a pathloss value
- */
- public void setDiscoveryFilter(List<UUID> uuids, int rssi, int pathloss, TransportType transportType) {
- List<String> uuidsFmt = new ArrayList<>(uuids.size());
- for (UUID uuid : uuids) {
- uuidsFmt.add(uuid.toString());
- }
- setDiscoveryFilter(uuidsFmt, rssi, pathloss, transportType.ordinal());
- }
-
- /** This method sets RSSI device discovery filter for the caller. When this method is called
- * with 0, filter is removed.
- * @param rssi a rssi value
- */
- public void setRssiDiscoveryFilter(int rssi) {
- setDiscoveryFilter(Collections.EMPTY_LIST, rssi, 0, TransportType.AUTO);
- }
-
- /** Returns the interface name of the adapter.
- * @return The interface name of the adapter.
- */
- public String getInterfaceName() {
- 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 BluetoothAdapter(long instance)
- {
- super(instance);
- }
-}
diff --git a/java/tinyb/BluetoothCallback.java b/java/tinyb/BluetoothCallback.java
deleted file mode 100644
index 0cbe0ed0..00000000
--- a/java/tinyb/BluetoothCallback.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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;
-
-public abstract class BluetoothCallback implements Runnable
-{
- protected BluetoothObject bObj;
-
- /*
- * public void run() is missing because it will be implemented
- * in children classes
- */
-}
diff --git a/java/tinyb/BluetoothDevice.java b/java/tinyb/BluetoothDevice.java
deleted file mode 100644
index da077117..00000000
--- a/java/tinyb/BluetoothDevice.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * 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;
-
-import java.util.*;
-import java.time.Duration;
-
-/**
- * Provides access to Bluetooth devices. Follows the BlueZ adapter API
- * available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt
- */
-public class BluetoothDevice extends BluetoothObject
-{
- public native BluetoothType getBluetoothType();
- public native BluetoothDevice clone();
-
- static BluetoothType class_type() { return BluetoothType.DEVICE; }
-
- /** Find a BluetoothGattService. If parameter UUID is not null,
- * the returned object will have to match it.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter UUID optionally specify the UUID of the BluetoothGattService you are
- * waiting for
- * @parameter timeout the function will return after timeout time, a
- * value of zero means wait forever. If object is not found during this time null will be returned.
- * @return An object matching the UUID or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothGattService find(String UUID, Duration duration) {
- BluetoothManager manager = BluetoothManager.getBluetoothManager();
- return (BluetoothGattService) manager.find(BluetoothType.GATT_SERVICE,
- null, UUID, this, duration);
- }
-
- /** Find a BluetoothGattService. If parameter UUID is not null,
- * the returned object will have to match it.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter UUID optionally specify the UUID of the BluetoothGattService you are
- * waiting for
- * @return An object matching the UUID or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothGattService find(String UUID) {
- return find(UUID, Duration.ZERO);
- }
-
- /* D-Bus method calls: */
- /** The connection to this device is removed, removing all connected
- * profiles.
- * @return TRUE if the device disconnected
- */
- public native boolean disconnect() throws BluetoothException;
-
- /** An asynchronous connection to this device is initiated,
- * connecting each profile flagged as auto-connectable.
- */
- public native void connectAsyncStart() throws BluetoothException;
-
- /** Completion of the initiated asynchronous connection.
- * @return TRUE if the device connected
- */
- public native boolean connectAsyncFinish() throws BluetoothException;
-
- /** A connection to this device is established, connecting each profile
- * flagged as auto-connectable.
- * @return TRUE if the device connected
- */
- public native boolean connect() throws BluetoothException;
-
- /** Connects a specific profile available on the device, given by UUID
- * @param arg_UUID The UUID of the profile to be connected
- * @return TRUE if the profile connected successfully
- */
- public native boolean connectProfile(String arg_UUID) throws BluetoothException;
-
- /** Disconnects a specific profile available on the device, given by UUID
- * @param arg_UUID The UUID of the profile to be disconnected
- * @return TRUE if the profile disconnected successfully
- */
- public native boolean disconnectProfile(String arg_UUID) throws BluetoothException;
-
- /** A connection to this device is established, and the device is then
- * paired.
- * @return TRUE if the device connected and paired
- */
- public native boolean pair() throws BluetoothException;
-
- /** Remove this device from the system (like an unpair).
- * @return TRUE if the device has been removed
- * @throws BluetoothException
- */
- public native boolean remove() throws BluetoothException;
-
- /** Cancels an initiated pairing operation
- * @return TRUE if the paring is cancelled successfully
- */
- public native boolean cancelPairing() throws BluetoothException;
-
- /** Returns a list of BluetoothGattServices available on this device.
- * @return A list of BluetoothGattServices available on this device,
- * NULL if an error occurred
- */
- public native List<BluetoothGattService> getServices();
-
- /* D-Bus property accessors: */
- /** Returns the hardware address of this device.
- * @return The hardware address of this device.
- */
- public native String getAddress();
-
- /** Returns the remote friendly name of this device.
- * @return The remote friendly name of this device, or NULL if not set.
- */
- public native String getName();
-
- /** Returns an alternative friendly name of this device.
- * @return The alternative friendly name of this device, or NULL if not set.
- */
- public native String getAlias();
-
- /** Sets an alternative friendly name of this device.
- */
- public native void setAlias(String value);
-
- /** Returns the Bluetooth class of the device.
- * @return The Bluetooth class of the device.
- */
- public native int getBluetoothClass();
-
- /** Returns the appearance of the device, as found by GAP service.
- * @return The appearance of the device, as found by GAP service.
- */
- public native short getAppearance();
-
- /** Returns the proposed icon name of the device.
- * @return The proposed icon name, or NULL if not set.
- */
- public native String getIcon();
-
- /** Returns the paired state the device.
- * @return The paired state of the device.
- */
- public native boolean getPaired();
-
- /**
- * Enables notifications for the paired property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the paired
- * property.
- */
- public native void enablePairedNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the paired property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disablePairedNotifications();
-
- /** Returns the trusted state the device.
- * @return The trusted state of the device.
- */
- public native boolean getTrusted();
-
- /**
- * Enables notifications for the trusted property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the trusted
- * property.
- */
- public native void enableTrustedNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the trusted property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableTrustedNotifications();
-
- /** Sets the trusted state the device.
- */
- public native void setTrusted(boolean value);
-
- /** Returns the blocked state the device.
- * @return The blocked state of the device.
- */
- public native boolean getBlocked();
-
- /**
- * Enables notifications for the blocked property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the blocked
- * property.
- */
- public native void enableBlockedNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the blocked property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableBlockedNotifications();
-
- /** Sets the blocked state the device.
- */
- public native void setBlocked(boolean value);
-
- /** Returns if device uses only pre-Bluetooth 2.1 pairing mechanism.
- * @return True if device uses only pre-Bluetooth 2.1 pairing mechanism.
- */
- public native boolean getLegacyPairing();
-
- /** Returns the Received Signal Strength Indicator of the device.
- * @return The Received Signal Strength Indicator of the device.
- */
- public native short getRSSI();
-
- /**
- * Enables notifications for the RSSI property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Short> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the RSSI
- * property.
- */
- public native void enableRSSINotifications(BluetoothNotification<Short> callback);
- /**
- * Disables notifications of the RSSI property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableRSSINotifications();
-
- /** Returns the connected state of the device.
- * @return The connected state of the device.
- */
- public native boolean getConnected();
-
- /**
- * Enables notifications for the connected property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the connected
- * property.
- */
- public native void enableConnectedNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the connected property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableConnectedNotifications();
-
- /** Returns the UUIDs of the device.
- * @return Array containing the UUIDs of the device, ends with NULL.
- */
- public native String[] getUUIDs();
-
- /** Returns the local ID of the adapter.
- * @return The local ID of the adapter.
- */
- public native String getModalias();
-
- /** Returns the adapter on which this device was discovered or
- * connected.
- * @return The adapter.
- */
- public native BluetoothAdapter getAdapter();
-
- /** Returns a map containing manufacturer specific advertisement data.
- * An entry has a uint16_t key and an array of bytes.
- * @return manufacturer specific advertisement data.
- */
- public native Map<Short, byte[]> getManufacturerData();
-
- /**
- * Enables notifications for the manufacturer data property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Map<Short, byte[]> > object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the manufacturer data
- * property.
- */
- public native void enableManufacturerDataNotifications(BluetoothNotification<Map<Short, byte[]> > callback);
- /**
- * Disables notifications of the manufacturer data property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableManufacturerDataNotifications();
-
-
- /** Returns a map containing service advertisement data.
- * An entry has a UUID string key and an array of bytes.
- * @return service advertisement data.
- */
- public native Map<String, byte[]> getServiceData();
-
- /**
- * Enables notifications for the service data property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Map<String, byte[]> > object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the service data
- * property.
- */
- public native void enableServiceDataNotifications(BluetoothNotification<Map<String, byte[]> > callback);
- /**
- * Disables notifications of the service data property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableServiceDataNotifications();
-
-
- /** Returns the transmission power level (0 means unknown).
- * @return the transmission power level (0 means unknown).
- */
- public native short getTxPower ();
-
- /** Returns true if service discovery has ended.
- * @return true if the service discovery has ended.
- */
- public native boolean getServicesResolved ();
-
- /**
- * Enables notifications for the services resolved property and calls run function of the
- * BluetoothNotification object.
- * @param callback A BluetoothNotification<Boolean> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the services resolved
- * property.
- */
- public native void enableServicesResolvedNotifications(BluetoothNotification<Boolean> callback);
- /**
- * Disables notifications of the services resolved property and unregisters the callback
- * object passed through the corresponding enable method.
- */
- public native void disableServicesResolvedNotifications();
-
- private native void delete();
-
- private BluetoothDevice(long instance)
- {
- super(instance);
- }
-
-}
diff --git a/java/tinyb/BluetoothException.java b/java/tinyb/BluetoothException.java
deleted file mode 100644
index d14b4903..00000000
--- a/java/tinyb/BluetoothException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Author: Petre Eftime <[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;
-
-public class BluetoothException extends RuntimeException {
- BluetoothException(String msg) {
- super(msg);
- }
-}
diff --git a/java/tinyb/BluetoothGattCharacteristic.java b/java/tinyb/BluetoothGattCharacteristic.java
deleted file mode 100644
index 9e20fffc..00000000
--- a/java/tinyb/BluetoothGattCharacteristic.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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;
-
-import java.util.*;
-import java.time.Duration;
-
-/**
- * Provides access to Bluetooth GATT characteristic. Follows the BlueZ adapter API
- * available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt
- */
-public class BluetoothGattCharacteristic extends BluetoothObject
-{
- public native BluetoothType getBluetoothType();
- public native BluetoothGattCharacteristic clone();
-
- static BluetoothType class_type() { return BluetoothType.GATT_CHARACTERISTIC; }
-
- /** Find a BluetoothGattDescriptor. If parameter UUID is not null,
- * the returned object will have to match it.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter UUID optionally specify the UUID of the BluetoothGattDescriptor you are
- * waiting for
- * @parameter timeout the function will return after timeout time, a
- * value of zero means wait forever. If object is not found during this time null will be returned.
- * @return An object matching the UUID or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothGattDescriptor find(String UUID, Duration duration) {
- BluetoothManager manager = BluetoothManager.getBluetoothManager();
- return (BluetoothGattDescriptor) manager.find(BluetoothType.GATT_DESCRIPTOR,
- null, UUID, this, duration);
- }
-
- /** Find a BluetoothGattDescriptor. If parameter UUID is not null,
- * the returned object will have to match it.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter UUID optionally specify the UUID of the BluetoothGattDescriptor you are
- * waiting for
- * @return An object matching the UUID or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothGattDescriptor find(String UUID) {
- return find(UUID, Duration.ZERO);
- }
-
- /* D-Bus method calls: */
- /** Reads the value of this characteristic.
- * @return A std::vector<unsgined char> containing the value of this characteristic.
- */
- public native byte[] readValue() throws BluetoothException;
-
- /**
- * Enables notifications for the value and calls run function of the BluetoothNotification
- * object. It enables notifications for this characteristic at BLE level.
- * @param callback A BluetoothNotification<byte[]> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the value
- * property.
- */
- public native void enableValueNotifications(BluetoothNotification<byte[]> callback);
- /**
- * Disables notifications of the value and unregisters the callback object
- * passed through the corresponding enable method. It disables notications
- * at BLE level for this characteristic.
- */
- public native void disableValueNotifications();
-
- /** Writes the value of this characteristic.
- * @param[in] arg_value The data as vector<uchar>
- * to be written packed in a GBytes struct
- * @return TRUE if value was written succesfully
- */
- public native boolean writeValue(byte[] argValue) throws BluetoothException;
-
-
- /* D-Bus property accessors: */
- /** Get the UUID of this characteristic.
- * @return The 128 byte UUID of this characteristic, NULL if an error occurred
- */
- public native String getUUID();
-
- /** Returns the service to which this characteristic belongs to.
- * @return The service.
- */
- public native BluetoothGattService getService();
-
- /** Returns the cached value of this characteristic, if any.
- * @return The cached value of this characteristic.
- */
- public native byte[] getValue();
-
- /** Returns true if notification for changes of this characteristic are
- * activated.
- * @return True if notificatios are activated.
- */
- public native boolean getNotifying();
-
- /** Returns the flags this characterstic has.
- * @return A list of flags for this characteristic.
- */
- public native String[] getFlags();
-
- /** Returns a list of BluetoothGattDescriptors this characteristic exposes.
- * @return A list of BluetoothGattDescriptors exposed by this characteristic
- * NULL if an error occurred
- */
- public native List<BluetoothGattDescriptor> getDescriptors();
-
- private native void init(BluetoothGattCharacteristic obj);
-
- private native void delete();
-
- private BluetoothGattCharacteristic(long instance)
- {
- super(instance);
- }
-}
diff --git a/java/tinyb/BluetoothGattService.java b/java/tinyb/BluetoothGattService.java
deleted file mode 100644
index 49b18739..00000000
--- a/java/tinyb/BluetoothGattService.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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;
-
-import java.util.*;
-import java.time.Duration;
-
-/**
- * Provides access to Bluetooth GATT characteristic. Follows the BlueZ adapter API
- * available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt
- */
-public class BluetoothGattService extends BluetoothObject
-{
- public native BluetoothType getBluetoothType();
- public native BluetoothAdapter clone();
-
- static BluetoothType class_type() { return BluetoothType.GATT_SERVICE; }
-
- /** Find a BluetoothGattCharacteristic. If parameter UUID is not null,
- * the returned object will have to match it.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter UUID optionally specify the UUID of the BluetoothGattCharacteristic you are
- * waiting for
- * @parameter timeout the function will return after timeout time, a
- * value of zero means wait forever. If object is not found during this time null will be returned.
- * @return An object matching the UUID or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothGattCharacteristic find(String UUID, Duration duration) {
- BluetoothManager manager = BluetoothManager.getBluetoothManager();
- return (BluetoothGattCharacteristic) manager.find(BluetoothType.GATT_CHARACTERISTIC,
- null, UUID, this, duration);
- }
-
- /** Find a BluetoothGattCharacteristic. If parameter UUID is not null,
- * the returned object will have to match it.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter UUID optionally specify the UUID of the BluetoothGattDescriptor you are
- * waiting for
- * @return An object matching the UUID or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothGattCharacteristic find(String UUID) {
- return find(UUID, Duration.ZERO);
- }
-
- /* D-Bus property accessors: */
-
- /** Get the UUID of this service
- * @return The 128 byte UUID of this service, NULL if an error occurred
- */
- public native String getUUID();
-
- /** Returns the device to which this service belongs to.
- * @return The device.
- */
- public native BluetoothDevice getDevice();
-
- /** Returns true if this service is a primary service, false if secondary.
- * @return true if this service is a primary service, false if secondary.
- */
- public native boolean getPrimary();
-
- /** Returns a list of BluetoothGattCharacteristics this service exposes.
- * @return A list of BluetoothGattCharacteristics exposed by this service
- */
- public native List<BluetoothGattCharacteristic> getCharacteristics();
-
- private native void delete();
-
- private BluetoothGattService(long instance)
- {
- super(instance);
- }
-}
diff --git a/java/tinyb/BluetoothManager.java b/java/tinyb/BluetoothManager.java
deleted file mode 100644
index 489ac3eb..00000000
--- a/java/tinyb/BluetoothManager.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * 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;
-
-import java.util.*;
-import java.time.Duration;
-
-public class BluetoothManager
-{
- private long nativeInstance;
- private static BluetoothManager inst;
-
- /**
- * The thread to watch for nearby devices
- */
- private Thread nearbyThread = null;
-
- static {
- try {
- System.loadLibrary("tinyb");
- System.loadLibrary("javatinyb");
- } catch (UnsatisfiedLinkError e) {
- System.err.println("Native code library failed to load.\n" + e);
- }
- }
-
- private native static String getNativeAPIVersion();
-
- public native BluetoothType getBluetoothType();
-
- private native BluetoothObject find(int type, String name, String identifier, BluetoothObject parent, long milliseconds);
-
- /** Find a BluetoothObject of a type matching type. If parameters name,
- * identifier and parent are not null, the returned object will have to
- * match them.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter type specify the type of the object you are
- * waiting for, NONE means anything.
- * @parameter name optionally specify the name of the object you are
- * waiting for (for Adapter or Device)
- * @parameter identifier optionally specify the identifier of the object you are
- * waiting for (UUID for GattService, GattCharacteristic or GattDescriptor, address
- * for Adapter or Device)
- * @parameter parent optionally specify the parent of the object you are
- * waiting for
- * @parameter timeout the function will return after timeout time, a
- * value of zero means wait forever. If object is not found during this time null will be returned.
- * @return An object matching the name, identifier, parent or null if not found before
- * timeout expires or event is canceled.
- */
- public BluetoothObject find(BluetoothType type, String name, String identifier, BluetoothObject parent, Duration timeout) {
- return find(type.ordinal(), name, identifier, parent, timeout.toNanos() / 1000000);
- }
-
-
- /** Find a BluetoothObject of a type matching type. If parameters name,
- * identifier and parent are not null, the returned object will have to
- * match them.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter type specify the type of the object you are
- * waiting for, NONE means anything.
- * @parameter name optionally specify the name of the object you are
- * waiting for (for Adapter or Device)
- * @parameter identifier optionally specify the identifier of the object you are
- * waiting for (UUID for GattService, GattCharacteristic or GattDescriptor, address
- * for Adapter or Device)
- * @parameter parent optionally specify the parent of the object you are
- * waiting for
- * @return An object matching the name, identifier and parent.
- */
- public BluetoothObject find(BluetoothType type, String name, String identifier, BluetoothObject parent) {
- return find(type, name, identifier, parent, Duration.ZERO);
- }
-
- /** Find a BluetoothObject of type T. If parameters name, identifier and
- * parent are not null, the returned object will have to match them.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter name optionally specify the name of the object you are
- * waiting for (for Adapter or Device)
- * @parameter identifier optionally specify the identifier of the object you are
- * waiting for (UUID for GattService, GattCharacteristic or GattDescriptor, address
- * for Adapter or Device)
- * @parameter parent optionally specify the parent of the object you are
- * waiting for
- * @parameter timeout the function will return after timeout time, a
- * value of zero means wait forever. If object is not found during this time null will be returned.
- * @return An object matching the name, identifier, parent or null if not found before
- * timeout expires or event is canceled.
- */
- public <T extends BluetoothObject> T find(String name, String identifier, BluetoothObject parent, Duration timeout) {
- return (T) find(T.class_type().ordinal(), name, identifier, parent, timeout.toNanos() / 1000000);
- }
-
- /** Find a BluetoothObject of type T. If parameters name, identifier and
- * parent are not null, the returned object will have to match them.
- * It will first check for existing objects. It will not turn on discovery
- * or connect to devices.
- * @parameter name optionally specify the name of the object you are
- * waiting for (for Adapter or Device)
- * @parameter identifier optionally specify the identifier of the object you are
- * waiting for (UUID for GattService, GattCharacteristic or GattDescriptor, address
- * for Adapter or Device)
- * @parameter parent optionally specify the parent of the object you are
- * waiting for
- * @return An object matching the name, identifier and parent.
- */
- public <T extends BluetoothObject> T find(String name, String identifier, BluetoothObject parent) {
- return (T) find(name, identifier, parent, Duration.ZERO);
- }
-
- /** Return a BluetoothObject of a type matching type. If parameters name,
- * identifier and parent are not null, the returned object will have to
- * match them. Only objects which are already in the system will be returned.
- * @parameter type specify the type of the object you are
- * waiting for, NONE means anything.
- * @parameter name optionally specify the name of the object you are
- * waiting for (for Adapter or Device)
- * @parameter identifier optionally specify the identifier of the object you are
- * waiting for (UUID for GattService, GattCharacteristic or GattDescriptor, address
- * for Adapter or Device)
- * @parameter parent optionally specify the parent of the object you are
- * waiting for
- * @return An object matching the name, identifier, parent or null if not found.
- */
- public BluetoothObject getObject(BluetoothType type, String name,
- String identifier, BluetoothObject parent) {
- return getObject(type.ordinal(), name, identifier, parent);
- }
- private native BluetoothObject getObject(int type, String name,
- String identifier, BluetoothObject parent);
-
- /** Return a List of BluetoothObject of a type matching type. If parameters name,
- * identifier and parent are not null, the returned object will have to
- * match them. Only objects which are already in the system will be returned.
- * @parameter type specify the type of the object you are
- * waiting for, NONE means anything.
- * @parameter name optionally specify the name of the object you are
- * waiting for (for Adapter or Device)
- * @parameter identifier optionally specify the identifier of the object you are
- * waiting for (UUID for GattService, GattCharacteristic or GattDescriptor, address
- * for Adapter or Device)
- * @parameter parent optionally specify the parent of the object you are
- * waiting for
- * @return A vector of object matching the name, identifier, parent.
- */
- public List<BluetoothObject> getObjects(BluetoothType type, String name,
- String identifier, BluetoothObject parent) {
- return getObjects(type.ordinal(), name, identifier, parent);
- }
- private native List<BluetoothObject> getObjects(int type, String name,
- String identifier, BluetoothObject parent);
-
- /** Returns a list of BluetoothAdapters available in the system
- * @return A list of BluetoothAdapters available in the system
- */
- public native List<BluetoothAdapter> getAdapters();
-
- /** Returns a list of discovered BluetoothDevices
- * @return A list of discovered BluetoothDevices
- */
- public native List<BluetoothDevice> getDevices();
-
- /** Returns a list of available BluetoothGattServices
- * @return A list of available BluetoothGattServices
- */
- public native List<BluetoothGattService> getServices();
-
- /** Sets a default adapter to use for discovery.
- * @return TRUE if the device was set
- */
- public native boolean setDefaultAdapter(BluetoothAdapter adapter);
-
- /** Gets the default adapter to use for discovery.
- * <p>
- * System default is the last detected adapter at initialisation.
- * </p>
- * @return the used default adapter
- */
- public native BluetoothAdapter getDefaultAdapter();
-
- /** Turns on device discovery on the default adapter if it is disabled.
- * @return TRUE if discovery was successfully enabled
- */
- public native boolean startDiscovery() throws BluetoothException;
-
- /** Turns off device discovery on the default adapter if it is enabled.
- * @return TRUE if discovery was successfully disabled
- */
- public native boolean stopDiscovery() throws BluetoothException;
-
- /** Returns if the discovers is running or not.
- * @return TRUE if discovery is running
- */
- public native boolean getDiscovering() throws BluetoothException;
-
- /**
- * When called, each new device found will fire an event to the passed
- * listener<p>
- *
- * This method will create a new thread to handle the discovery process
- * which is a simple polling of the current list (getDevices)
- * <p>
- *
- * The thread is stopped when the nearbyStopDiscovery is called<p>
- *
- * @param listener
- * @param pollingRate The polling rate is miliseconds (1000 = 1s)
- * @param onlyManufacturerFilled If true, then only if the manufacturer data is filled, the event will be fired
- */
- public void startNearbyDiscovery(final BluetoothDeviceDiscoveryListener listener, final int pollingRate, final boolean onlyManufacturerFilled) {
- //--- If alreay started, does nothing
- if ((nearbyThread != null) && nearbyThread.isAlive()) return;
-
- //--- Remove all devices to have a clean start
- getAdapters().get(0).removeDevices();
-
- //--- Start the bluez discovery
- startDiscovery();
-
- //--- Thread to poll the devices list
- nearbyThread = new Thread() {
- public void run() {
- //--- The key is the address
- HashMap<String, BluetoothDevice> discovered = new HashMap<String, BluetoothDevice>();
- try {
- while (Thread.interrupted() == false) {
- List<BluetoothDevice> list = getDevices();
- for (BluetoothDevice d:list) {
- if (!discovered.containsKey(d.getAddress())) {
- if (onlyManufacturerFilled) {
- if (!d.getManufacturerData().isEmpty()) {
- discovered.put(d.getAddress(), d);
- if (listener != null) listener.bluetoothDeviceDiscovered(d);
- }
-
- } else {
- discovered.put(d.getAddress(), d);
- if (listener != null) listener.bluetoothDeviceDiscovered(d);
- }
- }
- }
- //--- Polling rate of 1 second
- sleep(pollingRate);
- }
-
- } catch (InterruptedException ex) {
- //--- Stopped by user or jvm
- }
- stopDiscovery();
-
- }
- };
- nearbyThread.start();
-
- }
-
- /**
- * Stop the nearby thread
- */
- public void stopNearbyDiscovery() {
- if ((nearbyThread != null) && nearbyThread.isAlive()) nearbyThread.interrupt();
-
- }
-
- /**
- * Interface to implement to receive the device discovery event
- */
- public interface BluetoothDeviceDiscoveryListener {
-
- public void bluetoothDeviceDiscovered(BluetoothDevice device);
- }
-
- private native void init() throws BluetoothException;
- private native void delete();
- private BluetoothManager()
- {
- 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)
- {
- String nativeAPIVersion = getNativeAPIVersion();
- String APIVersion = BluetoothManager.class.getPackage().getSpecificationVersion();
- if ( null != APIVersion && APIVersion.equals(nativeAPIVersion) == false) {
- String[] nativeAPIVersionCode = nativeAPIVersion.split("\\D");
- 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 BluetoothManager();
- inst.init();
- }
- return inst;
- }
-
- protected void finalize()
- {
- delete();
- }
-}
diff --git a/java/tinyb/BluetoothNotification.java b/java/tinyb/BluetoothNotification.java
deleted file mode 100644
index 79fe800c..00000000
--- a/java/tinyb/BluetoothNotification.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Author: Petre Eftime <[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;
-
-/*
- * This interface is used by notifications.
- * Implement a class inheriting BluetoothNotification and pass an object of that type
- * to the enable*Notifications function. When a notification of that type is received,
- * the run function of the class will be called.
- */
-public interface BluetoothNotification<T> {
- public void run(T value);
-}
diff --git a/java/tinyb/BluetoothType.java b/java/tinyb/BluetoothType.java
deleted file mode 100644
index ac2fb02e..00000000
--- a/java/tinyb/BluetoothType.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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;
-
-public enum BluetoothType
-{
- NONE, ADAPTER, DEVICE,
- GATT_SERVICE, GATT_CHARACTERISTIC,
- GATT_DESCRIPTOR;
-
- private long nativeInstance;
-}
diff --git a/java/tinyb/ObjectArgCallback.java b/java/tinyb/ObjectArgCallback.java
deleted file mode 100644
index 898c9cbc..00000000
--- a/java/tinyb/ObjectArgCallback.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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;
-
-public class ObjectArgCallback extends BluetoothCallback
-{
- private Object callbackArg;
-
- public ObjectArgCallback(BluetoothObject bObj, Object callbackArg)
- {
- this.bObj = bObj;
- this.callbackArg = callbackArg;
- }
-
- public void run()
- {
- }
-}
diff --git a/java/tinyb/ObjectArrayArgCallback.java b/java/tinyb/ObjectArrayArgCallback.java
deleted file mode 100644
index b0d83410..00000000
--- a/java/tinyb/ObjectArrayArgCallback.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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;
-
-public class ObjectArrayArgCallback extends BluetoothCallback
-{
- private Object[] callbackArg;
-
- public ObjectArrayArgCallback(BluetoothObject bObj, Object[] callbackArg)
- {
- this.bObj = bObj;
- this.callbackArg = callbackArg;
- }
-
- public void run()
- {
- }
-}
diff --git a/java/tinyb/TransportType.java b/java/tinyb/TransportType.java
deleted file mode 100644
index ab71a1cb..00000000
--- a/java/tinyb/TransportType.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package tinyb;
-
-/**
- * TransportType determines type of bluetooth scan.
- */
-public enum TransportType {
- /**
- * interleaved scan
- */
- AUTO,
- /**
- * BR/EDR inquiry
- */
- BREDR,
- /**
- * LE scan only
- */
- LE
-}
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/BluetoothEvent.java b/java/tinyb/dbus/DBusEvent.java
index b2141131..fe6d4c40 100644
--- a/java/tinyb/BluetoothEvent.java
+++ b/java/tinyb/dbus/DBusEvent.java
@@ -22,30 +22,38 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package tinyb;
+package tinyb.dbus;
-import java.util.*;
+import org.tinyb.BluetoothCallback;
+import org.tinyb.BluetoothEvent;
+import org.tinyb.BluetoothType;
-public class BluetoothEvent
+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,
- BluetoothObject parent, BluetoothCallback cb, Object data);
+ DBusObject parent, BluetoothCallback cb, Object data);
private native void delete();
- public BluetoothEvent(BluetoothType type, String name, String identifier,
- BluetoothObject parent, BluetoothCallback cb, Object data)
+ 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/BluetoothGattDescriptor.java b/java/tinyb/dbus/DBusGattDescriptor.java
index d5911d23..5c59ea8c 100644
--- a/java/tinyb/BluetoothGattDescriptor.java
+++ b/java/tinyb/dbus/DBusGattDescriptor.java
@@ -1,4 +1,8 @@
-/*
+/**
+ * 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.
*
@@ -22,67 +26,50 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package tinyb;
+package tinyb.dbus;
-import java.util.*;
+import org.tinyb.BluetoothException;
+import org.tinyb.BluetoothGattDescriptor;
+import org.tinyb.BluetoothNotification;
+import org.tinyb.BluetoothType;
-/**
- * Provides access to Bluetooth GATT descriptor. Follows the BlueZ adapter API
- * available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt
- */
-public class BluetoothGattDescriptor extends BluetoothObject
+public class DBusGattDescriptor extends DBusObject implements BluetoothGattDescriptor
{
+ @Override
public native BluetoothType getBluetoothType();
- public native BluetoothAdapter clone();
+ @Override
+ public native BluetoothGattDescriptor clone();
static BluetoothType class_type() { return BluetoothType.GATT_DESCRIPTOR; }
/* D-Bus method calls: */
- /** Reads the value of this descriptor
- * @return A vector<uchar> containing data from this descriptor
- */
+
+ @Override
public native byte[] readValue();
- /** Writes the value of this descriptor.
- * @param[in] arg_value The data as vector<uchar>
- * to be written packed in a GBytes struct
- * @return TRUE if value was written succesfully
- */
+ @Override
public native boolean writeValue(byte[] argValue) throws BluetoothException;
- /**
- * Enables notifications for the value and calls run function of the BluetoothNotification
- * object.
- * @param callback A BluetoothNotification<byte[]> object. Its run function will be called
- * when a notification is issued. The run function will deliver the new value of the value
- * property.
- */
+ @Override
public native void enableValueNotifications(BluetoothNotification<byte[]> callback);
- /**
- * Disables notifications of the value and unregisters the callback object
- * passed through the corresponding enable method.
- */
+
+ @Override
public native void disableValueNotifications();
/* D-Bus property accessors: */
- /** Get the UUID of this descriptor.
- * @return The 128 byte UUID of this descriptor, NULL if an error occurred
- */
+
+ @Override
public native String getUUID();
- /** Returns the characteristic to which this descriptor belongs to.
- * @return The characteristic.
- */
- public native BluetoothGattCharacteristic getCharacteristic();
+ @Override
+ public native DBusGattCharacteristic getCharacteristic();
- /** Returns the cached value of this descriptor, if any.
- * @return The cached value of this descriptor.
- */
+ @Override
public native byte[] getValue();
private native void delete();
- private BluetoothGattDescriptor(long instance)
+ 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/BluetoothObject.java b/java/tinyb/dbus/DBusObject.java
index 2afb8c3c..a9095d1a 100644
--- a/java/tinyb/BluetoothObject.java
+++ b/java/tinyb/dbus/DBusObject.java
@@ -1,4 +1,8 @@
-/*
+/**
+ * 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.
*
@@ -22,11 +26,12 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package tinyb;
+package tinyb.dbus;
-import java.util.*;
+import org.tinyb.BluetoothObject;
+import org.tinyb.BluetoothType;
-public abstract class BluetoothObject implements Cloneable,AutoCloseable
+public class DBusObject implements BluetoothObject
{
protected long nativeInstance;
private boolean isValid;
@@ -34,55 +39,50 @@ public abstract class BluetoothObject implements Cloneable,AutoCloseable
static {
try {
System.loadLibrary("javatinyb");
- } catch (UnsatisfiedLinkError e) {
+ } catch (final UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
}
}
static BluetoothType class_type() { return BluetoothType.NONE; }
- /** Returns the BluetoothType of this object
- * @return The BluetoothType of this object
- */
+ @Override
public native BluetoothType getBluetoothType();
- /** Returns a clone of the BluetoothObject
- * @return A clone of the BluetoothObject
- */
+ @Override
public native BluetoothObject clone();
private native void delete();
- private native boolean operatorEqual(BluetoothObject obj);
+ private native boolean operatorEqual(DBusObject obj);
- protected BluetoothObject(long instance)
+ protected DBusObject(final long instance)
{
nativeInstance = instance;
isValid = true;
}
+ @Override
protected void finalize()
{
close();
}
- public boolean equals(Object obj)
+ @Override
+ public boolean equals(final Object obj)
{
- if (obj == null || !(obj instanceof BluetoothObject))
+ if (obj == null || !(obj instanceof DBusObject))
return false;
- return operatorEqual((BluetoothObject)obj);
+ return operatorEqual((DBusObject)obj);
}
protected native String getObjectPath();
+ @Override
public int hashCode() {
- String objectPath = getObjectPath();
+ final String objectPath = getObjectPath();
return objectPath.hashCode();
}
- /**
- * Release the native memory associated with this object
- * The object should not be used following a call to close
- */
@Override
public synchronized void close() {
if (!isValid)