summaryrefslogtreecommitdiffstats
path: root/java/jni
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-24 00:14:11 +0200
committerSven Gothel <[email protected]>2020-05-24 00:14:11 +0200
commitc14827e615c53f1c091cc0f04f4bf0550dcdb4d2 (patch)
tree0b84c1c4ed3120109ee09d31672a0af0dc8fcc5f /java/jni
parent6291468795a915d5fc7e2ec896711c849cded452 (diff)
C++ multithreading fixes and example
DBTAdapter: - Add HCI mutex - openHCI() returns already open HCIComm - Notify device on disconnected DBTDevice: - Add data mutex, covering race-condition on data update(..) and data usage - notifyDisconnected(): Clear hciConnHandle - getServices() -> getGATTServices() to differenciate from scan-result +++ Java/JNI DBTAdapter: - Remove open/openImpl() in favor of implicit openHCI() @ connect call. +++ Added multithreading example dbt_scanner10.cpp
Diffstat (limited to 'java/jni')
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx20
1 files changed, 5 insertions, 15 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index 360084b1..1e32ade8 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -392,21 +392,6 @@ jstring Java_direct_1bt_tinyb_DBTAdapter_toStringImpl(JNIEnv *env, jobject obj)
return nullptr;
}
-jboolean Java_direct_1bt_tinyb_DBTAdapter_openImpl(JNIEnv *env, jobject obj) {
- try {
- DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
- DBG_PRINT("Java_direct_1bt_tinyb_DBTAdapter_deleteImpl %s", adapter->toString().c_str());
- std::shared_ptr<direct_bt::HCIComm> hciSession = adapter->openHCI();
- if( nullptr == hciSession ) {
- throw BluetoothException("Couldn't open adapter "+adapter->toString(), E_FILE_LINE);
- }
- return JNI_TRUE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
void Java_direct_1bt_tinyb_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj)
{
try {
@@ -594,6 +579,11 @@ jobject Java_direct_1bt_tinyb_DBTAdapter_connectDevice(JNIEnv *env, jobject obj,
getBDAddressTypeString(addressType).c_str(), getBDAddressTypeString(addressTypeDevice).c_str(),
device->toString().c_str());
}
+
+ std::shared_ptr<direct_bt::HCIComm> hci = adapter->openHCI();
+ if( nullptr == hci ) {
+ throw BluetoothException("Couldn't get or open adapter's HCIComm "+adapter->toString(), E_FILE_LINE);
+ }
std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);