aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-28 19:07:20 +0200
committerSven Gothel <[email protected]>2020-05-28 19:07:20 +0200
commitfafc8db2ed2f2975148665e7224412b72ac03df2 (patch)
treedd6ac35e6db3617fee632003cc2a005a6d99c516 /java
parent7af0d9dee655f67b8531f3e42cb318b54259e135 (diff)
AdapterStatusListener (C++): Add toString() for error handling purposes; DBTDevice::toString(..) defaults to not incl. services
Diffstat (limited to 'java')
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx16
1 files changed, 12 insertions, 4 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index bba2f94f..decfbd41 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -65,7 +65,9 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
public void deviceConnectionChanged(final BluetoothDevice device, final boolean connected, final long timestamp) { }
};
*/
- const DBTDevice * deviceMatchRef;
+ static std::atomic<int> iname_next;
+ int const iname;
+ DBTDevice const * const deviceMatchRef;
std::shared_ptr<JavaAnonObj> adapterObjRef;
std::unique_ptr<JNIGlobalRef> adapterSettingsClazzRef;
jmethodID adapterSettingsClazzCtor;
@@ -83,7 +85,14 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
public:
- JNIAdapterStatusListener(JNIEnv *env, DBTAdapter *adapter, jobject statusListener, const DBTDevice * deviceMatchRef) {
+ std::string toString() const override {
+ const std::string devMatchAddr = nullptr != deviceMatchRef ? deviceMatchRef->address.toString() : "nil";
+ return "JNIAdapterStatusListener[this "+aptrHexString(this)+", iname "+std::to_string(iname)+", devMatchAddr "+devMatchAddr+"]";
+ }
+
+ JNIAdapterStatusListener(JNIEnv *env, DBTAdapter *adapter, jobject statusListener, const DBTDevice * _deviceMatchRef)
+ : iname(iname_next.fetch_add(1)), deviceMatchRef(_deviceMatchRef)
+ {
adapterObjRef = adapter->getJavaObject();
JavaGlobalObj::check(adapterObjRef, E_FILE_LINE);
@@ -94,8 +103,6 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
throw InternalError("AdapterStatusListener not found", E_FILE_LINE);
}
- this->deviceMatchRef = deviceMatchRef;
-
// adapterSettingsClazzRef, adapterSettingsClazzCtor
{
jclass adapterSettingsClazz = search_class(env, _adapterSettingsClassName.c_str());
@@ -311,6 +318,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
}
}
};
+std::atomic<int> JNIAdapterStatusListener::iname_next(0);
jboolean Java_direct_1bt_tinyb_DBTAdapter_addStatusListener(JNIEnv *env, jobject obj, jobject statusListener, jobject jdeviceMatch)
{