diff options
Diffstat (limited to 'trial')
-rw-r--r-- | trial/direct_bt/dbt_client00.hpp | 23 | ||||
-rw-r--r-- | trial/direct_bt/dbt_client01.hpp | 31 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTClient00.java | 23 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTClient01.java | 24 |
4 files changed, 82 insertions, 19 deletions
diff --git a/trial/direct_bt/dbt_client00.hpp b/trial/direct_bt/dbt_client00.hpp index 345f9355..903ed477 100644 --- a/trial/direct_bt/dbt_client00.hpp +++ b/trial/direct_bt/dbt_client00.hpp @@ -442,6 +442,7 @@ class DBTClient00 : public DBTClientTest { // cmd.close(); // done via dtor } + bool gattListenerError = false; std::vector<BTGattCharListenerRef> gattListener; int loop = 0; do { @@ -487,9 +488,12 @@ class DBTClient00 : public DBTClientTest { // ClientCharConfigDescriptor (CCD) is available std::shared_ptr<BTGattCharListener> gattEventListener = std::make_shared<MyGATTEventListener>(*this); bool clAdded = serviceChar->addCharListener( gattEventListener ); - REQUIRE( true == clAdded ); if( clAdded ) { gattListener.push_back(gattEventListener); + } else { + gattListenerError = true; + fprintf_td(stderr, "Client Error: Failed to add GattListener: %s @ %s, gattListener %zu\n", + gattEventListener->toString().c_str(), serviceChar->toString().c_str(), gattListener.size()); } if( GATT_VERBOSE ) { fprintf_td(stderr, " [%2.2d.%2.2d] Characteristic-Listener: Notification(%d), Indication(%d): Added %d\n", @@ -505,10 +509,21 @@ class DBTClient00 : public DBTClientTest { } success = notificationsReceived >= 2 || indicationsReceived >= 2; ++loop; - } while( !success && device->getConnected() ); + } while( !success && device->getConnected() && !gattListenerError ); - for(BTGattCharListenerRef gcl : gattListener) { - REQUIRE( true == device->removeCharListener(gcl) ); + if( gattListenerError ) { + success = false; + } + { + int i = 0; + for(BTGattCharListenerRef gcl : gattListener) { + if( !device->removeCharListener(gcl) ) { + fprintf_td(stderr, "Client: Failed to remove GattListener[%d/%zu]: %s @ %s\n", + i, gattListener.size(), gcl->toString().c_str(), device->toString().c_str()); + success = false; + } + ++i; + } } if( device->getConnected() ) { diff --git a/trial/direct_bt/dbt_client01.hpp b/trial/direct_bt/dbt_client01.hpp index 1490ab4e..faf128e1 100644 --- a/trial/direct_bt/dbt_client01.hpp +++ b/trial/direct_bt/dbt_client01.hpp @@ -205,8 +205,12 @@ class DBTClient01 : public DBTClientTest { static std::uniform_int_distribution<int> rng_dist(sleep_min, sleep_max); const int64_t sleep_dur = rng_dist(rng_hw); jau::sleep_for( sleep_dur * 1_ms ); - fprintf_td(stderr, "****** Client i470 disconnectDevice(delayed %d ms): client %s\n", sleep_dur, device->toString().c_str()); - device->disconnect(); + if( nullptr != device ) { + fprintf_td(stderr, "****** Client i470 disconnectDevice(delayed %d ms): client %s\n", sleep_dur, device->toString().c_str()); + device->disconnect(); + } else { + fprintf_td(stderr, "****** Client i470 disconnectDevice(delayed %d ms): client null\n", sleep_dur); + } } void deviceReady(BTDeviceRef device, const uint64_t timestamp) override { @@ -437,6 +441,7 @@ class DBTClient01 : public DBTClientTest { td13, td12, td23, td35); } + bool gattListenerError = false; std::vector<BTGattCharListenerRef> gattListener; int loop = 0; do { @@ -482,9 +487,12 @@ class DBTClient01 : public DBTClientTest { // ClientCharConfigDescriptor (CCD) is available std::shared_ptr<BTGattCharListener> gattEventListener = std::make_shared<MyGATTEventListener>(*this); bool clAdded = serviceChar->addCharListener( gattEventListener ); - REQUIRE( true == clAdded ); if( clAdded ) { gattListener.push_back(gattEventListener); + } else { + gattListenerError = true; + fprintf_td(stderr, "Client Error: Failed to add GattListener: %s @ %s, gattListener %zu\n", + gattEventListener->toString().c_str(), serviceChar->toString().c_str(), gattListener.size()); } if( GATT_VERBOSE ) { fprintf_td(stderr, " [%2.2d.%2.2d] Characteristic-Listener: Notification(%d), Indication(%d): Added %d\n", @@ -500,10 +508,21 @@ class DBTClient01 : public DBTClientTest { } success = notificationsReceived >= 2 || indicationsReceived >= 2; ++loop; - } while( !success && device->getConnected() ); + } while( !success && device->getConnected() && !gattListenerError ); - for(BTGattCharListenerRef gcl : gattListener) { - REQUIRE( true == device->removeCharListener(gcl) ); + if( gattListenerError ) { + success = false; + } + { + int i = 0; + for(BTGattCharListenerRef gcl : gattListener) { + if( !device->removeCharListener(gcl) ) { + fprintf_td(stderr, "Client Error: Failed to remove GattListener[%d/%zu]: %s @ %s\n", + i, gattListener.size(), gcl->toString().c_str(), device->toString().c_str()); + success = false; + } + ++i; + } } if( device->getConnected() ) { diff --git a/trial/java/trial/org/direct_bt/DBTClient00.java b/trial/java/trial/org/direct_bt/DBTClient00.java index db9ec99f..7366eb72 100644 --- a/trial/java/trial/org/direct_bt/DBTClient00.java +++ b/trial/java/trial/org/direct_bt/DBTClient00.java @@ -466,6 +466,7 @@ public class DBTClient00 implements DBTClientTest { cmd.close(); } + boolean gattListenerError = false; final List<BTGattCharListener> gattListener = new ArrayList<BTGattCharListener>(); int loop = 0; do { @@ -508,9 +509,12 @@ public class DBTClient00 implements DBTClientTest { // ClientCharConfigDescriptor (CCD) is available final MyGATTEventListener gattEventListener = new MyGATTEventListener(); final boolean clAdded = serviceChar.addCharListener( gattEventListener ); - Assert.assertTrue(clAdded); if( clAdded ) { gattListener.add(gattEventListener); + } else { + gattListenerError = true; + BTUtils.fprintf_td(System.err, "Client Error: Failed to add GattListener: %s @ %s, gattListener %d\n", + gattEventListener.toString(), serviceChar.toString(), gattListener.size()); } if( GATT_VERBOSE ) { BTUtils.fprintf_td(System.err, " [%02d.%02d] Characteristic-Listener: Notification(%b), Indication(%b): Added %b\n", @@ -530,10 +534,21 @@ public class DBTClient00 implements DBTClientTest { BTUtils.println(System.err, "****** Client Processing Ready Device: Exception.2 caught for " + device.toString() + ": "+ex.getMessage()); ex.printStackTrace(); } - } while( !success && device.getConnected() ); + } while( !success && device.getConnected() && !gattListenerError ); - for(final BTGattCharListener gcl : gattListener) { - Assert.assertTrue( device.removeCharListener(gcl) ); + if( gattListenerError ) { + success = false; + } + { + int i = 0; + for(final BTGattCharListener gcl : gattListener) { + if( !device.removeCharListener(gcl) ) { + BTUtils.fprintf_td(System.err, "Client Error: Failed to remove GattListener[%d/%d]: %s @ %s\n", + i, gattListener.size(), gcl.toString(), device.toString()); + success = false; + } + ++i; + } } if( device.getConnected() ) { diff --git a/trial/java/trial/org/direct_bt/DBTClient01.java b/trial/java/trial/org/direct_bt/DBTClient01.java index 6a9488a7..22d905e3 100644 --- a/trial/java/trial/org/direct_bt/DBTClient01.java +++ b/trial/java/trial/org/direct_bt/DBTClient01.java @@ -57,7 +57,6 @@ import org.direct_bt.SMPKeyBin; import org.direct_bt.SMPPairingState; import org.direct_bt.ScanType; import org.jau.net.EUI48; -import org.junit.Assert; /** * This central BTRole::Master participant works with DBTServer00. @@ -448,6 +447,7 @@ public class DBTClient01 implements DBTClientTest { "PERF: get-gatt-services " + td35 + " ms,"+System.lineSeparator()); } + boolean gattListenerError = false; final List<BTGattCharListener> gattListener = new ArrayList<BTGattCharListener>(); int loop = 0; do { @@ -490,9 +490,12 @@ public class DBTClient01 implements DBTClientTest { // ClientCharConfigDescriptor (CCD) is available final MyGATTEventListener gattEventListener = new MyGATTEventListener(); final boolean clAdded = serviceChar.addCharListener( gattEventListener ); - Assert.assertTrue(clAdded); if( clAdded ) { gattListener.add(gattEventListener); + } else { + gattListenerError = true; + BTUtils.fprintf_td(System.err, "Client Error: Failed to add GattListener: %s @ %s, gattListener %d\n", + gattEventListener.toString(), serviceChar.toString(), gattListener.size()); } if( GATT_VERBOSE ) { BTUtils.fprintf_td(System.err, " [%02d.%02d] Characteristic-Listener: Notification(%b), Indication(%b): Added %b\n", @@ -512,10 +515,21 @@ public class DBTClient01 implements DBTClientTest { BTUtils.println(System.err, "****** Client Processing Ready Device: Exception.2 caught for " + device.toString() + ": "+ex.getMessage()); ex.printStackTrace(); } - } while( !success && device.getConnected() ); + } while( !success && device.getConnected() && !gattListenerError ); - for(final BTGattCharListener gcl : gattListener) { - Assert.assertTrue( device.removeCharListener(gcl) ); + if( gattListenerError ) { + success = false; + } + { + int i = 0; + for(final BTGattCharListener gcl : gattListener) { + if( !device.removeCharListener(gcl) ) { + BTUtils.fprintf_td(System.err, "Client Error: Failed to remove GattListener[%d/%d]: %s @ %s\n", + i, gattListener.size(), gcl.toString(), device.toString()); + success = false; + } + ++i; + } } if( device.getConnected() ) { |