aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni/direct_bt/DBTAdapter.cxx
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-10 06:17:20 +0200
committerSven Gothel <[email protected]>2020-05-10 06:17:20 +0200
commitb784da70133b4b5859bb8b6f86ab48a48a6d87af (patch)
tree28f1baa5caf8e4ce1c3fb9b3592b33398e1e7c08 /java/jni/direct_bt/DBTAdapter.cxx
parent0f53fde528dea4470d152d30f33f357dde1b2e10 (diff)
Converging Java/JNI and C++ API to match tinyb interface requirements (step-2)
- BasicTypes: Align exception names w/ Java. - BTTypes / EInfoReport: Add getDeviceIDModalias() - DBTManager: Add getConnectionInfo(..) and setLocalName(..) - OctetTypes: Fix put_octets(..), removed sizeof(). Adding put/get string methods +++ DBTTypes: - Fix Comments - DBTDevice: Add appearance, getConnectionInfo(), connectGATT(..) and disconnectGATT(). Last two GATT's ease association of GATTHandler w/ device for tinyb binding. - DBTDevice: Fix defaultConnect(): Differenciate le public/random - DBTDevice: New getConnectionInfo() - also may issue deviceUpdate callback on rssi/tx_power changes - DBTAdapter: Add missing DBTAdapterStatusListener list declaration of previous commit. - DBTAdapter: Add misc information access for tinyb binding. +++ Java - DBTAdapter: Adding more tinyb implementation code, sorting methods - ~90% complete - DBTDevice: Adding more tinyb implementation code, sorting methods - ~70% complete
Diffstat (limited to 'java/jni/direct_bt/DBTAdapter.cxx')
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx84
1 files changed, 84 insertions, 0 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index 6a8c4aa6..825285bb 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -499,3 +499,87 @@ void Java_direct_1bt_tinyb_DBTAdapter_enableDiscoveringNotifications(JNIEnv *env
rethrow_and_raise_java_exception(env);
}
}
+
+//
+// misc
+//
+
+void Java_direct_1bt_tinyb_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jboolean value) {
+ try {
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ adapter->setPowered(JNI_TRUE == value ? true : false);
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}
+
+jstring Java_direct_1bt_tinyb_DBTAdapter_getAlias(JNIEnv *env, jobject obj) {
+ try {
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ return from_string_to_jstring(env, adapter->getLocalName().getName());
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return nullptr;
+}
+
+void Java_direct_1bt_tinyb_DBTAdapter_setAlias(JNIEnv *env, jobject obj, jstring jnewalias) {
+ try {
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ std::string newalias = from_jstring_to_string(env, jnewalias);
+ adapter->setLocalName(newalias, std::string());
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}
+
+void Java_direct_1bt_tinyb_DBTAdapter_setDiscoverable(JNIEnv *env, jobject obj, jboolean value) {
+ try {
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ adapter->setDiscoverable(JNI_TRUE == value ? true : false);
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}
+
+jobject Java_direct_1bt_tinyb_DBTAdapter_connectDevice(JNIEnv *env, jobject obj, jstring jaddress, jstring jaddressType) {
+ try {
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ std::string saddress = from_jstring_to_string(env, jaddress);
+ EUI48 address(saddress);
+ std::shared_ptr<DBTDevice> device = adapter->findDiscoveredDevice(address);
+ if( nullptr != device ) {
+ const BDAddressType addressType = fromJavaAdressTypeToBDAddressType(env, jaddressType);
+ const BDAddressType addressTypeDevice = device->getAddressType();
+ if( addressTypeDevice != addressType ) {
+ // oops?
+ WARN_PRINT("DBTAdapter::connectDevice: AddressType mismatch, ignoring request: Requested %s, Device %s %s",
+ getBDAddressTypeString(addressType).c_str(), getBDAddressTypeString(addressTypeDevice).c_str(),
+ device->toString().c_str());
+ }
+ std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
+ JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+
+ device->defaultConnect();
+ return JavaGlobalObj::GetObject(jDeviceRef);
+ }
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return nullptr;
+}
+
+void Java_direct_1bt_tinyb_DBTAdapter_setPairable(JNIEnv *env, jobject obj, jboolean value) {
+ try {
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ adapter->setBondable(JNI_TRUE == value ? true : false);
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}