diff options
-rw-r--r-- | examples/direct_bt_scanner10/dbt_scanner10.cpp | 12 | ||||
-rw-r--r-- | examples/java/DBTScanner10.java | 7 | ||||
-rw-r--r-- | java/direct_bt/tinyb/DBTAdapter.java | 75 |
3 files changed, 54 insertions, 40 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp index d8d87ac0..0653c4c5 100644 --- a/examples/direct_bt_scanner10/dbt_scanner10.cpp +++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp @@ -132,10 +132,14 @@ class MyAdapterStatusListener : public AdapterStatusListener { void adapterSettingsChanged(DBTAdapter const &a, const AdapterSetting oldmask, const AdapterSetting newmask, const AdapterSetting changedmask, const uint64_t timestamp) override { - fprintf(stderr, "****** SETTINGS_CHANGED: %s -> %s, changed %s\n", - getAdapterSettingsString(oldmask).c_str(), - getAdapterSettingsString(newmask).c_str(), - getAdapterSettingsString(changedmask).c_str()); + const bool initialSetting = AdapterSetting::NONE == oldmask; + if( initialSetting ) { + fprintf(stderr, "****** SETTINGS_INITIAL: %s -> %s, changed %s\n", getAdapterSettingsString(oldmask).c_str(), + getAdapterSettingsString(newmask).c_str(), getAdapterSettingsString(changedmask).c_str()); + } else { + fprintf(stderr, "****** SETTINGS_CHANGED: %s -> %s, changed %s\n", getAdapterSettingsString(oldmask).c_str(), + getAdapterSettingsString(newmask).c_str(), getAdapterSettingsString(changedmask).c_str()); + } fprintf(stderr, "Status DBTAdapter:\n"); fprintf(stderr, "%s\n", a.toString().c_str()); (void)timestamp; diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java index 71528ad1..caa72def 100644 --- a/examples/java/DBTScanner10.java +++ b/examples/java/DBTScanner10.java @@ -106,7 +106,12 @@ public class DBTScanner10 { @Override public void adapterSettingsChanged(final BluetoothAdapter adapter, final AdapterSettings oldmask, final AdapterSettings newmask, final AdapterSettings changedmask, final long timestamp) { - println("****** SETTINGS: "+oldmask+" -> "+newmask+", changed "+changedmask); + final boolean initialSetting = oldmask.isEmpty(); + if( initialSetting ) { + println("****** SETTINGS: "+oldmask+" -> "+newmask+", initial "+changedmask); + } else { + println("****** SETTINGS: "+oldmask+" -> "+newmask+", changed "+changedmask); + } println("Status Adapter:"); println(adapter.toString()); if( changedmask.isSet(AdapterSettings.SettingType.POWERED) && diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java index 7e4d5e8b..549de9bf 100644 --- a/java/direct_bt/tinyb/DBTAdapter.java +++ b/java/direct_bt/tinyb/DBTAdapter.java @@ -65,15 +65,15 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter private final Object discoveredDevicesLock = new Object(); private final Object userCallbackLock = new Object(); + private final AtomicBoolean isPowered = new AtomicBoolean(false); // AdapterSettings + private BluetoothNotification<Boolean> userPairableNotificationCB = null; + private final AtomicBoolean isDiscoverable = new AtomicBoolean(false); // AdapterSettings private BluetoothNotification<Boolean> userDiscoverableNotificationCB = null; - private final AtomicBoolean isDiscoverable = new AtomicBoolean(false); - private BluetoothNotification<Boolean> userDiscoveringNotificationCB = null; - private final AtomicBoolean isDiscovering = new AtomicBoolean(false); - + private final AtomicBoolean isPairable = new AtomicBoolean(false); // AdapterSettings private BluetoothNotification<Boolean> userPoweredNotificationCB = null; - private final AtomicBoolean isPowered = new AtomicBoolean(false); - private BluetoothNotification<Boolean> userPairableNotificationCB = null; - private final AtomicBoolean isPairable = new AtomicBoolean(false); + + private final AtomicBoolean isDiscovering = new AtomicBoolean(false); // AdapterStatusListener and powerdOff + private BluetoothNotification<Boolean> userDiscoveringNotificationCB = null; private final List<BluetoothDevice> discoveredDevices = new ArrayList<BluetoothDevice>(); @@ -415,44 +415,49 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter @Override public void adapterSettingsChanged(final BluetoothAdapter a, final AdapterSettings oldmask, final AdapterSettings newmask, final AdapterSettings changedmask, final long timestamp) { + final boolean initialSetting = oldmask.isEmpty(); if( DEBUG ) { - System.err.println("Adapter.StatusListener.SETTINGS_CHANGED: "+oldmask+" -> "+newmask+", changed "+changedmask+" on "+a); + if( initialSetting ) { + System.err.println("Adapter.StatusListener.SETTINGS: "+oldmask+" -> "+newmask+", initial "+changedmask+" on "+a); + } else { + System.err.println("Adapter.StatusListener.SETTINGS: "+oldmask+" -> "+newmask+", changed "+changedmask+" on "+a); + } } - { - if( changedmask.isSet(AdapterSettings.SettingType.POWERED) ) { - final boolean _isPowered = newmask.isSet(AdapterSettings.SettingType.POWERED); - if( isPowered.compareAndSet(!_isPowered, _isPowered) ) { - if( !_isPowered ) { - poweredOff(); - } - synchronized(userCallbackLock) { - if( null != userPoweredNotificationCB ) { - userPoweredNotificationCB.run(_isPowered); - } + if( initialSetting ) { + isPowered.set( newmask.isSet(AdapterSettings.SettingType.POWERED) ); + isDiscoverable.set( newmask.isSet(AdapterSettings.SettingType.DISCOVERABLE) ); + isPairable.set( newmask.isSet(AdapterSettings.SettingType.BONDABLE) ); + return; + } + if( changedmask.isSet(AdapterSettings.SettingType.POWERED) ) { + final boolean _isPowered = newmask.isSet(AdapterSettings.SettingType.POWERED); + if( isPowered.compareAndSet(!_isPowered, _isPowered) ) { + if( !_isPowered ) { + poweredOff(); + } + synchronized(userCallbackLock) { + if( null != userPoweredNotificationCB ) { + userPoweredNotificationCB.run(_isPowered); } } } } - { - if( changedmask.isSet(AdapterSettings.SettingType.DISCOVERABLE) ) { - final boolean _isDiscoverable = newmask.isSet(AdapterSettings.SettingType.DISCOVERABLE); - if( isDiscoverable.compareAndSet(!_isDiscoverable, _isDiscoverable) ) { - synchronized(userCallbackLock) { - if( null != userDiscoverableNotificationCB ) { - userDiscoverableNotificationCB.run( _isDiscoverable ); - } + if( changedmask.isSet(AdapterSettings.SettingType.DISCOVERABLE) ) { + final boolean _isDiscoverable = newmask.isSet(AdapterSettings.SettingType.DISCOVERABLE); + if( isDiscoverable.compareAndSet(!_isDiscoverable, _isDiscoverable) ) { + synchronized(userCallbackLock) { + if( null != userDiscoverableNotificationCB ) { + userDiscoverableNotificationCB.run( _isDiscoverable ); } } } } - { - if( changedmask.isSet(AdapterSettings.SettingType.BONDABLE) ) { - final boolean _isPairable = newmask.isSet(AdapterSettings.SettingType.BONDABLE); - if( isPairable.compareAndSet(!_isPairable, _isPairable) ) { - synchronized(userCallbackLock) { - if( null != userPairableNotificationCB ) { - userPairableNotificationCB.run( _isPairable ); - } + if( changedmask.isSet(AdapterSettings.SettingType.BONDABLE) ) { + final boolean _isPairable = newmask.isSet(AdapterSettings.SettingType.BONDABLE); + if( isPairable.compareAndSet(!_isPairable, _isPairable) ) { + synchronized(userCallbackLock) { + if( null != userPairableNotificationCB ) { + userPairableNotificationCB.run( _isPairable ); } } } |