diff options
Diffstat (limited to 'java/jni/direct_bt/DBTGattService.cxx')
-rw-r--r-- | java/jni/direct_bt/DBTGattService.cxx | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/java/jni/direct_bt/DBTGattService.cxx b/java/jni/direct_bt/DBTGattService.cxx index 3361a44c..6b3668e1 100644 --- a/java/jni/direct_bt/DBTGattService.cxx +++ b/java/jni/direct_bt/DBTGattService.cxx @@ -25,7 +25,7 @@ #include "direct_bt_tinyb_DBTGattService.h" -#define VERBOSE_ON 1 +// #define VERBOSE_ON 1 #include <dbt_debug.hpp> #include "JNIMem.hpp" @@ -37,10 +37,21 @@ using namespace direct_bt; +jstring Java_direct_1bt_tinyb_DBTGattService_toStringImpl(JNIEnv *env, jobject obj) { + try { + GATTService *nativePtr = getInstance<GATTService>(env, obj); + JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE); + return from_string_to_jstring(env, nativePtr->toString()); + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return nullptr; +} + + void Java_direct_1bt_tinyb_DBTGattService_deleteImpl(JNIEnv *env, jobject obj) { try { GATTService *service = getInstance<GATTService>(env, obj); - JavaGlobalObj::check(service->getJavaObject(), E_FILE_LINE); (void)service; // No delete: Service instance owned by DBTDevice } catch(...) { @@ -48,16 +59,19 @@ void Java_direct_1bt_tinyb_DBTGattService_deleteImpl(JNIEnv *env, jobject obj) { } } -static const std::string _characteristicClazzCtorArgs("(JLorg/tinyb/BluetoothGattService;[Ljava/lang/String;Ljava/lang/String;)V"); +static const std::string _characteristicClazzCtorArgs("(JLdirect_bt/tinyb/DBTGattService;S[Ljava/lang/String;Ljava/lang/String;SI)V"); -jobject Java_direct_1bt_tinyb_DBTGattService_getCharacteristics(JNIEnv *env, jobject obj) { +jobject Java_direct_1bt_tinyb_DBTGattService_getCharacteristicsImpl(JNIEnv *env, jobject obj) { try { GATTService *service = getInstance<GATTService>(env, obj); JavaGlobalObj::check(service->getJavaObject(), E_FILE_LINE); std::vector<std::shared_ptr<GATTCharacteristic>> & characteristics = service->characteristicList; - // DBTGattCharacteristic(final long nativeInstance, final BluetoothGattService service, final String[] properties, final String uuid) + // DBTGattCharacteristic(final long nativeInstance, final DBTGattService service, + // final short handle, final String[] properties, + // final String value_type_uuid, final short value_handle, + // final int clientCharacteristicsConfigIndex) std::function<jobject(JNIEnv*, jclass, jmethodID, GATTCharacteristic *)> ctor_char = [](JNIEnv *env, jclass clazz, jmethodID clazz_ctor, GATTCharacteristic *characteristic)->jobject { @@ -70,19 +84,21 @@ jobject Java_direct_1bt_tinyb_DBTGattService_getCharacteristics(JNIEnv *env, job jclass string_class = search_class(env, "Ljava/lang/String;"); jobjectArray jproperties = env->NewObjectArray(props_size, string_class, 0); - if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; } + java_exception_check_and_throw(env, E_FILE_LINE); for (unsigned int i = 0; i < props_size; ++i) { jobject elem = from_string_to_jstring(env, *props[i].get()); env->SetObjectArrayElement(jproperties, i, elem); } - if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; } + java_exception_check_and_throw(env, E_FILE_LINE); const jstring uuid = from_string_to_jstring(env, characteristic->value_type->toString()); - if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; } + java_exception_check_and_throw(env, E_FILE_LINE); - jobject jchar = env->NewObject(clazz, clazz_ctor, (jlong)characteristic, jservice, jproperties, uuid); - if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; } + jobject jchar = env->NewObject(clazz, clazz_ctor, (jlong)characteristic, jservice, + characteristic->handle, jproperties, + uuid, characteristic->value_handle, characteristic->clientCharacteristicsConfigIndex); + java_exception_check_and_throw(env, E_FILE_LINE); JNIGlobalRef::check(jchar, E_FILE_LINE); std::shared_ptr<JavaAnonObj> jCharRef = characteristic->getJavaObject(); JavaGlobalObj::check(jCharRef, E_FILE_LINE); |