summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-05-10 03:57:49 +0200
committerSven Gothel <[email protected]>2022-05-10 03:57:49 +0200
commit4faded58c1f5662b8baea6b1259cd297986a278c (patch)
treeab2df60f577efefa43f5472de4c3e79e01f893bf /examples
parent4d5b98cade63a3cb0208bade2b5ff0d531594d74 (diff)
JNI Lifecycle Fix: BTGattCharListener: Adopt full Java/Native link via DBTNativeDownlink and JavaUplink like AdapterStatusListener change, clean listener API + impl.
AdapterStatusListener adopted fully linked via DBTNativeDownlink (java->native) and JavaUplink (native->java). This allows intrinsic lifecycle management. Native destruction leads to its reference removal from the java object and destruction of the java object removes its reference from the native object. Both reference removals may lead to their destruction if reaching zero. (was commit 9c5f25ccd1637728d6e79592279e4b38ecd32f59) Same applies to BTGattCharListener: - This removed BTGattChar::Listener, simply use BTGattCharListener - Using private BTGattHandler::GattCharListenerPair struct for BTGattChar mapping - No more manual or exposed BTGattChar mapping - Java: An added BTGattCharListener instance can be used for removal now, no more wrapper object magic returned. Further: - moved removed `namespace impl`, moved StatusListenerPair into private BTAdapter - have all add/remove*Listener methods noexcept Unit tests validating BTGattCharListener add and remove.
Diffstat (limited to 'examples')
-rw-r--r--examples/dbt_scanner10.cpp5
-rw-r--r--examples/java/DBTScanner10.java5
2 files changed, 5 insertions, 5 deletions
diff --git a/examples/dbt_scanner10.cpp b/examples/dbt_scanner10.cpp
index b6db78b3..c3e28dad 100644
--- a/examples/dbt_scanner10.cpp
+++ b/examples/dbt_scanner10.cpp
@@ -324,7 +324,7 @@ class MyAdapterStatusListener : public AdapterStatusListener {
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT);
-class MyGATTEventListener : public BTGattChar::Listener {
+class MyGATTEventListener : public BTGattCharListener {
private:
int i, j;
@@ -559,8 +559,7 @@ static void processReadyDevice(BTDeviceRef device) {
bool cccdEnableResult[2];
if( serviceChar->enableNotificationOrIndication( cccdEnableResult ) ) {
// ClientCharConfigDescriptor (CCD) is available
- std::shared_ptr<BTGattChar::Listener> cl = std::make_shared<MyGATTEventListener>(i, j);
- bool clAdded = serviceChar->addCharListener( cl );
+ bool clAdded = serviceChar->addCharListener( std::make_shared<MyGATTEventListener>(i, j) );
{
fprintf_td(stderr, " [%2.2d.%2.2d] Characteristic-Listener: Notification(%d), Indication(%d): Added %d\n",
(int)i, (int)j, cccdEnableResult[0], cccdEnableResult[1], clAdded);
diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java
index 2845f9e0..98be7aea 100644
--- a/examples/java/DBTScanner10.java
+++ b/examples/java/DBTScanner10.java
@@ -39,6 +39,7 @@ import org.direct_bt.BTDeviceRegistry;
import org.direct_bt.BTException;
import org.direct_bt.BTFactory;
import org.direct_bt.BTGattChar;
+import org.direct_bt.BTGattCharListener;
import org.direct_bt.BTGattCmd;
import org.direct_bt.BTGattDesc;
import org.direct_bt.BTGattService;
@@ -277,7 +278,7 @@ public class DBTScanner10 {
}
};
- class MyGATTEventListener implements BTGattChar.Listener {
+ class MyGATTEventListener extends BTGattCharListener {
private final int i, j;
public MyGATTEventListener(final int i_, final int j_) { i=i_; j=j_; }
@@ -518,7 +519,7 @@ public class DBTScanner10 {
final boolean cccdEnableResult[] = { false, false };
if( serviceChar.enableNotificationOrIndication( cccdEnableResult ) ) {
// ClientCharConfigDescriptor (CCD) is available
- final boolean clAdded = null != serviceChar.addCharListener( new MyGATTEventListener(i, j) );
+ final boolean clAdded = serviceChar.addCharListener( new MyGATTEventListener(i, j) );
{
BTUtils.fprintf_td(System.err, " [%02d.%02d] Characteristic-Listener: Notification(%b), Indication(%b): Added %b\n",
i, j, cccdEnableResult[0], cccdEnableResult[1], clAdded);