summaryrefslogtreecommitdiffstats
path: root/java
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
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')
-rw-r--r--java/direct_bt/tinyb/DBTAdapter.java9
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx20
2 files changed, 5 insertions, 24 deletions
diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java
index 6c9e9f03..9b60d27b 100644
--- a/java/direct_bt/tinyb/DBTAdapter.java
+++ b/java/direct_bt/tinyb/DBTAdapter.java
@@ -233,13 +233,6 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
/* internal */
- private synchronized void open() {
- if( !isOpen ) {
- isOpen = openImpl();
- }
- }
- private native boolean openImpl();
-
@Override
protected native void deleteImpl();
@@ -247,7 +240,6 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
@Override
public synchronized boolean startDiscovery() throws BluetoothException {
- open();
removeDevices();
final boolean res = startDiscoveryImpl();
isDiscovering = res;
@@ -278,7 +270,6 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
@Override
public int removeDevices() throws BluetoothException {
- open();
final int cj = removeDiscoveredDevices();
final int cn = removeDevicesImpl();
if( cj != cn ) {
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);