diff options
author | Sven Gothel <[email protected]> | 2021-09-15 10:50:04 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-09-15 10:50:04 +0200 |
commit | 9ce665e96f5b87d83e909330f262378810a8cbb3 (patch) | |
tree | 74484ccdde505c758bd5d0f99da78e49ebe20178 /java/jni | |
parent | 9b69298eb95b7a0dd7a0d28103fd9b4d03c0a06a (diff) |
Multi Direct-BT application, each using 1 adapter: Have user explicitly initialize adapter with given BTMode, leave others untouched.
Only mutating the desired adapter within one application allows
running multiple Direct-BT applications on one platform,
each using one selected adapter.
BTMode:
- Use byte value, matching native counterpart
BTManager:
- Remove (default) BTMode
BTAdapter:
- Add initialze(const BTMode btMode=BTMode::DUAL),
must be called by user for desired adapter when found
via ChangedAdapterSetFunc/BTManager.ChangedAdapterSetListener.
AdapterInfo:
- Expose mutable ops to public, remove friend decl.
Diffstat (limited to 'java/jni')
-rw-r--r-- | java/jni/direct_bt/DBTAdapter.cxx | 13 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTDevice.cxx | 6 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTManager.cxx | 5 |
3 files changed, 18 insertions, 6 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index 5fceee87..028011fe 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -855,6 +855,19 @@ jboolean Java_jau_direct_1bt_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jbo return JNI_FALSE; } +jbyte Java_jau_direct_1bt_DBTAdapter_initializeImpl(JNIEnv *env, jobject obj, jbyte jbtMode) { + try { + BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); + jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE); + const BTMode btMode = static_cast<BTMode>(jbtMode); + HCIStatusCode res = adapter->initialize(btMode); + return (jbyte) number(res); + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE); +} + jbyte Java_jau_direct_1bt_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) { try { BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj); diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx index 13d965f4..a76c0e4d 100644 --- a/java/jni/direct_bt/DBTDevice.cxx +++ b/java/jni/direct_bt/DBTDevice.cxx @@ -718,9 +718,9 @@ jobject Java_jau_direct_1bt_DBTDevice_getManufacturerData(JNIEnv *env, jobject o if( nullptr != mdata ) { result = env->NewObject(map_cls, map_ctor, 1); - jbyteArray arr = env->NewByteArray(mdata->data.getSize()); - env->SetByteArrayRegion(arr, 0, mdata->data.getSize(), (const jbyte *)mdata->data.get_ptr()); - jobject key = env->NewObject(short_cls, short_ctor, mdata->company); + jbyteArray arr = env->NewByteArray(mdata->getData().getSize()); + env->SetByteArrayRegion(arr, 0, mdata->getData().getSize(), (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); diff --git a/java/jni/direct_bt/DBTManager.cxx b/java/jni/direct_bt/DBTManager.cxx index b35fe37a..985cb5b8 100644 --- a/java/jni/direct_bt/DBTManager.cxx +++ b/java/jni/direct_bt/DBTManager.cxx @@ -109,12 +109,11 @@ static void _addMgmtCBOnce(JNIEnv *env, BTManager & mgmt, JNIGlobalRef jmgmtRef, } } -void Java_jau_direct_1bt_DBTManager_initImpl(JNIEnv *env, jobject obj, jboolean unifyUUID128Bit, jint jbtMode) +void Java_jau_direct_1bt_DBTManager_initImpl(JNIEnv *env, jobject obj, jboolean unifyUUID128Bit) { directBTJNISettings.setUnifyUUID128Bit(unifyUUID128Bit); try { - BTMode btMode = static_cast<BTMode>(jbtMode); - BTManager *manager = &BTManager::get(btMode); // special: static singleton + BTManager *manager = &BTManager::get(); // special: static singleton setInstance<BTManager>(env, obj, manager); java_exception_check_and_throw(env, E_FILE_LINE); manager->setJavaObject( std::shared_ptr<JavaAnon>( new JavaGlobalObj(obj, nullptr) ) ); |