aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni/direct_bt/DBTGattService.cxx
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-14 14:15:01 +0200
committerSven Gothel <[email protected]>2020-05-14 14:15:01 +0200
commit768169322ff9652cbb9b080a8049fe2db10a8adc (patch)
treed1e8e6cfcb44e35773d4646d9b84f4cf1414dc03 /java/jni/direct_bt/DBTGattService.cxx
parentbececd5a61af0ac86e764a4bba7d3a0234a1d350 (diff)
GATT Service and Characteristic Java <-> JNI binding (incomplete, TODO Descriptor)
Diffstat (limited to 'java/jni/direct_bt/DBTGattService.cxx')
-rw-r--r--java/jni/direct_bt/DBTGattService.cxx66
1 files changed, 65 insertions, 1 deletions
diff --git a/java/jni/direct_bt/DBTGattService.cxx b/java/jni/direct_bt/DBTGattService.cxx
index 84ce946d..0e893031 100644
--- a/java/jni/direct_bt/DBTGattService.cxx
+++ b/java/jni/direct_bt/DBTGattService.cxx
@@ -25,10 +25,74 @@
#include "direct_bt_tinyb_DBTGattService.h"
+#define VERBOSE_ON 1
+#include <dbt_debug.hpp>
+
#include "JNIMem.hpp"
#include "helper_base.hpp"
+#include "helper_dbt.hpp"
-#include "direct_bt/DBTTypes.hpp"
+#include "direct_bt/DBTDevice.hpp"
+#include "direct_bt/DBTAdapter.hpp"
using namespace direct_bt;
+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(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}
+
+static const std::string _characteristicClazzCtorArgs("(JLorg/tinyb/BluetoothGattService;[Ljava/lang/String;Ljava/lang/String;)V");
+
+jobject Java_direct_1bt_tinyb_DBTGattService_getCharacteristics(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->characteristicDeclList;
+
+ // DBTGattCharacteristic(final long nativeInstance, final BluetoothGattService service, final String[] properties, final String uuid)
+
+ std::function<jobject(JNIEnv*, jclass, jmethodID, GATTCharacteristic *)> ctor_char =
+ [](JNIEnv *env, jclass clazz, jmethodID clazz_ctor, GATTCharacteristic *characteristic)->jobject {
+ // prepare adapter ctor
+ JavaGlobalObj::check(characteristic->service->getJavaObject(), E_FILE_LINE);
+ jobject jservice = JavaGlobalObj::GetObject(characteristic->service->getJavaObject());
+
+ std::vector<std::unique_ptr<std::string>> props = GATTCharacteristic::getPropertiesStringList(characteristic->properties);
+ unsigned int props_size = props.size();
+
+ 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; }
+
+ 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; }
+
+ const jstring uuid = from_string_to_jstring(env, characteristic->uuid->toString());
+ if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; }
+
+ jobject jchar = env->NewObject(clazz, clazz_ctor, (jlong)characteristic, jservice, jproperties, uuid);
+ if( java_exception_check(env, E_FILE_LINE) ) { return nullptr; }
+ JNIGlobalRef::check(jchar, E_FILE_LINE);
+ std::shared_ptr<JavaAnonObj> jCharRef = characteristic->getJavaObject();
+ JavaGlobalObj::check(jCharRef, E_FILE_LINE);
+
+ return JavaGlobalObj::GetObject(jCharRef);
+ };
+ return convert_vector_sharedptr_to_jarraylist<GATTCharacteristic>(env, characteristics, _characteristicClazzCtorArgs.c_str(), ctor_char);
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return nullptr;
+}
+