summaryrefslogtreecommitdiffstats
path: root/java/jni/direct_bt/DBTManager.cxx
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-04-21 13:05:53 +0200
committerSven Gothel <[email protected]>2020-04-21 13:05:53 +0200
commit2bacdad45d6c7a315937c4c3723fba54fb83b631 (patch)
tree912cc4c8440a00aee8ab5cbe8a8c1d5c6e07a2cb /java/jni/direct_bt/DBTManager.cxx
parentd123b2363692d4e95340aa63bf5246cd293b4f30 (diff)
Refine: DBT API, HCISession/DBTAdapter lifecycle, API doc and C++ and C++/JNI exception handling
- HCISession: Handle multiple connections - DBTDevice holds le_conn_handle and provides the le_disconnect as well - HCISession maintains a vector of connected devices - HCISession/DBTAdapter: Cleanup shutdown and refine lifecycle - DBTDevice/DBTAdapter: Drop explicit HCISession argument, simply use the attached HCISession of DBTAdapter. - Refine API doc in general +++ - Device Java/JNI: Add a few more methods to test connect/disconnect. +++ Refine C++ and C++/JNI exception handling: - Use new java_exception_check_and_throw(..): Throw C++ exception on pending Java exception, retrieving toString() message. - Use new java_exception_check(..): Return immediately from JNI on pending Java exception. - Replace macro CATCH_EXCEPTION_AND_RAISE_JAVA(..) with new rethrow_and_raise_java_exception(..), re-trhowing exception and raising detailed Java exception.
Diffstat (limited to 'java/jni/direct_bt/DBTManager.cxx')
-rw-r--r--java/jni/direct_bt/DBTManager.cxx21
1 files changed, 15 insertions, 6 deletions
diff --git a/java/jni/direct_bt/DBTManager.cxx b/java/jni/direct_bt/DBTManager.cxx
index 063a716d..8c7182c5 100644
--- a/java/jni/direct_bt/DBTManager.cxx
+++ b/java/jni/direct_bt/DBTManager.cxx
@@ -41,10 +41,13 @@ void Java_direct_1bt_tinyb_DBTManager_initImpl(JNIEnv *env, jobject obj)
try {
DBTManager *manager = &DBTManager::get(); // special: static singleton
setInstance<DBTManager>(env, obj, manager);
+ if( java_exception_check(env, E_FILE_LINE) ) { return; }
manager->setJavaObject( std::shared_ptr<JavaAnonObj>( new JavaGlobalObj(obj) ) );
JavaGlobalObj::check(manager->getJavaObject(), E_FILE_LINE);
DBG_PRINT("Java_direct_1bt_tinyb_DBTManager_init: Manager %s", manager->toString().c_str());
- } CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
}
void Java_direct_1bt_tinyb_DBTManager_deleteImpl(JNIEnv *env, jobject obj)
@@ -54,7 +57,9 @@ void Java_direct_1bt_tinyb_DBTManager_deleteImpl(JNIEnv *env, jobject obj)
manager->setJavaObject(nullptr);
// delete manager;
(void) manager;
- } CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
}
static const std::string _adapterClazzCtorArgs("(JLjava/lang/String;Ljava/lang/String;)V");
@@ -83,24 +88,28 @@ jobject Java_direct_1bt_tinyb_DBTManager_getDefaultAdapterImpl(JNIEnv *env, jobj
// prepare adapter ctor
const jstring addr = from_string_to_jstring(env, adapter->getAddressString());
const jstring name = from_string_to_jstring(env, adapter->getName());
+ if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; }
const jclass clazz = search_class(env, *adapter);
+ if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; }
if( nullptr == clazz ) {
throw InternalError("Adapter class not found: "+DBTAdapter::java_class(), E_FILE_LINE);
}
const jmethodID clazz_ctor = search_method(env, clazz, "<init>", _adapterClazzCtorArgs.c_str(), false);
+ if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; }
if( nullptr == clazz_ctor ) {
throw InternalError("Adapter ctor not found: "+DBTAdapter::java_class()+".<init>"+_adapterClazzCtorArgs, E_FILE_LINE);
}
- exception_check_raise_and_throw(env, E_FILE_LINE);
jobject jAdapter = env->NewObject(clazz, clazz_ctor, (jlong)adapter, addr, name);
- exception_check_raise_and_throw(env, E_FILE_LINE);
+ if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; }
JNIGlobalRef::check(jAdapter, E_FILE_LINE);
std::shared_ptr<JavaAnonObj> jAdapterRef = adapter->getJavaObject();
JavaGlobalObj::check(jAdapterRef, E_FILE_LINE);
DBG_PRINT("Java_direct_1bt_tinyb_DBTManager_getDefaultAdapterImpl: New Adapter %s", adapter->toString().c_str());
return JavaGlobalObj::GetObject(jAdapterRef);
- } CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
- return NULL;
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return nullptr;
}