diff options
author | Sven Gothel <[email protected]> | 2022-01-18 01:30:19 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-01-18 01:30:19 +0100 |
commit | e68702ae586d3eedc337103a31c9c8ccba8bc6da (patch) | |
tree | 7748b42de4fbdf037d8afe1e931c53d4b864639c /java/jni | |
parent | a972ac863f1cb1b7b07ba682715336166bb92284 (diff) |
Add EInfoReport::set(const EInfoReport&) to merger multiple scanned EIR; toString() only shows the set EIRDataType
Diffstat (limited to 'java/jni')
-rw-r--r-- | java/jni/direct_bt/EInfoReport.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/java/jni/direct_bt/EInfoReport.cxx b/java/jni/direct_bt/EInfoReport.cxx index 08608453..37201b27 100644 --- a/java/jni/direct_bt/EInfoReport.cxx +++ b/java/jni/direct_bt/EInfoReport.cxx @@ -73,6 +73,17 @@ void Java_org_direct_1bt_EInfoReport_dtorImpl(JNIEnv *env, jclass clazz, jlong n } } +jint Java_org_direct_1bt_EInfoReport_setImpl(JNIEnv *env, jobject obj, jobject jeir_other) { + try { + EInfoReport * eir_ptr = jau::getInstance<EInfoReport>(env, obj); + EInfoReport * eir_other_ptr = jau::getInstance<EInfoReport>(env, jeir_other); + return static_cast<jint>( number( eir_ptr->set(*eir_other_ptr) ) ); + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return 0; +} + /* * Class: org_direct_bt_EInfoReport * Method: setAddressTypeImpl @@ -427,6 +438,42 @@ jbyte Java_org_direct_1bt_EInfoReport_getTxPower(JNIEnv *env, jobject obj) { return 0; } +jobject Java_org_direct_1bt_EInfoReport_getManufacturerData(JNIEnv *env, jobject obj) +{ + try { + EInfoReport * eir_ptr = jau::getInstance<EInfoReport>(env, obj); + std::shared_ptr<ManufactureSpecificData> mdata = eir_ptr->getManufactureSpecificData(); + + jclass map_cls = jau::search_class(env, "java/util/HashMap"); + jmethodID map_ctor = jau::search_method(env, map_cls, "<init>", "(I)V", false); + jmethodID map_put = jau::search_method(env, map_cls, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false); + + jclass short_cls = jau::search_class(env, "java/lang/Short"); + jmethodID short_ctor = jau::search_method(env, short_cls, "<init>", "(S)V", false); + jobject result = nullptr; + + if( nullptr != mdata ) { + result = env->NewObject(map_cls, map_ctor, 1); + jbyteArray arr = env->NewByteArray(mdata->getData().size()); + env->SetByteArrayRegion(arr, 0, mdata->getData().size(), (const jbyte *)mdata->getData().get_ptr()); + jobject key = env->NewObject(short_cls, short_ctor, mdata->getCompany()); + env->CallObjectMethod(result, map_put, key, arr); + + env->DeleteLocalRef(arr); + env->DeleteLocalRef(key); + } else { + result = env->NewObject(map_cls, map_ctor, 0); + } + if (nullptr == result) { + throw jau::OutOfMemoryError("new HashMap() returned null", E_FILE_LINE); + } + return result; + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return nullptr; +} + /* * Class: org_direct_bt_EInfoReport * Method: getServices |