diff options
Diffstat (limited to 'java')
56 files changed, 1123 insertions, 1124 deletions
diff --git a/java/jau/direct_bt/DBTAdapter.java b/java/jau/direct_bt/DBTAdapter.java index 79b61d6e..a421dd69 100644 --- a/java/jau/direct_bt/DBTAdapter.java +++ b/java/jau/direct_bt/DBTAdapter.java @@ -38,16 +38,16 @@ import org.direct_bt.AdapterSettings; import org.direct_bt.AdapterStatusListener; import org.direct_bt.BDAddressAndType; import org.direct_bt.BDAddressType; -import org.direct_bt.BluetoothAdapter; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTAdapter; +import org.direct_bt.BTDevice; +import org.direct_bt.BTException; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTGattService; +import org.direct_bt.BTManager; +import org.direct_bt.BTNotification; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; import org.direct_bt.EIRDataTypeSet; import org.direct_bt.EUI48; import org.direct_bt.HCIStatusCode; @@ -57,7 +57,7 @@ import org.direct_bt.SMPPairingState; import org.direct_bt.ScanType; import org.direct_bt.TransportType; -public class DBTAdapter extends DBTObject implements BluetoothAdapter +public class DBTAdapter extends DBTObject implements BTAdapter { private static final boolean DEBUG = DBTManager.DEBUG; @@ -75,16 +75,16 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter private final AtomicBoolean isClosing = new AtomicBoolean(false); private final AtomicBoolean powered_state = new AtomicBoolean(false); // AdapterSettings - private BluetoothNotification<Boolean> userPairableNotificationCB = null; + private BTNotification<Boolean> userPairableNotificationCB = null; private final AtomicBoolean isDiscoverable = new AtomicBoolean(false); // AdapterSettings - private BluetoothNotification<Boolean> userDiscoverableNotificationCB = null; + private BTNotification<Boolean> userDiscoverableNotificationCB = null; private final AtomicBoolean isPairable = new AtomicBoolean(false); // AdapterSettings - private BluetoothNotification<Boolean> userPoweredNotificationCB = null; + private BTNotification<Boolean> userPoweredNotificationCB = null; private final AtomicReference<ScanType> currentMetaScanType = new AtomicReference<ScanType>(ScanType.NONE); // AdapterStatusListener and powerdOff - private BluetoothNotification<Boolean> userDiscoveringNotificationCB = null; + private BTNotification<Boolean> userDiscoveringNotificationCB = null; - private final List<BluetoothDevice> discoveredDevices = new ArrayList<BluetoothDevice>(); + private final List<BTDevice> discoveredDevices = new ArrayList<BTDevice>(); /* pp */ DBTAdapter(final long nativeInstance, final byte byteAddress[/*6*/], final String name, final int dev_id) { @@ -96,7 +96,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } @Override - public final BluetoothManager getManager() { return DBTManager.getManager(); } + public final BTManager getManager() { return DBTManager.getManager(); } @Override public void close() { @@ -116,8 +116,8 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter stopDiscovery(); - final List<BluetoothDevice> devices = getDiscoveredDevices(); - for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) { + final List<BTDevice> devices = getDiscoveredDevices(); + for(final Iterator<BTDevice> id = devices.iterator(); id.hasNext(); ) { final DBTDevice d = (DBTDevice) id.next(); d.close(); } @@ -162,17 +162,17 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter public int getDevID() { return dev_id; } @Override - public BluetoothType getBluetoothType() { return class_type(); } + public BTType getBluetoothType() { return class_type(); } - static BluetoothType class_type() { return BluetoothType.ADAPTER; } + static BTType class_type() { return BTType.ADAPTER; } @Override - public BluetoothDevice find(final String name, final BDAddressAndType addressAndType, final long timeoutMS) { + public BTDevice find(final String name, final BDAddressAndType addressAndType, final long timeoutMS) { return findDeviceInCache(name, addressAndType); } @Override - public BluetoothDevice find(final String name, final BDAddressAndType addressAndType) { + public BTDevice find(final String name, final BDAddressAndType addressAndType) { return find(name, addressAndType, 0); } @@ -211,7 +211,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter public long getBluetoothClass() { throw new UnsupportedOperationException(); } // FIXME @Override - public final BluetoothAdapter clone() { throw new UnsupportedOperationException(); } // FIXME + public final BTAdapter clone() { throw new UnsupportedOperationException(); } // FIXME @Override public String getInterfaceName() { throw new UnsupportedOperationException(); } // FIXME @@ -238,7 +238,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter /* Java callbacks */ @Override - public void enablePoweredNotifications(final BluetoothNotification<Boolean> callback) { + public void enablePoweredNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userPoweredNotificationCB = callback; } @@ -255,7 +255,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter public boolean getDiscoverable() { return isDiscoverable.get(); } @Override - public void enableDiscoverableNotifications(final BluetoothNotification<Boolean> callback) { + public void enableDiscoverableNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userDiscoverableNotificationCB = callback; } @@ -279,7 +279,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } @Override - public final void enableDiscoveringNotifications(final BluetoothNotification<Boolean> callback) { + public final void enableDiscoveringNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userDiscoveringNotificationCB = callback; } @@ -296,7 +296,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter public final boolean getPairable() { return isPairable.get(); } @Override - public void enablePairableNotifications(final BluetoothNotification<Boolean> callback) { + public void enablePairableNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userPairableNotificationCB = callback; } @@ -342,10 +342,10 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter public native boolean setDiscoverable(boolean value); @Override - public final BluetoothDevice connectDevice(final BDAddressAndType addressAndType) { + public final BTDevice connectDevice(final BDAddressAndType addressAndType) { return connectDeviceImpl(addressAndType.address.b, addressAndType.type.value); } - private native BluetoothDevice connectDeviceImpl(byte[] address, byte addressType); + private native BTDevice connectDeviceImpl(byte[] address, byte addressType); @Override public native boolean setPairable(boolean value); @@ -373,12 +373,12 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter /* discovery */ @Override - public boolean startDiscovery() throws BluetoothException { + public boolean startDiscovery() throws BTException { return HCIStatusCode.SUCCESS == startDiscovery(true); } @Override - public HCIStatusCode startDiscovery(final boolean keepAlive) throws BluetoothException { + public HCIStatusCode startDiscovery(final boolean keepAlive) throws BTException { synchronized( discoveryLock ) { // Ignoring 'isDiscovering', as native implementation also handles change of 'keepAlive'. // The discoveredDevices shall always get cleared. @@ -386,28 +386,28 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter return HCIStatusCode.get( startDiscoveryImpl(keepAlive) ); // event callbacks will be generated by implementation } } - private native byte startDiscoveryImpl(boolean keepAlive) throws BluetoothException; + private native byte startDiscoveryImpl(boolean keepAlive) throws BTException; @Override - public HCIStatusCode stopDiscovery() throws BluetoothException { + public HCIStatusCode stopDiscovery() throws BTException { synchronized( discoveryLock ) { // Ignoring 'isDiscovering', be consistent with startDiscovery return HCIStatusCode.get( stopDiscoveryImpl() ); // event callbacks will be generated by implementation } } - private native byte stopDiscoveryImpl() throws BluetoothException; + private native byte stopDiscoveryImpl() throws BTException; @Override - public List<BluetoothDevice> getDiscoveredDevices() { + public List<BTDevice> getDiscoveredDevices() { synchronized(discoveredDevicesLock) { - return new ArrayList<BluetoothDevice>(discoveredDevices); + return new ArrayList<BTDevice>(discoveredDevices); } } // std::vector<std::shared_ptr<direct_bt::HCIDevice>> discoveredDevices = adapter.getDiscoveredDevices(); - private native List<BluetoothDevice> getDiscoveredDevicesImpl(); + private native List<BTDevice> getDiscoveredDevicesImpl(); @Override - public int removeDiscoveredDevices() throws BluetoothException { + public int removeDiscoveredDevices() throws BTException { final int cj = removeDiscoveredDevicesImpl2j(); final int cn = removeDiscoveredDevicesImpl1(); if( cj != cn ) { @@ -417,7 +417,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } return cn; } - private native int removeDiscoveredDevicesImpl1() throws BluetoothException; + private native int removeDiscoveredDevicesImpl1() throws BTException; private int removeDiscoveredDevicesImpl2j() { synchronized(discoveredDevicesLock) { final int n = discoveredDevices.size(); @@ -425,7 +425,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter return n; } } - /* pp */ boolean removeDiscoveredDevice(final BluetoothDevice device) { + /* pp */ boolean removeDiscoveredDevice(final BTDevice device) { synchronized(discoveredDevicesLock) { return discoveredDevices.remove(device); } @@ -445,8 +445,8 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter private native boolean removeDiscoveredDeviceImpl1(final byte[] address, final byte addressType); private boolean removeDiscoveredDeviceImpl2j(final BDAddressAndType addressAndType) { synchronized(discoveredDevicesLock) { - for( final Iterator<BluetoothDevice> iter = discoveredDevices.iterator(); iter.hasNext(); ) { - final BluetoothDevice device = iter.next(); + for( final Iterator<BTDevice> iter = discoveredDevices.iterator(); iter.hasNext(); ) { + final BTDevice device = iter.next(); if( device.getAddressAndType().equals(addressAndType) ) { iter.remove(); return true; @@ -457,7 +457,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } @Override - public native boolean addStatusListener(final AdapterStatusListener l, final BluetoothDevice deviceMatch); + public native boolean addStatusListener(final AdapterStatusListener l, final BTDevice deviceMatch); @Override public boolean removeStatusListener(final AdapterStatusListener l) { @@ -492,7 +492,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter private final AdapterStatusListener statusListener = new AdapterStatusListener() { @Override - public void adapterSettingsChanged(final BluetoothAdapter a, final AdapterSettings oldmask, final AdapterSettings newmask, + public void adapterSettingsChanged(final BTAdapter a, final AdapterSettings oldmask, final AdapterSettings newmask, final AdapterSettings changedmask, final long timestamp) { final boolean initialSetting = oldmask.isEmpty(); if( DEBUG ) { @@ -543,7 +543,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } } @Override - public void discoveringChanged(final BluetoothAdapter adapter, final ScanType currentMeta, final ScanType changedType, final boolean changedEnabled, final boolean keepAlive, final long timestamp) { + public void discoveringChanged(final BTAdapter adapter, final ScanType currentMeta, final ScanType changedType, final boolean changedEnabled, final boolean keepAlive, final long timestamp) { if( DEBUG ) { System.err.println("Adapter.StatusListener.DISCOVERING: meta "+currentMeta+", changed["+changedType+", enabled "+changedEnabled+", keepAlive "+keepAlive+"] on "+adapter); } @@ -560,7 +560,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } } @Override - public boolean deviceFound(final BluetoothDevice device, final long timestamp) { + public boolean deviceFound(final BTDevice device, final long timestamp) { if( DEBUG ) { System.err.println("Adapter.FOUND: "+device+" on "+device.getAdapter()); } @@ -571,7 +571,7 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } @Override - public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) { + public void deviceUpdated(final BTDevice device, final EIRDataTypeSet updateMask, final long timestamp) { final boolean rssiUpdated = updateMask.isSet( EIRDataTypeSet.DataType.RSSI ); final boolean mdUpdated = updateMask.isSet( EIRDataTypeSet.DataType.MANUF_DATA ); if( DEBUG && !rssiUpdated && !mdUpdated) { @@ -581,28 +581,28 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter } @Override - public void deviceConnected(final BluetoothDevice device, final short handle, final long timestamp) { + public void deviceConnected(final BTDevice device, final short handle, final long timestamp) { if( DEBUG ) { System.err.println("Adapter.CONNECTED: "+device+" on "+device.getAdapter()); } } @Override - public void devicePairingState(final BluetoothDevice device, final SMPPairingState state, final PairingMode mode, final long timestamp) { + public void devicePairingState(final BTDevice device, final SMPPairingState state, final PairingMode mode, final long timestamp) { if( DEBUG ) { System.err.println("Adapter.PAIRING_STATE: state "+state+", mode "+mode+": "+device); } } @Override - public void deviceReady(final BluetoothDevice device, final long timestamp) { + public void deviceReady(final BTDevice device, final long timestamp) { if( DEBUG ) { System.err.println("Adapter.READY: "+device); } } @Override - public void deviceDisconnected(final BluetoothDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { + public void deviceDisconnected(final BTDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { if( DEBUG ) { System.err.println("Adapter.DISCONNECTED: Reason "+reason+", old handle 0x"+Integer.toHexString(handle)+": "+device+" on "+device.getAdapter()); } @@ -617,35 +617,35 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter * <ul> * <li>{@link DBTDevice}</li> * <li>{@link DBTGattService}</li> - * <li>{@link DBTGattCharacteristic}</li> - * <li>{@link DBTGattDescriptor}</li> + * <li>{@link DBTGattChar}</li> + * <li>{@link DBTGattDesc}</li> * </ul> - * or alternatively in {@link BluetoothObject} space + * or alternatively in {@link BTObject} space * <ul> - * <li>{@link BluetoothType#DEVICE} -> {@link BluetoothDevice}</li> - * <li>{@link BluetoothType#GATT_SERVICE} -> {@link BluetoothGattService}</li> - * <li>{@link BluetoothType#GATT_CHARACTERISTIC} -> {@link BluetoothGattCharacteristic}</li> - * <li>{@link BluetoothType#GATT_DESCRIPTOR} -> {@link BluetoothGattDescriptor}</li> + * <li>{@link BTType#DEVICE} -> {@link BTDevice}</li> + * <li>{@link BTType#GATT_SERVICE} -> {@link BTGattService}</li> + * <li>{@link BTType#GATT_CHARACTERISTIC} -> {@link BTGattChar}</li> + * <li>{@link BTType#GATT_DESCRIPTOR} -> {@link BTGattDesc}</li> * </ul> * </p> - * @param name name of the desired {@link BluetoothType#DEVICE device}. + * @param name name of the desired {@link BTType#DEVICE device}. * Maybe {@code null}. - * @param identifier EUI48 address of the desired {@link BluetoothType#DEVICE device} - * or UUID of the desired {@link BluetoothType#GATT_SERVICE service}, - * {@link BluetoothType#GATT_CHARACTERISTIC characteristic} or {@link BluetoothType#GATT_DESCRIPTOR descriptor} to be found. + * @param identifier EUI48 address of the desired {@link BTType#DEVICE device} + * or UUID of the desired {@link BTType#GATT_SERVICE service}, + * {@link BTType#GATT_CHARACTERISTIC characteristic} or {@link BTType#GATT_DESCRIPTOR descriptor} to be found. * Maybe {@code null}, in which case the first object of the desired type is being returned - if existing. * @param type specify the type of the object to be found, either - * {@link BluetoothType#DEVICE device}, - * {@link BluetoothType#GATT_SERVICE service}, {@link BluetoothType#GATT_CHARACTERISTIC characteristic} - * or {@link BluetoothType#GATT_DESCRIPTOR descriptor}. - * {@link BluetoothType#NONE none} means anything. + * {@link BTType#DEVICE device}, + * {@link BTType#GATT_SERVICE service}, {@link BTType#GATT_CHARACTERISTIC characteristic} + * or {@link BTType#GATT_DESCRIPTOR descriptor}. + * {@link BTType#NONE none} means anything. */ - /* pp */ DBTObject findInCache(final String name, final String identifier, final BluetoothType type) { - final boolean anyType = BluetoothType.NONE == type; - final boolean deviceType = BluetoothType.DEVICE == type; - final boolean serviceType = BluetoothType.GATT_SERVICE == type; - final boolean charType = BluetoothType.GATT_CHARACTERISTIC== type; - final boolean descType = BluetoothType.GATT_DESCRIPTOR == type; + /* pp */ DBTObject findInCache(final String name, final String identifier, final BTType type) { + final boolean anyType = BTType.NONE == type; + final boolean deviceType = BTType.DEVICE == type; + final boolean serviceType = BTType.GATT_SERVICE == type; + final boolean charType = BTType.GATT_CHARACTERISTIC== type; + final boolean descType = BTType.GATT_DESCRIPTOR == type; if( !anyType && !deviceType && !serviceType && !charType && !descType ) { return null; diff --git a/java/jau/direct_bt/DBTDevice.java b/java/jau/direct_bt/DBTDevice.java index 7bad208c..d582358e 100644 --- a/java/jau/direct_bt/DBTDevice.java +++ b/java/jau/direct_bt/DBTDevice.java @@ -35,17 +35,17 @@ import org.direct_bt.AdapterStatusListener; import org.direct_bt.BDAddressAndType; import org.direct_bt.BDAddressType; import org.direct_bt.BTSecurityLevel; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTDevice; +import org.direct_bt.BTException; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTGattService; +import org.direct_bt.BTNotification; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; import org.direct_bt.EIRDataTypeSet; import org.direct_bt.EUI48; -import org.direct_bt.GATTCharacteristicListener; +import org.direct_bt.BTGattCharListener; import org.direct_bt.HCIStatusCode; import org.direct_bt.PairingMode; import org.direct_bt.SMPIOCapability; @@ -54,7 +54,7 @@ import org.direct_bt.SMPLongTermKeyInfo; import org.direct_bt.SMPPairingState; import org.direct_bt.SMPSignatureResolvingKeyInfo; -public class DBTDevice extends DBTObject implements BluetoothDevice +public class DBTDevice extends DBTObject implements BTDevice { private static final boolean DEBUG = DBTManager.DEBUG; @@ -74,29 +74,29 @@ public class DBTDevice extends DBTObject implements BluetoothDevice private final Object userCallbackLock = new Object(); private final long blockedNotificationRef = 0; - private BluetoothNotification<Boolean> userBlockedNotificationsCB = null; + private BTNotification<Boolean> userBlockedNotificationsCB = null; private final AtomicBoolean isBlocked = new AtomicBoolean(false); private final long pairedNotificationRef = 0; - private BluetoothNotification<Boolean> userPairedNotificationsCB = null; + private BTNotification<Boolean> userPairedNotificationsCB = null; private final AtomicBoolean isPaired = new AtomicBoolean(false); private final long trustedNotificationRef = 0; - private BluetoothNotification<Boolean> userTrustedNotificationsCB = null; + private BTNotification<Boolean> userTrustedNotificationsCB = null; private final AtomicBoolean isTrusted = new AtomicBoolean(false); - private BluetoothNotification<Boolean> userConnectedNotificationsCB = null; + private BTNotification<Boolean> userConnectedNotificationsCB = null; private final AtomicBoolean isConnected = new AtomicBoolean(false); - private BluetoothNotification<Short> userRSSINotificationsCB = null; - private BluetoothNotification<Map<Short, byte[]> > userManufDataNotificationsCB = null; - private BluetoothNotification<Boolean> userServicesResolvedNotificationsCB = null; + private BTNotification<Short> userRSSINotificationsCB = null; + private BTNotification<Map<Short, byte[]> > userManufDataNotificationsCB = null; + private BTNotification<Boolean> userServicesResolvedNotificationsCB = null; private final AtomicBoolean servicesResolved = new AtomicBoolean(false); private short appearance = 0; final AdapterStatusListener statusListener = new AdapterStatusListener() { @Override - public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) { + public void deviceUpdated(final BTDevice device, final EIRDataTypeSet updateMask, final long timestamp) { final boolean nameUpdated = updateMask.isSet( EIRDataTypeSet.DataType.NAME ); final boolean rssiUpdated = updateMask.isSet( EIRDataTypeSet.DataType.RSSI ); final boolean mdUpdated = updateMask.isSet( EIRDataTypeSet.DataType.MANUF_DATA ); @@ -119,7 +119,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } } @Override - public void deviceConnected(final BluetoothDevice device, final short handle, final long timestamp) { + public void deviceConnected(final BTDevice device, final short handle, final long timestamp) { if( isConnected.compareAndSet(false, true) ) { synchronized(userCallbackLock) { if( null != userConnectedNotificationsCB ) { @@ -134,7 +134,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } } @Override - public void deviceDisconnected(final BluetoothDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { + public void deviceDisconnected(final BTDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { devicePaired(false); if( isConnected.compareAndSet(true, false) ) { @@ -153,7 +153,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } }; - final private BluetoothNotification<Boolean> blockedNotificationsCB = new BluetoothNotification<Boolean>() { + final private BTNotification<Boolean> blockedNotificationsCB = new BTNotification<Boolean>() { @Override public void run(final Boolean value) { if( DEBUG ) { @@ -182,14 +182,14 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } } } - final private BluetoothNotification<Boolean> pairedNotificationsCB = new BluetoothNotification<Boolean>() { + final private BTNotification<Boolean> pairedNotificationsCB = new BTNotification<Boolean>() { @Override public void run(final Boolean value) { devicePaired( value.booleanValue() ); } }; - final private BluetoothNotification<Boolean> trustedNotificationsCB = new BluetoothNotification<Boolean>() { + final private BTNotification<Boolean> trustedNotificationsCB = new BTNotification<Boolean>() { @Override public void run(final Boolean value) { if( DEBUG ) { @@ -298,17 +298,17 @@ public class DBTDevice extends DBTObject implements BluetoothDevice private native String getNameImpl(); @Override - public BluetoothType getBluetoothType() { return class_type(); } + public BTType getBluetoothType() { return class_type(); } - static BluetoothType class_type() { return BluetoothType.DEVICE; } + static BTType class_type() { return BTType.DEVICE; } @Override - public BluetoothGattService find(final String UUID, final long timeoutMS) { - return (DBTGattService) findInCache(UUID, BluetoothType.GATT_SERVICE); + public BTGattService find(final String UUID, final long timeoutMS) { + return (DBTGattService) findInCache(UUID, BTType.GATT_SERVICE); } @Override - public BluetoothGattService find(final String UUID) { + public BTGattService find(final String UUID) { return find(UUID, 0); } @@ -318,7 +318,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice public int getBluetoothClass() { throw new UnsupportedOperationException(); } // FIXME @Override - public final BluetoothDevice clone() { throw new UnsupportedOperationException(); } // FIXME + public final BTDevice clone() { throw new UnsupportedOperationException(); } // FIXME @Override public final SMPKeyMask getAvailableSMPKeys(final boolean responder) { @@ -351,7 +351,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice private final native void getSignatureResolvingKeyInfoImpl(final boolean responder, final byte[] sink); @Override - public final boolean pair() throws BluetoothException { + public final boolean pair() throws BTException { return false; } @@ -412,7 +412,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice public HCIStatusCode setPairingPasskey(final int passkey) { return HCIStatusCode.get( setPairingPasskeyImpl(passkey) ); } - private native byte setPairingPasskeyImpl(final int passkey) throws BluetoothException; + private native byte setPairingPasskeyImpl(final int passkey) throws BTException; @Override public HCIStatusCode setPairingNumericComparison(final boolean equal) { @@ -433,7 +433,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice private native byte getPairingStateImpl(); @Override - public final boolean cancelPairing() throws BluetoothException { + public final boolean cancelPairing() throws BTException { // FIXME: Not supporter (yet) return false; } @@ -451,7 +451,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice /* DBT method calls: Connection */ @Override - public final void enableConnectedNotifications(final BluetoothNotification<Boolean> callback) { + public final void enableConnectedNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userConnectedNotificationsCB = callback; } @@ -470,22 +470,22 @@ public class DBTDevice extends DBTObject implements BluetoothDevice public final short getConnectionHandle() { return hciConnHandle; } @Override - public final HCIStatusCode disconnect() throws BluetoothException { + public final HCIStatusCode disconnect() throws BTException { if( isConnected.get() ) { return HCIStatusCode.get( disconnectImpl() ); // event callbacks will be generated by implementation } return HCIStatusCode.CONNECTION_TERMINATED_BY_LOCAL_HOST; } - private native byte disconnectImpl() throws BluetoothException; + private native byte disconnectImpl() throws BTException; @Override - public final HCIStatusCode connect() throws BluetoothException { + public final HCIStatusCode connect() throws BTException { if( !isConnected.get() ) { return HCIStatusCode.get( connectDefaultImpl() ); // event callbacks will be generated by implementation } return HCIStatusCode.CONNECTION_ALREADY_EXISTS; } - private native byte connectDefaultImpl() throws BluetoothException; + private native byte connectDefaultImpl() throws BTException; @Override public HCIStatusCode connectLE(final short le_scan_interval, final short le_scan_window, @@ -510,7 +510,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice /* DBT Java callbacks */ @Override - public final void enableRSSINotifications(final BluetoothNotification<Short> callback) { + public final void enableRSSINotifications(final BTNotification<Short> callback) { synchronized(userCallbackLock) { userRSSINotificationsCB = callback; } @@ -525,7 +525,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice @Override - public final void enableManufacturerDataNotifications(final BluetoothNotification<Map<Short, byte[]> > callback) { + public final void enableManufacturerDataNotifications(final BTNotification<Map<Short, byte[]> > callback) { synchronized(userCallbackLock) { userManufDataNotificationsCB = callback; } @@ -540,7 +540,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice @Override - public final void enableServicesResolvedNotifications(final BluetoothNotification<Boolean> callback) { + public final void enableServicesResolvedNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userServicesResolvedNotificationsCB = callback; } @@ -560,7 +560,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice public short getAppearance() { return appearance; } @Override - public void enableBlockedNotifications(final BluetoothNotification<Boolean> callback) { + public void enableBlockedNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userBlockedNotificationsCB = callback; } @@ -580,8 +580,8 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } @Override - public void enableServiceDataNotifications(final BluetoothNotification<Map<String, byte[]> > callback) { - // FIXME: Isn't this GATTCharacteristic data notification/indication? Then map it or drop! + public void enableServiceDataNotifications(final BTNotification<Map<String, byte[]> > callback) { + // FIXME: Isn't this BTGattChar data notification/indication? Then map it or drop! } @Override @@ -595,7 +595,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } @Override - public void enablePairedNotifications(final BluetoothNotification<Boolean> callback) { + public void enablePairedNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userPairedNotificationsCB = callback; } @@ -612,7 +612,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice public final boolean getPaired() { return isPaired.get(); } @Override - public void enableTrustedNotifications(final BluetoothNotification<Boolean> callback) { + public void enableTrustedNotifications(final BTNotification<Boolean> callback) { synchronized(userCallbackLock) { userTrustedNotificationsCB = callback; } @@ -650,12 +650,12 @@ public class DBTDevice extends DBTObject implements BluetoothDevice private native String toStringImpl(); - private native void enableBlockedNotificationsImpl(BluetoothNotification<Boolean> callback); + private native void enableBlockedNotificationsImpl(BTNotification<Boolean> callback); private native void disableBlockedNotificationsImpl(); private native void setBlockedImpl(final boolean value); // Note that this is only called natively for unpaired, i.e. paired:=false. Using deviceConnected for paired:=true. - private native void enablePairedNotificationsImpl(BluetoothNotification<Boolean> callback); + private native void enablePairedNotificationsImpl(BTNotification<Boolean> callback); private native void disablePairedNotificationsImpl(); /** @@ -669,28 +669,28 @@ public class DBTDevice extends DBTObject implements BluetoothDevice /* DBT native method calls: */ @Override - public native boolean connectProfile(String arg_UUID) throws BluetoothException; + public native boolean connectProfile(String arg_UUID) throws BTException; @Override - public native boolean disconnectProfile(String arg_UUID) throws BluetoothException; + public native boolean disconnectProfile(String arg_UUID) throws BTException; /** * {@inheritDoc} */ @Override - public final boolean remove() throws BluetoothException { + public final boolean remove() throws BTException { // close: clear java-listener, super.close() // -> DBTNativeDownlink.delete(): deleteNativeJavaObject(..), deleteImpl(..) -> DBTDevice::remove() close(); // return removeImpl(); return true; } - private native boolean removeImpl() throws BluetoothException; + private native boolean removeImpl() throws BTException; @Override - public List<BluetoothGattService> getServices() { + public List<BTGattService> getServices() { try { - final List<BluetoothGattService> services = getServicesImpl(); + final List<BTGattService> services = getServicesImpl(); updateServiceCache(services); return services; } catch (final Throwable t) { @@ -701,7 +701,7 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } return null; } - private native List<BluetoothGattService> getServicesImpl(); + private native List<BTGattService> getServicesImpl(); @Override public boolean pingGATT() { @@ -747,19 +747,19 @@ public class DBTDevice extends DBTObject implements BluetoothDevice protected native void deleteImpl(long nativeInstance); @Override - public boolean addCharacteristicListener(final GATTCharacteristicListener listener) { - return addCharacteristicListener(listener, (DBTGattCharacteristic)listener.getAssociatedCharacteristic()); + public boolean addCharListener(final BTGattCharListener listener) { + return addCharListener(listener, (DBTGattChar)listener.getAssociatedChar()); } - private native boolean addCharacteristicListener(final GATTCharacteristicListener listener, final DBTGattCharacteristic associatedCharacteristic); + private native boolean addCharListener(final BTGattCharListener listener, final DBTGattChar associatedCharacteristic); @Override - public native boolean removeCharacteristicListener(final GATTCharacteristicListener l); + public native boolean removeCharListener(final BTGattCharListener l); @Override - public native int removeAllAssociatedCharacteristicListener(final BluetoothGattCharacteristic associatedCharacteristic); + public native int removeAllAssociatedCharListener(final BTGattChar associatedCharacteristic); @Override - public native int removeAllCharacteristicListener(); + public native int removeAllCharListener(); /* local functionality */ @@ -771,11 +771,11 @@ public class DBTDevice extends DBTObject implements BluetoothDevice } } } - private void updateServiceCache(final List<BluetoothGattService> services) { + private void updateServiceCache(final List<BTGattService> services) { synchronized(serviceCache) { clearServiceCache(); if( null != services ) { - for(final BluetoothGattService service : services) { + for(final BTGattService service : services) { serviceCache.add( new WeakReference<DBTGattService>( (DBTGattService)service ) ); } } @@ -805,29 +805,29 @@ public class DBTDevice extends DBTObject implements BluetoothDevice * The returned {@link DBTObject} may be of type * <ul> * <li>{@link DBTGattService}</li> - * <li>{@link DBTGattCharacteristic}</li> - * <li>{@link DBTGattDescriptor}</li> + * <li>{@link DBTGattChar}</li> + * <li>{@link DBTGattDesc}</li> * </ul> - * or alternatively in {@link BluetoothObject} space + * or alternatively in {@link BTObject} space * <ul> - * <li>{@link BluetoothType#GATT_SERVICE} -> {@link BluetoothGattService}</li> - * <li>{@link BluetoothType#GATT_CHARACTERISTIC} -> {@link BluetoothGattCharacteristic}</li> - * <li>{@link BluetoothType#GATT_DESCRIPTOR} -> {@link BluetoothGattDescriptor}</li> + * <li>{@link BTType#GATT_SERVICE} -> {@link BTGattService}</li> + * <li>{@link BTType#GATT_CHARACTERISTIC} -> {@link BTGattChar}</li> + * <li>{@link BTType#GATT_DESCRIPTOR} -> {@link BTGattDesc}</li> * </ul> * </p> - * @param uuid UUID of the desired {@link BluetoothType#GATT_SERVICE service}, - * {@link BluetoothType#GATT_CHARACTERISTIC characteristic} or {@link BluetoothType#GATT_DESCRIPTOR descriptor} to be found. + * @param uuid UUID of the desired {@link BTType#GATT_SERVICE service}, + * {@link BTType#GATT_CHARACTERISTIC characteristic} or {@link BTType#GATT_DESCRIPTOR descriptor} to be found. * Maybe {@code null}, in which case the first object of the desired type is being returned - if existing. * @param type specify the type of the object to be found, either - * {@link BluetoothType#GATT_SERVICE service}, {@link BluetoothType#GATT_CHARACTERISTIC characteristic} - * or {@link BluetoothType#GATT_DESCRIPTOR descriptor}. - * {@link BluetoothType#NONE none} means anything. + * {@link BTType#GATT_SERVICE service}, {@link BTType#GATT_CHARACTERISTIC characteristic} + * or {@link BTType#GATT_DESCRIPTOR descriptor}. + * {@link BTType#NONE none} means anything. */ - /* pp */ DBTObject findInCache(final String uuid, final BluetoothType type) { - final boolean anyType = BluetoothType.NONE == type; - final boolean serviceType = BluetoothType.GATT_SERVICE == type; - final boolean charType = BluetoothType.GATT_CHARACTERISTIC== type; - final boolean descType = BluetoothType.GATT_DESCRIPTOR == type; + /* pp */ DBTObject findInCache(final String uuid, final BTType type) { + final boolean anyType = BTType.NONE == type; + final boolean serviceType = BTType.GATT_SERVICE == type; + final boolean charType = BTType.GATT_CHARACTERISTIC== type; + final boolean descType = BTType.GATT_DESCRIPTOR == type; if( !anyType && !serviceType && !charType && !descType ) { return null; diff --git a/java/jau/direct_bt/DBTEvent.java b/java/jau/direct_bt/DBTEvent.java index de27dabe..bd176944 100644 --- a/java/jau/direct_bt/DBTEvent.java +++ b/java/jau/direct_bt/DBTEvent.java @@ -25,16 +25,16 @@ package jau.direct_bt; -import org.direct_bt.BluetoothCallback; -import org.direct_bt.BluetoothEvent; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTCallback; +import org.direct_bt.BTEvent; +import org.direct_bt.BTType; -public class DBTEvent implements BluetoothEvent +public class DBTEvent implements BTEvent { private long nativeInstance; @Override - public native BluetoothType getType(); + public native BTType getType(); @Override public native String getName(); @Override @@ -44,12 +44,12 @@ public class DBTEvent implements BluetoothEvent @Override public native boolean hasCallback(); - private native void init(BluetoothType type, String name, String identifier, - DBTObject parent, BluetoothCallback cb, Object data); + private native void init(BTType type, String name, String identifier, + DBTObject parent, BTCallback cb, Object data); private native void delete(); - public DBTEvent(final BluetoothType type, final String name, final String identifier, - final DBTObject parent, final BluetoothCallback cb, final Object data) + public DBTEvent(final BTType type, final String name, final String identifier, + final DBTObject parent, final BTCallback cb, final Object data) { init(type, name, identifier, parent, cb, data); } diff --git a/java/jau/direct_bt/DBTGattCharacteristic.java b/java/jau/direct_bt/DBTGattChar.java index 5ec0940f..86863e5c 100644 --- a/java/jau/direct_bt/DBTGattCharacteristic.java +++ b/java/jau/direct_bt/DBTGattChar.java @@ -29,18 +29,18 @@ import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.List; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothFactory; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; -import org.direct_bt.BluetoothUtils; -import org.direct_bt.GATTCharacteristicListener; - -public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCharacteristic +import org.direct_bt.BTException; +import org.direct_bt.BTFactory; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTGattService; +import org.direct_bt.BTNotification; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; +import org.direct_bt.BTUtils; +import org.direct_bt.BTGattCharListener; + +public class DBTGattChar extends DBTObject implements BTGattChar { private static final boolean DEBUG = DBTManager.DEBUG; @@ -74,7 +74,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha /* Optional Client Characteristic Configuration index within descriptorList */ private final int clientCharacteristicsConfigIndex; - /* pp */ final List<BluetoothGattDescriptor> descriptorList; + /* pp */ final List<BTGattDesc> descriptorList; private final boolean supCharValueCacheNotification; @@ -82,7 +82,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha boolean enabledIndicateState = false; private byte[] cachedValue = null; - private BluetoothNotification<byte[]> valueNotificationCB = null; + private BTNotification<byte[]> valueNotificationCB = null; private boolean updateCachedValue(final byte[] value, final boolean notify) { boolean valueChanged = false; @@ -101,7 +101,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha return valueChanged; } - /* pp */ DBTGattCharacteristic(final long nativeInstance, final DBTGattService service, + /* pp */ DBTGattChar(final long nativeInstance, final DBTGattService service, final short handle, final String[] properties, final boolean hasNotify, final boolean hasIndicate, final String value_type_uuid, final short value_handle, @@ -120,19 +120,19 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha this.descriptorList = getDescriptorsImpl(); this.supCharValueCacheNotification = DBTManager.getManager().getSettings().isCharacteristicValueCacheNotificationSupported(); - if( ( BluetoothFactory.DEBUG || supCharValueCacheNotification ) && + if( ( BTFactory.DEBUG || supCharValueCacheNotification ) && ( hasNotify || hasIndicate ) ) { // This characteristicListener serves TinyB 'enableValueNotification(..)' and 'getValue()' (cached value) // backwards compatibility only! - final GATTCharacteristicListener characteristicListener = new GATTCharacteristicListener(this) { + final BTGattCharListener characteristicListener = new BTGattCharListener(this) { @Override - public void notificationReceived(final BluetoothGattCharacteristic charDecl, final byte[] value, final long timestamp) { - final DBTGattCharacteristic cd = (DBTGattCharacteristic)charDecl; - if( !cd.equals(DBTGattCharacteristic.this) ) { + public void notificationReceived(final BTGattChar charDecl, final byte[] value, final long timestamp) { + final DBTGattChar cd = (DBTGattChar)charDecl; + if( !cd.equals(DBTGattChar.this) ) { throw new InternalError("Filtered GATTCharacteristicListener.notificationReceived: Wrong Characteristic: Got "+charDecl+ - ", expected "+DBTGattCharacteristic.this.toString()); + ", expected "+DBTGattChar.this.toString()); } final boolean valueChanged; if( supCharValueCacheNotification ) { @@ -142,16 +142,16 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha } if( DEBUG ) { System.err.println("GATTCharacteristicListener.notificationReceived: "+charDecl+ - ", value[changed "+valueChanged+", len "+value.length+": "+BluetoothUtils.bytesHexString(value, 0, -1, true, true, true)+"]"); + ", value[changed "+valueChanged+", len "+value.length+": "+BTUtils.bytesHexString(value, 0, -1, true, true, true)+"]"); } } @Override - public void indicationReceived(final BluetoothGattCharacteristic charDecl, final byte[] value, final long timestamp, + public void indicationReceived(final BTGattChar charDecl, final byte[] value, final long timestamp, final boolean confirmationSent) { - final DBTGattCharacteristic cd = (DBTGattCharacteristic)charDecl; - if( !cd.equals(DBTGattCharacteristic.this) ) { + final DBTGattChar cd = (DBTGattChar)charDecl; + if( !cd.equals(DBTGattChar.this) ) { throw new InternalError("Filtered GATTCharacteristicListener.indicationReceived: Wrong Characteristic: Got "+charDecl+ - ", expected "+DBTGattCharacteristic.this.toString()); + ", expected "+DBTGattChar.this.toString()); } final boolean valueChanged; if( supCharValueCacheNotification ) { @@ -161,7 +161,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha } if( DEBUG ) { System.err.println("GATTCharacteristicListener.indicationReceived: "+charDecl+ - ", value[changed "+valueChanged+", len "+value.length+": "+BluetoothUtils.bytesHexString(value, 0, -1, true, true, true)+ + ", value[changed "+valueChanged+", len "+value.length+": "+BTUtils.bytesHexString(value, 0, -1, true, true, true)+ "], confirmationSent "+confirmationSent); } } @@ -182,10 +182,10 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha @Override public boolean equals(final Object obj) { - if (obj == null || !(obj instanceof DBTGattCharacteristic)) { + if (obj == null || !(obj instanceof DBTGattChar)) { return false; } - final DBTGattCharacteristic other = (DBTGattCharacteristic)obj; + final DBTGattChar other = (DBTGattChar)obj; return handle == other.handle; /** unique attribute handles */ } @@ -193,29 +193,29 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha public String getUUID() { return value_type_uuid; } @Override - public BluetoothType getBluetoothType() { return class_type(); } + public BTType getBluetoothType() { return class_type(); } - static BluetoothType class_type() { return BluetoothType.GATT_CHARACTERISTIC; } + static BTType class_type() { return BTType.GATT_CHARACTERISTIC; } @Override - public BluetoothGattCharacteristic clone() + public BTGattChar clone() { throw new UnsupportedOperationException(); } // FIXME @Override - public BluetoothGattDescriptor find(final String UUID, final long timeoutMS) { + public BTGattDesc find(final String UUID, final long timeoutMS) { if( !checkServiceCache() ) { return null; } - return (DBTGattDescriptor) findInCache(UUID, BluetoothType.GATT_DESCRIPTOR); + return (DBTGattDesc) findInCache(UUID, BTType.GATT_DESCRIPTOR); } @Override - public BluetoothGattDescriptor find(final String UUID) { + public BTGattDesc find(final String UUID) { return find(UUID, 0); } @Override - public final BluetoothGattService getService() { return wbr_service.get(); } + public final BTGattService getService() { return wbr_service.get(); } @Override public final String[] getFlags() { return properties; } @@ -224,7 +224,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha public final byte[] getValue() { return cachedValue; } @Override - public final byte[] readValue() throws BluetoothException { + public final byte[] readValue() throws BTException { if( supCharValueCacheNotification ) { final byte[] value = readValueImpl(); updateCachedValue(value, true); @@ -235,7 +235,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha } @Override - public final boolean writeValue(final byte[] value, final boolean withResponse) throws BluetoothException { + public final boolean writeValue(final byte[] value, final boolean withResponse) throws BTException { final boolean res = writeValueImpl(value, withResponse); if( supCharValueCacheNotification && res ) { updateCachedValue(value, false); @@ -244,7 +244,7 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha } @Override - public final List<BluetoothGattDescriptor> getDescriptors() { return descriptorList; } + public final List<BTGattDesc> getDescriptors() { return descriptorList; } @Override public final synchronized boolean configNotificationIndication(final boolean enableNotification, final boolean enableIndication, final boolean enabledState[/*2*/]) @@ -302,24 +302,24 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha } @Override - public final boolean addCharacteristicListener(final GATTCharacteristicListener listener) { - return getService().getDevice().addCharacteristicListener(listener); + public final boolean addCharacteristicListener(final BTGattCharListener listener) { + return getService().getDevice().addCharListener(listener); } @Override - public final boolean addCharacteristicListener(final GATTCharacteristicListener listener, final boolean enabledState[/*2*/]) { + public final boolean addCharacteristicListener(final BTGattCharListener listener, final boolean enabledState[/*2*/]) { if( !enableNotificationOrIndication(enabledState) ) { return false; } - return getService().getDevice().addCharacteristicListener(listener); + return getService().getDevice().addCharListener(listener); } @Override - public final boolean removeCharacteristicListener(final GATTCharacteristicListener l, final boolean disableIndicationNotification) { + public final boolean removeCharacteristicListener(final BTGattCharListener l, final boolean disableIndicationNotification) { if( disableIndicationNotification ) { configNotificationIndication(false /* enableNotification */, false /* enableIndication */, new boolean[2]); } - return getService().getDevice().removeCharacteristicListener(l); + return getService().getDevice().removeCharListener(l); } @Override @@ -328,11 +328,11 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha configNotificationIndication(false /* enableNotification */, false /* enableIndication */, new boolean[2]); } valueNotificationCB = null; - return getService().getDevice().removeAllAssociatedCharacteristicListener(this); + return getService().getDevice().removeAllAssociatedCharListener(this); } @Override - public final synchronized void enableValueNotifications(final BluetoothNotification<byte[]> callback) { + public final synchronized void enableValueNotifications(final BTNotification<byte[]> callback) { if( !configNotificationIndication(true /* enableNotification */, true /* enableIndication */, new boolean[2]) ) { valueNotificationCB = null; } else { @@ -382,11 +382,11 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha private native String toStringImpl(); - private native byte[] readValueImpl() throws BluetoothException; + private native byte[] readValueImpl() throws BTException; - private native boolean writeValueImpl(byte[] argValue, boolean withResponse) throws BluetoothException; + private native boolean writeValueImpl(byte[] argValue, boolean withResponse) throws BTException; - private native List<BluetoothGattDescriptor> getDescriptorsImpl(); + private native List<BTGattDesc> getDescriptorsImpl(); @Override protected native void deleteImpl(long nativeInstance); @@ -408,29 +408,29 @@ public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCha * <p> * The returned {@link DBTObject} may be of type * <ul> - * <li>{@link DBTGattDescriptor}</li> + * <li>{@link DBTGattDesc}</li> * </ul> - * or alternatively in {@link BluetoothObject} space + * or alternatively in {@link BTObject} space * <ul> - * <li>{@link BluetoothType#GATT_DESCRIPTOR} -> {@link BluetoothGattDescriptor}</li> + * <li>{@link BTType#GATT_DESCRIPTOR} -> {@link BTGattDesc}</li> * </ul> * </p> * @param uuid UUID of the desired - * {@link BluetoothType#GATT_DESCRIPTOR descriptor} to be found. + * {@link BTType#GATT_DESCRIPTOR descriptor} to be found. * Maybe {@code null}, in which case the first object of the desired type is being returned - if existing. - * @param type specify the type of the object to be found, a {@link BluetoothType#GATT_DESCRIPTOR descriptor}. - * {@link BluetoothType#NONE none} means anything. + * @param type specify the type of the object to be found, a {@link BTType#GATT_DESCRIPTOR descriptor}. + * {@link BTType#NONE none} means anything. */ - /* pp */ DBTObject findInCache(final String uuid, final BluetoothType type) { - final boolean anyType = BluetoothType.NONE == type; - final boolean descType = BluetoothType.GATT_DESCRIPTOR == type; + /* pp */ DBTObject findInCache(final String uuid, final BTType type) { + final boolean anyType = BTType.NONE == type; + final boolean descType = BTType.GATT_DESCRIPTOR == type; if( !anyType && !descType ) { return null; } final int size = descriptorList.size(); for(int i = 0; i < size; i++ ) { - final DBTGattDescriptor descr = (DBTGattDescriptor) descriptorList.get(i); + final DBTGattDesc descr = (DBTGattDesc) descriptorList.get(i); if( null == uuid || descr.getUUID().equals(uuid) ) { return descr; } diff --git a/java/jau/direct_bt/DBTGattDescriptor.java b/java/jau/direct_bt/DBTGattDesc.java index f375cc38..7c080e39 100644 --- a/java/jau/direct_bt/DBTGattDescriptor.java +++ b/java/jau/direct_bt/DBTGattDesc.java @@ -28,15 +28,15 @@ package jau.direct_bt; import java.lang.ref.WeakReference; import java.util.Arrays; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTException; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTNotification; +import org.direct_bt.BTType; -public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescriptor +public class DBTGattDesc extends DBTObject implements BTGattDesc { /** Descriptor's characteristic weak back-reference */ - final WeakReference<DBTGattCharacteristic> wbr_characteristic; + final WeakReference<DBTGattChar> wbr_characteristic; /** Type of Descriptor */ private final String type_uuid; @@ -50,7 +50,7 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip private final short handle; private byte[] cachedValue; - private BluetoothNotification<byte[]> valueNotificationCB = null; + private BTNotification<byte[]> valueNotificationCB = null; private boolean updateCachedValue(final byte[] value, final boolean notify) { boolean valueChanged = false; @@ -69,11 +69,11 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip return valueChanged; } - /* pp */ DBTGattDescriptor(final long nativeInstance, final DBTGattCharacteristic characteristic, + /* pp */ DBTGattDesc(final long nativeInstance, final DBTGattChar characteristic, final String type_uuid, final short handle, final byte[] value) { super(nativeInstance, handle /* hash */); - this.wbr_characteristic = new WeakReference<DBTGattCharacteristic>(characteristic); + this.wbr_characteristic = new WeakReference<DBTGattChar>(characteristic); this.type_uuid = type_uuid; this.handle = handle; this.cachedValue = value; @@ -91,10 +91,10 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip @Override public boolean equals(final Object obj) { - if (obj == null || !(obj instanceof DBTGattDescriptor)) { + if (obj == null || !(obj instanceof DBTGattDesc)) { return false; } - final DBTGattDescriptor other = (DBTGattDescriptor)obj; + final DBTGattDesc other = (DBTGattDesc)obj; return handle == other.handle; /** unique attribute handles */ } @@ -102,16 +102,16 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip public String getUUID() { return type_uuid; } @Override - public BluetoothType getBluetoothType() { return class_type(); } + public BTType getBluetoothType() { return class_type(); } - static BluetoothType class_type() { return BluetoothType.GATT_DESCRIPTOR; } + static BTType class_type() { return BTType.GATT_DESCRIPTOR; } @Override - public final BluetoothGattDescriptor clone() + public final BTGattDesc clone() { throw new UnsupportedOperationException(); } // FIXME @Override - public final DBTGattCharacteristic getCharacteristic() { return wbr_characteristic.get(); } + public final DBTGattChar getCharacteristic() { return wbr_characteristic.get(); } @Override public final byte[] getValue() { return cachedValue; } @@ -124,7 +124,7 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip } @Override - public final boolean writeValue(final byte[] value) throws BluetoothException { + public final boolean writeValue(final byte[] value) throws BTException { final boolean res = writeValueImpl(value); if( res ) { updateCachedValue(value, false); @@ -133,7 +133,7 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip } @Override - public final synchronized void enableValueNotifications(final BluetoothNotification<byte[]> callback) { + public final synchronized void enableValueNotifications(final BTNotification<byte[]> callback) { valueNotificationCB = callback; } @@ -164,7 +164,7 @@ public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescrip private native byte[] readValueImpl(); - private native boolean writeValueImpl(byte[] argValue) throws BluetoothException; + private native boolean writeValueImpl(byte[] argValue) throws BTException; @Override protected native void deleteImpl(long nativeInstance); diff --git a/java/jau/direct_bt/DBTGattService.java b/java/jau/direct_bt/DBTGattService.java index f836b920..4e65ba8b 100644 --- a/java/jau/direct_bt/DBTGattService.java +++ b/java/jau/direct_bt/DBTGattService.java @@ -28,14 +28,14 @@ package jau.direct_bt; import java.lang.ref.WeakReference; import java.util.List; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; - -public class DBTGattService extends DBTObject implements BluetoothGattService +import org.direct_bt.BTDevice; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTGattService; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; + +public class DBTGattService extends DBTObject implements BTGattService { /** Service's device weak back-reference */ final WeakReference<DBTDevice> wbr_device; @@ -44,7 +44,7 @@ public class DBTGattService extends DBTObject implements BluetoothGattService private final String type_uuid; private final short handleStart; private final short handleEnd; - /* pp */ final List<BluetoothGattCharacteristic> characteristicList; + /* pp */ final List<BTGattChar> charList; /* pp */ DBTGattService(final long nativeInstance, final DBTDevice device, final boolean isPrimary, final String type_uuid, final short handleStart, final short handleEnd) @@ -55,7 +55,7 @@ public class DBTGattService extends DBTObject implements BluetoothGattService this.type_uuid = type_uuid; this.handleStart = handleStart; this.handleEnd = handleEnd; - this.characteristicList = getCharacteristicsImpl(); + this.charList = getCharsImpl(); } @Override @@ -72,35 +72,35 @@ public class DBTGattService extends DBTObject implements BluetoothGattService public String getUUID() { return type_uuid; } @Override - public BluetoothType getBluetoothType() { return class_type(); } + public BTType getBluetoothType() { return class_type(); } - static BluetoothType class_type() { return BluetoothType.GATT_SERVICE; } + static BTType class_type() { return BTType.GATT_SERVICE; } @Override - public final BluetoothGattService clone() + public final BTGattService clone() { throw new UnsupportedOperationException(); } // FIXME @Override - public BluetoothGattCharacteristic find(final String UUID, final long timeoutMS) { + public BTGattChar find(final String UUID, final long timeoutMS) { if( !checkServiceCache() ) { return null; } - return (DBTGattCharacteristic) findInCache(UUID, BluetoothType.GATT_CHARACTERISTIC); + return (DBTGattChar) findInCache(UUID, BTType.GATT_CHARACTERISTIC); } @Override - public BluetoothGattCharacteristic find(final String UUID) { + public BTGattChar find(final String UUID) { return find(UUID, 0); } @Override - public final BluetoothDevice getDevice() { return wbr_device.get(); } + public final BTDevice getDevice() { return wbr_device.get(); } @Override public final boolean getPrimary() { return isPrimary; } @Override - public final List<BluetoothGattCharacteristic> getCharacteristics() { return characteristicList; } + public final List<BTGattChar> getChars() { return charList; } /** * Returns the service start handle. @@ -130,7 +130,7 @@ public class DBTGattService extends DBTObject implements BluetoothGattService private native String toStringImpl(); - private native List<BluetoothGattCharacteristic> getCharacteristicsImpl(); + private native List<BTGattChar> getCharsImpl(); @Override protected native void deleteImpl(long nativeInstance); @@ -148,34 +148,34 @@ public class DBTGattService extends DBTObject implements BluetoothGattService * <p> * The returned {@link DBTObject} may be of type * <ul> - * <li>{@link DBTGattCharacteristic}</li> - * <li>{@link DBTGattDescriptor}</li> + * <li>{@link DBTGattChar}</li> + * <li>{@link DBTGattDesc}</li> * </ul> - * or alternatively in {@link BluetoothObject} space + * or alternatively in {@link BTObject} space * <ul> - * <li>{@link BluetoothType#GATT_CHARACTERISTIC} -> {@link BluetoothGattCharacteristic}</li> - * <li>{@link BluetoothType#GATT_DESCRIPTOR} -> {@link BluetoothGattDescriptor}</li> + * <li>{@link BTType#GATT_CHARACTERISTIC} -> {@link BTGattChar}</li> + * <li>{@link BTType#GATT_DESCRIPTOR} -> {@link BTGattDesc}</li> * </ul> * </p> * @param uuid UUID of the desired - * {@link BluetoothType#GATT_CHARACTERISTIC characteristic} or {@link BluetoothType#GATT_DESCRIPTOR descriptor} to be found. + * {@link BTType#GATT_CHARACTERISTIC characteristic} or {@link BTType#GATT_DESCRIPTOR descriptor} to be found. * Maybe {@code null}, in which case the first object of the desired type is being returned - if existing. * @param type specify the type of the object to be found, either - * {@link BluetoothType#GATT_CHARACTERISTIC characteristic} - * or {@link BluetoothType#GATT_DESCRIPTOR descriptor}. - * {@link BluetoothType#NONE none} means anything. + * {@link BTType#GATT_CHARACTERISTIC characteristic} + * or {@link BTType#GATT_DESCRIPTOR descriptor}. + * {@link BTType#NONE none} means anything. */ - /* pp */ DBTObject findInCache(final String uuid, final BluetoothType type) { - final boolean anyType = BluetoothType.NONE == type; - final boolean charType = BluetoothType.GATT_CHARACTERISTIC== type; - final boolean descType = BluetoothType.GATT_DESCRIPTOR == type; + /* pp */ DBTObject findInCache(final String uuid, final BTType type) { + final boolean anyType = BTType.NONE == type; + final boolean charType = BTType.GATT_CHARACTERISTIC== type; + final boolean descType = BTType.GATT_DESCRIPTOR == type; if( !anyType && !charType && !descType ) { return null; } - final int characteristicSize = characteristicList.size(); + final int characteristicSize = charList.size(); for(int charIdx = 0; charIdx < characteristicSize; charIdx++ ) { - final DBTGattCharacteristic characteristic = (DBTGattCharacteristic) characteristicList.get(charIdx); + final DBTGattChar characteristic = (DBTGattChar) charList.get(charIdx); if( ( anyType || charType ) && ( null == uuid || characteristic.getUUID().equals(uuid) ) ) { return characteristic; } diff --git a/java/jau/direct_bt/DBTManager.java b/java/jau/direct_bt/DBTManager.java index 7ae148e7..ecebbed2 100644 --- a/java/jau/direct_bt/DBTManager.java +++ b/java/jau/direct_bt/DBTManager.java @@ -34,22 +34,22 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; import java.util.function.Predicate; -import org.direct_bt.BluetoothAdapter; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothFactory; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTAdapter; +import org.direct_bt.BTDevice; +import org.direct_bt.BTException; +import org.direct_bt.BTFactory; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTGattService; +import org.direct_bt.BTManager; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; import org.direct_bt.HCIStatusCode; -public class DBTManager implements BluetoothManager +public class DBTManager implements BTManager { - protected static final boolean DEBUG = BluetoothFactory.DEBUG; - protected static final boolean VERBOSE = BluetoothFactory.VERBOSE; + protected static final boolean DEBUG = BTFactory.DEBUG; + protected static final boolean VERBOSE = BTFactory.VERBOSE; private static volatile boolean isJVMShuttingDown = false; private static final List<Runnable> userShutdownHooks = new ArrayList<Runnable>(); @@ -96,7 +96,7 @@ public class DBTManager implements BluetoothManager } try { - final BluetoothManager mgmt = getManager(); + final BTManager mgmt = getManager(); mgmt.shutdown(); } catch(final Throwable t) { System.err.println("DBTManager.shutdown: Caught "+t.getClass().getName()+" during DBTManager.shutdown()"); @@ -152,7 +152,7 @@ public class DBTManager implements BluetoothManager public static void setUnifyUUID128Bit(final boolean v) { unifyUUID128Bit=v; } private long nativeInstance; - private final List<BluetoothAdapter> adapters = new CopyOnWriteArrayList<BluetoothAdapter>(); + private final List<BTAdapter> adapters = new CopyOnWriteArrayList<BTAdapter>(); private final List<ChangedAdapterSetListener> changedAdapterSetListenerList = new CopyOnWriteArrayList<ChangedAdapterSetListener>(); private final Settings settings; @@ -160,20 +160,20 @@ public class DBTManager implements BluetoothManager @Override public final Settings getSettings() { return settings; } - public BluetoothType getBluetoothType() { return BluetoothType.NONE; } + public BTType getBluetoothType() { return BTType.NONE; } @Override - public DBTObject find(final BluetoothType type, final String name, final String identifier, final BluetoothObject parent, final long timeoutMS) { + public DBTObject find(final BTType type, final String name, final String identifier, final BTObject parent, final long timeoutMS) { return findInCache((DBTObject)parent, type, name, identifier); } @Override - public DBTObject find(final BluetoothType type, final String name, final String identifier, final BluetoothObject parent) { + public DBTObject find(final BTType type, final String name, final String identifier, final BTObject parent) { return find(type, name, identifier, parent, 0); } @Override - public <T extends BluetoothObject> T find(final String name, final String identifier, final BluetoothObject parent, final long timeoutMS) { + public <T extends BTObject> T find(final String name, final String identifier, final BTObject parent, final long timeoutMS) { // Due to generic type erasure, we cannot determine the matching BluetoothType for the return parameter, // hence this orig TinyB API method is rather misleading than useful. throw new UnsupportedOperationException("Generic return type 'find' won't be implemented."); @@ -181,7 +181,7 @@ public class DBTManager implements BluetoothManager } @Override - public <T extends BluetoothObject> T find(final String name, final String identifier, final BluetoothObject parent) { + public <T extends BTObject> T find(final String name, final String identifier, final BTObject parent) { // Due to generic type erasure, we cannot determine the matching BluetoothType for the return parameter, // hence this orig TinyB API method is rather misleading than useful. throw new UnsupportedOperationException("Generic return type 'find' won't be implemented."); @@ -189,28 +189,28 @@ public class DBTManager implements BluetoothManager } @Override - public BluetoothObject getObject(final BluetoothType type, final String name, - final String identifier, final BluetoothObject parent) { + public BTObject getObject(final BTType type, final String name, + final String identifier, final BTObject parent) { return getObject(type.ordinal(), name, identifier, parent); } - private BluetoothObject getObject(final int type, final String name, final String identifier, final BluetoothObject parent) + private BTObject getObject(final int type, final String name, final String identifier, final BTObject parent) { throw new UnsupportedOperationException(); } // FIXME @Override - public List<BluetoothObject> getObjects(final BluetoothType type, final String name, - final String identifier, final BluetoothObject parent) { + public List<BTObject> getObjects(final BTType type, final String name, + final String identifier, final BTObject parent) { return getObjects(type.ordinal(), name, identifier, parent); } - private List<BluetoothObject> getObjects(final int type, final String name, final String identifier, final BluetoothObject parent) + private List<BTObject> getObjects(final int type, final String name, final String identifier, final BTObject parent) { throw new UnsupportedOperationException(); } // FIXME @Override - public List<BluetoothAdapter> getAdapters() { return new ArrayList<BluetoothAdapter>(adapters); } + public List<BTAdapter> getAdapters() { return new ArrayList<BTAdapter>(adapters); } @Override - public BluetoothAdapter getAdapter(final int dev_id) { - for(final Iterator<BluetoothAdapter> iter = adapters.iterator(); iter.hasNext(); ) { - final BluetoothAdapter a = iter.next(); + public BTAdapter getAdapter(final int dev_id) { + for(final Iterator<BTAdapter> iter = adapters.iterator(); iter.hasNext(); ) { + final BTAdapter a = iter.next(); if( dev_id == a.getDevID() ) { return a; } @@ -219,7 +219,7 @@ public class DBTManager implements BluetoothManager } @Override - public List<BluetoothDevice> getDevices() { return getDefaultAdapter().getDiscoveredDevices(); } + public List<BTDevice> getDevices() { return getDefaultAdapter().getDiscoveredDevices(); } /** * {@inheritDoc} @@ -227,23 +227,23 @@ public class DBTManager implements BluetoothManager * This call could be a quite expensive service query, see below. * </p> * <p> - * This implementation returns all {@link BluetoothGattService} from all {@link BluetoothDevice}s - * from the {@link #getDefaultAdapter()} using {@link BluetoothDevice#getServices()}. + * This implementation returns all {@link BTGattService} from all {@link BTDevice}s + * from the {@link #getDefaultAdapter()} using {@link BTDevice#getServices()}. * </p> * <p> - * This implementation does not {@link BluetoothAdapter#startDiscovery() start} an explicit discovery, - * but previous {@link BluetoothAdapter#getDiscoveredDevices() discovered devices} are being queried. + * This implementation does not {@link BTAdapter#startDiscovery() start} an explicit discovery, + * but previous {@link BTAdapter#getDiscoveredDevices() discovered devices} are being queried. * </p> */ @Override - public List<BluetoothGattService> getServices() { - final List<BluetoothGattService> res = new ArrayList<BluetoothGattService>(); - for(final Iterator<BluetoothAdapter> iterA=adapters.iterator(); iterA.hasNext(); ) { - final BluetoothAdapter adapter = iterA.next(); - final List<BluetoothDevice> devices = adapter.getDiscoveredDevices(); - for(final Iterator<BluetoothDevice> iterD=devices.iterator(); iterD.hasNext(); ) { - final BluetoothDevice device = iterD.next(); - final List<BluetoothGattService> devServices = device.getServices(); + public List<BTGattService> getServices() { + final List<BTGattService> res = new ArrayList<BTGattService>(); + for(final Iterator<BTAdapter> iterA=adapters.iterator(); iterA.hasNext(); ) { + final BTAdapter adapter = iterA.next(); + final List<BTDevice> devices = adapter.getDiscoveredDevices(); + for(final Iterator<BTDevice> iterD=devices.iterator(); iterD.hasNext(); ) { + final BTDevice device = iterD.next(); + final List<BTGattService> devServices = device.getServices(); if( null != devServices ) { res.addAll(devServices); } @@ -253,14 +253,14 @@ public class DBTManager implements BluetoothManager } @Override - public boolean setDefaultAdapter(final BluetoothAdapter adapter) { + public boolean setDefaultAdapter(final BTAdapter adapter) { return false; } @Override - public BluetoothAdapter getDefaultAdapter() { - for(final Iterator<BluetoothAdapter> iter = adapters.iterator(); iter.hasNext(); ) { - final BluetoothAdapter a = iter.next(); + public BTAdapter getDefaultAdapter() { + for(final Iterator<BTAdapter> iter = adapters.iterator(); iter.hasNext(); ) { + final BTAdapter a = iter.next(); if( a.isPowered() ) { return a; } @@ -269,25 +269,25 @@ public class DBTManager implements BluetoothManager } @Override - public boolean startDiscovery() throws BluetoothException { return HCIStatusCode.SUCCESS == startDiscovery(true); } + public boolean startDiscovery() throws BTException { return HCIStatusCode.SUCCESS == startDiscovery(true); } @Override - public HCIStatusCode startDiscovery(final boolean keepAlive) throws BluetoothException { return getDefaultAdapter().startDiscovery(keepAlive); } + public HCIStatusCode startDiscovery(final boolean keepAlive) throws BTException { return getDefaultAdapter().startDiscovery(keepAlive); } @Override - public HCIStatusCode stopDiscovery() throws BluetoothException { return getDefaultAdapter().stopDiscovery(); } + public HCIStatusCode stopDiscovery() throws BTException { return getDefaultAdapter().stopDiscovery(); } @SuppressWarnings("deprecation") @Override - public boolean getDiscovering() throws BluetoothException { return getDefaultAdapter().getDiscovering(); } + public boolean getDiscovering() throws BTException { return getDefaultAdapter().getDiscovering(); } @Override public final void addChangedAdapterSetListener(final ChangedAdapterSetListener l) { changedAdapterSetListenerList.add(l); - adapters.forEach(new Consumer<BluetoothAdapter>() { + adapters.forEach(new Consumer<BTAdapter>() { @Override - public void accept(final BluetoothAdapter adapter) { + public void accept(final BTAdapter adapter) { l.adapterAdded(adapter); } }); @@ -310,8 +310,8 @@ public class DBTManager implements BluetoothManager return count[0]; } - private native List<BluetoothAdapter> getAdapterListImpl(); - private native BluetoothAdapter getAdapterImpl(int dev_id); + private native List<BTAdapter> getAdapterListImpl(); + private native BTAdapter getAdapterImpl(int dev_id); /** * Removal entry for DBTAdapter.close() @@ -334,11 +334,11 @@ public class DBTManager implements BluetoothManager /** callback from native adapter remove */ /* pp */ final void removeAdapterCB(final int dev_id, final int opc_reason) { - final BluetoothAdapter[] removed = { null }; + final BTAdapter[] removed = { null }; final int count[] = { 0 }; - adapters.removeIf(new Predicate<BluetoothAdapter>() { + adapters.removeIf(new Predicate<BTAdapter>() { @Override - public boolean test(final BluetoothAdapter a) { + public boolean test(final BTAdapter a) { if( 0 == count[0] && dev_id == a.getDevID() ) { removed[0] = a; count[0]++; @@ -370,7 +370,7 @@ public class DBTManager implements BluetoothManager } /** callback from native adapter add or POWERED on */ private final void updatedAdapterCB(final int dev_id, final int opc_reason) { - final BluetoothAdapter preInstance = getAdapter(dev_id); + final BTAdapter preInstance = getAdapter(dev_id); if( null != preInstance ) { if( DEBUG ) { System.err.println("DBTManager.updatedAdapterCB[dev_id "+dev_id+", opc 0x"+Integer.toHexString(opc_reason)+ @@ -378,7 +378,7 @@ public class DBTManager implements BluetoothManager } return; } - final BluetoothAdapter newInstance = getAdapterImpl(dev_id); + final BTAdapter newInstance = getAdapterImpl(dev_id); if( null == newInstance ) { if( DEBUG ) { System.err.println("DBTManager.updatedAdapterCB[dev_id "+dev_id+", opc 0x"+Integer.toHexString(opc_reason)+ @@ -401,14 +401,14 @@ public class DBTManager implements BluetoothManager } } - private native void initImpl(final boolean unifyUUID128Bit, final int btMode) throws BluetoothException; + private native void initImpl(final boolean unifyUUID128Bit, final int btMode) throws BTException; private native void deleteImpl(long nativeInstance); private DBTManager() { - initImpl(unifyUUID128Bit, BluetoothFactory.DEFAULT_BTMODE.value); + initImpl(unifyUUID128Bit, BTFactory.DEFAULT_BTMODE.value); try { adapters.addAll(getAdapterListImpl()); - } catch (final BluetoothException be) { + } catch (final BTException be) { be.printStackTrace(); } final boolean supCharValCacheNotify; @@ -440,7 +440,7 @@ public class DBTManager implements BluetoothManager /** Returns an instance of BluetoothManager, to be used instead of constructor. * @return An initialized BluetoothManager instance. */ - public static BluetoothManager getManager() throws RuntimeException, BluetoothException { + public static BTManager getManager() throws RuntimeException, BTException { return LazySingletonHolder.singleton; } /** Initialize-On-Demand Holder Class, similar to C++11's "Magic Statics". */ @@ -455,7 +455,7 @@ public class DBTManager implements BluetoothManager @Override public void shutdown() { - for(final Iterator<BluetoothAdapter> ia= adapters.iterator(); ia.hasNext(); ) { + for(final Iterator<BTAdapter> ia= adapters.iterator(); ia.hasNext(); ) { final DBTAdapter a = (DBTAdapter)ia.next(); a.close(); } @@ -472,33 +472,33 @@ public class DBTManager implements BluetoothManager * <li>{@link DBTAdapter}</li> * <li>{@link DBTDevice}</li> * <li>{@link DBTGattService}</li> - * <li>{@link DBTGattCharacteristic}</li> - * <li>{@link DBTGattDescriptor}</li> + * <li>{@link DBTGattChar}</li> + * <li>{@link DBTGattDesc}</li> * </ul> - * or alternatively in {@link BluetoothObject} space + * or alternatively in {@link BTObject} space * <ul> - * <li>{@link BluetoothType#ADAPTER} -> {@link BluetoothAdapter}</li> - * <li>{@link BluetoothType#DEVICE} -> {@link BluetoothDevice}</li> - * <li>{@link BluetoothType#GATT_SERVICE} -> {@link BluetoothGattService}</li> - * <li>{@link BluetoothType#GATT_CHARACTERISTIC} -> {@link BluetoothGattCharacteristic}</li> - * <li>{@link BluetoothType#GATT_DESCRIPTOR} -> {@link BluetoothGattDescriptor}</li> + * <li>{@link BTType#ADAPTER} -> {@link BTAdapter}</li> + * <li>{@link BTType#DEVICE} -> {@link BTDevice}</li> + * <li>{@link BTType#GATT_SERVICE} -> {@link BTGattService}</li> + * <li>{@link BTType#GATT_CHARACTERISTIC} -> {@link BTGattChar}</li> + * <li>{@link BTType#GATT_DESCRIPTOR} -> {@link BTGattDesc}</li> * </ul> * </p> - * @param name name of the desired {@link BluetoothType#ADAPTER adapter} or {@link BluetoothType#DEVICE device}. + * @param name name of the desired {@link BTType#ADAPTER adapter} or {@link BTType#DEVICE device}. * Maybe {@code null}. - * @param identifier EUI48 address of the desired {@link BluetoothType#ADAPTER adapter} or {@link BluetoothType#DEVICE device} - * or UUID of the desired {@link BluetoothType#GATT_SERVICE service}, - * {@link BluetoothType#GATT_CHARACTERISTIC characteristic} or {@link BluetoothType#GATT_DESCRIPTOR descriptor} to be found. + * @param identifier EUI48 address of the desired {@link BTType#ADAPTER adapter} or {@link BTType#DEVICE device} + * or UUID of the desired {@link BTType#GATT_SERVICE service}, + * {@link BTType#GATT_CHARACTERISTIC characteristic} or {@link BTType#GATT_DESCRIPTOR descriptor} to be found. * Maybe {@code null}, in which case the first object of the desired type is being returned - if existing. * @param type specify the type of the object to be found, either - * {@link BluetoothType#ADAPTER adapter}, {@link BluetoothType#DEVICE device}, - * {@link BluetoothType#GATT_SERVICE service}, {@link BluetoothType#GATT_CHARACTERISTIC characteristic} - * or {@link BluetoothType#GATT_DESCRIPTOR descriptor}. - * {@link BluetoothType#NONE none} means anything. + * {@link BTType#ADAPTER adapter}, {@link BTType#DEVICE device}, + * {@link BTType#GATT_SERVICE service}, {@link BTType#GATT_CHARACTERISTIC characteristic} + * or {@link BTType#GATT_DESCRIPTOR descriptor}. + * {@link BTType#NONE none} means anything. */ - /* pp */ DBTObject findInCache(final String name, final String identifier, final BluetoothType type) { - final boolean anyType = BluetoothType.NONE == type; - final boolean adapterType = BluetoothType.ADAPTER == type; + /* pp */ DBTObject findInCache(final String name, final String identifier, final BTType type) { + final boolean anyType = BTType.NONE == type; + final boolean adapterType = BTType.ADAPTER == type; if( null == name && null == identifier && ( anyType || adapterType ) ) { // special case for 1st valid adapter @@ -507,7 +507,7 @@ public class DBTManager implements BluetoothManager } return null; // no adapter } - for(final Iterator<BluetoothAdapter> iter = adapters.iterator(); iter.hasNext(); ) { + for(final Iterator<BTAdapter> iter = adapters.iterator(); iter.hasNext(); ) { final DBTAdapter adapter = (DBTAdapter) iter.next(); if( !adapter.isValid() ) { continue; @@ -541,31 +541,31 @@ public class DBTManager implements BluetoothManager return null; } - /* pp */ DBTObject findInCache(final DBTObject parent, final BluetoothType type, final String name, final String identifier) { + /* pp */ DBTObject findInCache(final DBTObject parent, final BTType type, final String name, final String identifier) { if( null == parent ) { return findInCache(name, identifier, type); } - final boolean anyType = BluetoothType.NONE == type; - final boolean deviceType = BluetoothType.DEVICE == type; - final boolean serviceType = BluetoothType.GATT_SERVICE == type; - final boolean charType = BluetoothType.GATT_CHARACTERISTIC== type; - final boolean descType = BluetoothType.GATT_DESCRIPTOR == type; + final boolean anyType = BTType.NONE == type; + final boolean deviceType = BTType.DEVICE == type; + final boolean serviceType = BTType.GATT_SERVICE == type; + final boolean charType = BTType.GATT_CHARACTERISTIC== type; + final boolean descType = BTType.GATT_DESCRIPTOR == type; - final BluetoothType parentType = parent.getBluetoothType(); + final BTType parentType = parent.getBluetoothType(); - if( BluetoothType.ADAPTER == parentType && + if( BTType.ADAPTER == parentType && ( anyType || deviceType || serviceType || charType || descType ) ) { return ((DBTAdapter) parent).findInCache(name, identifier, type); } - if( BluetoothType.DEVICE == parentType && + if( BTType.DEVICE == parentType && ( anyType || serviceType || charType || descType ) ) { return ((DBTDevice) parent).findInCache(identifier, type); } - if( BluetoothType.GATT_SERVICE == parentType && + if( BTType.GATT_SERVICE == parentType && ( anyType || charType || descType ) ) { @@ -575,11 +575,11 @@ public class DBTManager implements BluetoothManager } return service.findInCache(identifier, type); } - if( BluetoothType.GATT_CHARACTERISTIC == parentType && + if( BTType.GATT_CHARACTERISTIC == parentType && ( anyType || descType ) ) { - final DBTGattCharacteristic characteristic = (DBTGattCharacteristic) parent; + final DBTGattChar characteristic = (DBTGattChar) parent; if( !characteristic.checkServiceCache() ) { return null; } diff --git a/java/jau/direct_bt/DBTNativeDownlink.java b/java/jau/direct_bt/DBTNativeDownlink.java index 9e3de0c1..71e72ce1 100644 --- a/java/jau/direct_bt/DBTNativeDownlink.java +++ b/java/jau/direct_bt/DBTNativeDownlink.java @@ -27,7 +27,7 @@ package jau.direct_bt; import java.util.concurrent.atomic.AtomicBoolean; -import org.direct_bt.BluetoothFactory; +import org.direct_bt.BTFactory; public abstract class DBTNativeDownlink { @@ -36,7 +36,7 @@ public abstract class DBTNativeDownlink private final Object nativeLock = new Object(); static { - BluetoothFactory.checkInitialized(); + BTFactory.checkInitialized(); } protected DBTNativeDownlink(final long nativeInstance) diff --git a/java/jau/direct_bt/DBTObject.java b/java/jau/direct_bt/DBTObject.java index d8fb4d7d..80266d84 100644 --- a/java/jau/direct_bt/DBTObject.java +++ b/java/jau/direct_bt/DBTObject.java @@ -25,10 +25,10 @@ package jau.direct_bt; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; -public abstract class DBTObject extends DBTNativeDownlink implements BluetoothObject +public abstract class DBTObject extends DBTNativeDownlink implements BTObject { private final int hashValue; @@ -49,7 +49,7 @@ public abstract class DBTObject extends DBTNativeDownlink implements BluetoothOb this.hashValue = hashValue; } - static BluetoothType class_type() { return BluetoothType.NONE; } + static BTType class_type() { return BTType.NONE; } @Override public abstract boolean equals(final Object obj); @@ -71,7 +71,7 @@ public abstract class DBTObject extends DBTNativeDownlink implements BluetoothOb } @Override - public BluetoothObject clone() + public BTObject clone() { throw new UnsupportedOperationException(); } // FIXME } diff --git a/java/jni/BluetoothFactory.cxx b/java/jni/BTFactory.cxx index 30856fa1..ace0a6b3 100644 --- a/java/jni/BluetoothFactory.cxx +++ b/java/jni/BTFactory.cxx @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "org_direct_bt_BluetoothFactory.h" +#include "org_direct_bt_BTFactory.h" #include "version.h" @@ -31,7 +31,7 @@ using namespace jau; -jstring Java_org_direct_bt_BluetoothFactory_getNativeAPIVersion(JNIEnv *env, jclass clazz) +jstring Java_org_direct_1bt_BTFactory_getNativeAPIVersion(JNIEnv *env, jclass clazz) { try { (void) clazz; @@ -44,7 +44,7 @@ jstring Java_org_direct_bt_BluetoothFactory_getNativeAPIVersion(JNIEnv *env, jcl return nullptr; } -void Java_org_direct_bt_BluetoothFactory_setenv(JNIEnv *env, jclass clazz, jstring jname, jstring jval, jboolean overwrite) +void Java_org_direct_1bt_BTFactory_setenv(JNIEnv *env, jclass clazz, jstring jname, jstring jval, jboolean overwrite) { try { (void) clazz; diff --git a/java/jni/BluetoothUtils.cxx b/java/jni/BTUtils.cxx index 7f86f3c5..2071c9e1 100644 --- a/java/jni/BluetoothUtils.cxx +++ b/java/jni/BTUtils.cxx @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "org_direct_bt_BluetoothUtils.h" +#include "org_direct_bt_BTUtils.h" #include <cstdint> #include <cinttypes> @@ -47,7 +47,7 @@ static const int64_t MilliPerOne = 1000L; * clock_gettime seems to be well supported at least on kernel >= 4.4. * Only bfin and sh are missing, while ia64 seems to be complicated. */ -jlong Java_org_direct_bt_BluetoothUtils_currentTimeMillis(JNIEnv *env, jclass clazz) { +jlong Java_org_direct_1bt_BTUtils_currentTimeMillis(JNIEnv *env, jclass clazz) { (void)env; (void)clazz; @@ -57,14 +57,14 @@ jlong Java_org_direct_bt_BluetoothUtils_currentTimeMillis(JNIEnv *env, jclass cl return (jlong)res; } -jlong Java_org_direct_bt_BluetoothUtils_startupTimeMillisImpl(JNIEnv *env, jclass clazz) { +jlong Java_org_direct_1bt_BTUtils_startupTimeMillisImpl(JNIEnv *env, jclass clazz) { (void)env; (void)clazz; return jau::environment::startupTimeMilliseconds; } -jstring Java_org_direct_bt_BluetoothUtils_decodeUTF8String(JNIEnv *env, jclass clazz, jbyteArray jbuffer, jint offset, jint size) { +jstring Java_org_direct_1bt_BTUtils_decodeUTF8String(JNIEnv *env, jclass clazz, jbyteArray jbuffer, jint offset, jint size) { (void)clazz; const int buffer_size = env->GetArrayLength(jbuffer); diff --git a/java/jni/direct_bt/CMakeLists.txt b/java/jni/direct_bt/CMakeLists.txt index 814273fa..ec5bddfc 100644 --- a/java/jni/direct_bt/CMakeLists.txt +++ b/java/jni/direct_bt/CMakeLists.txt @@ -23,17 +23,17 @@ set (direct_bt_JNI_SRCS ${PROJECT_SOURCE_DIR}/jaulib/java_jni/jni/jni_mem.cxx ${PROJECT_SOURCE_DIR}/jaulib/java_jni/jni/helper_jni.cxx ${PROJECT_SOURCE_DIR}/java/jni/helper_base.cxx - ${PROJECT_SOURCE_DIR}/java/jni/BluetoothFactory.cxx - ${PROJECT_SOURCE_DIR}/java/jni/BluetoothUtils.cxx + ${PROJECT_SOURCE_DIR}/java/jni/BTFactory.cxx + ${PROJECT_SOURCE_DIR}/java/jni/BTUtils.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/helper_dbt.cxx - ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTNativeDownlink.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTAdapter.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTDevice.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTEvent.cxx - ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattCharacteristic.cxx - ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattDescriptor.cxx + ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattChar.cxx + ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattDesc.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattService.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTManager.cxx + ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTNativeDownlink.cxx ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTObject.cxx ) diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index 3f490011..15348f9b 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -31,33 +31,33 @@ #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTAdapter.hpp" -#include "direct_bt/DBTManager.hpp" +#include "direct_bt/BTAdapter.hpp" +#include "direct_bt/BTManager.hpp" using namespace direct_bt; -static const std::string _adapterSettingsClassName("org/tinyb/AdapterSettings"); +static const std::string _adapterSettingsClassName("org/direct_bt/AdapterSettings"); static const std::string _adapterSettingsClazzCtorArgs("(I)V"); -static const std::string _eirDataTypeSetClassName("org/tinyb/EIRDataTypeSet"); +static const std::string _eirDataTypeSetClassName("org/direct_bt/EIRDataTypeSet"); static const std::string _eirDataTypeSetClazzCtorArgs("(I)V"); -static const std::string _hciStatusCodeClassName("org/tinyb/HCIStatusCode"); -static const std::string _hciStatusCodeClazzGetArgs("(B)Lorg/tinyb/HCIStatusCode;"); -static const std::string _scanTypeClassName("org/tinyb/ScanType"); -static const std::string _scanTypeClazzGetArgs("(B)Lorg/tinyb/ScanType;"); -static const std::string _pairingModeClassName("org/tinyb/PairingMode"); -static const std::string _pairingModeClazzGetArgs("(B)Lorg/tinyb/PairingMode;"); -static const std::string _pairingStateClassName("org/tinyb/SMPPairingState"); -static const std::string _pairingStateClazzGetArgs("(B)Lorg/tinyb/SMPPairingState;"); -static const std::string _deviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTAdapter;[BBLjava/lang/String;J)V"); - -static const std::string _adapterSettingsChangedMethodArgs("(Lorg/tinyb/BluetoothAdapter;Lorg/tinyb/AdapterSettings;Lorg/tinyb/AdapterSettings;Lorg/tinyb/AdapterSettings;J)V"); -static const std::string _discoveringChangedMethodArgs("(Lorg/tinyb/BluetoothAdapter;Lorg/tinyb/ScanType;Lorg/tinyb/ScanType;ZZJ)V"); -static const std::string _deviceFoundMethodArgs("(Lorg/tinyb/BluetoothDevice;J)Z"); -static const std::string _deviceUpdatedMethodArgs("(Lorg/tinyb/BluetoothDevice;Lorg/tinyb/EIRDataTypeSet;J)V"); -static const std::string _deviceConnectedMethodArgs("(Lorg/tinyb/BluetoothDevice;SJ)V"); -static const std::string _devicePairingStateMethodArgs("(Lorg/tinyb/BluetoothDevice;Lorg/tinyb/SMPPairingState;Lorg/tinyb/PairingMode;J)V"); -static const std::string _deviceReadyMethodArgs("(Lorg/tinyb/BluetoothDevice;J)V"); -static const std::string _deviceDisconnectedMethodArgs("(Lorg/tinyb/BluetoothDevice;Lorg/tinyb/HCIStatusCode;SJ)V"); +static const std::string _hciStatusCodeClassName("org/direct_bt/HCIStatusCode"); +static const std::string _hciStatusCodeClazzGetArgs("(B)Lorg/direct_bt/HCIStatusCode;"); +static const std::string _scanTypeClassName("org/direct_bt/ScanType"); +static const std::string _scanTypeClazzGetArgs("(B)Lorg/direct_bt/ScanType;"); +static const std::string _pairingModeClassName("org/direct_bt/PairingMode"); +static const std::string _pairingModeClazzGetArgs("(B)Lorg/direct_bt/PairingMode;"); +static const std::string _pairingStateClassName("org/direct_bt/SMPPairingState"); +static const std::string _pairingStateClazzGetArgs("(B)Lorg/direct_bt/SMPPairingState;"); +static const std::string _deviceClazzCtorArgs("(JLjau/direct_bt/DBTAdapter;[BBLjava/lang/String;J)V"); + +static const std::string _adapterSettingsChangedMethodArgs("(Lorg/direct_bt/BTAdapter;Lorg/direct_bt/AdapterSettings;Lorg/direct_bt/AdapterSettings;Lorg/direct_bt/AdapterSettings;J)V"); +static const std::string _discoveringChangedMethodArgs("(Lorg/direct_bt/BTAdapter;Lorg/direct_bt/ScanType;Lorg/direct_bt/ScanType;ZZJ)V"); +static const std::string _deviceFoundMethodArgs("(Lorg/direct_bt/BTDevice;J)Z"); +static const std::string _deviceUpdatedMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/EIRDataTypeSet;J)V"); +static const std::string _deviceConnectedMethodArgs("(Lorg/direct_bt/BTDevice;SJ)V"); +static const std::string _devicePairingStateMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/SMPPairingState;Lorg/direct_bt/PairingMode;J)V"); +static const std::string _deviceReadyMethodArgs("(Lorg/direct_bt/BTDevice;J)V"); +static const std::string _deviceDisconnectedMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/HCIStatusCode;SJ)V"); class JNIAdapterStatusListener : public AdapterStatusListener { private: @@ -83,7 +83,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { */ static std::atomic<int> iname_next; int const iname; - DBTDevice const * const deviceMatchRef; + BTDevice const * const deviceMatchRef; std::shared_ptr<jau::JavaAnon> adapterObjRef; JNIGlobalRef adapterSettingsClazzRef; jmethodID adapterSettingsClazzCtor; @@ -124,9 +124,9 @@ class JNIAdapterStatusListener : public AdapterStatusListener { // listenerObjRef dtor will call notifyDelete and clears the nativeInstance handle } - JNIAdapterStatusListener(JNIEnv *env, DBTAdapter *adapter, + JNIAdapterStatusListener(JNIEnv *env, BTAdapter *adapter, jclass listenerClazz, jobject statusListenerObj, jmethodID statusListenerNotifyDeleted, - const DBTDevice * _deviceMatchRef) + const BTDevice * _deviceMatchRef) : iname(iname_next.fetch_add(1)), deviceMatchRef(_deviceMatchRef), listenerObjRef(statusListenerObj, statusListenerNotifyDeleted) { adapterObjRef = adapter->getJavaObject(); @@ -137,7 +137,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jclass adapterSettingsClazz = jau::search_class(env, _adapterSettingsClassName.c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == adapterSettingsClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+_adapterSettingsClassName, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+_adapterSettingsClassName, E_FILE_LINE); } adapterSettingsClazzRef = JNIGlobalRef(adapterSettingsClazz); env->DeleteLocalRef(adapterSettingsClazz); @@ -153,7 +153,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jclass eirDataTypeSetClazz = jau::search_class(env, _eirDataTypeSetClassName.c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == eirDataTypeSetClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+_eirDataTypeSetClassName, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+_eirDataTypeSetClassName, E_FILE_LINE); } eirDataTypeSetClazzRef = JNIGlobalRef(eirDataTypeSetClazz); env->DeleteLocalRef(eirDataTypeSetClazz); @@ -169,7 +169,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jclass hciErrorCodeClazz = jau::search_class(env, _hciStatusCodeClassName.c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == hciErrorCodeClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+_hciStatusCodeClassName, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+_hciStatusCodeClassName, E_FILE_LINE); } hciStatusCodeClazzRef = JNIGlobalRef(hciErrorCodeClazz); env->DeleteLocalRef(hciErrorCodeClazz); @@ -185,7 +185,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jclass scanTypeClazz = jau::search_class(env, _scanTypeClassName.c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == scanTypeClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+_scanTypeClassName, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+_scanTypeClassName, E_FILE_LINE); } scanTypeClazzRef = JNIGlobalRef(scanTypeClazz); env->DeleteLocalRef(scanTypeClazz); @@ -201,7 +201,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jclass pairingModeClazz = jau::search_class(env, _pairingModeClassName.c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == pairingModeClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+_pairingModeClassName, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+_pairingModeClassName, E_FILE_LINE); } pairingModeClazzRef = JNIGlobalRef(pairingModeClazz); env->DeleteLocalRef(pairingModeClazz); @@ -217,7 +217,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jclass pairingStateClazz = jau::search_class(env, _pairingStateClassName.c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == pairingStateClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+_pairingStateClassName, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+_pairingStateClassName, E_FILE_LINE); } pairingStateClazzRef = JNIGlobalRef(pairingStateClazz); env->DeleteLocalRef(pairingStateClazz); @@ -230,10 +230,10 @@ class JNIAdapterStatusListener : public AdapterStatusListener { // deviceClazzRef, deviceClazzCtor { - jclass deviceClazz = jau::search_class(env, DBTDevice::java_class().c_str()); + jclass deviceClazz = jau::search_class(env, BTDevice::java_class().c_str()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == deviceClazz ) { - throw jau::InternalError("DBTDevice::java_class not found: "+DBTDevice::java_class(), E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class not found: "+BTDevice::java_class(), E_FILE_LINE); } deviceClazzRef = JNIGlobalRef(deviceClazz); env->DeleteLocalRef(deviceClazz); @@ -241,22 +241,22 @@ class JNIAdapterStatusListener : public AdapterStatusListener { deviceClazzCtor = jau::search_method(env, deviceClazzRef.getClass(), "<init>", _deviceClazzCtorArgs.c_str(), false); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == deviceClazzCtor ) { - throw jau::InternalError("DBTDevice::java_class ctor not found: "+DBTDevice::java_class()+".<init>"+_deviceClazzCtorArgs, E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class ctor not found: "+BTDevice::java_class()+".<init>"+_deviceClazzCtorArgs, E_FILE_LINE); } deviceClazzTSLastDiscoveryField = env->GetFieldID(deviceClazzRef.getClass(), "ts_last_discovery", "J"); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == deviceClazzTSLastDiscoveryField ) { - throw jau::InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_last_discovery", E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class field not found: "+BTDevice::java_class()+".ts_last_discovery", E_FILE_LINE); } deviceClazzTSLastUpdateField = env->GetFieldID(deviceClazzRef.getClass(), "ts_last_update", "J"); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == deviceClazzTSLastUpdateField ) { - throw jau::InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_last_update", E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class field not found: "+BTDevice::java_class()+".ts_last_update", E_FILE_LINE); } deviceClazzConnectionHandleField = env->GetFieldID(deviceClazzRef.getClass(), "hciConnHandle", "S"); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == deviceClazzConnectionHandleField ) { - throw jau::InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".hciConnHandle", E_FILE_LINE); + throw jau::InternalError("BTDevice::java_class field not found: "+BTDevice::java_class()+".hciConnHandle", E_FILE_LINE); } mAdapterSettingsChanged = jau::search_method(env, listenerClazz, "adapterSettingsChanged", _adapterSettingsChangedMethodArgs.c_str(), false); @@ -301,14 +301,14 @@ class JNIAdapterStatusListener : public AdapterStatusListener { } } - bool matchDevice(const DBTDevice & device) override { + bool matchDevice(const BTDevice & device) override { if( nullptr == deviceMatchRef ) { return true; } return device == *deviceMatchRef; } - void adapterSettingsChanged(DBTAdapter &a, const AdapterSetting oldmask, const AdapterSetting newmask, + void adapterSettingsChanged(BTAdapter &a, const AdapterSetting oldmask, const AdapterSetting newmask, const AdapterSetting changedmask, const uint64_t timestamp) override { JNIEnv *env = *jni_env; (void)a; @@ -332,7 +332,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { env->DeleteLocalRef(adapterSettingChanged); } - void discoveringChanged(DBTAdapter &a, const ScanType currentMeta, const ScanType changedType, const bool changedEnabled, const bool keepAlive, const uint64_t timestamp) override { + void discoveringChanged(BTAdapter &a, const ScanType currentMeta, const ScanType changedType, const bool changedEnabled, const bool keepAlive, const uint64_t timestamp) override { JNIEnv *env = *jni_env; (void)a; @@ -349,7 +349,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { jau::java_exception_check_and_throw(env, E_FILE_LINE); } - bool deviceFound(std::shared_ptr<DBTDevice> device, const uint64_t timestamp) override { + bool deviceFound(std::shared_ptr<BTDevice> device, const uint64_t timestamp) override { JNIEnv *env = *jni_env; jobject jdevice; std::shared_ptr<jau::JavaAnon> jDeviceRef0 = device->getJavaObject(); @@ -384,7 +384,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { return JNI_TRUE == res; } - void deviceUpdated(std::shared_ptr<DBTDevice> device, const EIRDataType updateMask, const uint64_t timestamp) override { + void deviceUpdated(std::shared_ptr<BTDevice> device, const EIRDataType updateMask, const uint64_t timestamp) override { std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject(); if( !jau::JavaGlobalObj::isValid(jDeviceRef) ) { return; // java device has been pulled @@ -402,7 +402,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { env->DeleteLocalRef(eirDataTypeSet); } - void deviceConnected(std::shared_ptr<DBTDevice> device, const uint16_t handle, const uint64_t timestamp) override { + void deviceConnected(std::shared_ptr<BTDevice> device, const uint16_t handle, const uint64_t timestamp) override { JNIEnv *env = *jni_env; jobject jdevice; @@ -441,7 +441,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { env->CallVoidMethod(listenerObjRef.getObject(), mDeviceConnected, jdevice, (jshort)handle, (jlong)timestamp); jau::java_exception_check_and_throw(env, E_FILE_LINE); } - void devicePairingState(std::shared_ptr<DBTDevice> device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) override { + void devicePairingState(std::shared_ptr<BTDevice> device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) override { std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject(); if( !jau::JavaGlobalObj::isValid(jDeviceRef) ) { return; // java device has been pulled @@ -463,7 +463,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { env->CallVoidMethod(listenerObjRef.getObject(), mDevicePairingState, jdevice, jstate, jmode, (jlong)timestamp); jau::java_exception_check_and_throw(env, E_FILE_LINE); } - void deviceReady(std::shared_ptr<DBTDevice> device, const uint64_t timestamp) override { + void deviceReady(std::shared_ptr<BTDevice> device, const uint64_t timestamp) override { std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject(); if( !jau::JavaGlobalObj::isValid(jDeviceRef) ) { return; // java device has been pulled @@ -477,7 +477,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { env->CallVoidMethod(listenerObjRef.getObject(), mDeviceReady, jdevice, (jlong)timestamp); jau::java_exception_check_and_throw(env, E_FILE_LINE); } - void deviceDisconnected(std::shared_ptr<DBTDevice> device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) override { + void deviceDisconnected(std::shared_ptr<BTDevice> device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) override { std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject(); if( !jau::JavaGlobalObj::isValid(jDeviceRef) ) { return; // java device has been pulled @@ -514,12 +514,12 @@ jboolean Java_jau_direct_1bt_DBTAdapter_addStatusListener(JNIEnv *env, jobject o return false; } } - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); - DBTDevice * deviceMatchRef = nullptr; + BTDevice * deviceMatchRef = nullptr; if( nullptr != jdeviceMatch ) { - deviceMatchRef = jau::getJavaUplinkObject<DBTDevice>(env, jdeviceMatch); + deviceMatchRef = jau::getJavaUplinkObject<BTDevice>(env, jdeviceMatch); jau::JavaGlobalObj::check(deviceMatchRef->getJavaObject(), E_FILE_LINE); } @@ -567,7 +567,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_removeStatusListenerImpl(JNIEnv *env, jo } jau::clearInstance(env, statusListener); - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( ! adapter->removeStatusListener( pre ) ) { @@ -590,7 +590,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_removeStatusListenerImpl(JNIEnv *env, jo jint Java_jau_direct_1bt_DBTAdapter_removeAllStatusListener(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); return adapter->removeAllStatusListener(); @@ -602,7 +602,7 @@ jint Java_jau_direct_1bt_DBTAdapter_removeAllStatusListener(JNIEnv *env, jobject jboolean Java_jau_direct_1bt_DBTAdapter_isDeviceWhitelisted(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( nullptr == jaddress ) { @@ -631,7 +631,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_addDeviceToWhitelistImpl1(JNIEnv *env, j jshort min_interval, jshort max_interval, jshort latency, jshort timeout) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( nullptr == jaddress ) { @@ -659,7 +659,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_addDeviceToWhitelistImpl1(JNIEnv *env, j jboolean Java_jau_direct_1bt_DBTAdapter_addDeviceToWhitelistImpl2(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType, int jctype) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( nullptr == jaddress ) { @@ -686,7 +686,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_addDeviceToWhitelistImpl2(JNIEnv *env, j } jboolean Java_jau_direct_1bt_DBTAdapter_removeDeviceFromWhitelistImpl(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( nullptr == jaddress ) { @@ -713,7 +713,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_removeDeviceFromWhitelistImpl(JNIEnv *en jstring Java_jau_direct_1bt_DBTAdapter_toStringImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *nativePtr = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *nativePtr = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE); return jau::from_string_to_jstring(env, nativePtr->toString()); } catch(...) { @@ -726,10 +726,10 @@ void Java_jau_direct_1bt_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj, jlong n { (void)obj; try { - DBTAdapter *adapter = jau::castInstance<DBTAdapter>(nativeInstance); + BTAdapter *adapter = jau::castInstance<BTAdapter>(nativeInstance); DBG_PRINT("Java_jau_direct_1bt_DBTAdapter_deleteImpl (close only) %s", adapter->toString().c_str()); adapter->close(); - // No delete: DBTAdapter instance owned by DBTManager + // No delete: BTAdapter instance owned by DBTManager // However, adapter->close() cleans up most.. } catch(...) { rethrow_and_raise_java_exception(env); @@ -739,7 +739,7 @@ void Java_jau_direct_1bt_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj, jlong n jboolean Java_jau_direct_1bt_DBTAdapter_isPoweredImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); return adapter->isPowered(); } catch(...) { rethrow_and_raise_java_exception(env); @@ -750,7 +750,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_isPoweredImpl(JNIEnv *env, jobject obj) jboolean Java_jau_direct_1bt_DBTAdapter_isSuspendedImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); return adapter->isSuspended(); } catch(...) { rethrow_and_raise_java_exception(env); @@ -761,7 +761,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_isSuspendedImpl(JNIEnv *env, jobject obj jboolean Java_jau_direct_1bt_DBTAdapter_isValidImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); return adapter->isValid(); } catch(...) { rethrow_and_raise_java_exception(env); @@ -772,7 +772,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_isValidImpl(JNIEnv *env, jobject obj) jbyte Java_jau_direct_1bt_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj, jboolean keepAlive) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); return (jbyte) number( adapter->startDiscovery(keepAlive) ); } catch(...) { rethrow_and_raise_java_exception(env); @@ -783,7 +783,7 @@ jbyte Java_jau_direct_1bt_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj jbyte Java_jau_direct_1bt_DBTAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); return (jbyte) number( adapter->stopDiscovery() ); } catch(...) { rethrow_and_raise_java_exception(env); @@ -794,8 +794,8 @@ jbyte Java_jau_direct_1bt_DBTAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj) jobject Java_jau_direct_1bt_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); - jau::darray<std::shared_ptr<DBTDevice>> array = adapter->getDiscoveredDevices(); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); + jau::darray<std::shared_ptr<BTDevice>> array = adapter->getDiscoveredDevices(); return convert_vector_sharedptr_to_jarraylist(env, array); } catch(...) { rethrow_and_raise_java_exception(env); @@ -806,7 +806,7 @@ jobject Java_jau_direct_1bt_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, job jint Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDevicesImpl1(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); return adapter->removeDiscoveredDevices(); } catch(...) { rethrow_and_raise_java_exception(env); @@ -817,7 +817,7 @@ jint Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDevicesImpl1(JNIEnv *env, jo jboolean Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDeviceImpl1(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( nullptr == jaddress ) { @@ -848,7 +848,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDeviceImpl1(JNIEnv *env, jboolean Java_jau_direct_1bt_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jboolean value) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); return adapter->setPowered(JNI_TRUE == value ? true : false) ? JNI_TRUE : JNI_FALSE; } catch(...) { @@ -859,7 +859,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jbo jbyte Java_jau_direct_1bt_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); HCIStatusCode res = adapter->reset(); return (jbyte) number(res); @@ -871,7 +871,7 @@ jbyte Java_jau_direct_1bt_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) { jstring Java_jau_direct_1bt_DBTAdapter_getAlias(JNIEnv *env, jobject obj) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); return jau::from_string_to_jstring(env, adapter->getLocalName().getName()); } catch(...) { @@ -882,7 +882,7 @@ jstring Java_jau_direct_1bt_DBTAdapter_getAlias(JNIEnv *env, jobject obj) { void Java_jau_direct_1bt_DBTAdapter_setAlias(JNIEnv *env, jobject obj, jstring jnewalias) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); std::string newalias = jau::from_jstring_to_string(env, jnewalias); adapter->setLocalName(newalias, std::string()); @@ -893,7 +893,7 @@ void Java_jau_direct_1bt_DBTAdapter_setAlias(JNIEnv *env, jobject obj, jstring j jboolean Java_jau_direct_1bt_DBTAdapter_setDiscoverable(JNIEnv *env, jobject obj, jboolean value) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); return adapter->setDiscoverable(JNI_TRUE == value ? true : false) ? JNI_TRUE : JNI_FALSE; } catch(...) { @@ -904,7 +904,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_setDiscoverable(JNIEnv *env, jobject obj jobject Java_jau_direct_1bt_DBTAdapter_connectDeviceImpl(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); if( nullptr == jaddress ) { @@ -922,14 +922,14 @@ jobject Java_jau_direct_1bt_DBTAdapter_connectDeviceImpl(JNIEnv *env, jobject ob const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr); const BDAddressType addressType = static_cast<BDAddressType>( jaddressType ); - std::shared_ptr<DBTDevice> device = adapter->findSharedDevice(address, addressType); + std::shared_ptr<BTDevice> device = adapter->findSharedDevice(address, addressType); if( nullptr == device ) { device = adapter->findDiscoveredDevice(address, addressType); } if( nullptr != device ) { direct_bt::HCIHandler & hci = adapter->getHCI(); if( !hci.isOpen() ) { - throw BluetoothException("Adapter's HCI closed "+adapter->toString(), E_FILE_LINE); + throw BTException("Adapter's HCI closed "+adapter->toString(), E_FILE_LINE); } std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject(); jau::JavaGlobalObj::check(jDeviceRef, E_FILE_LINE); @@ -945,7 +945,7 @@ jobject Java_jau_direct_1bt_DBTAdapter_connectDeviceImpl(JNIEnv *env, jobject ob jboolean Java_jau_direct_1bt_DBTAdapter_setPairable(JNIEnv *env, jobject obj, jboolean value) { try { - DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj); + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); return adapter->setBondable(JNI_TRUE == value ? true : false) ? JNI_TRUE : JNI_FALSE; } catch(...) { diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx index 8409f75d..a52d5d3c 100644 --- a/java/jni/direct_bt/DBTDevice.cxx +++ b/java/jni/direct_bt/DBTDevice.cxx @@ -31,36 +31,36 @@ #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTDevice.hpp" -#include "direct_bt/DBTAdapter.hpp" -#include "direct_bt/DBTManager.hpp" +#include "direct_bt/BTDevice.hpp" +#include "direct_bt/BTAdapter.hpp" +#include "direct_bt/BTManager.hpp" using namespace direct_bt; using namespace jau; -static const std::string _notificationReceivedMethodArgs("(Lorg/tinyb/BluetoothGattCharacteristic;[BJ)V"); -static const std::string _indicationReceivedMethodArgs("(Lorg/tinyb/BluetoothGattCharacteristic;[BJZ)V"); +static const std::string _notificationReceivedMethodArgs("(Lorg/direct_bt/BTGattChar;[BJ)V"); +static const std::string _indicationReceivedMethodArgs("(Lorg/direct_bt/BTGattChar;[BJZ)V"); -class JNICharacteristicListener : public GATTCharacteristicListener { +class JNICharacteristicListener : public BTGattCharListener { private: /** package org.tinyb; - public abstract class GATTCharacteristicListener { + public abstract class BTGattCharListener { long nativeInstance; - public void notificationReceived(final BluetoothGattCharacteristic charDecl, + public void notificationReceived(final BTGattChar charDecl, final byte[] value, final long timestamp) { } - public void indicationReceived(final BluetoothGattCharacteristic charDecl, + public void indicationReceived(final BTGattChar charDecl, final byte[] value, final long timestamp, final boolean confirmationSent) { } }; */ - const GATTCharacteristic * associatedCharacteristicRef; + const BTGattChar * associatedCharacteristicRef; JNIGlobalRef listenerObj; // keep listener instance alive JNIGlobalRef associatedCharacteristicObj; // keeps associated characteristic alive, if not null jmethodID mNotificationReceived = nullptr; @@ -68,7 +68,7 @@ class JNICharacteristicListener : public GATTCharacteristicListener { public: - JNICharacteristicListener(JNIEnv *env, DBTDevice *device, jobject listener, GATTCharacteristic * associatedCharacteristicRef_) + JNICharacteristicListener(JNIEnv *env, BTDevice *device, jobject listener, BTGattChar * associatedCharacteristicRef_) : associatedCharacteristicRef(associatedCharacteristicRef_), listenerObj(listener) { @@ -86,23 +86,23 @@ class JNICharacteristicListener : public GATTCharacteristicListener { mNotificationReceived = search_method(env, listenerClazz, "notificationReceived", _notificationReceivedMethodArgs.c_str(), false); java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == mNotificationReceived ) { - throw InternalError("GATTCharacteristicListener has no notificationReceived"+_notificationReceivedMethodArgs+" method, for "+device->toString(), E_FILE_LINE); + throw InternalError("BTGattCharListener has no notificationReceived"+_notificationReceivedMethodArgs+" method, for "+device->toString(), E_FILE_LINE); } mIndicationReceived = search_method(env, listenerClazz, "indicationReceived", _indicationReceivedMethodArgs.c_str(), false); java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == mNotificationReceived ) { - throw InternalError("GATTCharacteristicListener has no indicationReceived"+_indicationReceivedMethodArgs+" method, for "+device->toString(), E_FILE_LINE); + throw InternalError("BTGattCharListener has no indicationReceived"+_indicationReceivedMethodArgs+" method, for "+device->toString(), E_FILE_LINE); } } - bool match(const GATTCharacteristic & characteristic) noexcept override { + bool match(const BTGattChar & characteristic) noexcept override { if( nullptr == associatedCharacteristicRef ) { return true; } return characteristic == *associatedCharacteristicRef; } - void notificationReceived(GATTCharacteristicRef charDecl, + void notificationReceived(BTGattCharRef charDecl, const TROOctets& charValue, const uint64_t timestamp) override { std::shared_ptr<jau::JavaAnon> jCharDeclRef = charDecl->getJavaObject(); if( !jau::JavaGlobalObj::isValid(jCharDeclRef) ) { @@ -122,7 +122,7 @@ class JNICharacteristicListener : public GATTCharacteristicListener { env->DeleteLocalRef(jval); } - void indicationReceived(GATTCharacteristicRef charDecl, + void indicationReceived(BTGattCharRef charDecl, const TROOctets& charValue, const uint64_t timestamp, const bool confirmationSent) override { std::shared_ptr<jau::JavaAnon> jCharDeclRef = charDecl->getJavaObject(); @@ -148,7 +148,7 @@ class JNICharacteristicListener : public GATTCharacteristicListener { void Java_jau_direct_1bt_DBTDevice_initImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); } catch(...) { rethrow_and_raise_java_exception(env); @@ -157,7 +157,7 @@ void Java_jau_direct_1bt_DBTDevice_initImpl(JNIEnv *env, jobject obj) jstring Java_jau_direct_1bt_DBTDevice_getNameImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *nativePtr = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *nativePtr = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE); return from_string_to_jstring(env, nativePtr->getName()); } catch(...) { @@ -168,7 +168,7 @@ jstring Java_jau_direct_1bt_DBTDevice_getNameImpl(JNIEnv *env, jobject obj) { jstring Java_jau_direct_1bt_DBTDevice_toStringImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *nativePtr = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *nativePtr = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE); return from_string_to_jstring(env, nativePtr->toString()); } catch(...) { @@ -177,7 +177,7 @@ jstring Java_jau_direct_1bt_DBTDevice_toStringImpl(JNIEnv *env, jobject obj) { return nullptr; } -jboolean Java_jau_direct_1bt_DBTDevice_addCharacteristicListener(JNIEnv *env, jobject obj, jobject listener, jobject jAssociatedCharacteristic) { +jboolean Java_jau_direct_1bt_DBTDevice_addCharListener(JNIEnv *env, jobject obj, jobject listener, jobject jAssociatedCharacteristic) { try { if( nullptr == listener ) { throw IllegalArgumentException("characteristicListener argument is null", E_FILE_LINE); @@ -190,22 +190,22 @@ jboolean Java_jau_direct_1bt_DBTDevice_addCharacteristicListener(JNIEnv *env, jo return false; } } - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); + std::shared_ptr<BTGattHandler> gatt = device->getGattHandler(); if( nullptr == gatt ) { throw IllegalStateException("Characteristic's device GATTHandle not connected: "+ device->toString(), E_FILE_LINE); } - GATTCharacteristic * associatedCharacteristicRef = nullptr; + BTGattChar * associatedCharacteristicRef = nullptr; if( nullptr != jAssociatedCharacteristic ) { - associatedCharacteristicRef = getJavaUplinkObject<GATTCharacteristic>(env, jAssociatedCharacteristic); + associatedCharacteristicRef = getJavaUplinkObject<BTGattChar>(env, jAssociatedCharacteristic); } - std::shared_ptr<GATTCharacteristicListener> l = - std::shared_ptr<GATTCharacteristicListener>( new JNICharacteristicListener(env, device, listener, associatedCharacteristicRef) ); + std::shared_ptr<BTGattCharListener> l = + std::shared_ptr<BTGattCharListener>( new JNICharacteristicListener(env, device, listener, associatedCharacteristicRef) ); - if( gatt->addCharacteristicListener(l) ) { + if( gatt->addCharListener(l) ) { setInstance(env, listener, l.get()); return JNI_TRUE; } @@ -215,7 +215,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_addCharacteristicListener(JNIEnv *env, jo return JNI_FALSE; } -jboolean Java_jau_direct_1bt_DBTDevice_removeCharacteristicListener(JNIEnv *env, jobject obj, jobject jlistener) { +jboolean Java_jau_direct_1bt_DBTDevice_removeCharListener(JNIEnv *env, jobject obj, jobject jlistener) { try { if( nullptr == jlistener ) { throw IllegalArgumentException("characteristicListener argument is null", E_FILE_LINE); @@ -228,20 +228,20 @@ jboolean Java_jau_direct_1bt_DBTDevice_removeCharacteristicListener(JNIEnv *env, } setObjectRef<JNICharacteristicListener>(env, jlistener, nullptr, "nativeInstance"); - DBTDevice *device = getJavaUplinkObjectUnchecked<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObjectUnchecked<BTDevice>(env, obj); if( nullptr == device ) { // OK to have device being deleted already @ shutdown return 0; } JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); + std::shared_ptr<BTGattHandler> gatt = device->getGattHandler(); if( nullptr == gatt ) { - // OK to have GATTHandler being shutdown @ disable + // OK to have BTGattHandler being shutdown @ disable DBG_PRINT("Characteristic's device GATTHandle not connected: %s", device->toString().c_str()); return false; } - if( ! gatt->removeCharacteristicListener(pre) ) { + if( ! gatt->removeCharListener(pre) ) { WARN_PRINT("Failed to remove characteristicListener with nativeInstance: %p at %s", pre, device->toString().c_str()); return false; } @@ -257,23 +257,23 @@ jint Java_jau_direct_1bt_DBTDevice_removeAllAssociatedCharacteristicListener(JNI if( nullptr == jAssociatedCharacteristic ) { throw IllegalArgumentException("associatedCharacteristic argument is null", E_FILE_LINE); } - DBTDevice *device = getJavaUplinkObjectUnchecked<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObjectUnchecked<BTDevice>(env, obj); if( nullptr == device ) { // OK to have device being deleted already @ shutdown return 0; } JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); + std::shared_ptr<BTGattHandler> gatt = device->getGattHandler(); if( nullptr == gatt ) { - // OK to have GATTHandler being shutdown @ disable + // OK to have BTGattHandler being shutdown @ disable DBG_PRINT("Characteristic's device GATTHandle not connected: %s", device->toString().c_str()); return 0; } - GATTCharacteristic * associatedCharacteristicRef = getJavaUplinkObject<GATTCharacteristic>(env, jAssociatedCharacteristic); + BTGattChar * associatedCharacteristicRef = getJavaUplinkObject<BTGattChar>(env, jAssociatedCharacteristic); JavaGlobalObj::check(associatedCharacteristicRef->getJavaObject(), E_FILE_LINE); - return gatt->removeAllAssociatedCharacteristicListener(associatedCharacteristicRef); + return gatt->removeAllAssociatedCharListener(associatedCharacteristicRef); } catch(...) { rethrow_and_raise_java_exception(env); } @@ -282,19 +282,19 @@ jint Java_jau_direct_1bt_DBTDevice_removeAllAssociatedCharacteristicListener(JNI jint Java_jau_direct_1bt_DBTDevice_removeAllCharacteristicListener(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObjectUnchecked<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObjectUnchecked<BTDevice>(env, obj); if( nullptr == device ) { // OK to have device being deleted already @ shutdown return 0; } JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); + std::shared_ptr<BTGattHandler> gatt = device->getGattHandler(); if( nullptr == gatt ) { - // OK to have GATTHandler being shutdown @ disable + // OK to have BTGattHandler being shutdown @ disable DBG_PRINT("Characteristic's device GATTHandle not connected: %s", device->toString().c_str()); return 0; } - return gatt->removeAllCharacteristicListener(); + return gatt->removeAllCharListener(); } catch(...) { rethrow_and_raise_java_exception(env); } @@ -305,10 +305,10 @@ void Java_jau_direct_1bt_DBTDevice_deleteImpl(JNIEnv *env, jobject obj, jlong na { (void)obj; try { - DBTDevice *device = castInstance<DBTDevice>(nativeInstance); + BTDevice *device = castInstance<BTDevice>(nativeInstance); DBG_PRINT("Java_jau_direct_1bt_DBTDevice_deleteImpl (remove only) %s", device->toString().c_str()); device->remove(); - // No delete: DBTDevice instance owned by DBTAdapter + // No delete: BTDevice instance owned by BTAdapter // However, device->remove() might issue destruction } catch(...) { rethrow_and_raise_java_exception(env); @@ -318,7 +318,7 @@ void Java_jau_direct_1bt_DBTDevice_deleteImpl(JNIEnv *env, jobject obj, jlong na jbyte Java_jau_direct_1bt_DBTDevice_disconnectImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return (jint) number( device->disconnect() ); } catch(...) { @@ -330,7 +330,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_disconnectImpl(JNIEnv *env, jobject obj) jboolean Java_jau_direct_1bt_DBTDevice_removeImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); device->remove(); } catch(...) { @@ -342,7 +342,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_removeImpl(JNIEnv *env, jobject obj) jbyte Java_jau_direct_1bt_DBTDevice_connectDefaultImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return (jbyte) number( device->connectDefault() ); } catch(...) { @@ -354,7 +354,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_connectDefaultImpl(JNIEnv *env, jobject obj) jbyte Java_jau_direct_1bt_DBTDevice_connectLEImpl0(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); HCIStatusCode res = device->connectLE(); return (jbyte) number(res); @@ -370,7 +370,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_connectLEImpl1(JNIEnv *env, jobject obj, jshort latency, jshort timeout) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); HCIStatusCode res = device->connectLE(interval, window, min_interval, max_interval, latency, timeout); return (jbyte) number(res); @@ -382,7 +382,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_connectLEImpl1(JNIEnv *env, jobject obj, jbyte Java_jau_direct_1bt_DBTDevice_getAvailableSMPKeysImpl(JNIEnv *env, jobject obj, jboolean responder) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return number( device->getAvailableSMPKeys(JNI_TRUE == responder) ); // assign data of new key copy to JNI critical-array @@ -394,7 +394,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_getAvailableSMPKeysImpl(JNIEnv *env, jobject void Java_jau_direct_1bt_DBTDevice_getLongTermKeyInfoImpl(JNIEnv *env, jobject obj, jboolean responder, jbyteArray jsink) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); if( nullptr == jsink ) { @@ -418,7 +418,7 @@ void Java_jau_direct_1bt_DBTDevice_getLongTermKeyInfoImpl(JNIEnv *env, jobject o jbyte Java_jau_direct_1bt_DBTDevice_setLongTermKeyInfoImpl(JNIEnv *env, jobject obj, jbyteArray jsource) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); if( nullptr == jsource ) { @@ -445,7 +445,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_setLongTermKeyInfoImpl(JNIEnv *env, jobject void Java_jau_direct_1bt_DBTDevice_getSignatureResolvingKeyInfoImpl(JNIEnv *env, jobject obj, jboolean responder, jbyteArray jsink) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); if( nullptr == jsink ) { @@ -469,7 +469,7 @@ void Java_jau_direct_1bt_DBTDevice_getSignatureResolvingKeyInfoImpl(JNIEnv *env, jbyte Java_jau_direct_1bt_DBTDevice_unpairImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); HCIStatusCode res = device->unpair(); return (jbyte) number(res); @@ -481,7 +481,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_unpairImpl(JNIEnv *env, jobject obj) { jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityLevelImpl(JNIEnv *env, jobject obj, jbyte jsec_level) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return device->setConnSecurityLevel( getBTSecurityLevel( static_cast<uint8_t>(jsec_level) )); @@ -493,7 +493,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityLevelImpl(JNIEnv *env, job jbyte Java_jau_direct_1bt_DBTDevice_getConnSecurityLevelImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return number( device->getConnSecurityLevel() ); @@ -505,7 +505,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_getConnSecurityLevelImpl(JNIEnv *env, jobjec jboolean Java_jau_direct_1bt_DBTDevice_setConnIOCapabilityImpl(JNIEnv *env, jobject obj, jbyte jio_cap) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return device->setConnIOCapability( getSMPIOCapability( static_cast<uint8_t>(jio_cap) )); @@ -517,7 +517,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_setConnIOCapabilityImpl(JNIEnv *env, jobj jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityImpl(JNIEnv *env, jobject obj, jbyte jsec_level, jbyte jio_cap) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return device->setConnSecurity( getBTSecurityLevel( static_cast<uint8_t>(jsec_level) ), @@ -530,7 +530,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityImpl(JNIEnv *env, jobject jbyte Java_jau_direct_1bt_DBTDevice_getConnIOCapabilityImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return number( device->getConnIOCapability() ); @@ -542,7 +542,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_getConnIOCapabilityImpl(JNIEnv *env, jobject jbyte Java_jau_direct_1bt_DBTDevice_getPairingModeImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return number( device->getPairingMode() ); @@ -554,7 +554,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_getPairingModeImpl(JNIEnv *env, jobject obj) jbyte Java_jau_direct_1bt_DBTDevice_getPairingStateImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return static_cast<uint8_t>( device->getPairingState() ); @@ -566,7 +566,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_getPairingStateImpl(JNIEnv *env, jobject obj jbyte Java_jau_direct_1bt_DBTDevice_setPairingPasskeyImpl(JNIEnv *env, jobject obj, jint jpasskey) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); // const std::string passkey = nullptr != jpasskey ? from_jstring_to_string(env, jpasskey) : std::string(); @@ -579,7 +579,7 @@ jbyte Java_jau_direct_1bt_DBTDevice_setPairingPasskeyImpl(JNIEnv *env, jobject o jbyte Java_jau_direct_1bt_DBTDevice_setPairingNumericComparisonImpl(JNIEnv *env, jobject obj, jboolean jequal) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return number( device->setPairingNumericComparison( JNI_TRUE == jequal ? true : false ) ); @@ -593,32 +593,32 @@ jbyte Java_jau_direct_1bt_DBTDevice_setPairingNumericComparisonImpl(JNIEnv *env, // getter // -static const std::string _serviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTDevice;ZLjava/lang/String;SS)V"); +static const std::string _serviceClazzCtorArgs("(JLjau/direct_bt/DBTDevice;ZLjava/lang/String;SS)V"); jobject Java_jau_direct_1bt_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - jau::darray<GATTServiceRef> services = device->getGATTServices(); // implicit GATT connect and discovery if required incl GenericAccess retrieval + jau::darray<BTGattServiceRef> services = device->getGattServices(); // implicit GATT connect and discovery if required incl GenericAccess retrieval if( services.size() > 0 ) { - std::shared_ptr<GattGenericAccessSvc> ga = device->getGATTGenericAccess(); + std::shared_ptr<GattGenericAccessSvc> ga = device->getGattGenericAccess(); if( nullptr != ga ) { env->SetShortField(obj, getField(env, obj, "appearance", "S"), static_cast<jshort>(ga->appearance)); java_exception_check_and_throw(env, E_FILE_LINE); - DBG_PRINT("DBTDevice.getServices(): GenericAccess: %s", ga->toString().c_str()); + DBG_PRINT("BTDevice.getServices(): GenericAccess: %s", ga->toString().c_str()); } } else { return nullptr; } - // DBTGattService(final long nativeInstance, final DBTDevice device, final boolean isPrimary, + // BTGattService(final long nativeInstance, final BTDevice device, final boolean isPrimary, // final String type_uuid, final short handleStart, final short handleEnd) - std::function<jobject(JNIEnv*, jclass, jmethodID, GATTService*)> ctor_service = - [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, GATTService *service)->jobject { + std::function<jobject(JNIEnv*, jclass, jmethodID, BTGattService*)> ctor_service = + [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTGattService *service)->jobject { // prepare adapter ctor - std::shared_ptr<DBTDevice> _device = service->getDeviceChecked(); + std::shared_ptr<BTDevice> _device = service->getDeviceChecked(); JavaGlobalObj::check(_device->getJavaObject(), E_FILE_LINE); jobject jdevice = JavaGlobalObj::GetObject(_device->getJavaObject()); const jboolean isPrimary = service->isPrimary; @@ -637,7 +637,7 @@ jobject Java_jau_direct_1bt_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj) env_->DeleteLocalRef(jservice); return JavaGlobalObj::GetObject(jServiceRef); }; - return convert_vector_sharedptr_to_jarraylist<jau::darray<GATTServiceRef>, GATTService>( + return convert_vector_sharedptr_to_jarraylist<jau::darray<BTGattServiceRef>, BTGattService>( env, services, _serviceClazzCtorArgs.c_str(), ctor_service); } catch(...) { rethrow_and_raise_java_exception(env); @@ -648,7 +648,7 @@ jobject Java_jau_direct_1bt_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj) jboolean Java_jau_direct_1bt_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return device->pingGATT() ? JNI_TRUE : JNI_FALSE; @@ -661,7 +661,7 @@ jboolean Java_jau_direct_1bt_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj) jstring Java_jau_direct_1bt_DBTDevice_getIcon(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return nullptr; // FIXME } catch(...) { @@ -673,7 +673,7 @@ jstring Java_jau_direct_1bt_DBTDevice_getIcon(JNIEnv *env, jobject obj) void Java_jau_direct_1bt_DBTDevice_setTrustedImpl(JNIEnv *env, jobject obj, jboolean value) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); (void)value; // FIXME @@ -685,7 +685,7 @@ void Java_jau_direct_1bt_DBTDevice_setTrustedImpl(JNIEnv *env, jobject obj, jboo void Java_jau_direct_1bt_DBTDevice_setBlockedImpl(JNIEnv *env, jobject obj, jboolean value) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); (void)value; // FIXME @@ -697,7 +697,7 @@ void Java_jau_direct_1bt_DBTDevice_setBlockedImpl(JNIEnv *env, jobject obj, jboo jboolean JNICALL Java_jau_direct_1bt_DBTDevice_getLegacyPairing(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return JNI_FALSE; // FIXME } catch(...) { @@ -709,7 +709,7 @@ jboolean JNICALL Java_jau_direct_1bt_DBTDevice_getLegacyPairing(JNIEnv *env, job jshort Java_jau_direct_1bt_DBTDevice_getRSSI(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return (jshort) device->getRSSI(); } catch(...) { @@ -722,7 +722,7 @@ jshort Java_jau_direct_1bt_DBTDevice_getRSSI(JNIEnv *env, jobject obj) jobjectArray Java_jau_direct_1bt_DBTDevice_getUUIDs(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return nullptr; // FIXME } catch(...) { @@ -734,7 +734,7 @@ jobjectArray Java_jau_direct_1bt_DBTDevice_getUUIDs(JNIEnv *env, jobject obj) jstring Java_jau_direct_1bt_DBTDevice_getModalias(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return nullptr; // FIXME } catch(...) { @@ -746,7 +746,7 @@ jstring Java_jau_direct_1bt_DBTDevice_getModalias(JNIEnv *env, jobject obj) jobject Java_jau_direct_1bt_DBTDevice_getManufacturerData(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); std::shared_ptr<ManufactureSpecificData> mdata = device->getManufactureSpecificData(); @@ -783,7 +783,7 @@ jobject Java_jau_direct_1bt_DBTDevice_getManufacturerData(JNIEnv *env, jobject o jshort Java_jau_direct_1bt_DBTDevice_getTxPower(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); return (jshort) device->getTxPower(); } catch(...) { @@ -834,7 +834,7 @@ typedef std::shared_ptr<BooleanDeviceCBContext> BooleanDeviceCBContextRef; // Blocked // -static void disableBlockedNotifications(JNIEnv *env, jobject obj, DBTManager &mgmt) +static void disableBlockedNotifications(JNIEnv *env, jobject obj, BTManager &mgmt) { InvocationFunc<bool, const MgmtEvent&> * funcptr = getObjectRef<InvocationFunc<bool, const MgmtEvent&>>(env, obj, "blockedNotificationRef"); @@ -854,9 +854,9 @@ static void disableBlockedNotifications(JNIEnv *env, jobject obj, DBTManager &mg void Java_jau_direct_1bt_DBTDevice_disableBlockedNotificationsImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - DBTManager & mgmt = device->getAdapter().getManager(); + BTManager & mgmt = device->getAdapter().getManager(); disableBlockedNotifications(env, obj, mgmt); } catch(...) { @@ -866,10 +866,10 @@ void Java_jau_direct_1bt_DBTDevice_disableBlockedNotificationsImpl(JNIEnv *env, void Java_jau_direct_1bt_DBTDevice_enableBlockedNotificationsImpl(JNIEnv *env, jobject obj, jobject javaCallback) { try { - DBTDevice *device= getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device= getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - DBTAdapter & adapter = device->getAdapter(); - DBTManager & mgmt = adapter.getManager(); + BTAdapter & adapter = device->getAdapter(); + BTManager & mgmt = adapter.getManager(); disableBlockedNotifications(env, obj, mgmt); @@ -924,7 +924,7 @@ void Java_jau_direct_1bt_DBTDevice_enableBlockedNotificationsImpl(JNIEnv *env, j // Paired // -static void disablePairedNotifications(JNIEnv *env, jobject obj, DBTManager &mgmt) +static void disablePairedNotifications(JNIEnv *env, jobject obj, BTManager &mgmt) { InvocationFunc<bool, const MgmtEvent&> * funcptr = getObjectRef<InvocationFunc<bool, const MgmtEvent&>>(env, obj, "pairedNotificationRef"); @@ -941,9 +941,9 @@ static void disablePairedNotifications(JNIEnv *env, jobject obj, DBTManager &mgm void Java_jau_direct_1bt_DBTDevice_disablePairedNotificationsImpl(JNIEnv *env, jobject obj) { try { - DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - DBTManager & mgmt = device->getAdapter().getManager(); + BTManager & mgmt = device->getAdapter().getManager(); disablePairedNotifications(env, obj, mgmt); } catch(...) { @@ -953,10 +953,10 @@ void Java_jau_direct_1bt_DBTDevice_disablePairedNotificationsImpl(JNIEnv *env, j void Java_jau_direct_1bt_DBTDevice_enablePairedNotificationsImpl(JNIEnv *env, jobject obj, jobject javaCallback) { try { - DBTDevice *device= getJavaUplinkObject<DBTDevice>(env, obj); + BTDevice *device= getJavaUplinkObject<BTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - DBTAdapter & adapter = device->getAdapter(); - DBTManager & mgmt = adapter.getManager(); + BTAdapter & adapter = device->getAdapter(); + BTManager & mgmt = adapter.getManager(); disablePairedNotifications(env, obj, mgmt); diff --git a/java/jni/direct_bt/DBTGattCharacteristic.cxx b/java/jni/direct_bt/DBTGattChar.cxx index 381c2e27..1695009b 100644 --- a/java/jni/direct_bt/DBTGattCharacteristic.cxx +++ b/java/jni/direct_bt/DBTGattChar.cxx @@ -23,22 +23,22 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "jau_direct_bt_DBTGattCharacteristic.h" +#include "jau_direct_bt_DBTGattChar.h" #include <jau/debug.hpp> #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTDevice.hpp" -#include "direct_bt/DBTAdapter.hpp" +#include "direct_bt/BTDevice.hpp" +#include "direct_bt/BTAdapter.hpp" using namespace direct_bt; using namespace jau; -jstring Java_jau_direct_1bt_DBTGattCharacteristic_toStringImpl(JNIEnv *env, jobject obj) { +jstring Java_jau_direct_1bt_DBTGattChar_toStringImpl(JNIEnv *env, jobject obj) { try { - GATTCharacteristic *nativePtr = getJavaUplinkObject<GATTCharacteristic>(env, obj); + BTGattChar *nativePtr = getJavaUplinkObject<BTGattChar>(env, obj); JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE); return from_string_to_jstring(env, nativePtr->toString()); } catch(...) { @@ -47,36 +47,36 @@ jstring Java_jau_direct_1bt_DBTGattCharacteristic_toStringImpl(JNIEnv *env, jobj return nullptr; } -void Java_jau_direct_1bt_DBTGattCharacteristic_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance) { +void Java_jau_direct_1bt_DBTGattChar_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance) { (void)obj; try { - GATTCharacteristic *characteristic = castInstance<GATTCharacteristic>(nativeInstance); + BTGattChar *characteristic = castInstance<BTGattChar>(nativeInstance); (void)characteristic; - // No delete: Service instance owned by GATTService -> DBTDevice + // No delete: Service instance owned by BTGattService -> BTDevice } catch(...) { rethrow_and_raise_java_exception(env); } } -static const std::string _descriptorClazzCtorArgs("(JLdirect_bt/tinyb/DBTGattCharacteristic;Ljava/lang/String;S[B)V"); +static const std::string _descriptorClazzCtorArgs("(JLjau/direct_bt/DBTGattChar;Ljava/lang/String;S[B)V"); -jobject Java_jau_direct_1bt_DBTGattCharacteristic_getDescriptorsImpl(JNIEnv *env, jobject obj) { +jobject Java_jau_direct_1bt_DBTGattChar_getDescriptorsImpl(JNIEnv *env, jobject obj) { try { - GATTCharacteristic *characteristic = getJavaUplinkObject<GATTCharacteristic>(env, obj); + BTGattChar *characteristic = getJavaUplinkObject<BTGattChar>(env, obj); JavaGlobalObj::check(characteristic->getJavaObject(), E_FILE_LINE); - jau::darray<GATTDescriptorRef> & descriptorList = characteristic->descriptorList; + jau::darray<BTGattDescRef> & descriptorList = characteristic->descriptorList; - // DBTGattDescriptor(final long nativeInstance, final DBTGattCharacteristic characteristic, + // BTGattDesc(final long nativeInstance, final BTGattChar characteristic, // final String type_uuid, final short handle, final byte[] value) - // DBTGattDescriptor(final long nativeInstance, final DBTGattCharacteristic characteristic, + // BTGattDesc(final long nativeInstance, final BTGattChar characteristic, // final String type_uuid, final short handle, final byte[] value) - std::function<jobject(JNIEnv*, jclass, jmethodID, GATTDescriptor *)> ctor_desc = - [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, GATTDescriptor *descriptor)->jobject { + std::function<jobject(JNIEnv*, jclass, jmethodID, BTGattDesc *)> ctor_desc = + [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTGattDesc *descriptor)->jobject { // prepare adapter ctor - std::shared_ptr<GATTCharacteristic> _characteristic = descriptor->getCharacteristicChecked(); + std::shared_ptr<BTGattChar> _characteristic = descriptor->getGattCharChecked(); JavaGlobalObj::check(_characteristic->getJavaObject(), E_FILE_LINE); jobject jcharacteristic = JavaGlobalObj::GetObject(_characteristic->getJavaObject()); @@ -101,7 +101,7 @@ jobject Java_jau_direct_1bt_DBTGattCharacteristic_getDescriptorsImpl(JNIEnv *env env_->DeleteLocalRef(jdesc); return JavaGlobalObj::GetObject(jDescRef); }; - return convert_vector_sharedptr_to_jarraylist<jau::darray<GATTDescriptorRef>, GATTDescriptor>( + return convert_vector_sharedptr_to_jarraylist<jau::darray<BTGattDescRef>, BTGattDesc>( env, descriptorList, _descriptorClazzCtorArgs.c_str(), ctor_desc); } catch(...) { rethrow_and_raise_java_exception(env); @@ -109,12 +109,12 @@ jobject Java_jau_direct_1bt_DBTGattCharacteristic_getDescriptorsImpl(JNIEnv *env return nullptr; } -jbyteArray Java_jau_direct_1bt_DBTGattCharacteristic_readValueImpl(JNIEnv *env, jobject obj) { +jbyteArray Java_jau_direct_1bt_DBTGattChar_readValueImpl(JNIEnv *env, jobject obj) { try { - GATTCharacteristic *characteristic = getJavaUplinkObject<GATTCharacteristic>(env, obj); + BTGattChar *characteristic = getJavaUplinkObject<BTGattChar>(env, obj); JavaGlobalObj::check(characteristic->getJavaObject(), E_FILE_LINE); - POctets res(GATTHandler::number(GATTHandler::Defaults::MAX_ATT_MTU), 0); + POctets res(BTGattHandler::number(BTGattHandler::Defaults::MAX_ATT_MTU), 0); if( !characteristic->readValue(res) ) { ERR_PRINT("Characteristic readValue failed: %s", characteristic->toString().c_str()); return env->NewByteArray((jsize)0); @@ -132,7 +132,7 @@ jbyteArray Java_jau_direct_1bt_DBTGattCharacteristic_readValueImpl(JNIEnv *env, return nullptr; } -jboolean Java_jau_direct_1bt_DBTGattCharacteristic_writeValueImpl(JNIEnv *env, jobject obj, jbyteArray jval, jboolean withResponse) { +jboolean Java_jau_direct_1bt_DBTGattChar_writeValueImpl(JNIEnv *env, jobject obj, jbyteArray jval, jboolean withResponse) { try { if( nullptr == jval ) { throw IllegalArgumentException("byte array null", E_FILE_LINE); @@ -141,7 +141,7 @@ jboolean Java_jau_direct_1bt_DBTGattCharacteristic_writeValueImpl(JNIEnv *env, j if( 0 == value_size ) { return JNI_TRUE; } - GATTCharacteristic *characteristic = getJavaUplinkObject<GATTCharacteristic>(env, obj); + BTGattChar *characteristic = getJavaUplinkObject<BTGattChar>(env, obj); JavaGlobalObj::check(characteristic->getJavaObject(), E_FILE_LINE); JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release @@ -168,10 +168,10 @@ jboolean Java_jau_direct_1bt_DBTGattCharacteristic_writeValueImpl(JNIEnv *env, j return JNI_FALSE; } -jboolean Java_jau_direct_1bt_DBTGattCharacteristic_configNotificationIndicationImpl(JNIEnv *env, jobject obj, +jboolean Java_jau_direct_1bt_DBTGattChar_configNotificationIndicationImpl(JNIEnv *env, jobject obj, jboolean enableNotification, jboolean enableIndication, jbooleanArray jEnabledState) { try { - GATTCharacteristic *characteristic = getJavaUplinkObjectUnchecked<GATTCharacteristic>(env, obj); + BTGattChar *characteristic = getJavaUplinkObjectUnchecked<BTGattChar>(env, obj); if( nullptr == characteristic ) { if( !enableNotification && !enableIndication ) { // OK to have native characteristic being shutdown @ disable @@ -197,7 +197,7 @@ jboolean Java_jau_direct_1bt_DBTGattCharacteristic_configNotificationIndicationI bool cccdEnableResult[2]; bool res = characteristic->configNotificationIndication(enableNotification, enableIndication, cccdEnableResult); - DBG_PRINT("DBTGattCharacteristic::configNotificationIndication Config Notification(%d), Indication(%d): Result %d", + DBG_PRINT("BTGattChar::configNotificationIndication Config Notification(%d), Indication(%d): Result %d", cccdEnableResult[0], cccdEnableResult[1], res); state_ptr[0] = cccdEnableResult[0]; state_ptr[1] = cccdEnableResult[1]; diff --git a/java/jni/direct_bt/DBTGattDescriptor.cxx b/java/jni/direct_bt/DBTGattDesc.cxx index a14f1611..97b0d3a5 100644 --- a/java/jni/direct_bt/DBTGattDescriptor.cxx +++ b/java/jni/direct_bt/DBTGattDesc.cxx @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "jau_direct_bt_DBTGattDescriptor.h" +#include "jau_direct_bt_DBTGattDesc.h" // #define VERBOSE_ON 1 #include <jau/debug.hpp> @@ -31,26 +31,26 @@ #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTDevice.hpp" -#include "direct_bt/DBTAdapter.hpp" +#include "direct_bt/BTDevice.hpp" +#include "direct_bt/BTAdapter.hpp" using namespace direct_bt; using namespace jau; -void Java_jau_direct_1bt_DBTGattDescriptor_deleteImpl(JNIEnv *env, jobject obj) { +void Java_jau_direct_1bt_DBTGattDesc_deleteImpl(JNIEnv *env, jobject obj) { try { - GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj); + BTGattDesc *descriptor = getJavaUplinkObject<BTGattDesc>(env, obj); (void)descriptor; - // No delete: Service instance owned by GATTService -> DBTDevice + // No delete: Service instance owned by GATTService -> BTDevice } catch(...) { rethrow_and_raise_java_exception(env); } } -jstring Java_jau_direct_1bt_DBTGattDescriptor_toStringImpl(JNIEnv *env, jobject obj) { +jstring Java_jau_direct_1bt_DBTGattDesc_toStringImpl(JNIEnv *env, jobject obj) { (void)obj; try { - GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj); + BTGattDesc *descriptor = getJavaUplinkObject<BTGattDesc>(env, obj); JavaGlobalObj::check(descriptor->getJavaObject(), E_FILE_LINE); return from_string_to_jstring(env, descriptor->toString()); } catch(...) { @@ -59,9 +59,9 @@ jstring Java_jau_direct_1bt_DBTGattDescriptor_toStringImpl(JNIEnv *env, jobject return nullptr; } -jbyteArray Java_jau_direct_1bt_DBTGattDescriptor_readValueImpl(JNIEnv *env, jobject obj) { +jbyteArray Java_jau_direct_1bt_DBTGattDesc_readValueImpl(JNIEnv *env, jobject obj) { try { - GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj); + BTGattDesc *descriptor = getJavaUplinkObject<BTGattDesc>(env, obj); JavaGlobalObj::check(descriptor->getJavaObject(), E_FILE_LINE); if( !descriptor->readValue() ) { @@ -80,7 +80,7 @@ jbyteArray Java_jau_direct_1bt_DBTGattDescriptor_readValueImpl(JNIEnv *env, jobj return nullptr; } -jboolean Java_jau_direct_1bt_DBTGattDescriptor_writeValueImpl(JNIEnv *env, jobject obj, jbyteArray jval) { +jboolean Java_jau_direct_1bt_DBTGattDesc_writeValueImpl(JNIEnv *env, jobject obj, jbyteArray jval) { try { if( nullptr == jval ) { throw IllegalArgumentException("byte array null", E_FILE_LINE); @@ -89,7 +89,7 @@ jboolean Java_jau_direct_1bt_DBTGattDescriptor_writeValueImpl(JNIEnv *env, jobje if( 0 == value_size ) { return JNI_TRUE; } - GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj); + BTGattDesc *descriptor = getJavaUplinkObject<BTGattDesc>(env, obj); JavaGlobalObj::check(descriptor->getJavaObject(), E_FILE_LINE); JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release diff --git a/java/jni/direct_bt/DBTGattService.cxx b/java/jni/direct_bt/DBTGattService.cxx index b367c445..085ef1a1 100644 --- a/java/jni/direct_bt/DBTGattService.cxx +++ b/java/jni/direct_bt/DBTGattService.cxx @@ -31,15 +31,15 @@ #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTDevice.hpp" -#include "direct_bt/DBTAdapter.hpp" +#include "direct_bt/BTDevice.hpp" +#include "direct_bt/BTAdapter.hpp" using namespace direct_bt; using namespace jau; jstring Java_jau_direct_1bt_DBTGattService_toStringImpl(JNIEnv *env, jobject obj) { try { - GATTService *nativePtr = getJavaUplinkObject<GATTService>(env, obj); + BTGattService *nativePtr = getJavaUplinkObject<BTGattService>(env, obj); JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE); return from_string_to_jstring(env, nativePtr->toString()); } catch(...) { @@ -52,37 +52,37 @@ jstring Java_jau_direct_1bt_DBTGattService_toStringImpl(JNIEnv *env, jobject obj void Java_jau_direct_1bt_DBTGattService_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance) { (void)obj; try { - GATTService *service = castInstance<GATTService>(nativeInstance); + BTGattService *service = castInstance<BTGattService>(nativeInstance); (void)service; - // No delete: Service instance owned by DBTDevice + // No delete: Service instance owned by BTDevice } catch(...) { rethrow_and_raise_java_exception(env); } } -static const std::string _characteristicClazzCtorArgs("(JLdirect_bt/tinyb/DBTGattService;S[Ljava/lang/String;ZZLjava/lang/String;SI)V"); +static const std::string _characteristicClazzCtorArgs("(JLjau/direct_bt/DBTGattService;S[Ljava/lang/String;ZZLjava/lang/String;SI)V"); -jobject Java_jau_direct_1bt_DBTGattService_getCharacteristicsImpl(JNIEnv *env, jobject obj) { +jobject Java_jau_direct_1bt_DBTGattService_getCharsImpl(JNIEnv *env, jobject obj) { try { - GATTService *service = getJavaUplinkObject<GATTService>(env, obj); + BTGattService *service = getJavaUplinkObject<BTGattService>(env, obj); JavaGlobalObj::check(service->getJavaObject(), E_FILE_LINE); - jau::darray<std::shared_ptr<GATTCharacteristic>> & characteristics = service->characteristicList; + jau::darray<std::shared_ptr<BTGattChar>> & characteristics = service->characteristicList; - // DBTGattCharacteristic(final long nativeInstance, final DBTGattService service, + // BTGattChar(final long nativeInstance, final BTGattService service, // final short handle, final String[] properties, // final boolean hasNotify, final boolean hasIndicate, // final String value_type_uuid, final short value_handle, // final int clientCharacteristicsConfigIndex) - std::function<jobject(JNIEnv*, jclass, jmethodID, GATTCharacteristic *)> ctor_char = - [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, GATTCharacteristic *characteristic)->jobject { + std::function<jobject(JNIEnv*, jclass, jmethodID, BTGattChar *)> ctor_char = + [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTGattChar *characteristic)->jobject { // prepare adapter ctor - std::shared_ptr<GATTService> _service = characteristic->getServiceChecked(); + std::shared_ptr<BTGattService> _service = characteristic->getServiceChecked(); JavaGlobalObj::check(_service->getJavaObject(), E_FILE_LINE); jobject jservice = JavaGlobalObj::GetObject(_service->getJavaObject()); - jau::darray<std::unique_ptr<std::string>> props = GATTCharacteristic::getPropertiesStringList(characteristic->properties); + jau::darray<std::unique_ptr<std::string>> props = BTGattChar::getPropertiesStringList(characteristic->properties); size_t props_size = props.size(); jobjectArray jproperties; @@ -99,8 +99,8 @@ jobject Java_jau_direct_1bt_DBTGattService_getCharacteristicsImpl(JNIEnv *env, j } java_exception_check_and_throw(env_, E_FILE_LINE); - const bool hasNotify = characteristic->hasProperties(GATTCharacteristic::PropertyBitVal::Notify); - const bool hasIndicate = characteristic->hasProperties(GATTCharacteristic::PropertyBitVal::Indicate); + const bool hasNotify = characteristic->hasProperties(BTGattChar::PropertyBitVal::Notify); + const bool hasIndicate = characteristic->hasProperties(BTGattChar::PropertyBitVal::Indicate); const jstring uuid = from_string_to_jstring(env_, directBTJNISettings.getUnifyUUID128Bit() ? characteristic->value_type->toUUID128String() : @@ -109,7 +109,7 @@ jobject Java_jau_direct_1bt_DBTGattService_getCharacteristicsImpl(JNIEnv *env, j jobject jcharVal = env_->NewObject(clazz, clazz_ctor, (jlong)characteristic, jservice, characteristic->handle, jproperties, hasNotify, hasIndicate, - uuid, characteristic->value_handle, characteristic->clientCharacteristicsConfigIndex); + uuid, characteristic->value_handle, characteristic->clientCharConfigIndex); java_exception_check_and_throw(env_, E_FILE_LINE); JNIGlobalRef::check(jcharVal, E_FILE_LINE); std::shared_ptr<JavaAnon> jCharRef = characteristic->getJavaObject(); // GlobalRef @@ -118,7 +118,7 @@ jobject Java_jau_direct_1bt_DBTGattService_getCharacteristicsImpl(JNIEnv *env, j env_->DeleteLocalRef(jcharVal); return JavaGlobalObj::GetObject(jCharRef); }; - return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<GATTCharacteristic>>, GATTCharacteristic>( + return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<BTGattChar>>, BTGattChar>( env, characteristics, _characteristicClazzCtorArgs.c_str(), ctor_char); } catch(...) { rethrow_and_raise_java_exception(env); diff --git a/java/jni/direct_bt/DBTManager.cxx b/java/jni/direct_bt/DBTManager.cxx index eb3e8a3e..24665b97 100644 --- a/java/jni/direct_bt/DBTManager.cxx +++ b/java/jni/direct_bt/DBTManager.cxx @@ -31,9 +31,9 @@ #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTDevice.hpp" -#include "direct_bt/DBTAdapter.hpp" -#include "direct_bt/DBTManager.hpp" +#include "direct_bt/BTDevice.hpp" +#include "direct_bt/BTAdapter.hpp" +#include "direct_bt/BTManager.hpp" using namespace direct_bt; using namespace jau; @@ -66,7 +66,7 @@ struct BooleanMgmtCBContext { }; typedef std::shared_ptr<BooleanMgmtCBContext> BooleanMgmtCBContextRef; -static void _addMgmtCBOnce(JNIEnv *env, DBTManager & mgmt, JNIGlobalRef jmgmtRef, MgmtEvent::Opcode opc, +static void _addMgmtCBOnce(JNIEnv *env, BTManager & mgmt, JNIGlobalRef jmgmtRef, MgmtEvent::Opcode opc, const std::string &jmethodName, const std::string &jmethodArgs) { try { @@ -93,12 +93,12 @@ static void _addMgmtCBOnce(JNIEnv *env, DBTManager & mgmt, JNIGlobalRef jmgmtRef jclass mgmtClazz = jau::search_class(env, jmgmtRef.getObject()); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == mgmtClazz ) { - throw jau::InternalError("DBTManager not found", E_FILE_LINE); + throw jau::InternalError("BTManager not found", E_FILE_LINE); } jmethodID mid = jau::search_method(env, mgmtClazz, jmethodName.c_str(), jmethodArgs.c_str(), false); jau::java_exception_check_and_throw(env, E_FILE_LINE); if( nullptr == mid ) { - throw jau::InternalError("DBTManager has no "+jmethodName+"."+jmethodArgs+" method, for "+mgmt.toString(), E_FILE_LINE); + throw jau::InternalError("BTManager has no "+jmethodName+"."+jmethodArgs+" method, for "+mgmt.toString(), E_FILE_LINE); } // move BooleanDeviceCBContextRef into CaptureInvocationFunc and operator== includes javaCallback comparison @@ -114,8 +114,8 @@ void Java_jau_direct_1bt_DBTManager_initImpl(JNIEnv *env, jobject obj, jboolean directBTJNISettings.setUnifyUUID128Bit(unifyUUID128Bit); try { BTMode btMode = static_cast<BTMode>(jbtMode); - DBTManager *manager = &DBTManager::get(btMode); // special: static singleton - setInstance<DBTManager>(env, obj, manager); + BTManager *manager = &BTManager::get(btMode); // special: static singleton + setInstance<BTManager>(env, obj, manager); java_exception_check_and_throw(env, E_FILE_LINE); manager->setJavaObject( std::shared_ptr<JavaAnon>( new JavaGlobalObj(obj, nullptr) ) ); JavaGlobalObj::check(manager->getJavaObject(), E_FILE_LINE); @@ -134,7 +134,7 @@ void Java_jau_direct_1bt_DBTManager_deleteImpl(JNIEnv *env, jobject obj, jlong n { (void)obj; try { - DBTManager *manager = castInstance<DBTManager>(nativeInstance); // special: static singleton + BTManager *manager = castInstance<BTManager>(nativeInstance); // special: static singleton manager->close(); manager->setJavaObject(); (void) manager; @@ -144,7 +144,7 @@ void Java_jau_direct_1bt_DBTManager_deleteImpl(JNIEnv *env, jobject obj, jlong n } static const std::string _adapterClazzCtorArgs("(J[BLjava/lang/String;I)V"); -static jobject _createJavaAdapter(JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, DBTAdapter* adapter) { +static jobject _createJavaAdapter(JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTAdapter* adapter) { // prepare adapter ctor const EUI48 addr = adapter->getAddress(); jbyteArray jaddr = env_->NewByteArray(sizeof(addr)); @@ -168,11 +168,11 @@ static jobject _createJavaAdapter(JNIEnv *env_, jclass clazz, jmethodID clazz_ct jobject Java_jau_direct_1bt_DBTManager_getAdapterListImpl(JNIEnv *env, jobject obj) { try { - DBTManager *manager = getInstance<DBTManager>(env, obj); + BTManager *manager = getInstance<BTManager>(env, obj); DBG_PRINT("Java_jau_direct_1bt_DBTManager_getAdapterListImpl: Manager %s", manager->toString().c_str()); - jau::darray<std::shared_ptr<DBTAdapter>> adapters = manager->getAdapters(); - return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<DBTAdapter>>, DBTAdapter>( + jau::darray<std::shared_ptr<BTAdapter>> adapters = manager->getAdapters(); + return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<BTAdapter>>, BTAdapter>( env, adapters, _adapterClazzCtorArgs.c_str(), _createJavaAdapter); } catch(...) { rethrow_and_raise_java_exception(env); @@ -183,16 +183,16 @@ jobject Java_jau_direct_1bt_DBTManager_getAdapterListImpl(JNIEnv *env, jobject o jobject Java_jau_direct_1bt_DBTManager_getAdapterImpl(JNIEnv *env, jobject obj, jint dev_id) { try { - DBTManager *manager = getInstance<DBTManager>(env, obj); + BTManager *manager = getInstance<BTManager>(env, obj); - std::shared_ptr<DBTAdapter> adapter = manager->getAdapter(dev_id); + std::shared_ptr<BTAdapter> adapter = manager->getAdapter(dev_id); if( nullptr == adapter ) { - ERR_PRINT("DBTManager::getAdapterImpl: Adapter dev_id %d: Not found", dev_id); + ERR_PRINT("BTManager::getAdapterImpl: Adapter dev_id %d: Not found", dev_id); return nullptr; } - DBG_PRINT("DBTManager::getAdapterImpl: Adapter dev_id %d: %s", dev_id, adapter->toString().c_str()); + DBG_PRINT("BTManager::getAdapterImpl: Adapter dev_id %d: %s", dev_id, adapter->toString().c_str()); - return jau::convert_instance_to_jobject<DBTAdapter>(env, adapter.get(), _adapterClazzCtorArgs.c_str(), _createJavaAdapter); + return jau::convert_instance_to_jobject<BTAdapter>(env, adapter.get(), _adapterClazzCtorArgs.c_str(), _createJavaAdapter); } catch(...) { rethrow_and_raise_java_exception(env); } diff --git a/java/jni/direct_bt/DBTNativeDownlink.cxx b/java/jni/direct_bt/DBTNativeDownlink.cxx index d912aaa3..88e0124a 100644 --- a/java/jni/direct_bt/DBTNativeDownlink.cxx +++ b/java/jni/direct_bt/DBTNativeDownlink.cxx @@ -30,7 +30,7 @@ #include "helper_base.hpp" #include "helper_dbt.hpp" -#include "direct_bt/DBTTypes.hpp" +#include "direct_bt/BTTypes1.hpp" using namespace direct_bt; using namespace jau; diff --git a/java/jni/direct_bt/DBTObject.cxx b/java/jni/direct_bt/DBTObject.cxx index f41e2028..e6908c11 100644 --- a/java/jni/direct_bt/DBTObject.cxx +++ b/java/jni/direct_bt/DBTObject.cxx @@ -27,7 +27,7 @@ #include "helper_base.hpp" -#include "direct_bt/DBTTypes.hpp" +#include "direct_bt/BTTypes1.hpp" using namespace direct_bt; diff --git a/java/jni/helper_base.cxx b/java/jni/helper_base.cxx index ceac1c78..a995718d 100644 --- a/java/jni/helper_base.cxx +++ b/java/jni/helper_base.cxx @@ -46,7 +46,7 @@ jobject get_bluetooth_type(JNIEnv *env, const char *field_name) return result; } -void raise_java_exception(JNIEnv *env, const direct_bt::BluetoothException &e, const char* file, int line) { +void raise_java_exception(JNIEnv *env, const direct_bt::BTException &e, const char* file, int line) { jau::print_native_caught_exception_fwd2java(e, file, line); env->ThrowNew(env->FindClass("org/tinyb/BluetoothException"), e.what()); } @@ -78,7 +78,7 @@ void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char* file, int li jau::raise_java_exception(env, e, file, line); } catch (const jau::IndexOutOfBoundsException &e) { jau::raise_java_exception(env, e, file, line); - } catch (const direct_bt::BluetoothException &e) { + } catch (const direct_bt::BTException &e) { raise_java_exception(env, e, file, line); } catch (const tinyb::BluetoothException &e) { raise_java_exception(env, e, file, line); diff --git a/java/jni/helper_base.hpp b/java/jni/helper_base.hpp index 7af77e2f..05293108 100644 --- a/java/jni/helper_base.hpp +++ b/java/jni/helper_base.hpp @@ -36,12 +36,12 @@ #include <jau/jni/helper_jni.hpp> -#include "direct_bt/BTTypes.hpp" +#include "direct_bt/BTTypes0.hpp" #include "tinyb/BluetoothException.hpp" jobject get_bluetooth_type(JNIEnv *env, const char *field_name); -void raise_java_exception(JNIEnv *env, const direct_bt::BluetoothException &e, const char* file, int line); +void raise_java_exception(JNIEnv *env, const direct_bt::BTException &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const tinyb::BluetoothException &e, const char* file, int line); /** diff --git a/java/jni/tinyb/CMakeLists.txt b/java/jni/tinyb/CMakeLists.txt index c54dd090..6ae9b25c 100644 --- a/java/jni/tinyb/CMakeLists.txt +++ b/java/jni/tinyb/CMakeLists.txt @@ -25,8 +25,8 @@ set (tinyb_JNI_SRCS ${PROJECT_SOURCE_DIR}/jaulib/java_jni/jni/helper_jni.cxx ${PROJECT_SOURCE_DIR}/jaulib/src/basic_types.cpp ${PROJECT_SOURCE_DIR}/java/jni/helper_base.cxx - ${PROJECT_SOURCE_DIR}/java/jni/BluetoothFactory.cxx - ${PROJECT_SOURCE_DIR}/java/jni/BluetoothUtils.cxx + ${PROJECT_SOURCE_DIR}/java/jni/BTFactory.cxx + ${PROJECT_SOURCE_DIR}/java/jni/BTUtils.cxx ${PROJECT_SOURCE_DIR}/java/jni/tinyb/helper_tinyb.cxx ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusAdapter.cxx ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusDevice.cxx diff --git a/java/jni/tinyb/DBusGattService.cxx b/java/jni/tinyb/DBusGattService.cxx index 99284e39..f621df2d 100644 --- a/java/jni/tinyb/DBusGattService.cxx +++ b/java/jni/tinyb/DBusGattService.cxx @@ -103,7 +103,7 @@ jboolean Java_tinyb_dbus_DBusGattService_getPrimary(JNIEnv *env, jobject obj) return JNI_FALSE; } -jobject Java_tinyb_dbus_DBusGattService_getCharacteristics(JNIEnv *env, jobject obj) +jobject Java_tinyb_dbus_DBusGattService_getChars(JNIEnv *env, jobject obj) { try { BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj); diff --git a/java/org/direct_bt/AdapterSettings.java b/java/org/direct_bt/AdapterSettings.java index 52a090d4..8bf0ea2d 100644 --- a/java/org/direct_bt/AdapterSettings.java +++ b/java/org/direct_bt/AdapterSettings.java @@ -25,7 +25,7 @@ package org.direct_bt; /** - * Bit mask of '{@link BluetoothAdapter} setting' data fields, + * Bit mask of '{@link BTAdapter} setting' data fields, * indicating a set of related data. * * @since 2.0.0 @@ -33,7 +33,7 @@ package org.direct_bt; public class AdapterSettings { /** - * Bits representing '{@link BluetoothAdapter} setting' data fields. + * Bits representing '{@link BTAdapter} setting' data fields. * * @since 2.0.0 */ diff --git a/java/org/direct_bt/AdapterStatusListener.java b/java/org/direct_bt/AdapterStatusListener.java index 7e3b1634..68377957 100644 --- a/java/org/direct_bt/AdapterStatusListener.java +++ b/java/org/direct_bt/AdapterStatusListener.java @@ -26,20 +26,20 @@ package org.direct_bt; /** - * {@link BluetoothAdapter} status listener for {@link BluetoothDevice} discovery events: Added, updated and removed; - * as well as for certain {@link BluetoothAdapter} events. + * {@link BTAdapter} status listener for {@link BTDevice} discovery events: Added, updated and removed; + * as well as for certain {@link BTAdapter} events. * <p> * User implementations shall return as early as possible to avoid blocking the event-handler thread, - * if not specified within the methods otherwise (see {@link #deviceReady(BluetoothDevice, long)}).<br> + * if not specified within the methods otherwise (see {@link #deviceReady(BTDevice, long)}).<br> * Especially complex mutable operations on DBTDevice or DBTAdapter should be issued off-thread! * </p> * <p> - * A listener instance may be attached to a {@link BluetoothAdapter} via - * {@link BluetoothAdapter#addStatusListener(AdapterStatusListener, BluetoothDevice)}. + * A listener instance may be attached to a {@link BTAdapter} via + * {@link BTAdapter#addStatusListener(AdapterStatusListener, BTDevice)}. * </p> * <p> * One {@link AdapterStatusListener} instance can only be attached to a listener receiver once at a time, - * i.e. you cannot attach the same instance more than once to a {@link BluetoothAdapter}. + * i.e. you cannot attach the same instance more than once to a {@link BTAdapter}. * <br> * To attach multiple listener, one instance per attachment must be created. * <br> @@ -67,75 +67,75 @@ public abstract class AdapterStatusListener { } /** - * {@link BluetoothAdapter} setting(s) changed. + * {@link BTAdapter} setting(s) changed. * @param adapter the adapter which settings have changed. * @param oldmask the previous settings mask. {@link AdapterSettings#isEmpty()} indicates the initial setting notification, - * see {@link BluetoothAdapter#addStatusListener(AdapterStatusListener, BluetoothDevice) addStatusListener(..)}. + * see {@link BTAdapter#addStatusListener(AdapterStatusListener, BTDevice) addStatusListener(..)}. * @param newmask the new settings mask * @param changedmask the changes settings mask. {@link AdapterSettings#isEmpty()} indicates the initial setting notification, - * see {@link BluetoothAdapter#addStatusListener(AdapterStatusListener, BluetoothDevice) addStatusListener(..)}. - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. + * see {@link BTAdapter#addStatusListener(AdapterStatusListener, BTDevice) addStatusListener(..)}. + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. */ - public void adapterSettingsChanged(final BluetoothAdapter adapter, + public void adapterSettingsChanged(final BTAdapter adapter, final AdapterSettings oldmask, final AdapterSettings newmask, final AdapterSettings changedmask, final long timestamp) { } /** - * {@link BluetoothAdapter}'s discovery state has changed, i.e. enabled or disabled. + * {@link BTAdapter}'s discovery state has changed, i.e. enabled or disabled. * @param adapter the adapter which discovering state has changed. * @param currentMeta the current meta {@link ScanType} * @param changedType denotes the changed {@link ScanType} * @param changedEnabled denotes whether the changed {@link ScanType} has been enabled or disabled * @param keepAlive if {@code true}, the denoted changed {@link ScanType} will be re-enabled if disabled by the underlying Bluetooth implementation. - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. */ - public void discoveringChanged(final BluetoothAdapter adapter, final ScanType currentMeta, final ScanType changedType, final boolean changedEnabled, final boolean keepAlive, final long timestamp) { } + public void discoveringChanged(final BTAdapter adapter, final ScanType currentMeta, final ScanType changedType, final boolean changedEnabled, final boolean keepAlive, final long timestamp) { } /** - * A {@link BluetoothDevice} has been newly discovered. + * A {@link BTDevice} has been newly discovered. * <p> * The boolean return value informs the adapter whether the device shall be made persistent for connection {@code true}, * or that it can be discarded {@code false}.<br> - * If no registered {@link AdapterStatusListener#deviceFound(BluetoothDevice, long) deviceFound(..)} implementation returns {@code true}, + * If no registered {@link AdapterStatusListener#deviceFound(BTDevice, long) deviceFound(..)} implementation returns {@code true}, * the device instance will be removed from all internal lists and can no longer being used.<br> - * If any registered {@link AdapterStatusListener#deviceFound(BluetoothDevice, long) deviceFound(..)} implementation returns {@code true}, - * the device will be made persistent, is ready to connect and {@link BluetoothDevice#remove() remove} shall be called after usage. + * If any registered {@link AdapterStatusListener#deviceFound(BTDevice, long) deviceFound(..)} implementation returns {@code true}, + * the device will be made persistent, is ready to connect and {@link BTDevice#remove() remove} shall be called after usage. * </p> * @param device the found device - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. - * @return true if the device shall be made persistent and {@link BluetoothDevice#remove() remove} issued later. Otherwise false to remove device right away. + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. + * @return true if the device shall be made persistent and {@link BTDevice#remove() remove} issued later. Otherwise false to remove device right away. */ - public boolean deviceFound(final BluetoothDevice device, final long timestamp) { return false; } + public boolean deviceFound(final BTDevice device, final long timestamp) { return false; } /** - * An already discovered {@link BluetoothDevice} has been updated. + * An already discovered {@link BTDevice} has been updated. * @param device the updated device * @param updateMask the update mask of changed data - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. */ - public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) { } + public void deviceUpdated(final BTDevice device, final EIRDataTypeSet updateMask, final long timestamp) { } /** - * {@link BluetoothDevice} got connected. + * {@link BTDevice} got connected. * @param device the device which has been connected, holding the new connection handle. * @param handle the new connection handle, which has been assigned to the device already - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. */ - public void deviceConnected(final BluetoothDevice device, final short handle, final long timestamp) { } + public void deviceConnected(final BTDevice device, final short handle, final long timestamp) { } /** - * An already connected {@link BluetoothDevice}'s {@link SMPPairingState} has changed. + * An already connected {@link BTDevice}'s {@link SMPPairingState} has changed. * @param device the device which {@link PairingMode} has been changed. * @param state the current {@link SMPPairingState} of the connected device, see DBTDevice::getCurrentPairingState() * @param mode the current {@link PairingMode} of the connected device, see DBTDevice::getCurrentPairingMode() - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. - * @see BluetoothDevice#setPairingPasskey(int) - * @see BluetoothDevice#setPairingNumericComparison(boolean) + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. + * @see BTDevice#setPairingPasskey(int) + * @see BTDevice#setPairingNumericComparison(boolean) */ - public void devicePairingState(final BluetoothDevice device, final SMPPairingState state, final PairingMode mode, final long timestamp) {} + public void devicePairingState(final BTDevice device, final SMPPairingState state, final PairingMode mode, final long timestamp) {} /** - * {@link BluetoothDevice} is ready for user (GATT) processing, i.e. already connected, optionally paired and ATT MTU size negotiated via connected GATT. + * {@link BTDevice} is ready for user (GATT) processing, i.e. already connected, optionally paired and ATT MTU size negotiated via connected GATT. * <p> * Method is being called from a dedicated native thread, hence restrictions on method duration and complex mutable operations don't apply here. * </p> @@ -143,14 +143,14 @@ public abstract class AdapterStatusListener { * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds(). * @see {@link SMPPairingState#COMPLETED} */ - public void deviceReady(final BluetoothDevice device, final long timestamp) {} + public void deviceReady(final BTDevice device, final long timestamp) {} /** - * {@link BluetoothDevice} got disconnected. + * {@link BTDevice} got disconnected. * @param device the device which has been disconnected with zeroed connection handle. * @param reason the {@link HCIStatusCode} reason for disconnection * @param handle the disconnected connection handle, which has been unassigned from the device already - * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BluetoothUtils#currentTimeMillis()}. + * @param timestamp the time in monotonic milliseconds when this event occurred. See {@link BTUtils#currentTimeMillis()}. */ - public void deviceDisconnected(final BluetoothDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { } + public void deviceDisconnected(final BTDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { } }; diff --git a/java/org/direct_bt/BluetoothAdapter.java b/java/org/direct_bt/BTAdapter.java index 65558731..77a00f8c 100644 --- a/java/org/direct_bt/BluetoothAdapter.java +++ b/java/org/direct_bt/BTAdapter.java @@ -35,15 +35,15 @@ import java.util.UUID; * 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 interface BluetoothAdapter extends BluetoothObject +public interface BTAdapter extends BTObject { @Override - public BluetoothAdapter clone(); + public BTAdapter clone(); /** - * Returns the used singleton {@link BluetoothManager} instance, used to create this adapter. + * Returns the used singleton {@link BTManager} instance, used to create this adapter. */ - public BluetoothManager getManager(); + public BTManager getManager(); /** Find a BluetoothDevice. If parameters name and address are not null, * the returned object will have to match them. @@ -58,7 +58,7 @@ public interface BluetoothAdapter extends BluetoothObject * @return An object matching the name and address or null if not found before * timeout expires. */ - public BluetoothDevice find(String name, BDAddressAndType addressAndType, long timeoutMS); + public BTDevice find(String name, BDAddressAndType addressAndType, long timeoutMS); /** Find a BluetoothDevice. If parameters name and address are not null, * the returned object will have to match them. @@ -70,7 +70,7 @@ public interface BluetoothAdapter extends BluetoothObject * waiting for * @return An object matching the name and address. */ - public BluetoothDevice find(String name, BDAddressAndType addressAndType); + public BTDevice find(String name, BDAddressAndType addressAndType); /* Bluetooth specific API */ @@ -145,7 +145,7 @@ public interface BluetoothAdapter extends BluetoothObject * @deprecated since 2.0.0, use {@link #startDiscovery(boolean)}. */ @Deprecated - public boolean startDiscovery() throws BluetoothException; + public boolean startDiscovery() throws BTException; /** * Turns on device discovery if it is disabled. @@ -168,12 +168,12 @@ public interface BluetoothAdapter extends BluetoothObject * and {@link #stopDiscovery()} is the recommended workflow * for a reliable discovery process. * @return {@link HCIStatusCode#SUCCESS} if successful, otherwise the {@link HCIStatusCode} error state - * @throws BluetoothException + * @throws BTException * @since 2.0.0 * @implNote {@code keepAlive} not implemented in tinyb.dbus * @see #getDiscovering() */ - public HCIStatusCode startDiscovery(final boolean keepAlive) throws BluetoothException; + public HCIStatusCode startDiscovery(final boolean keepAlive) throws BTException; /** * Turns off device discovery if it is enabled. @@ -181,23 +181,23 @@ public interface BluetoothAdapter extends BluetoothObject * @apiNote return {@link HCIStatusCode} since 2.0.0 * @since 2.0.0 */ - public HCIStatusCode stopDiscovery() throws BluetoothException; + public HCIStatusCode stopDiscovery() throws BTException; /** Returns a list of discovered BluetoothDevices from this adapter. * @return A list of discovered BluetoothDevices on this adapter, * NULL if an error occurred */ - public List<BluetoothDevice> getDiscoveredDevices(); + public List<BTDevice> getDiscoveredDevices(); /** * Remove all the discovered devices found on this adapter. * * @return The number of removed discovered devices on this adapter - * @throws BluetoothException + * @throws BTException * @since 2.2.0 * @implNote Changed from 'removeDiscoveredDevices()' for clarity since version 2.2.0 */ - public int removeDiscoveredDevices() throws BluetoothException; + public int removeDiscoveredDevices() throws BTException; /** * Discards matching discovered devices. @@ -304,7 +304,7 @@ public interface BluetoothAdapter extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the powered * property. */ - public void enablePoweredNotifications(BluetoothNotification<Boolean> callback); + public void enablePoweredNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the powered property and unregisters the callback @@ -346,7 +346,7 @@ public interface BluetoothAdapter extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the discoverable * property. */ - public void enableDiscoverableNotifications(BluetoothNotification<Boolean> callback); + public void enableDiscoverableNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the discoverable property and unregisters the callback * object passed through the corresponding enable method. @@ -397,7 +397,7 @@ public interface BluetoothAdapter extends BluetoothObject * <li>{@code random} - Random address</li> * </ul> */ - public BluetoothDevice connectDevice(BDAddressAndType addressAndType); + public BTDevice connectDevice(BDAddressAndType addressAndType); /** Returns the pairable state the adapter. * @return The pairable state of the adapter. @@ -411,7 +411,7 @@ public interface BluetoothAdapter extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the pairable * property. */ - public void enablePairableNotifications(BluetoothNotification<Boolean> callback); + public void enablePairableNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the pairable property and unregisters the callback @@ -469,18 +469,18 @@ public interface BluetoothAdapter extends BluetoothObject * Add the given {@link AdapterStatusListener} to the list if not already present. * <p> * The newly added {@link AdapterStatusListener} will receive an initial - * {@link AdapterStatusListener#adapterSettingsChanged(BluetoothAdapter, AdapterSettings, AdapterSettings, AdapterSettings, long) adapterSettingsChanged} + * {@link AdapterStatusListener#adapterSettingsChanged(BTAdapter, AdapterSettings, AdapterSettings, AdapterSettings, long) adapterSettingsChanged} * event, passing an {@link AdapterSettings empty oldMask and changedMask}, as well as {@link AdapterSettings current newMask}. <br> * This allows the receiver to be aware of this adapter's current settings. * </p> * @param listener A {@link AdapterStatusListener} instance - * @param deviceMatch Optional {@link BluetoothDevice} to be matched before calling any + * @param deviceMatch Optional {@link BTDevice} to be matched before calling any * {@link AdapterStatusListener} {@code device*} methods. Pass {@code null} for no filtering. * @return true if the given listener is not element of the list and has been newly added, otherwise false. * @since 2.0.0 * @implNote not implemented in tinyb.dbus */ - public boolean addStatusListener(final AdapterStatusListener listener, final BluetoothDevice deviceMatch); + public boolean addStatusListener(final AdapterStatusListener listener, final BTDevice deviceMatch); /** * Remove the given {@link AdapterStatusListener} from the list. @@ -506,7 +506,7 @@ public interface BluetoothAdapter extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the discovering * property. */ - public void enableDiscoveringNotifications(BluetoothNotification<Boolean> callback); + public void enableDiscoveringNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the discovering property and unregisters the discovering diff --git a/java/org/direct_bt/BluetoothCallback.java b/java/org/direct_bt/BTCallback.java index a179c812..86b3f542 100644 --- a/java/org/direct_bt/BluetoothCallback.java +++ b/java/org/direct_bt/BTCallback.java @@ -26,7 +26,7 @@ package org.direct_bt; import tinyb.dbus.DBusObject; -public abstract class BluetoothCallback implements Runnable +public abstract class BTCallback implements Runnable { protected DBusObject bObj; diff --git a/java/org/direct_bt/BluetoothDevice.java b/java/org/direct_bt/BTDevice.java index d80e2d64..4a92cf57 100644 --- a/java/org/direct_bt/BluetoothDevice.java +++ b/java/org/direct_bt/BTDevice.java @@ -35,10 +35,10 @@ import java.util.Map; * Provides access to Bluetooth adapters. Follows the BlueZ adapter API * available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt */ -public interface BluetoothDevice extends BluetoothObject +public interface BTDevice extends BTObject { @Override - public BluetoothDevice clone(); + public BTDevice clone(); /** Find a BluetoothGattService. If parameter UUID is not null, * the returned object will have to match it. @@ -51,7 +51,7 @@ public interface BluetoothDevice extends BluetoothObject * @return An object matching the UUID or null if not found before * timeout expires or event is canceled. */ - BluetoothGattService find(String UUID, long timeoutMS); + BTGattService find(String UUID, long timeoutMS); /** Find a BluetoothGattService. If parameter UUID is not null, * the returned object will have to match it. @@ -62,7 +62,7 @@ public interface BluetoothDevice extends BluetoothObject * @return An object matching the UUID or null if not found before * timeout expires or event is canceled. */ - BluetoothGattService find(String UUID); + BTGattService find(String UUID); /* Bluetooth method calls: */ @@ -78,7 +78,7 @@ public interface BluetoothDevice extends BluetoothObject * </p> * <p> * The device will be removed from the managing adapter's connected devices - * when {@link AdapterStatusListener#deviceDisconnected(BluetoothDevice, HCIStatusCode, long)} has been received. + * when {@link AdapterStatusListener#deviceDisconnected(BTDevice, HCIStatusCode, long)} has been received. * </p> * <p> * An open GATT connection will also be closed.<br> @@ -92,7 +92,7 @@ public interface BluetoothDevice extends BluetoothObject * @return {@link HCIStatusCode#SUCCESS} if the command has been accepted, otherwise {@link HCIStatusCode} may disclose reason for rejection. * @since 2.1.0 change API, i.e. return value from boolean to HCIStatusCode in favor of <i>direct_bt</i> */ - HCIStatusCode disconnect() throws BluetoothException; + HCIStatusCode disconnect() throws BTException; /** * <b>direct_bt.tinyb</b>: Establish a default HCI connection to this device, using certain default parameter. @@ -107,8 +107,8 @@ public interface BluetoothDevice extends BluetoothObject * </p> * <p> * The actual new connection handle will be delivered asynchronous and - * the connection event can be caught via {@link AdapterStatusListener#deviceConnected(BluetoothDevice, long)}, - * or if failed via {@link AdapterStatusListener#deviceDisconnected(BluetoothDevice, HCIStatusCode, long)}. + * the connection event can be caught via {@link AdapterStatusListener#deviceConnected(BTDevice, long)}, + * or if failed via {@link AdapterStatusListener#deviceDisconnected(BTDevice, HCIStatusCode, long)}. * </p> * <p> * The device is tracked by the managing adapter. @@ -121,7 +121,7 @@ public interface BluetoothDevice extends BluetoothObject * @see #connectLE(short, short, short, short, short, short) * @since 2.1.0 change API, i.e. return value from boolean to HCIStatusCode in favor of <i>direct_bt</i> */ - HCIStatusCode connect() throws BluetoothException; + HCIStatusCode connect() throws BTException; /** * Establish a HCI BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM connection to this device. @@ -134,8 +134,8 @@ public interface BluetoothDevice extends BluetoothObject * </p> * <p> * The actual new connection handle will be delivered asynchronous and - * the connection event can be caught via {@link AdapterStatusListener#deviceConnected(BluetoothDevice, long)}, - * or if failed via {@link AdapterStatusListener#deviceDisconnected(BluetoothDevice, HCIStatusCode, long)}. + * the connection event can be caught via {@link AdapterStatusListener#deviceConnected(BTDevice, long)}, + * or if failed via {@link AdapterStatusListener#deviceDisconnected(BTDevice, HCIStatusCode, long)}. * </p> * <p> * The device is tracked by the managing adapter. @@ -158,7 +158,7 @@ public interface BluetoothDevice extends BluetoothObject * @param conn_latency slave latency in units of connection events, default value 0; Value range [0 .. 0x01F3]. * @param supervision_timeout in units of 10ms, default value >= 10 x conn_interval_max, we use 500 ms minimum; Value range [0xA-0x0C80] for [100ms - 32s]. * @return {@link HCIStatusCode#SUCCESS} if the command has been accepted, otherwise {@link HCIStatusCode} may disclose reason for rejection. - * @see BluetoothUtils#getHCIConnSupervisorTimeout(int, int, int, int) + * @see BTUtils#getHCIConnSupervisorTimeout(int, int, int, int) * @see #connect() * @since 2.1.0 change API, i.e. return value from boolean to HCIStatusCode in favor of <i>direct_bt</i> * @implNote not implemented in <b>tinyb.dbus</b> @@ -172,13 +172,13 @@ public interface BluetoothDevice extends BluetoothObject * @param arg_UUID The UUID of the profile to be connected * @return TRUE if the profile connected successfully */ - boolean connectProfile(String arg_UUID) throws BluetoothException; + boolean connectProfile(String arg_UUID) throws BTException; /** 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 */ - boolean disconnectProfile(String arg_UUID) throws BluetoothException; + boolean disconnectProfile(String arg_UUID) throws BTException; /** * Returns the available {@link SMPKeyMask.KeyType} {@link SMPKeyMask} for the responder (LL slave) or initiator (LL master). @@ -194,7 +194,7 @@ public interface BluetoothDevice extends BluetoothObject * @param responder true will return the responder's LTK info (remote device, LL slave), otherwise the initiator's (the LL master). * @return the resulting key. {@link SMPLongTermKeyInfo#enc_size} will be zero if invalid. * @see {@link SMPPairingState#COMPLETED} - * @see {@link AdapterStatusListener#deviceReady(BluetoothDevice, long)} + * @see {@link AdapterStatusListener#deviceReady(BTDevice, long)} * @since 2.2.0 * @implNote not implemented in tinyb.dbus */ @@ -217,7 +217,7 @@ public interface BluetoothDevice extends BluetoothObject * @param responder true will return the responder's LTK info (remote device, LL slave), otherwise the initiator's (the LL master). * @return the resulting key * @see {@link SMPPairingState#COMPLETED} - * @see {@link AdapterStatusListener#deviceReady(BluetoothDevice, long)} + * @see {@link AdapterStatusListener#deviceReady(BTDevice, long)} * @since 2.2.0 * @implNote not implemented in tinyb.dbus */ @@ -232,7 +232,7 @@ public interface BluetoothDevice extends BluetoothObject * @return TRUE if the device connected and paired * @implNote not implemented in direct_bt.tinyb */ - boolean pair() throws BluetoothException; + boolean pair() throws BTException; /** * Unpairs this device from the adapter while staying connected. @@ -390,7 +390,7 @@ public interface BluetoothDevice extends BluetoothObject * Method sets the given passkey entry, see {@link PairingMode#PASSKEY_ENTRY_ini}. * <p> * Call this method if the device shall be securely paired with {@link PairingMode#PASSKEY_ENTRY_ini}, - * i.e. when notified via {@link AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) devicePairingState} + * i.e. when notified via {@link AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) devicePairingState} * in state {@link SMPPairingState#PASSKEY_EXPECTED}. * </p> * @@ -400,7 +400,7 @@ public interface BluetoothDevice extends BluetoothObject * @return {@link HCIStatusCode#SUCCESS} if the command has been accepted, otherwise {@link HCIStatusCode} may disclose reason for rejection. * @see PairingMode * @see SMPPairingState - * @see AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) + * @see AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) * @see #setPairingPasskey(int) * @see #setPairingNumericComparison(boolean) * @see #getPairingMode() @@ -414,7 +414,7 @@ public interface BluetoothDevice extends BluetoothObject * Method sets the numeric comparison result, see {@link PairingMode#NUMERIC_COMPARE_ini}. * <p> * Call this method if the device shall be securely paired with {@link PairingMode#NUMERIC_COMPARE_ini}, - * i.e. when notified via {@link AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) devicePairingState} + * i.e. when notified via {@link AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) devicePairingState} * in state {@link SMPPairingState#NUMERIC_COMPARE_EXPECTED}. * </p> * @@ -424,7 +424,7 @@ public interface BluetoothDevice extends BluetoothObject * @return {@link HCIStatusCode#SUCCESS} if the command has been accepted, otherwise {@link HCIStatusCode} may disclose reason for rejection. * @see PairingMode * @see SMPPairingState - * @see AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) + * @see AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) * @see #setPairingPasskey(int) * @see #setPairingNumericComparison(boolean) * @see #getPairingMode() @@ -442,7 +442,7 @@ public interface BluetoothDevice extends BluetoothObject * <p> * If the Pairing Feature Exchange is completed, i.e. {@link SMPPairingState#FEATURE_EXCHANGE_COMPLETED} * as notified by - * {@link AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) devicePairingState} + * {@link AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) devicePairingState} * the current mode reflects the currently used {@link PairingMode}. * </p> * <p> @@ -451,7 +451,7 @@ public interface BluetoothDevice extends BluetoothObject * @return current PairingMode. * @see PairingMode * @see SMPPairingState - * @see AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) + * @see AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) * @see #setPairingPasskey(int) * @see #setPairingNumericComparison(boolean) * @see #getPairingMode() @@ -468,7 +468,7 @@ public interface BluetoothDevice extends BluetoothObject * </p> * @see PairingMode * @see SMPPairingState - * @see AdapterStatusListener#devicePairingState(BluetoothDevice, SMPPairingState, PairingMode, long) + * @see AdapterStatusListener#devicePairingState(BTDevice, SMPPairingState, PairingMode, long) * @see #setPairingPasskey(int) * @see #setPairingNumericComparison(boolean) * @see #getPairingMode() @@ -504,20 +504,20 @@ public interface BluetoothDevice extends BluetoothObject * but never issue remove() after disconnect() if the device is in use. * </p> * @return TRUE if the device has been removed - * @throws BluetoothException + * @throws BTException */ - boolean remove() throws BluetoothException; + boolean remove() throws BTException; /** Cancels an initiated pairing operation * @return TRUE if the paring is cancelled successfully */ - boolean cancelPairing() throws BluetoothException; + boolean cancelPairing() throws BTException; /** Returns a list of BluetoothGattServices available on this device. * @return A list of BluetoothGattServices available on this device, * NULL if an error occurred */ - List<BluetoothGattService> getServices(); + List<BTGattService> getServices(); /** * Issues a GATT ping to the device, validating whether it is still reachable. @@ -541,7 +541,7 @@ public interface BluetoothDevice extends BluetoothObject * Returns the timestamp in monotonic milliseconds when this device instance has been created, * either via its initial discovery or its initial direct connection. * - * @see BluetoothUtils#currentTimeMillis() + * @see BTUtils#currentTimeMillis() * @since 2.0.0 */ long getCreationTimestamp(); @@ -550,7 +550,7 @@ public interface BluetoothDevice extends BluetoothObject * Returns the timestamp in monotonic milliseconds when this device instance has * discovered or connected directly the last time. * - * @see BluetoothUtils#currentTimeMillis() + * @see BTUtils#currentTimeMillis() * @since 2.0.0 * @implNote not implemented in tinyb.dbus, returns {@link #getCreationTimestamp()} */ @@ -560,7 +560,7 @@ public interface BluetoothDevice extends BluetoothObject * Returns the timestamp in monotonic milliseconds when this device instance underlying data * has been updated the last time. * - * @see BluetoothUtils#currentTimeMillis() + * @see BTUtils#currentTimeMillis() * @since 2.0.0 * @implNote not implemented in tinyb.dbus, returns {@link #getCreationTimestamp()} */ @@ -623,7 +623,7 @@ public interface BluetoothDevice extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the paired * property. */ - void enablePairedNotifications(BluetoothNotification<Boolean> callback); + void enablePairedNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the paired property and unregisters the callback @@ -643,7 +643,7 @@ public interface BluetoothDevice extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the trusted * property. */ - void enableTrustedNotifications(BluetoothNotification<Boolean> callback); + void enableTrustedNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the trusted property and unregisters the callback @@ -667,7 +667,7 @@ public interface BluetoothDevice extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the blocked * property. */ - void enableBlockedNotifications(BluetoothNotification<Boolean> callback); + void enableBlockedNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the blocked property and unregisters the callback @@ -696,7 +696,7 @@ public interface BluetoothDevice extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the RSSI * property. */ - void enableRSSINotifications(BluetoothNotification<Short> callback); + void enableRSSINotifications(BTNotification<Short> callback); /** * Disables notifications of the RSSI property and unregisters the callback @@ -723,7 +723,7 @@ public interface BluetoothDevice extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the connected * property. */ - void enableConnectedNotifications(BluetoothNotification<Boolean> callback); + void enableConnectedNotifications(BTNotification<Boolean> callback); /** * Disables notifications of the connected property and unregisters the callback @@ -745,7 +745,7 @@ public interface BluetoothDevice extends BluetoothObject * connected. * @return The adapter. */ - BluetoothAdapter getAdapter(); + BTAdapter getAdapter(); /** Returns a map containing manufacturer specific advertisement data. * An entry has a uint16_t key and an array of bytes. @@ -761,7 +761,7 @@ public interface BluetoothDevice extends BluetoothObject * property. */ void enableManufacturerDataNotifications( - BluetoothNotification<Map<Short, byte[]>> callback); + BTNotification<Map<Short, byte[]>> callback); /** * Disables notifications of the manufacturer data property and unregisters the callback @@ -783,7 +783,7 @@ public interface BluetoothDevice extends BluetoothObject * property. */ void enableServiceDataNotifications( - BluetoothNotification<Map<String, byte[]>> callback); + BTNotification<Map<String, byte[]>> callback); /** * Disables notifications of the service data property and unregisters the callback @@ -809,7 +809,7 @@ public interface BluetoothDevice extends BluetoothObject * property. */ void enableServicesResolvedNotifications( - BluetoothNotification<Boolean> callback); + BTNotification<Boolean> callback); /** * Disables notifications of the services resolved property and unregisters the callback @@ -818,40 +818,40 @@ public interface BluetoothDevice extends BluetoothObject void disableServicesResolvedNotifications(); /** - * Add the given {@link GATTCharacteristicListener} to the listener list if not already present. + * Add the given {@link BTGattCharListener} to the listener list if not already present. * <p> * To enable the actual BLE notification and/or indication, one needs to call - * {@link BluetoothGattCharacteristic#configNotificationIndication(boolean, boolean, boolean[])} - * or {@link BluetoothGattCharacteristic#enableNotificationOrIndication(boolean[])}. + * {@link BTGattChar#configNotificationIndication(boolean, boolean, boolean[])} + * or {@link BTGattChar#enableNotificationOrIndication(boolean[])}. * </p> - * @param listener A {@link GATTCharacteristicListener} instance, listening to all {@link BluetoothGattCharacteristic} events of this device + * @param listener A {@link BTGattCharListener} instance, listening to all {@link BTGattChar} events of this device * @return true if the given listener is not element of the list and has been newly added, otherwise false. - * @throws IllegalStateException if the {@link BluetoothDevice}'s GATTHandler is null, i.e. not connected - * @throws IllegalStateException if the given {@link GATTCharacteristicListener} is already in use, i.e. added. - * @see BluetoothGattCharacteristic#configNotificationIndication(boolean, boolean, boolean[]) - * @see BluetoothGattCharacteristic#enableNotificationOrIndication(boolean[]) + * @throws IllegalStateException if the {@link BTDevice}'s GATTHandler is null, i.e. not connected + * @throws IllegalStateException if the given {@link BTGattCharListener} is already in use, i.e. added. + * @see BTGattChar#configNotificationIndication(boolean, boolean, boolean[]) + * @see BTGattChar#enableNotificationOrIndication(boolean[]) * @since 2.0.0 * @implNote not implemented in <b>tinyb.dbus</b> */ - public boolean addCharacteristicListener(final GATTCharacteristicListener listener) + public boolean addCharListener(final BTGattCharListener listener) throws IllegalStateException; /** - * Remove the given {@link GATTCharacteristicListener} from the listener list. + * Remove the given {@link BTGattCharListener} from the listener list. * <p> - * If the {@link BluetoothDevice}'s GATTHandler is null, i.e. not connected, {@code false} is being returned. + * If the {@link BTDevice}'s GATTHandler is null, i.e. not connected, {@code false} is being returned. * </p> - * @param listener A {@link GATTCharacteristicListener} instance + * @param listener A {@link BTGattCharListener} instance * @return true if the given listener is an element of the list and has been removed, otherwise false. * @since 2.0.0 * @implNote not implemented in <b>tinyb.dbus</b> */ - public boolean removeCharacteristicListener(final GATTCharacteristicListener l); + public boolean removeCharListener(final BTGattCharListener l); /** - * Remove all {@link GATTCharacteristicListener} from the list, which are associated to the given {@link BluetoothGattCharacteristic}. + * Remove all {@link BTGattCharListener} from the list, which are associated to the given {@link BTGattChar}. * <p> - * Implementation tests all listener's {@link GATTCharacteristicListener#getAssociatedCharacteristic()} + * Implementation tests all listener's {@link BTGattCharListener#getAssociatedChar()} * to match with the given associated characteristic. * </p> * @param associatedCharacteristic the match criteria to remove any GATTCharacteristicListener from the list @@ -859,13 +859,13 @@ public interface BluetoothDevice extends BluetoothObject * @since 2.0.0 * @implNote not implemented in <b>tinyb.dbus</b> */ - public int removeAllAssociatedCharacteristicListener(final BluetoothGattCharacteristic associatedCharacteristic); + public int removeAllAssociatedCharListener(final BTGattChar associatedCharacteristic); /** - * Remove all {@link GATTCharacteristicListener} from the list. + * Remove all {@link BTGattCharListener} from the list. * @return number of removed listener. * @since 2.0.0 * @implNote not implemented in <b>tinyb.dbus</b> */ - public int removeAllCharacteristicListener(); + public int removeAllCharListener(); } diff --git a/java/org/direct_bt/BluetoothEvent.java b/java/org/direct_bt/BTEvent.java index 8ccce79b..12cf5f9e 100644 --- a/java/org/direct_bt/BluetoothEvent.java +++ b/java/org/direct_bt/BTEvent.java @@ -28,9 +28,9 @@ package org.direct_bt; -public interface BluetoothEvent +public interface BTEvent { - public BluetoothType getType(); + public BTType getType(); public String getName(); public String getIdentifier(); public boolean executeCallback(); diff --git a/java/org/direct_bt/BluetoothException.java b/java/org/direct_bt/BTException.java index d89eb154..b3ef62dd 100644 --- a/java/org/direct_bt/BluetoothException.java +++ b/java/org/direct_bt/BTException.java @@ -29,8 +29,8 @@ package org.direct_bt; @SuppressWarnings("serial") -public class BluetoothException extends RuntimeException { - protected BluetoothException(final String msg) { +public class BTException extends RuntimeException { + protected BTException(final String msg) { super(msg); } } diff --git a/java/org/direct_bt/BluetoothFactory.java b/java/org/direct_bt/BTFactory.java index 66db7917..cee2aa7f 100644 --- a/java/org/direct_bt/BluetoothFactory.java +++ b/java/org/direct_bt/BTFactory.java @@ -41,17 +41,17 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; /** - * One stop {@link BluetoothManager} API entry point. + * One stop {@link BTManager} API entry point. * <p> * Further provides access to certain property settings, * see {@link #DEBUG}, {@link #VERBOSE}, {@link #DIRECTBT_CHARACTERISTIC_VALUE_CACHE_NOTIFICATION_COMPAT}. * </p> */ -public class BluetoothFactory { +public class BTFactory { /** - * Identifier names, allowing {@link BluetoothFactory#getBluetoothManager(ImplementationIdentifier)} - * to initialize the required native libraries and to instantiate the root {@link BluetoothManager} instance. + * Identifier names, allowing {@link BTFactory#getBluetoothManager(ImplementationIdentifier)} + * to initialize the required native libraries and to instantiate the root {@link BTManager} instance. * <p> * The implementation class must provide the static factory method * <pre> @@ -61,7 +61,7 @@ public class BluetoothFactory { */ public static class ImplementationIdentifier { /** - * Fully qualified class name for the {@link BluetoothManager} implementation + * Fully qualified class name for the {@link BTManager} implementation * <p> * The implementation class must provide the static factory method * <pre> @@ -120,7 +120,7 @@ public class BluetoothFactory { * This value is exposed for convenience, user implementations are welcome. * </p> */ - public static final ImplementationIdentifier DirectBTImplementationID = new ImplementationIdentifier("direct_bt.tinyb.DBTManager", "direct_bt", "javadirect_bt"); + public static final ImplementationIdentifier DirectBTImplementationID = new ImplementationIdentifier("jau.direct_bt.DBTManager", "direct_bt", "javadirect_bt"); private static final List<ImplementationIdentifier> implIDs = new ArrayList<ImplementationIdentifier>(); @@ -206,10 +206,10 @@ public class BluetoothFactory { try { final Throwable[] t = { null }; - if( !PlatformToolkit.loadLibrary(id.ImplementationNativeLibraryBasename, BluetoothFactory.class.getClassLoader(), t) ) { + if( !PlatformToolkit.loadLibrary(id.ImplementationNativeLibraryBasename, BTFactory.class.getClassLoader(), t) ) { throw new RuntimeException("Couldn't load native library with basename <"+id.ImplementationNativeLibraryBasename+">", t[0]); } - if( !PlatformToolkit.loadLibrary(id.JavaNativeLibraryBasename, BluetoothFactory.class.getClassLoader(), t) ) { + if( !PlatformToolkit.loadLibrary(id.JavaNativeLibraryBasename, BTFactory.class.getClassLoader(), t) ) { throw new RuntimeException("Couldn't load native library with basename <"+id.JavaNativeLibraryBasename+">", t[0]); } } catch (final Throwable e) { @@ -247,7 +247,7 @@ public class BluetoothFactory { } try { - final Manifest manifest = getManifest(BluetoothFactory.class.getClassLoader(), new String[] { "org.tinyb" } ); + final Manifest manifest = getManifest(BTFactory.class.getClassLoader(), new String[] { "org.tinyb" } ); final Attributes mfAttributes = null != manifest ? manifest.getMainAttributes() : null; // major.minor must match! @@ -301,12 +301,12 @@ public class BluetoothFactory { } } - private static synchronized BluetoothManager getBluetoothManager(final Class<?> factoryImplClass) - throws BluetoothException, NoSuchMethodException, SecurityException, + private static synchronized BTManager getBluetoothManager(final Class<?> factoryImplClass) + throws BTException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Method m = factoryImplClass.getMethod("getManager"); - return (BluetoothManager)m.invoke(null); + return (BTManager)m.invoke(null); } /** @@ -328,7 +328,7 @@ public class BluetoothFactory { /** * Returns the matching {@link ImplementationIdentifier} from the internal list or {@code null} if not found. - * @param fqBluetoothManagerImplementationClassName fully qualified class name for the {@link BluetoothManager} implementation + * @param fqBluetoothManagerImplementationClassName fully qualified class name for the {@link BTManager} implementation */ public static synchronized ImplementationIdentifier getImplementationIdentifier(final String fqBluetoothManagerImplementationClassName) { for(final ImplementationIdentifier id : implIDs) { @@ -349,8 +349,8 @@ public class BluetoothFactory { * The chosen implementation can't be changed within a running implementation, an exception is thrown if tried. * </p> * - * @param fqBluetoothManagerImplementationClassName fully qualified class name for the {@link BluetoothManager} implementation - * @throws BluetoothException + * @param fqBluetoothManagerImplementationClassName fully qualified class name for the {@link BTManager} implementation + * @throws BTException * @throws NoSuchMethodException * @throws SecurityException * @throws IllegalAccessException @@ -360,8 +360,8 @@ public class BluetoothFactory { * @see {@link #DBusFactoryImplClassName} * @see {@link #DirectBTFactoryImplClassName} */ - public static synchronized BluetoothManager getBluetoothManager(final String fqBluetoothManagerImplementationClassName) - throws BluetoothException, NoSuchMethodException, SecurityException, + public static synchronized BTManager getBluetoothManager(final String fqBluetoothManagerImplementationClassName) + throws BTException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { final ImplementationIdentifier id = getImplementationIdentifier(fqBluetoothManagerImplementationClassName); @@ -381,7 +381,7 @@ public class BluetoothFactory { * The chosen implementation can't be changed within a running implementation, an exception is thrown if tried. * </p> * @param id the specific {@link ImplementationIdentifier} - * @throws BluetoothException + * @throws BTException * @throws NoSuchMethodException * @throws SecurityException * @throws IllegalAccessException @@ -391,8 +391,8 @@ public class BluetoothFactory { * @see {@link #DBusFactoryImplClassName} * @see {@link #DirectBTFactoryImplClassName} */ - public static synchronized BluetoothManager getBluetoothManager(final ImplementationIdentifier id) - throws BluetoothException, NoSuchMethodException, SecurityException, + public static synchronized BTManager getBluetoothManager(final ImplementationIdentifier id) + throws BTException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { registerImplementationIdentifier(id); @@ -409,7 +409,7 @@ public class BluetoothFactory { * <p> * The chosen implementation can't be changed within a running implementation, an exception is thrown if tried. * </p> - * @throws BluetoothException + * @throws BTException * @throws NoSuchMethodException * @throws SecurityException * @throws IllegalAccessException @@ -417,8 +417,8 @@ public class BluetoothFactory { * @throws InvocationTargetException * @throws ClassNotFoundException */ - public static synchronized BluetoothManager getDBusBluetoothManager() - throws BluetoothException, NoSuchMethodException, SecurityException, + public static synchronized BTManager getDBusBluetoothManager() + throws BTException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { return getBluetoothManager(DBusImplementationID); @@ -432,7 +432,7 @@ public class BluetoothFactory { * <p> * The chosen implementation can't be changed within a running implementation, an exception is thrown if tried. * </p> - * @throws BluetoothException + * @throws BTException * @throws NoSuchMethodException * @throws SecurityException * @throws IllegalAccessException @@ -440,8 +440,8 @@ public class BluetoothFactory { * @throws InvocationTargetException * @throws ClassNotFoundException */ - public static synchronized BluetoothManager getDirectBTBluetoothManager() - throws BluetoothException, NoSuchMethodException, SecurityException, + public static synchronized BTManager getDirectBTBluetoothManager() + throws BTException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { return getBluetoothManager(DirectBTImplementationID); diff --git a/java/org/direct_bt/BluetoothGattCharacteristic.java b/java/org/direct_bt/BTGattChar.java index 580e30a3..8e7330dc 100644 --- a/java/org/direct_bt/BluetoothGattCharacteristic.java +++ b/java/org/direct_bt/BTGattChar.java @@ -34,10 +34,10 @@ import java.util.List; * 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 interface BluetoothGattCharacteristic extends BluetoothObject +public interface BTGattChar extends BTObject { @Override - public BluetoothGattCharacteristic clone(); + public BTGattChar clone(); /** Find a BluetoothGattDescriptor. If parameter UUID is not null, * the returned object will have to match it. @@ -50,7 +50,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * @return An object matching the UUID or null if not found before * timeout expires or event is canceled. */ - public BluetoothGattDescriptor find(final String UUID, final long timeoutMS); + public BTGattDesc find(final String UUID, final long timeoutMS); /** Find a BluetoothGattDescriptor. If parameter UUID is not null, * the returned object will have to match it. @@ -61,14 +61,14 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * @return An object matching the UUID or null if not found before * timeout expires or event is canceled. */ - public BluetoothGattDescriptor find(final String UUID); + public BTGattDesc find(final String UUID); /* D-Bus method calls: */ /** Reads the value of this characteristic. * @return A std::vector<unsgined char> containing the value of this characteristic. */ - public byte[] readValue() throws BluetoothException; + public byte[] readValue() throws BTException; /** * BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration @@ -93,7 +93,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * or there is no GATTDescriptor of type ClientCharacteristicConfiguration, or if the operation has failed. * Otherwise returns true. * @throws IllegalStateException if notification or indication is set to be enabled - * and the {@link BluetoothDevice}'s GATTHandler is null, i.e. not connected + * and the {@link BTDevice}'s GATTHandler is null, i.e. not connected * @see #enableNotificationOrIndication(boolean[]) * @since 2.0.0 * @implNote not implemented in tinyb.dbus @@ -119,7 +119,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * or there is no GATTDescriptor of type ClientCharacteristicConfiguration, or if the operation has failed. * Otherwise returns true. * @throws IllegalStateException if notification or indication is set to be enabled - * and the {@link BluetoothDevice}'s GATTHandler is null, i.e. not connected + * and the {@link BTDevice}'s GATTHandler is null, i.e. not connected * @see #configNotificationIndication(boolean, boolean, boolean[]) * @since 2.0.0 * @implNote not implemented in tinyb.dbus @@ -128,26 +128,26 @@ public interface BluetoothGattCharacteristic extends BluetoothObject throws IllegalStateException; /** - * Add the given {@link GATTCharacteristicListener} to the listener list if not already present. + * Add the given {@link BTGattCharListener} to the listener list if not already present. * <p> * Occurring notifications and indications, if enabled via {@link #configNotificationIndication(boolean, boolean, boolean[])} * or {@link #enableNotificationOrIndication(boolean[])}, * will call the respective GATTCharacteristicListener callback method. * </p> - * @param listener A {@link GATTCharacteristicListener} instance, listening to this {@link BluetoothGattCharacteristic}'s events + * @param listener A {@link BTGattCharListener} instance, listening to this {@link BTGattChar}'s events * @return true if the given listener is not element of the list and has been newly added, otherwise false. * @throws IllegalStateException if the DBTDevice's GATTHandler is null, i.e. not connected - * @throws IllegalStateException if the given {@link GATTCharacteristicListener} is already in use, i.e. added. + * @throws IllegalStateException if the given {@link BTGattCharListener} is already in use, i.e. added. * @see #enableNotificationOrIndication(boolean[]) * @see #configNotificationIndication(boolean, boolean, boolean[]) * @since 2.0.0 * @implNote not implemented in tinyb.dbus */ - public boolean addCharacteristicListener(final GATTCharacteristicListener listener) + public boolean addCharacteristicListener(final BTGattCharListener listener) throws IllegalStateException; /** - * Add the given {@link GATTCharacteristicListener} to the listener list if not already present + * Add the given {@link BTGattCharListener} to the listener list if not already present * and if enabling the notification <i>or</i> indication for this characteristic at BLE level was successful.<br> * Notification and/or indication configuration is only performed per characteristic if changed. * <p> @@ -156,33 +156,33 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * Implementation uses {@link #enableNotificationOrIndication(boolean[])} to enable one. * </p> * <p> - * Occurring notifications and indications will call the respective {@link GATTCharacteristicListener} + * Occurring notifications and indications will call the respective {@link BTGattCharListener} * callback method. * </p> - * @param listener A {@link GATTCharacteristicListener} instance, listening to this {@link BluetoothGattCharacteristic}'s events + * @param listener A {@link BTGattCharListener} instance, listening to this {@link BTGattChar}'s events * @param enabledState array of size 2, holding the resulting enabled state for notification and indication * using {@link #enableNotificationOrIndication(boolean[])} * @return true if enabling the notification and/or indication was successful * and if the given listener is not element of the list and has been newly added, otherwise false. - * @throws IllegalStateException if the {@link BluetoothDevice}'s GATTHandler is null, i.e. not connected - * @throws IllegalStateException if the given {@link GATTCharacteristicListener} is already in use, i.e. added. + * @throws IllegalStateException if the {@link BTDevice}'s GATTHandler is null, i.e. not connected + * @throws IllegalStateException if the given {@link BTGattCharListener} is already in use, i.e. added. * @see #enableNotificationOrIndication(boolean[]) * @see #configNotificationIndication(boolean, boolean, boolean[]) * @since 2.0.0 * @implNote not implemented in tinyb.dbus */ - public boolean addCharacteristicListener(final GATTCharacteristicListener listener, final boolean enabledState[/*2*/]) + public boolean addCharacteristicListener(final BTGattCharListener listener, final boolean enabledState[/*2*/]) throws IllegalStateException; /** * Disables the notification and/or indication for this characteristic at BLE level * if {@code disableIndicationNotification == true} - * and removes the given {@link GATTCharacteristicListener} from the listener list. + * and removes the given {@link BTGattCharListener} from the listener list. * <p> * If the DBTDevice's GATTHandler is null, i.e. not connected, {@code false} is being returned. * </p> * - * @param listener A {@link GATTCharacteristicListener} instance + * @param listener A {@link BTGattCharListener} instance * @param disableIndicationNotification if true, disables the notification and/or indication for this characteristic * using {@link #configNotificationIndication(boolean, boolean, boolean[])} * @return true if the given listener is an element of the list and has been removed, otherwise false. @@ -190,15 +190,15 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * @since 2.0.0 * @implNote not implemented in tinyb.dbus */ - public boolean removeCharacteristicListener(final GATTCharacteristicListener l, final boolean disableIndicationNotification); + public boolean removeCharacteristicListener(final BTGattCharListener l, final boolean disableIndicationNotification); /** * Disables the notification and/or indication for this characteristic BLE level * if {@code disableIndicationNotification == true} - * and removes all {@link GATTCharacteristicListener} from the listener list, + * and removes all {@link BTGattCharListener} from the listener list, * which are associated with this characteristic instance. * <p> - * Implementation tests all listener's {@link GATTCharacteristicListener#getAssociatedCharacteristic()} + * Implementation tests all listener's {@link BTGattCharListener#getAssociatedChar()} * to match with this characteristic instance. * </p> * <p> @@ -209,7 +209,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * using {@link #configNotificationIndication(boolean, boolean, boolean[])} * @return number of removed listener. * @see #configNotificationIndication(boolean, boolean, boolean[]) - * @see BluetoothDevice#removeAllAssociatedCharacteristicListener(BluetoothGattCharacteristic) + * @see BTDevice#removeAllAssociatedCharacteristicListener(BTGattChar) * @since 2.0.0 * @implNote not implemented in tinyb.dbus */ @@ -225,7 +225,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the value * property. */ - public void enableValueNotifications(BluetoothNotification<byte[]> callback); + public void enableValueNotifications(BTNotification<byte[]> callback); /** * Disables notifications of the value and unregisters the callback object @@ -249,7 +249,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * @implNote {@code withResponse} parameter has been added since 2.0.0 * @implNote tinyb.dbus does not support {@code withResponse = true} */ - public boolean writeValue(byte[] argValue, boolean withResponse) throws BluetoothException; + public boolean writeValue(byte[] argValue, boolean withResponse) throws BTException; /* D-Bus property accessors: */ @@ -261,7 +261,7 @@ public interface BluetoothGattCharacteristic extends BluetoothObject /** Returns the service to which this characteristic belongs to. * @return The service. */ - public BluetoothGattService getService(); + public BTGattService getService(); /** Returns the cached value of this characteristic, if any. * @return The cached value of this characteristic. @@ -293,5 +293,5 @@ public interface BluetoothGattCharacteristic extends BluetoothObject * @return A list of BluetoothGattDescriptors exposed by this characteristic * NULL if an error occurred */ - public List<BluetoothGattDescriptor> getDescriptors(); + public List<BTGattDesc> getDescriptors(); } diff --git a/java/org/direct_bt/GATTCharacteristicListener.java b/java/org/direct_bt/BTGattCharListener.java index fad76d51..f95e0166 100644 --- a/java/org/direct_bt/GATTCharacteristicListener.java +++ b/java/org/direct_bt/BTGattCharListener.java @@ -28,25 +28,25 @@ package org.direct_bt; import java.lang.ref.WeakReference; /** - * {@link BluetoothGattCharacteristic} event listener for notification and indication events. + * {@link BTGattChar} event listener for notification and indication events. * <p> - * A listener instance may be attached to a {@link BluetoothGattCharacteristic} via - * {@link BluetoothGattCharacteristic#addCharacteristicListener(GATTCharacteristicListener)} to listen to its events. + * A listener instance may be attached to a {@link BTGattChar} via + * {@link BTGattChar#addCharacteristicListener(BTGattCharListener)} to listen to its events. * </p> * <p> - * A listener instance may be attached to a {@link BluetoothDevice} via - * {@link BluetoothDevice#addCharacteristicListener(GATTCharacteristicListener, BluetoothGattCharacteristic)} + * A listener instance may be attached to a {@link BTDevice} via + * {@link BTDevice#addCharacteristicListener(BTGattCharListener, BTGattChar)} * to listen to all events of the device or the matching filtered events. * </p> * <p> - * One {@link GATTCharacteristicListener} instance can only be attached to a listener receiver once at a time, - * i.e. you cannot attach the same instance more than once to a {@link BluetoothDevice} - * or {@link BluetoothGattCharacteristic}. + * One {@link BTGattCharListener} instance can only be attached to a listener receiver once at a time, + * i.e. you cannot attach the same instance more than once to a {@link BTDevice} + * or {@link BTGattChar}. * <br> * To attach multiple listener, one instance per attachment must be created. * <br> * This restriction is due to implementation semantics of strictly associating - * one Java {@link GATTCharacteristicListener} instance to one C++ {@code GATTCharacteristicListener} instance. + * one Java {@link BTGattCharListener} instance to one C++ {@code GATTCharacteristicListener} instance. * The latter will be added to the native list of listeners. * This class's {@code nativeInstance} field links the Java instance to mentioned C++ listener. * <br> @@ -54,61 +54,61 @@ import java.lang.ref.WeakReference; * this restriction is more esoteric. * </p> */ -public abstract class GATTCharacteristicListener { +public abstract class BTGattCharListener { @SuppressWarnings("unused") private long nativeInstance; - private final WeakReference<BluetoothGattCharacteristic> associatedCharacteristic; + private final WeakReference<BTGattChar> associatedChar; /** - * Returns the weakly associated {@link BluetoothGattCharacteristic} to this listener instance. + * Returns the weakly associated {@link BTGattChar} to this listener instance. * <p> * Returns {@code null} if no association has been made - * or if the associated {@link BluetoothGattCharacteristic} has been garbage collected. + * or if the associated {@link BTGattChar} has been garbage collected. * </p> */ - public final BluetoothGattCharacteristic getAssociatedCharacteristic() { - return null != associatedCharacteristic ? associatedCharacteristic.get() : null; + public final BTGattChar getAssociatedChar() { + return null != associatedChar ? associatedChar.get() : null; } /** - * @param associatedCharacteristic weakly associates this listener instance to one {@link BluetoothGattCharacteristic}, + * @param associatedCharacteristic weakly associates this listener instance to one {@link BTGattChar}, * may be {@code null} for no association. - * @see #getAssociatedCharacteristic() + * @see #getAssociatedChar() */ - public GATTCharacteristicListener(final BluetoothGattCharacteristic associatedCharacteristic) { + public BTGattCharListener(final BTGattChar associatedCharacteristic) { if( null != associatedCharacteristic ) { - this.associatedCharacteristic = new WeakReference<BluetoothGattCharacteristic>(associatedCharacteristic); + this.associatedChar = new WeakReference<BTGattChar>(associatedCharacteristic); } else { - this.associatedCharacteristic = null; + this.associatedChar = null; } } /** * Called from native BLE stack, initiated by a received notification associated - * with the given {@link BluetoothGattCharacteristic}. - * @param charDecl {@link BluetoothGattCharacteristic} related to this notification + * with the given {@link BTGattChar}. + * @param charDecl {@link BTGattChar} related to this notification * @param value the notification value - * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#currentTimeMillis()} + * @param timestamp the indication monotonic timestamp, see {@link BTUtils#currentTimeMillis()} */ - public void notificationReceived(final BluetoothGattCharacteristic charDecl, + public void notificationReceived(final BTGattChar charDecl, final byte[] value, final long timestamp) { } /** * Called from native BLE stack, initiated by a received indication associated - * with the given {@link BluetoothGattCharacteristic}. - * @param charDecl {@link BluetoothGattCharacteristic} related to this indication + * with the given {@link BTGattChar}. + * @param charDecl {@link BTGattChar} related to this indication * @param value the indication value - * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#currentTimeMillis()} + * @param timestamp the indication monotonic timestamp, see {@link BTUtils#currentTimeMillis()} * @param confirmationSent if true, the native stack has sent the confirmation, otherwise user is required to do so. */ - public void indicationReceived(final BluetoothGattCharacteristic charDecl, + public void indicationReceived(final BTGattChar charDecl, final byte[] value, final long timestamp, final boolean confirmationSent) { } public String toString() { - final BluetoothGattCharacteristic c = getAssociatedCharacteristic(); + final BTGattChar c = getAssociatedChar(); final String cs = null != c ? c.toString() : "null"; return "GATTCharacteristicListener[associated "+cs+"]"; } diff --git a/java/org/direct_bt/BluetoothGattDescriptor.java b/java/org/direct_bt/BTGattDesc.java index b09f58c0..68db424a 100644 --- a/java/org/direct_bt/BluetoothGattDescriptor.java +++ b/java/org/direct_bt/BTGattDesc.java @@ -32,10 +32,10 @@ package org.direct_bt; * 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 interface BluetoothGattDescriptor extends BluetoothObject +public interface BTGattDesc extends BTObject { @Override - public BluetoothGattDescriptor clone(); + public BTGattDesc clone(); /* D-Bus method calls: */ @@ -49,7 +49,7 @@ public interface BluetoothGattDescriptor extends BluetoothObject * to be written packed in a GBytes struct * @return TRUE if value was written succesfully */ - public boolean writeValue(byte[] argValue) throws BluetoothException; + public boolean writeValue(byte[] argValue) throws BTException; /** * Enables notifications for the value and calls run function of the BluetoothNotification @@ -58,7 +58,7 @@ public interface BluetoothGattDescriptor extends BluetoothObject * when a notification is issued. The run function will deliver the new value of the value * property. */ - public void enableValueNotifications(BluetoothNotification<byte[]> callback); + public void enableValueNotifications(BTNotification<byte[]> callback); /** * Disables notifications of the value and unregisters the callback object * passed through the corresponding enable method. @@ -75,7 +75,7 @@ public interface BluetoothGattDescriptor extends BluetoothObject /** Returns the characteristic to which this descriptor belongs to. * @return The characteristic. */ - public BluetoothGattCharacteristic getCharacteristic(); + public BTGattChar getCharacteristic(); /** Returns the cached value of this descriptor, if any. * @return The cached value of this descriptor. diff --git a/java/org/direct_bt/BluetoothGattService.java b/java/org/direct_bt/BTGattService.java index 35d4fe9c..898fd959 100644 --- a/java/org/direct_bt/BluetoothGattService.java +++ b/java/org/direct_bt/BTGattService.java @@ -35,10 +35,10 @@ import java.util.List; * 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 interface BluetoothGattService extends BluetoothObject +public interface BTGattService extends BTObject { @Override - public BluetoothGattService clone(); + public BTGattService clone(); /** Find a BluetoothGattCharacteristic. If parameter UUID is not null, * the returned object will have to match it. @@ -51,7 +51,7 @@ public interface BluetoothGattService extends BluetoothObject * @return An object matching the UUID or null if not found before * timeout expires or event is canceled. */ - public BluetoothGattCharacteristic find(String UUID, long timeoutMS); + public BTGattChar find(String UUID, long timeoutMS); /** Find a BluetoothGattCharacteristic. If parameter UUID is not null, * the returned object will have to match it. @@ -62,7 +62,7 @@ public interface BluetoothGattService extends BluetoothObject * @return An object matching the UUID or null if not found before * timeout expires or event is canceled. */ - public BluetoothGattCharacteristic find(String UUID); + public BTGattChar find(String UUID); /* D-Bus property accessors: */ @@ -74,45 +74,45 @@ public interface BluetoothGattService extends BluetoothObject /** Returns the device to which this service belongs to. * @return The device. */ - public BluetoothDevice getDevice(); + public BTDevice 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 boolean getPrimary(); - /** Returns a list of BluetoothGattCharacteristics this service exposes. - * @return A list of BluetoothGattCharacteristics exposed by this service + /** Returns a list of BTGattChar this service exposes. + * @return A list of BTGattChar exposed by this service */ - public List<BluetoothGattCharacteristic> getCharacteristics(); + public List<BTGattChar> getChars(); /** - * Adds the given {@link GATTCharacteristicListener} to the {@link BluetoothDevice} - * and {@link BluetoothGattCharacteristic#enableNotificationOrIndication(boolean[])} for all {@link BluetoothGattCharacteristic} instances. - * @param listener {@link GATTCharacteristicListener} to add to the {@link BluetoothDevice}. - * It is important to have hte listener's {@link GATTCharacteristicListener#getAssociatedCharacteristic() associated characteristic} == null, + * Adds the given {@link BTGattCharListener} to the {@link BTDevice} + * and {@link BTGattChar#enableNotificationOrIndication(boolean[])} for all {@link BTGattChar} instances. + * @param listener {@link BTGattCharListener} to add to the {@link BTDevice}. + * It is important to have hte listener's {@link BTGattCharListener#getAssociatedChar() associated characteristic} == null, * otherwise the listener can't be used for all characteristics. * @return true if successful, otherwise false - * @throws IllegalArgumentException if listener's {@link GATTCharacteristicListener#getAssociatedCharacteristic() associated characteristic} + * @throws IllegalArgumentException if listener's {@link BTGattCharListener#getAssociatedChar() associated characteristic} * is not null. * @since 2.0.0 * @implNote not implemented in tinyb.dbus - * @see BluetoothGattCharacteristic#enableNotificationOrIndication(boolean[]) - * @see BluetoothDevice#addCharacteristicListener(GATTCharacteristicListener, BluetoothGattCharacteristic) + * @see BTGattChar#enableNotificationOrIndication(boolean[]) + * @see BTDevice#addCharacteristicListener(BTGattCharListener, BTGattChar) */ - public static boolean addCharacteristicListenerToAll(final BluetoothDevice device, final List<BluetoothGattService> services, - final GATTCharacteristicListener listener) { + public static boolean addCharListenerToAll(final BTDevice device, final List<BTGattService> services, + final BTGattCharListener listener) { if( null == listener ) { throw new IllegalArgumentException("listener argument null"); } - if( null != listener.getAssociatedCharacteristic() ) { + if( null != listener.getAssociatedChar() ) { throw new IllegalArgumentException("listener's associated characteristic is not null"); } - final boolean res = device.addCharacteristicListener(listener); - for(final Iterator<BluetoothGattService> is = services.iterator(); is.hasNext(); ) { - final BluetoothGattService s = is.next(); - final List<BluetoothGattCharacteristic> characteristics = s.getCharacteristics(); - for(final Iterator<BluetoothGattCharacteristic> ic = characteristics.iterator(); ic.hasNext(); ) { + final boolean res = device.addCharListener(listener); + for(final Iterator<BTGattService> is = services.iterator(); is.hasNext(); ) { + final BTGattService s = is.next(); + final List<BTGattChar> characteristics = s.getChars(); + for(final Iterator<BTGattChar> ic = characteristics.iterator(); ic.hasNext(); ) { ic.next().enableNotificationOrIndication(new boolean[2]); } } @@ -120,42 +120,42 @@ public interface BluetoothGattService extends BluetoothObject } /** - * Removes the given {@link GATTCharacteristicListener} from the {@link BluetoothDevice}. - * @param listener {@link GATTCharacteristicListener} to remove from the {@link BluetoothDevice}. + * Removes the given {@link BTGattCharListener} from the {@link BTDevice}. + * @param listener {@link BTGattCharListener} to remove from the {@link BTDevice}. * @return true if successful, otherwise false * @since 2.0.0 * @implNote not implemented in tinyb.dbus - * @see BluetoothGattCharacteristic#configNotificationIndication(boolean, boolean, boolean[]) - * @see BluetoothDevice#removeCharacteristicListener(GATTCharacteristicListener) + * @see BTGattChar#configNotificationIndication(boolean, boolean, boolean[]) + * @see BTDevice#removeCharacteristicListener(BTGattCharListener) */ - public static boolean removeCharacteristicListenerFromAll(final BluetoothDevice device, final List<BluetoothGattService> services, - final GATTCharacteristicListener listener) { - for(final Iterator<BluetoothGattService> is = services.iterator(); is.hasNext(); ) { - final BluetoothGattService s = is.next(); - final List<BluetoothGattCharacteristic> characteristics = s.getCharacteristics(); - for(final Iterator<BluetoothGattCharacteristic> ic = characteristics.iterator(); ic.hasNext(); ) { + public static boolean removeCharListenerFromAll(final BTDevice device, final List<BTGattService> services, + final BTGattCharListener listener) { + for(final Iterator<BTGattService> is = services.iterator(); is.hasNext(); ) { + final BTGattService s = is.next(); + final List<BTGattChar> characteristics = s.getChars(); + for(final Iterator<BTGattChar> ic = characteristics.iterator(); ic.hasNext(); ) { ic.next().configNotificationIndication(false /* enableNotification */, false /* enableIndication */, new boolean[2]); } } - return device.removeCharacteristicListener(listener); + return device.removeCharListener(listener); } /** - * Removes all {@link GATTCharacteristicListener} from the {@link BluetoothDevice}. - * @return count of removed {@link GATTCharacteristicListener} + * Removes all {@link BTGattCharListener} from the {@link BTDevice}. + * @return count of removed {@link BTGattCharListener} * @since 2.0.0 * @implNote not implemented in tinyb.dbus - * @see BluetoothGattCharacteristic#configNotificationIndication(boolean, boolean, boolean[]) - * @see BluetoothDevice#removeAllCharacteristicListener() + * @see BTGattChar#configNotificationIndication(boolean, boolean, boolean[]) + * @see BTDevice#removeAllCharacteristicListener() */ - public static int removeAllCharacteristicListener(final BluetoothDevice device, final List<BluetoothGattService> services) { - for(final Iterator<BluetoothGattService> is = services.iterator(); is.hasNext(); ) { - final BluetoothGattService s = is.next(); - final List<BluetoothGattCharacteristic> characteristics = s.getCharacteristics(); - for(final Iterator<BluetoothGattCharacteristic> ic = characteristics.iterator(); ic.hasNext(); ) { + public static int removeAllCharListener(final BTDevice device, final List<BTGattService> services) { + for(final Iterator<BTGattService> is = services.iterator(); is.hasNext(); ) { + final BTGattService s = is.next(); + final List<BTGattChar> characteristics = s.getChars(); + for(final Iterator<BTGattChar> ic = characteristics.iterator(); ic.hasNext(); ) { ic.next().configNotificationIndication(false /* enableNotification */, false /* enableIndication */, new boolean[2]); } } - return device.removeAllCharacteristicListener(); + return device.removeAllCharListener(); } } diff --git a/java/org/direct_bt/BluetoothManager.java b/java/org/direct_bt/BTManager.java index 2c80a7e6..c770d6cf 100644 --- a/java/org/direct_bt/BluetoothManager.java +++ b/java/org/direct_bt/BTManager.java @@ -30,7 +30,7 @@ package org.direct_bt; import java.util.List; -public interface BluetoothManager +public interface BTManager { /** * Interface allowing to retrieve certain settings @@ -52,15 +52,15 @@ public interface BluetoothManager boolean isTinyB(); /** - * Returns whether {@link BluetoothGattCharacteristic} API: {@link BluetoothGattCharacteristic#getValue() value cache} and - * {@link BluetoothGattCharacteristic#enableValueNotifications(BluetoothNotification) value notification} + * Returns whether {@link BTGattChar} API: {@link BTGattChar#getValue() value cache} and + * {@link BTGattChar#enableValueNotifications(BluetoothNotification) value notification} * is supported. * <p> * This is enabled using {@link #isTinyB() TinyB}, but disabled by default using {@link #isDirectBT() Direct-BT}. * </p> * <p> * If using {@link #isDirectBT() Direct-BT}, user are encouraged to - * {@link BluetoothGattCharacteristic#addCharacteristicListener(GATTCharacteristicListener, boolean[]) utilize GATTCharacteristicListener} + * {@link BTGattChar#addCharacteristicListener(GATTCharacteristicListener, boolean[]) utilize GATTCharacteristicListener} * to handle value notifications when they occur w/o caching. * </p> * <p> @@ -77,8 +77,8 @@ public interface BluetoothManager /** - * Event listener to receive change events regarding the system's {@link BluetoothAdapter} set, - * e.g. a removed or added {@link BluetoothAdapter} due to user interaction or 'cold reset'. + * Event listener to receive change events regarding the system's {@link BTAdapter} set, + * e.g. a removed or added {@link BTAdapter} due to user interaction or 'cold reset'. * <p> * When a new callback is added, all available adapter's will be reported as added, * this allows a fully event driven workflow. @@ -89,25 +89,25 @@ public interface BluetoothManager * </p> * @since 2.0.0 * @implNote Not implemented on tinyb.dbus - * @see BluetoothManager#addChangedAdapterSetListener(ChangedAdapterSetListener) - * @see BluetoothManager#removeChangedAdapterSetListener(ChangedAdapterSetListener) + * @see BTManager#addChangedAdapterSetListener(ChangedAdapterSetListener) + * @see BTManager#removeChangedAdapterSetListener(ChangedAdapterSetListener) */ public static interface ChangedAdapterSetListener { /** - * {@link BluetoothAdapter} was added to the system. - * @param adapter the newly added {@link BluetoothAdapter} to the system + * {@link BTAdapter} was added to the system. + * @param adapter the newly added {@link BTAdapter} to the system */ - void adapterAdded(final BluetoothAdapter adapter); + void adapterAdded(final BTAdapter adapter); /** - * {@link BluetoothAdapter} was removed from the system. + * {@link BTAdapter} was removed from the system. * <p> - * {@link BluetoothAdapter#close()} is being called by the native manager after issuing all - * {@link #adapterRemoved(BluetoothAdapter)} calls. + * {@link BTAdapter#close()} is being called by the native manager after issuing all + * {@link #adapterRemoved(BTAdapter)} calls. * </p> - * @param adapter the removed {@link BluetoothAdapter} from the system + * @param adapter the removed {@link BTAdapter} from the system */ - void adapterRemoved(final BluetoothAdapter adapter); + void adapterRemoved(final BTAdapter adapter); } /** @@ -134,7 +134,7 @@ public interface BluetoothManager * @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, long timeoutMS); + public BTObject find(BTType type, String name, String identifier, BTObject parent, long timeoutMS); /** Find a BluetoothObject of a type matching type. If parameters name, @@ -153,7 +153,7 @@ public interface BluetoothManager * waiting for * @return An object matching the name, identifier and parent. */ - public BluetoothObject find(BluetoothType type, String name, String identifier, BluetoothObject parent); + public BTObject find(BTType type, String name, String identifier, BTObject parent); /** Find a BluetoothObject of type T. If parameters name, identifier and * parent are not null, the returned object will have to match them. @@ -171,7 +171,7 @@ public interface BluetoothManager * @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, long timeoutMS); + public <T extends BTObject> T find(String name, String identifier, BTObject parent, long timeoutMS); /** Find a BluetoothObject of type T. If parameters name, identifier and * parent are not null, the returned object will have to match them. @@ -186,7 +186,7 @@ public interface BluetoothManager * waiting for * @return An object matching the name, identifier and parent. */ - public <T extends BluetoothObject> T find(String name, String identifier, BluetoothObject parent); + public <T extends BTObject> T find(String name, String identifier, BTObject parent); /** Return a BluetoothObject of a type matching type. If parameters name, * identifier and parent are not null, the returned object will have to @@ -202,8 +202,8 @@ public interface BluetoothManager * 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); + public BTObject getObject(BTType type, String name, + String identifier, BTObject 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 @@ -219,13 +219,13 @@ public interface BluetoothManager * waiting for * @return A vector of object matching the name, identifier, parent. */ - public List<BluetoothObject> getObjects(BluetoothType type, String name, - String identifier, BluetoothObject parent); + public List<BTObject> getObjects(BTType type, String name, + String identifier, BTObject parent); /** Returns a list of BluetoothAdapters available in the system * @return A list of BluetoothAdapters available in the system */ - public List<BluetoothAdapter> getAdapters(); + public List<BTAdapter> getAdapters(); /** * Returns the BluetoothAdapter matching the given dev_id or null if not found. @@ -237,29 +237,29 @@ public interface BluetoothManager * @since 2.0.0 * @implNote Not implemented on tinyb.dbus */ - public BluetoothAdapter getAdapter(final int dev_id); + public BTAdapter getAdapter(final int dev_id); /** Returns a list of discovered BluetoothDevices * @return A list of discovered BluetoothDevices */ - public List<BluetoothDevice> getDevices(); + public List<BTDevice> getDevices(); /** Returns a list of available BluetoothGattServices * @return A list of available BluetoothGattServices */ - public List<BluetoothGattService> getServices(); + public List<BTGattService> getServices(); /** * Sets a default adapter to use for discovery. * @return TRUE if the device was set * @implNote not implemented for direct_bt.tinyb */ - public boolean setDefaultAdapter(BluetoothAdapter adapter); + public boolean setDefaultAdapter(BTAdapter adapter); /** * Gets the default adapter to use for discovery. * <p> - * <i>direct_bt.tinyb</i>: The default adapter is either the first {@link BluetoothAdapter#isPowered() powered} {@link BluetoothAdapter}, + * <i>direct_bt.tinyb</i>: The default adapter is either the first {@link BTAdapter#isPowered() powered} {@link BTAdapter}, * or function returns nullptr if none is enabled. * </p> * <p> @@ -267,14 +267,14 @@ public interface BluetoothManager * </p> * @return the used default adapter */ - public BluetoothAdapter getDefaultAdapter(); + public BTAdapter getDefaultAdapter(); /** Turns on device discovery on the default adapter if it is disabled. * @return TRUE if discovery was successfully enabled * @deprecated since 2.0.0, use {@link #startDiscovery(boolean)}. */ @Deprecated - public boolean startDiscovery() throws BluetoothException; + public boolean startDiscovery() throws BTException; /** * Turns on device discovery on the default adapter if it is disabled. @@ -284,11 +284,11 @@ public interface BluetoothManager * and {@link #stopDiscovery()} is the recommended workflow * for a reliable discovery process. * @return {@link HCIStatusCode#SUCCESS} if successful, otherwise the {@link HCIStatusCode} error state - * @throws BluetoothException + * @throws BTException * @since 2.0.0 * @implNote {@code keepAlive} not implemented in tinyb.dbus */ - public HCIStatusCode startDiscovery(final boolean keepAlive) throws BluetoothException; + public HCIStatusCode startDiscovery(final boolean keepAlive) throws BTException; /** * Turns off device discovery on the default adapter if it is enabled. @@ -296,12 +296,12 @@ public interface BluetoothManager * @apiNote return {@link HCIStatusCode} since 2.0.0 * @since 2.0.0 */ - public HCIStatusCode stopDiscovery() throws BluetoothException; + public HCIStatusCode stopDiscovery() throws BTException; /** Returns if the discovers is running or not. * @return TRUE if discovery is running */ - public boolean getDiscovering() throws BluetoothException; + public boolean getDiscovering() throws BTException; /** * Add the given {@link ChangedAdapterSetListener} to this manager. diff --git a/java/org/direct_bt/BluetoothNotification.java b/java/org/direct_bt/BTNotification.java index 01e145bb..961008f7 100644 --- a/java/org/direct_bt/BluetoothNotification.java +++ b/java/org/direct_bt/BTNotification.java @@ -30,6 +30,6 @@ package org.direct_bt; * 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 interface BTNotification<T> { public void run(T value); } diff --git a/java/org/direct_bt/BluetoothObject.java b/java/org/direct_bt/BTObject.java index df90df4a..05821e48 100644 --- a/java/org/direct_bt/BluetoothObject.java +++ b/java/org/direct_bt/BTObject.java @@ -27,17 +27,17 @@ */ package org.direct_bt; -public interface BluetoothObject extends Cloneable, AutoCloseable +public interface BTObject extends Cloneable, AutoCloseable { /** Returns the BluetoothType of this object * @return The BluetoothType of this object */ - public BluetoothType getBluetoothType(); + public BTType getBluetoothType(); /** Returns a clone of the BluetoothObject * @return A clone of the BluetoothObject */ - public BluetoothObject clone(); + public BTObject clone(); @Override public boolean equals(Object obj); diff --git a/java/org/direct_bt/BluetoothType.java b/java/org/direct_bt/BTType.java index ef62d803..07817897 100644 --- a/java/org/direct_bt/BluetoothType.java +++ b/java/org/direct_bt/BTType.java @@ -24,7 +24,7 @@ package org.direct_bt; -public enum BluetoothType +public enum BTType { NONE, ADAPTER, DEVICE, GATT_SERVICE, GATT_CHARACTERISTIC, diff --git a/java/org/direct_bt/BluetoothUtils.java b/java/org/direct_bt/BTUtils.java index 99ded5a9..e2266856 100644 --- a/java/org/direct_bt/BluetoothUtils.java +++ b/java/org/direct_bt/BTUtils.java @@ -24,7 +24,7 @@ */ package org.direct_bt; -public class BluetoothUtils { +public class BTUtils { private static long t0; static { t0 = startupTimeMillisImpl(); @@ -62,8 +62,8 @@ public class BluetoothUtils { * @param min_result_ms the minimum resulting supervisor timeout, defaults to 500ms. * If above formula results in a smaller value, min_result_ms/10 will be returned. * @param multiplier recommendation is 6, we use 10 as default for safety. - * @return the resulting supervising timeout in 1/10 [ms], suitable for the {@link BluetoothDevice#connectLE(short, short, short, short, short, short)}. - * @see BluetoothDevice#connectLE(short, short, short, short, short, short) + * @return the resulting supervising timeout in 1/10 [ms], suitable for the {@link BTDevice#connectLE(short, short, short, short, short, short)}. + * @see BTDevice#connectLE(short, short, short, short, short, short) */ public static int getHCIConnSupervisorTimeout(final int conn_latency, final int conn_interval_max_ms, final int min_result_ms, final int multiplier) { diff --git a/java/org/direct_bt/EUI48.java b/java/org/direct_bt/EUI48.java index 1d9c2618..2d4b2756 100644 --- a/java/org/direct_bt/EUI48.java +++ b/java/org/direct_bt/EUI48.java @@ -241,7 +241,7 @@ public class EUI48 { public final String toString() { final StringBuilder sb = new StringBuilder(17); for(int i=byte_size-1; 0 <= i; i--) { - BluetoothUtils.byteHexString(sb, b[i], false /* lowerCase */); + BTUtils.byteHexString(sb, b[i], false /* lowerCase */); if( 0 < i ) { sb.append(":"); } diff --git a/java/org/direct_bt/ObjectArgCallback.java b/java/org/direct_bt/ObjectArgCallback.java index a2f22f48..36430f8a 100644 --- a/java/org/direct_bt/ObjectArgCallback.java +++ b/java/org/direct_bt/ObjectArgCallback.java @@ -26,7 +26,7 @@ package org.direct_bt; import tinyb.dbus.DBusObject; -public class ObjectArgCallback extends BluetoothCallback +public class ObjectArgCallback extends BTCallback { @SuppressWarnings("unused") private final Object callbackArg; diff --git a/java/org/direct_bt/ObjectArrayArgCallback.java b/java/org/direct_bt/ObjectArrayArgCallback.java index 59d2d72e..8fb196b4 100644 --- a/java/org/direct_bt/ObjectArrayArgCallback.java +++ b/java/org/direct_bt/ObjectArrayArgCallback.java @@ -26,7 +26,7 @@ package org.direct_bt; import tinyb.dbus.DBusObject; -public class ObjectArrayArgCallback extends BluetoothCallback +public class ObjectArrayArgCallback extends BTCallback { @SuppressWarnings("unused") private final Object[] callbackArg; diff --git a/java/org/direct_bt/PlatformToolkit.java b/java/org/direct_bt/PlatformToolkit.java index decee20c..480200e3 100644 --- a/java/org/direct_bt/PlatformToolkit.java +++ b/java/org/direct_bt/PlatformToolkit.java @@ -279,7 +279,7 @@ final class PlatformToolkit { final String _os_arch2 = getArchName(CPU_TYPE, ABI_TYPE, LITTLE_ENDIAN); os_arch = null != _os_arch2 ? _os_arch2 : _os_arch1; os_and_arch = os_name+"-"+os_arch; - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println("PlatformToolkit: os_name "+os_name+", os_arch ("+_os_arch1+" -> "+_os_arch2+" ->) "+os_arch+" (final), "+ "CPU_TYPE "+CPU_TYPE+", ABI_TYPE "+ABI_TYPE+", LITTLE_ENDIAN "+LITTLE_ENDIAN); } @@ -458,7 +458,7 @@ final class PlatformToolkit { // f.getCanonicalPath() also resolved '.', '..' and symbolic links in contrast to f.getAbsolutePath() return f.getCanonicalPath(); } catch (final Throwable t) { - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println("getAbsolutePath("+path+") failed: "+t.getMessage()); } return null; @@ -471,7 +471,7 @@ final class PlatformToolkit { final String abspath = getCanonicalPath(fullpath); if( null != abspath ) { final boolean isDup = paths.contains(abspath); - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(" "+abspath+" (addPath "+msg+", dropped duplicate "+isDup+")"); } if( !isDup ) { @@ -542,12 +542,12 @@ final class PlatformToolkit { * @return {@code true} if successful, otherwise {@code false}. */ static boolean loadLibrary(final String libBaseName, final ClassLoader cl, final Throwable[] t) { - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(); System.err.println("PlatformToolkit.loadLibrary: libBaseName "+libBaseName+":"); } final List<String> possiblePaths = enumerateLibraryPaths(libBaseName, true /* searchSystemPath */, false /* searchSystemPathFirst */, cl); - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(); } @@ -556,12 +556,12 @@ final class PlatformToolkit { final String path = iter.next(); try { System.load(path); - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(" "+path+" success"); } return true; } catch (final Throwable t0) { - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(" "+path+" failed: "+t0.getMessage()); } t[0] = t0; @@ -571,12 +571,12 @@ final class PlatformToolkit { // Fall back to loadLibrary try { System.loadLibrary(libBaseName); - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(" "+libBaseName+" success"); } return true; } catch (final Throwable t0) { - if( BluetoothFactory.DEBUG ) { + if( BTFactory.DEBUG ) { System.err.println(" "+libBaseName+" failed: "+t0.getMessage()); } t[0] = t0; diff --git a/java/org/direct_bt/SMPLongTermKeyInfo.java b/java/org/direct_bt/SMPLongTermKeyInfo.java index ce3e3254..7db7455e 100644 --- a/java/org/direct_bt/SMPLongTermKeyInfo.java +++ b/java/org/direct_bt/SMPLongTermKeyInfo.java @@ -208,9 +208,9 @@ public class SMPLongTermKeyInfo { @Override public String toString() { // hex-fmt aligned with btmon return "LTK[props "+properties.toString()+", enc_size "+enc_size+ - ", ediv "+BluetoothUtils.bytesHexString(ediv, 0, -1, false /* lsbFirst */, true /* leading0X */, true /* lowerCase */)+ - ", rand "+BluetoothUtils.bytesHexString(rand, 0, -1, false /* lsbFirst */, true /* leading0X */, true /* lowerCase */)+ - ", ltk "+BluetoothUtils.bytesHexString(ltk, 0, -1, true /* lsbFirst */, false /* leading0X */, true /* lowerCase */)+ + ", ediv "+BTUtils.bytesHexString(ediv, 0, -1, false /* lsbFirst */, true /* leading0X */, true /* lowerCase */)+ + ", rand "+BTUtils.bytesHexString(rand, 0, -1, false /* lsbFirst */, true /* leading0X */, true /* lowerCase */)+ + ", ltk "+BTUtils.bytesHexString(ltk, 0, -1, true /* lsbFirst */, false /* leading0X */, true /* lowerCase */)+ "]"; } diff --git a/java/org/direct_bt/SMPSignatureResolvingKeyInfo.java b/java/org/direct_bt/SMPSignatureResolvingKeyInfo.java index c517741f..89e8428c 100644 --- a/java/org/direct_bt/SMPSignatureResolvingKeyInfo.java +++ b/java/org/direct_bt/SMPSignatureResolvingKeyInfo.java @@ -180,7 +180,7 @@ public class SMPSignatureResolvingKeyInfo { @Override public String toString() { // hex-fmt aligned with btmon return "LTK[props "+properties.toString()+ - ", csrk "+BluetoothUtils.bytesHexString(csrk, 0, -1, true /* lsbFirst */, false /* leading0X */, true /* lowerCase */)+ + ", csrk "+BTUtils.bytesHexString(csrk, 0, -1, true /* lsbFirst */, false /* leading0X */, true /* lowerCase */)+ "]"; } diff --git a/java/tinyb/dbus/DBusAdapter.java b/java/tinyb/dbus/DBusAdapter.java index 11a81af4..bf44ebd3 100644 --- a/java/tinyb/dbus/DBusAdapter.java +++ b/java/tinyb/dbus/DBusAdapter.java @@ -36,36 +36,36 @@ import java.util.UUID; import org.direct_bt.AdapterStatusListener; import org.direct_bt.BDAddressAndType; -import org.direct_bt.BluetoothAdapter; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTAdapter; +import org.direct_bt.BTDevice; +import org.direct_bt.BTException; +import org.direct_bt.BTManager; +import org.direct_bt.BTNotification; +import org.direct_bt.BTType; import org.direct_bt.EUI48; import org.direct_bt.HCIStatusCode; import org.direct_bt.HCIWhitelistConnectType; import org.direct_bt.ScanType; import org.direct_bt.TransportType; -public class DBusAdapter extends DBusObject implements BluetoothAdapter +public class DBusAdapter extends DBusObject implements BTAdapter { @Override - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); @Override - public native BluetoothAdapter clone(); + public native BTAdapter clone(); - static BluetoothType class_type() { return BluetoothType.ADAPTER; } + static BTType class_type() { return BTType.ADAPTER; } @Override - public BluetoothDevice find(final String name, final BDAddressAndType addressAndType, final long timeoutMS) { - final BluetoothManager manager = DBusManager.getManager(); - return (BluetoothDevice) manager.find(BluetoothType.DEVICE, name, addressAndType.address.toString(), this, timeoutMS); + public BTDevice find(final String name, final BDAddressAndType addressAndType, final long timeoutMS) { + final BTManager manager = DBusManager.getManager(); + return (BTDevice) manager.find(BTType.DEVICE, name, addressAndType.address.toString(), this, timeoutMS); } @Override - public BluetoothDevice find(final String name, final BDAddressAndType addressAndType) { + public BTDevice find(final String name, final BDAddressAndType addressAndType) { return find(name, addressAndType, 0); } @@ -103,30 +103,30 @@ public class DBusAdapter extends DBusObject implements BluetoothAdapter } @Override - public final BluetoothManager getManager() { return DBusManager.getManager(); } + public final BTManager getManager() { return DBusManager.getManager(); } /* D-Bus method calls: */ @Override @Deprecated - public native boolean startDiscovery() throws BluetoothException; + public native boolean startDiscovery() throws BTException; @Override - public synchronized HCIStatusCode startDiscovery(final boolean keepAlive) throws BluetoothException { + public synchronized HCIStatusCode startDiscovery(final boolean keepAlive) throws BTException { return startDiscovery() ? HCIStatusCode.SUCCESS : HCIStatusCode.INTERNAL_FAILURE; // FIXME keepAlive } @Override - public HCIStatusCode stopDiscovery() throws BluetoothException { + public HCIStatusCode stopDiscovery() throws BTException { return stopDiscoveryImpl() ? HCIStatusCode.SUCCESS : HCIStatusCode.INTERNAL_FAILURE; } - private native boolean stopDiscoveryImpl() throws BluetoothException; + private native boolean stopDiscoveryImpl() throws BTException; @Override - public native List<BluetoothDevice> getDiscoveredDevices(); + public native List<BTDevice> getDiscoveredDevices(); @Override - public native int removeDiscoveredDevices() throws BluetoothException; + public native int removeDiscoveredDevices() throws BTException; @Override public boolean removeDiscoveredDevice(final BDAddressAndType addressAndType) { @@ -160,7 +160,7 @@ public class DBusAdapter extends DBusObject implements BluetoothAdapter public native boolean getPoweredState(); @Override - public native void enablePoweredNotifications(BluetoothNotification<Boolean> callback); + public native void enablePoweredNotifications(BTNotification<Boolean> callback); @Override public native void disablePoweredNotifications(); @@ -175,7 +175,7 @@ public class DBusAdapter extends DBusObject implements BluetoothAdapter public native boolean getDiscoverable(); @Override - public native void enableDiscoverableNotifications(BluetoothNotification<Boolean> callback); + public native void enableDiscoverableNotifications(BTNotification<Boolean> callback); @Override public native void disableDiscoverableNotifications(); @@ -190,16 +190,16 @@ public class DBusAdapter extends DBusObject implements BluetoothAdapter public native boolean setDiscoverableTimout(long value); @Override - public BluetoothDevice connectDevice(final BDAddressAndType addressAndType) { + public BTDevice connectDevice(final BDAddressAndType addressAndType) { return connectDeviceImpl(addressAndType.address.toString(), addressAndType.type.toDbusString()); } - private native BluetoothDevice connectDeviceImpl(String address, String addressType); + private native BTDevice connectDeviceImpl(String address, String addressType); @Override public native boolean getPairable(); @Override - public native void enablePairableNotifications(BluetoothNotification<Boolean> callback); + public native void enablePairableNotifications(BTNotification<Boolean> callback); @Override public native void disablePairableNotifications(); @@ -221,7 +221,7 @@ public class DBusAdapter extends DBusObject implements BluetoothAdapter public native boolean getDiscovering(); @Override - public boolean addStatusListener(final AdapterStatusListener l, final BluetoothDevice deviceMatch) { + public boolean addStatusListener(final AdapterStatusListener l, final BTDevice deviceMatch) { return false; // FIXME } @@ -236,7 +236,7 @@ public class DBusAdapter extends DBusObject implements BluetoothAdapter } @Override - public native void enableDiscoveringNotifications(BluetoothNotification<Boolean> callback); + public native void enableDiscoveringNotifications(BTNotification<Boolean> callback); @Override public native void disableDiscoveringNotifications(); diff --git a/java/tinyb/dbus/DBusBluetoothException.java b/java/tinyb/dbus/DBusBluetoothException.java index 03e0233f..b2630dfd 100644 --- a/java/tinyb/dbus/DBusBluetoothException.java +++ b/java/tinyb/dbus/DBusBluetoothException.java @@ -28,10 +28,10 @@ package tinyb.dbus; -import org.direct_bt.BluetoothException; +import org.direct_bt.BTException; @SuppressWarnings("serial") -public class DBusBluetoothException extends BluetoothException { +public class DBusBluetoothException extends BTException { DBusBluetoothException(final String msg) { super(msg); } diff --git a/java/tinyb/dbus/DBusDevice.java b/java/tinyb/dbus/DBusDevice.java index f0f445d8..902efec0 100644 --- a/java/tinyb/dbus/DBusDevice.java +++ b/java/tinyb/dbus/DBusDevice.java @@ -33,18 +33,17 @@ import java.util.Map; import org.direct_bt.BDAddressAndType; import org.direct_bt.BDAddressType; -import org.direct_bt.BLERandomAddressType; import org.direct_bt.BTSecurityLevel; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothType; -import org.direct_bt.BluetoothUtils; +import org.direct_bt.BTDevice; +import org.direct_bt.BTException; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattService; +import org.direct_bt.BTManager; +import org.direct_bt.BTNotification; +import org.direct_bt.BTType; +import org.direct_bt.BTUtils; import org.direct_bt.EUI48; -import org.direct_bt.GATTCharacteristicListener; +import org.direct_bt.BTGattCharListener; import org.direct_bt.HCIStatusCode; import org.direct_bt.PairingMode; import org.direct_bt.SMPIOCapability; @@ -53,7 +52,7 @@ import org.direct_bt.SMPLongTermKeyInfo; import org.direct_bt.SMPPairingState; import org.direct_bt.SMPSignatureResolvingKeyInfo; -public class DBusDevice extends DBusObject implements BluetoothDevice +public class DBusDevice extends DBusObject implements BTDevice { @Override public final long getCreationTimestamp() { return ts_creation; } @@ -65,38 +64,38 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public final long getLastUpdateTimestamp() { return ts_creation; } // FIXME @Override - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); @Override public native DBusDevice clone(); - static BluetoothType class_type() { return BluetoothType.DEVICE; } + static BTType class_type() { return BTType.DEVICE; } @Override - public BluetoothGattService find(final String UUID, final long timeoutMS) { - final BluetoothManager manager = DBusManager.getManager(); - return (BluetoothGattService) manager.find(BluetoothType.GATT_SERVICE, + public BTGattService find(final String UUID, final long timeoutMS) { + final BTManager manager = DBusManager.getManager(); + return (BTGattService) manager.find(BTType.GATT_SERVICE, null, UUID, this, timeoutMS); } @Override - public BluetoothGattService find(final String UUID) { + public BTGattService find(final String UUID) { return find(UUID, 0); } /* D-Bus method calls: */ @Override - public final HCIStatusCode disconnect() throws BluetoothException { + public final HCIStatusCode disconnect() throws BTException { return disconnectImpl() ? HCIStatusCode.SUCCESS : HCIStatusCode.UNSPECIFIED_ERROR ; } - private native boolean disconnectImpl() throws BluetoothException; + private native boolean disconnectImpl() throws BTException; @Override - public final HCIStatusCode connect() throws BluetoothException { + public final HCIStatusCode connect() throws BTException { return connectImpl() ? HCIStatusCode.SUCCESS : HCIStatusCode.UNSPECIFIED_ERROR ; } - private native boolean connectImpl() throws BluetoothException; + private native boolean connectImpl() throws BTException; @Override public HCIStatusCode connectLE(final short interval, final short window, @@ -106,10 +105,10 @@ public class DBusDevice extends DBusObject implements BluetoothDevice } @Override - public native boolean connectProfile(String arg_UUID) throws BluetoothException; + public native boolean connectProfile(String arg_UUID) throws BTException; @Override - public native boolean disconnectProfile(String arg_UUID) throws BluetoothException; + public native boolean disconnectProfile(String arg_UUID) throws BTException; @Override public final SMPKeyMask getAvailableSMPKeys(final boolean responder) { return new SMPKeyMask(); } @@ -124,7 +123,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public final SMPSignatureResolvingKeyInfo getSignatureResolvingKeyInfo(final boolean responder) { return new SMPSignatureResolvingKeyInfo(); } // FIXME @Override - public native boolean pair() throws BluetoothException; + public native boolean pair() throws BTException; @Override public final HCIStatusCode unpair() { return HCIStatusCode.NOT_SUPPORTED; } // FIXME @@ -160,13 +159,13 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public SMPPairingState getPairingState() { return SMPPairingState.NONE; } @Override - public native boolean remove() throws BluetoothException; + public native boolean remove() throws BTException; @Override - public native boolean cancelPairing() throws BluetoothException; + public native boolean cancelPairing() throws BTException; @Override - public native List<BluetoothGattService> getServices(); + public native List<BTGattService> getServices(); @Override public boolean pingGATT() { return true; } // FIXME @@ -201,7 +200,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native boolean getPaired(); @Override - public native void enablePairedNotifications(BluetoothNotification<Boolean> callback); + public native void enablePairedNotifications(BTNotification<Boolean> callback); @Override public native void disablePairedNotifications(); @@ -210,7 +209,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native boolean getTrusted(); @Override - public native void enableTrustedNotifications(BluetoothNotification<Boolean> callback); + public native void enableTrustedNotifications(BTNotification<Boolean> callback); @Override public native void disableTrustedNotifications(); @@ -222,7 +221,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native boolean getBlocked(); @Override - public native void enableBlockedNotifications(BluetoothNotification<Boolean> callback); + public native void enableBlockedNotifications(BTNotification<Boolean> callback); @Override public native void disableBlockedNotifications(); @@ -237,7 +236,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native short getRSSI(); @Override - public native void enableRSSINotifications(BluetoothNotification<Short> callback); + public native void enableRSSINotifications(BTNotification<Short> callback); @Override public native void disableRSSINotifications(); @@ -249,7 +248,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public final short getConnectionHandle() { return 0; /* FIXME */ } @Override - public native void enableConnectedNotifications(BluetoothNotification<Boolean> callback); + public native void enableConnectedNotifications(BTNotification<Boolean> callback); @Override public native void disableConnectedNotifications(); @@ -267,7 +266,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native Map<Short, byte[]> getManufacturerData(); @Override - public native void enableManufacturerDataNotifications(BluetoothNotification<Map<Short, byte[]> > callback); + public native void enableManufacturerDataNotifications(BTNotification<Map<Short, byte[]> > callback); @Override public native void disableManufacturerDataNotifications(); @@ -277,7 +276,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native Map<String, byte[]> getServiceData(); @Override - public native void enableServiceDataNotifications(BluetoothNotification<Map<String, byte[]> > callback); + public native void enableServiceDataNotifications(BTNotification<Map<String, byte[]> > callback); @Override public native void disableServiceDataNotifications(); @@ -289,28 +288,28 @@ public class DBusDevice extends DBusObject implements BluetoothDevice public native boolean getServicesResolved (); @Override - public native void enableServicesResolvedNotifications(BluetoothNotification<Boolean> callback); + public native void enableServicesResolvedNotifications(BTNotification<Boolean> callback); @Override public native void disableServicesResolvedNotifications(); @Override - public boolean addCharacteristicListener(final GATTCharacteristicListener listener) { + public boolean addCharListener(final BTGattCharListener listener) { return false; // FIXME } @Override - public boolean removeCharacteristicListener(final GATTCharacteristicListener l) { + public boolean removeCharListener(final BTGattCharListener l) { return false; // FIXME } @Override - public int removeAllAssociatedCharacteristicListener(final BluetoothGattCharacteristic associatedCharacteristic) { + public int removeAllAssociatedCharListener(final BTGattChar associatedCharacteristic) { return 0; // FIXME } @Override - public int removeAllCharacteristicListener() { + public int removeAllCharListener() { return 0; // FIXME } @@ -319,7 +318,7 @@ public class DBusDevice extends DBusObject implements BluetoothDevice private DBusDevice(final long instance) { super(instance); - ts_creation = BluetoothUtils.currentTimeMillis(); + ts_creation = BTUtils.currentTimeMillis(); } final long ts_creation; diff --git a/java/tinyb/dbus/DBusEvent.java b/java/tinyb/dbus/DBusEvent.java index dc9b8d0c..ddc080bc 100644 --- a/java/tinyb/dbus/DBusEvent.java +++ b/java/tinyb/dbus/DBusEvent.java @@ -24,16 +24,16 @@ package tinyb.dbus; -import org.direct_bt.BluetoothCallback; -import org.direct_bt.BluetoothEvent; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTCallback; +import org.direct_bt.BTEvent; +import org.direct_bt.BTType; -public class DBusEvent implements BluetoothEvent +public class DBusEvent implements BTEvent { private long nativeInstance; @Override - public native BluetoothType getType(); + public native BTType getType(); @Override public native String getName(); @Override @@ -43,12 +43,12 @@ public class DBusEvent implements BluetoothEvent @Override public native boolean hasCallback(); - private native void init(BluetoothType type, String name, String identifier, - DBusObject parent, BluetoothCallback cb, Object data); + private native void init(BTType type, String name, String identifier, + DBusObject parent, BTCallback cb, Object data); private native void delete(); - public DBusEvent(final BluetoothType type, final String name, final String identifier, - final DBusObject parent, final BluetoothCallback cb, final Object data) + public DBusEvent(final BTType type, final String name, final String identifier, + final DBusObject parent, final BTCallback cb, final Object data) { init(type, name, identifier, parent, cb, data); } diff --git a/java/tinyb/dbus/DBusGattCharacteristic.java b/java/tinyb/dbus/DBusGattCharacteristic.java index 702ac886..01d67e15 100644 --- a/java/tinyb/dbus/DBusGattCharacteristic.java +++ b/java/tinyb/dbus/DBusGattCharacteristic.java @@ -30,55 +30,55 @@ package tinyb.dbus; import java.util.List; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothType; -import org.direct_bt.GATTCharacteristicListener; - -public class DBusGattCharacteristic extends DBusObject implements BluetoothGattCharacteristic +import org.direct_bt.BTException; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTGattService; +import org.direct_bt.BTManager; +import org.direct_bt.BTNotification; +import org.direct_bt.BTType; +import org.direct_bt.BTGattCharListener; + +public class DBusGattCharacteristic extends DBusObject implements BTGattChar { @Override - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); @Override public native DBusGattCharacteristic clone(); - static BluetoothType class_type() { return BluetoothType.GATT_CHARACTERISTIC; } + static BTType class_type() { return BTType.GATT_CHARACTERISTIC; } @Override - public BluetoothGattDescriptor find(final String UUID, final long timeoutMS) { - final BluetoothManager manager = DBusManager.getManager(); - return (BluetoothGattDescriptor) manager.find(BluetoothType.GATT_DESCRIPTOR, + public BTGattDesc find(final String UUID, final long timeoutMS) { + final BTManager manager = DBusManager.getManager(); + return (BTGattDesc) manager.find(BTType.GATT_DESCRIPTOR, null, UUID, this, timeoutMS); } @Override - public BluetoothGattDescriptor find(final String UUID) { + public BTGattDesc find(final String UUID) { return find(UUID, 0); } /* D-Bus method calls: */ @Override - public native byte[] readValue() throws BluetoothException; + public native byte[] readValue() throws BTException; @Override - public native void enableValueNotifications(BluetoothNotification<byte[]> callback); + public native void enableValueNotifications(BTNotification<byte[]> callback); @Override public native void disableValueNotifications(); @Override - public boolean writeValue(final byte[] argValue, final boolean withResponse) throws BluetoothException { + public boolean writeValue(final byte[] argValue, final boolean withResponse) throws BTException { if( withResponse ) { throw new DBusBluetoothException("writeValue with response not yet supported"); } return writeValueImpl(argValue); } - private native boolean writeValueImpl(byte[] argValue) throws BluetoothException; + private native boolean writeValueImpl(byte[] argValue) throws BTException; /* D-Bus property accessors: */ @@ -86,7 +86,7 @@ public class DBusGattCharacteristic extends DBusObject implements BluetoothGattC public native String getUUID(); @Override - public native BluetoothGattService getService(); + public native BTGattService getService(); @Override public native byte[] getValue(); @@ -98,7 +98,7 @@ public class DBusGattCharacteristic extends DBusObject implements BluetoothGattC public native String[] getFlags(); @Override - public native List<BluetoothGattDescriptor> getDescriptors(); + public native List<BTGattDesc> getDescriptors(); private native void init(DBusGattCharacteristic obj); @@ -110,7 +110,7 @@ public class DBusGattCharacteristic extends DBusObject implements BluetoothGattC } @Override - public boolean addCharacteristicListener(final GATTCharacteristicListener listener) { + public boolean addCharacteristicListener(final BTGattCharListener listener) { return false; // FIXME } @Override @@ -126,13 +126,13 @@ public class DBusGattCharacteristic extends DBusObject implements BluetoothGattC return false; // FIXME } @Override - public boolean addCharacteristicListener(final GATTCharacteristicListener listener, final boolean[] enabledState) + public boolean addCharacteristicListener(final BTGattCharListener listener, final boolean[] enabledState) throws IllegalStateException { return false; // FIXME } @Override - public boolean removeCharacteristicListener(final GATTCharacteristicListener l, final boolean disableIndicationNotification) { + public boolean removeCharacteristicListener(final BTGattCharListener l, final boolean disableIndicationNotification) { return false; // FIXME } @Override diff --git a/java/tinyb/dbus/DBusGattDescriptor.java b/java/tinyb/dbus/DBusGattDescriptor.java index 03d25cd8..f1741dba 100644 --- a/java/tinyb/dbus/DBusGattDescriptor.java +++ b/java/tinyb/dbus/DBusGattDescriptor.java @@ -28,19 +28,19 @@ package tinyb.dbus; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattDescriptor; -import org.direct_bt.BluetoothNotification; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTException; +import org.direct_bt.BTGattDesc; +import org.direct_bt.BTNotification; +import org.direct_bt.BTType; -public class DBusGattDescriptor extends DBusObject implements BluetoothGattDescriptor +public class DBusGattDescriptor extends DBusObject implements BTGattDesc { @Override - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); @Override - public native BluetoothGattDescriptor clone(); + public native BTGattDesc clone(); - static BluetoothType class_type() { return BluetoothType.GATT_DESCRIPTOR; } + static BTType class_type() { return BTType.GATT_DESCRIPTOR; } /* D-Bus method calls: */ @@ -48,10 +48,10 @@ public class DBusGattDescriptor extends DBusObject implements BluetoothGattDescr public native byte[] readValue(); @Override - public native boolean writeValue(byte[] argValue) throws BluetoothException; + public native boolean writeValue(byte[] argValue) throws BTException; @Override - public native void enableValueNotifications(BluetoothNotification<byte[]> callback); + public native void enableValueNotifications(BTNotification<byte[]> callback); @Override public native void disableValueNotifications(); diff --git a/java/tinyb/dbus/DBusGattService.java b/java/tinyb/dbus/DBusGattService.java index d1c157d8..feb24e65 100644 --- a/java/tinyb/dbus/DBusGattService.java +++ b/java/tinyb/dbus/DBusGattService.java @@ -30,30 +30,30 @@ package tinyb.dbus; import java.util.List; -import org.direct_bt.BluetoothGattCharacteristic; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTGattChar; +import org.direct_bt.BTGattService; +import org.direct_bt.BTManager; +import org.direct_bt.BTType; -public class DBusGattService extends DBusObject implements BluetoothGattService +public class DBusGattService extends DBusObject implements BTGattService { @Override - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); @Override - public native BluetoothGattService clone(); + public native BTGattService clone(); - static BluetoothType class_type() { return BluetoothType.GATT_SERVICE; } + static BTType class_type() { return BTType.GATT_SERVICE; } @Override - public BluetoothGattCharacteristic find(final String UUID, final long timeoutMS) { - final BluetoothManager manager = DBusManager.getManager(); - return (DBusGattCharacteristic) manager.find(BluetoothType.GATT_CHARACTERISTIC, + public BTGattChar find(final String UUID, final long timeoutMS) { + final BTManager manager = DBusManager.getManager(); + return (DBusGattCharacteristic) manager.find(BTType.GATT_CHARACTERISTIC, null, UUID, this, timeoutMS); } @Override - public BluetoothGattCharacteristic find(final String UUID) { + public BTGattChar find(final String UUID) { return find(UUID, 0); } @@ -69,7 +69,7 @@ public class DBusGattService extends DBusObject implements BluetoothGattService public native boolean getPrimary(); @Override - public native List<BluetoothGattCharacteristic> getCharacteristics(); + public native List<BTGattChar> getChars(); private native void delete(); diff --git a/java/tinyb/dbus/DBusManager.java b/java/tinyb/dbus/DBusManager.java index a32cf875..faade7a1 100644 --- a/java/tinyb/dbus/DBusManager.java +++ b/java/tinyb/dbus/DBusManager.java @@ -30,26 +30,26 @@ package tinyb.dbus; import java.util.List; -import org.direct_bt.BluetoothAdapter; -import org.direct_bt.BluetoothDevice; -import org.direct_bt.BluetoothException; -import org.direct_bt.BluetoothGattService; -import org.direct_bt.BluetoothManager; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTAdapter; +import org.direct_bt.BTDevice; +import org.direct_bt.BTException; +import org.direct_bt.BTGattService; +import org.direct_bt.BTManager; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; import org.direct_bt.HCIStatusCode; -import org.direct_bt.BluetoothManager.ChangedAdapterSetListener; +import org.direct_bt.BTManager.ChangedAdapterSetListener; -public class DBusManager implements BluetoothManager +public class DBusManager implements BTManager { private long nativeInstance; private final Settings settings; private native static String getNativeAPIVersion(); - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); - private native DBusObject find(int type, String name, String identifier, BluetoothObject parent, long milliseconds); + private native DBusObject find(int type, String name, String identifier, BTObject parent, long milliseconds); @Override public final Settings getSettings() { @@ -57,77 +57,77 @@ public class DBusManager implements BluetoothManager } @Override - public DBusObject find(final BluetoothType type, final String name, final String identifier, final BluetoothObject parent, final long timeoutMS) { + public DBusObject find(final BTType type, final String name, final String identifier, final BTObject 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) { + public DBusObject find(final BTType type, final String name, final String identifier, final BTObject 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) { + public <T extends BTObject> T find(final String name, final String identifier, final BTObject 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) { + public <T extends BTObject> T find(final String name, final String identifier, final BTObject parent) { return (T) find(name, identifier, parent, 0); } @Override - public BluetoothObject getObject(final BluetoothType type, final String name, - final String identifier, final BluetoothObject parent) { + public BTObject getObject(final BTType type, final String name, + final String identifier, final BTObject parent) { return getObject(type.ordinal(), name, identifier, parent); } - private native BluetoothObject getObject(int type, String name, String identifier, BluetoothObject parent); + private native BTObject getObject(int type, String name, String identifier, BTObject parent); @Override - public List<BluetoothObject> getObjects(final BluetoothType type, final String name, - final String identifier, final BluetoothObject parent) { + public List<BTObject> getObjects(final BTType type, final String name, + final String identifier, final BTObject parent) { return getObjects(type.ordinal(), name, identifier, parent); } - private native List<BluetoothObject> getObjects(int type, String name, String identifier, BluetoothObject parent); + private native List<BTObject> getObjects(int type, String name, String identifier, BTObject parent); @Override - public native List<BluetoothAdapter> getAdapters(); + public native List<BTAdapter> getAdapters(); @Override - public BluetoothAdapter getAdapter(final int dev_id) { return null; } // FIXME + public BTAdapter getAdapter(final int dev_id) { return null; } // FIXME @Override - public native List<BluetoothDevice> getDevices(); + public native List<BTDevice> getDevices(); @Override - public native List<BluetoothGattService> getServices(); + public native List<BTGattService> getServices(); @Override - public native boolean setDefaultAdapter(BluetoothAdapter adapter); + public native boolean setDefaultAdapter(BTAdapter adapter); @Override - public native BluetoothAdapter getDefaultAdapter(); + public native BTAdapter getDefaultAdapter(); @Override - public native boolean startDiscovery() throws BluetoothException; + public native boolean startDiscovery() throws BTException; @Override - public HCIStatusCode startDiscovery(final boolean keepAlive) throws BluetoothException { + public HCIStatusCode startDiscovery(final boolean keepAlive) throws BTException { return startDiscovery() ? HCIStatusCode.SUCCESS : HCIStatusCode.INTERNAL_FAILURE; // FIXME keepAlive } @Override - public HCIStatusCode stopDiscovery() throws BluetoothException { + public HCIStatusCode stopDiscovery() throws BTException { return stopDiscoveryImpl() ? HCIStatusCode.SUCCESS : HCIStatusCode.INTERNAL_FAILURE; } - private native boolean stopDiscoveryImpl() throws BluetoothException; + private native boolean stopDiscoveryImpl() throws BTException; @Override - public native boolean getDiscovering() throws BluetoothException; + public native boolean getDiscovering() throws BTException; - private native void init() throws BluetoothException; + private native void init() throws BTException; private native void delete(); private DBusManager() { @@ -156,7 +156,7 @@ public class DBusManager implements BluetoothManager /** Returns an instance of BluetoothManager, to be used instead of constructor. * @return An initialized BluetoothManager instance. */ - public static synchronized BluetoothManager getManager() throws RuntimeException, BluetoothException { + public static synchronized BTManager getManager() throws RuntimeException, BTException { return LazySingletonHolder.singleton; } /** Initialize-On-Demand Holder Class, similar to C++11's "Magic Statics". */ diff --git a/java/tinyb/dbus/DBusObject.java b/java/tinyb/dbus/DBusObject.java index 7cb873a8..f28ba858 100644 --- a/java/tinyb/dbus/DBusObject.java +++ b/java/tinyb/dbus/DBusObject.java @@ -28,26 +28,26 @@ package tinyb.dbus; -import org.direct_bt.BluetoothFactory; -import org.direct_bt.BluetoothObject; -import org.direct_bt.BluetoothType; +import org.direct_bt.BTFactory; +import org.direct_bt.BTObject; +import org.direct_bt.BTType; -public class DBusObject implements BluetoothObject +public class DBusObject implements BTObject { protected long nativeInstance; private boolean isValid; static { - BluetoothFactory.checkInitialized(); + BTFactory.checkInitialized(); } - static BluetoothType class_type() { return BluetoothType.NONE; } + static BTType class_type() { return BTType.NONE; } @Override - public native BluetoothType getBluetoothType(); + public native BTType getBluetoothType(); @Override - public native BluetoothObject clone(); + public native BTObject clone(); private native void delete(); private native boolean operatorEqual(DBusObject obj); |