aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni
diff options
context:
space:
mode:
Diffstat (limited to 'java/jni')
-rw-r--r--java/jni/direct_bt/CMakeLists.txt1
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx15
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx173
-rw-r--r--java/jni/direct_bt/DBTEvent.cxx87
-rw-r--r--java/jni/direct_bt/DBTGattService.cxx63
-rw-r--r--java/jni/direct_bt/helper_dbt.hpp2
-rw-r--r--java/jni/helper_base.cxx6
-rw-r--r--java/jni/helper_base.hpp2
-rw-r--r--java/jni/tinyb/CMakeLists.txt64
-rw-r--r--java/jni/tinyb/DBusAdapter.cxx594
-rw-r--r--java/jni/tinyb/DBusDevice.cxx883
-rw-r--r--java/jni/tinyb/DBusEvent.cxx86
-rw-r--r--java/jni/tinyb/DBusGattCharacteristic.cxx255
-rw-r--r--java/jni/tinyb/DBusGattDescriptor.cxx197
-rw-r--r--java/jni/tinyb/DBusGattService.cxx130
-rw-r--r--java/jni/tinyb/DBusManager.cxx352
-rw-r--r--java/jni/tinyb/DBusObject.cxx71
-rw-r--r--java/jni/tinyb/helper_tinyb.cxx111
-rw-r--r--java/jni/tinyb/helper_tinyb.hpp44
19 files changed, 41 insertions, 3095 deletions
diff --git a/java/jni/direct_bt/CMakeLists.txt b/java/jni/direct_bt/CMakeLists.txt
index 92f83970..3952d63a 100644
--- a/java/jni/direct_bt/CMakeLists.txt
+++ b/java/jni/direct_bt/CMakeLists.txt
@@ -28,7 +28,6 @@ set (direct_bt_JNI_SRCS
${PROJECT_SOURCE_DIR}/java/jni/direct_bt/helper_dbt.cxx
${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTAdapter.cxx
${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTDevice.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTEvent.cxx
${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattChar.cxx
${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattDesc.cxx
${PROJECT_SOURCE_DIR}/java/jni/direct_bt/DBTGattService.cxx
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index 0b19145e..5fceee87 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -62,8 +62,6 @@ static const std::string _deviceDisconnectedMethodArgs("(Lorg/direct_bt/BTDevice
class JNIAdapterStatusListener : public AdapterStatusListener {
private:
/**
- package org.tinyb;
-
public abstract class AdapterStatusListener {
private long nativeInstance;
@@ -503,7 +501,7 @@ jboolean Java_jau_direct_1bt_DBTAdapter_addStatusListenerImpl(JNIEnv *env, jobje
{
JNIAdapterStatusListener * pre = jau::getInstanceUnchecked<JNIAdapterStatusListener>(env, statusListener);
if( nullptr != pre ) {
- WARN_PRINT("JNIAdapterStatusListener::addStatusListener: statusListener's nativeInstance not null, already in use");
+ throw jau::IllegalStateException("JNIAdapterStatusListener::addStatusListener: statusListener's nativeInstance not null, already in use", E_FILE_LINE);
return false;
}
}
@@ -549,7 +547,6 @@ jboolean Java_jau_direct_1bt_DBTAdapter_addStatusListenerImpl(JNIEnv *env, jobje
jau::clearInstance(env, statusListener);
rethrow_and_raise_java_exception(env);
}
- ERR_PRINT("JNIAdapterStatusListener::addStatusListener: FAILED XX");
return JNI_FALSE;
}
@@ -955,16 +952,6 @@ jboolean Java_jau_direct_1bt_DBTAdapter_setPairable(JNIEnv *env, jobject obj, jb
return JNI_FALSE;
}
-void Java_jau_direct_1bt_DBTAdapter_setDiscoveryFilter(JNIEnv *env, jobject obj, jobject juuids, jint rssi, jint pathloss, jint transportType) {
- // List<String> uuids
- (void)env;
- (void)obj;
- (void)juuids;
- (void)rssi;
- (void)pathloss;
- (void)transportType;
-}
-
void Java_jau_direct_1bt_DBTAdapter_printDeviceListsImpl(JNIEnv *env, jobject obj) {
try {
BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 1ca51fe5..13d965f4 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -44,8 +44,6 @@ static const std::string _indicationReceivedMethodArgs("(Lorg/direct_bt/BTGattCh
class JNIGattCharListener : public BTGattCharListener {
private:
/**
- package org.tinyb;
-
public abstract class BTGattCharListener {
long nativeInstance;
@@ -639,8 +637,6 @@ jobject Java_jau_direct_1bt_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj)
if( services.size() > 0 ) {
std::shared_ptr<GattGenericAccessSvc> ga = device->getGattGenericAccess();
if( nullptr != ga ) {
- env->SetShortField(obj, getField(env, obj, "appearance", "S"), static_cast<jshort>(ga->appearance));
- java_exception_check_and_throw(env, E_FILE_LINE);
DBG_PRINT("BTDevice.getServices(): GenericAccess: %s", ga->toString().c_str());
}
} else {
@@ -693,54 +689,6 @@ jboolean Java_jau_direct_1bt_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj)
return JNI_FALSE;
}
-jstring Java_jau_direct_1bt_DBTDevice_getIcon(JNIEnv *env, jobject obj)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return nullptr; // FIXME
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr; // FIXME;
-}
-
-void Java_jau_direct_1bt_DBTDevice_setTrustedImpl(JNIEnv *env, jobject obj, jboolean value)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- (void)value;
- // FIXME
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_jau_direct_1bt_DBTDevice_setBlockedImpl(JNIEnv *env, jobject obj, jboolean value)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- (void)value;
- // FIXME
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean JNICALL Java_jau_direct_1bt_DBTDevice_getLegacyPairing(JNIEnv *env, jobject obj)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return JNI_FALSE; // FIXME
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
jshort Java_jau_direct_1bt_DBTDevice_getRSSI(JNIEnv *env, jobject obj)
{
try {
@@ -753,31 +701,6 @@ jshort Java_jau_direct_1bt_DBTDevice_getRSSI(JNIEnv *env, jobject obj)
return 0;
}
-
-jobjectArray Java_jau_direct_1bt_DBTDevice_getUUIDs(JNIEnv *env, jobject obj)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return nullptr; // FIXME
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_jau_direct_1bt_DBTDevice_getModalias(JNIEnv *env, jobject obj)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return nullptr; // FIXME
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
jobject Java_jau_direct_1bt_DBTDevice_getManufacturerData(JNIEnv *env, jobject obj)
{
try {
@@ -827,6 +750,10 @@ jshort Java_jau_direct_1bt_DBTDevice_getTxPower(JNIEnv *env, jobject obj)
return 0;
}
+#if 0
+//
+// Leave below code 'in' disabled, as an example of how to bind Java callback functions to C++ callback functions ad-hoc.
+
//
// BooleanDeviceCBContext
//
@@ -866,99 +793,8 @@ typedef std::shared_ptr<BooleanDeviceCBContext> BooleanDeviceCBContextRef;
//
-// Blocked
-//
-
-static void disableBlockedNotifications(JNIEnv *env, jobject obj, BTManager &mgmt)
-{
- InvocationFunc<bool, const MgmtEvent&> * funcptr =
- getObjectRef<InvocationFunc<bool, const MgmtEvent&>>(env, obj, "blockedNotificationRef");
- if( nullptr != funcptr ) {
- FunctionDef<bool, const MgmtEvent&> funcDef( funcptr );
- funcptr = nullptr;
- setObjectRef(env, obj, funcptr, "blockedNotificationRef"); // clear java ref
- int count;
- if( 1 != ( count = mgmt.removeMgmtEventCallback(MgmtEvent::Opcode::DEVICE_BLOCKED, funcDef) ) ) {
- throw InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
- }
- if( 1 != ( count = mgmt.removeMgmtEventCallback(MgmtEvent::Opcode::DEVICE_UNBLOCKED, funcDef) ) ) {
- throw InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
- }
- }
-}
-void Java_jau_direct_1bt_DBTDevice_disableBlockedNotificationsImpl(JNIEnv *env, jobject obj)
-{
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- BTManager & mgmt = device->getAdapter().getManager();
-
- disableBlockedNotifications(env, obj, mgmt);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-void Java_jau_direct_1bt_DBTDevice_enableBlockedNotificationsImpl(JNIEnv *env, jobject obj, jobject javaCallback)
-{
- try {
- BTDevice *device= getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- BTAdapter & adapter = device->getAdapter();
- BTManager & mgmt = adapter.getManager();
-
- disableBlockedNotifications(env, obj, mgmt);
-
- bool(*nativeCallback)(BooleanDeviceCBContextRef&, const MgmtEvent&) =
- [](BooleanDeviceCBContextRef& ctx_ref, const MgmtEvent& e)->bool {
- bool isBlocked = false;
- if( MgmtEvent::Opcode::DEVICE_BLOCKED == e.getOpcode() ) {
- const MgmtEvtDeviceBlocked &event = *static_cast<const MgmtEvtDeviceBlocked *>(&e);
- if( event.getAddress() != ctx_ref->addressAndType.address || event.getAddressType() != ctx_ref->addressAndType.type ) {
- return false; // not this device
- }
- isBlocked = true;
- } else if( MgmtEvent::Opcode::DEVICE_UNBLOCKED == e.getOpcode() ) {
- const MgmtEvtDeviceUnblocked &event = *static_cast<const MgmtEvtDeviceUnblocked *>(&e);
- if( event.getAddress() != ctx_ref->addressAndType.address || event.getAddressType() != ctx_ref->addressAndType.type ) {
- return false; // not this device
- }
- isBlocked = false;
- } else {
- return false; // oops
- }
-
- jobject result = jni_env->NewObject(ctx_ref->boolean_cls_ref.getClass(), ctx_ref->boolean_ctor, isBlocked ? JNI_TRUE : JNI_FALSE);
- jni_env->CallVoidMethod(*(ctx_ref->javaCallback_ref), ctx_ref->mRun, result);
- jni_env->DeleteLocalRef(result);
- return true;
- };
- jclass notification = search_class(*jni_env, javaCallback);
- jmethodID mRun = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- java_exception_check_and_throw(env, E_FILE_LINE);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID boolean_ctor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
- java_exception_check_and_throw(env, E_FILE_LINE);
-
- BooleanDeviceCBContextRef ctx_ref = std::make_shared<BooleanDeviceCBContext>(
- device->getAddressAndType(), JNIGlobalRef(javaCallback), mRun, JNIGlobalRef(boolean_cls), boolean_ctor );
- jni_env->DeleteLocalRef(boolean_cls);
-
- // move BooleanDeviceCBContextRef into CaptureInvocationFunc and operator== includes javaCallback comparison
- FunctionDef<bool, const MgmtEvent&> funcDef = bindCaptureFunc(ctx_ref, nativeCallback);
- setObjectRef(env, obj, funcDef.cloneFunction(), "blockedNotificationRef"); // set java ref
- mgmt.addMgmtEventCallback(adapter.dev_id, MgmtEvent::Opcode::DEVICE_BLOCKED, funcDef);
- mgmt.addMgmtEventCallback(adapter.dev_id, MgmtEvent::Opcode::DEVICE_UNBLOCKED, funcDef);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-//
// Paired
//
-
static void disablePairedNotifications(JNIEnv *env, jobject obj, BTManager &mgmt)
{
InvocationFunc<bool, const MgmtEvent&> * funcptr =
@@ -1028,3 +864,4 @@ void Java_jau_direct_1bt_DBTDevice_enablePairedNotificationsImpl(JNIEnv *env, jo
rethrow_and_raise_java_exception(env);
}
}
+#endif
diff --git a/java/jni/direct_bt/DBTEvent.cxx b/java/jni/direct_bt/DBTEvent.cxx
deleted file mode 100644
index 39dd4cf4..00000000
--- a/java/jni/direct_bt/DBTEvent.cxx
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Author: Sven Gothel <[email protected]>
- * Copyright (c) 2020 Gothel Software e.K.
- * Copyright (c) 2020 ZAFENA AB
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "jau_direct_bt_DBTEvent.h"
-
-jobject Java_jau_direct_1bt_DBTEvent_getType(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return NULL;
-}
-
-jstring Java_jau_direct_1bt_DBTEvent_getName(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return NULL;
-}
-
-jstring Java_jau_direct_1bt_DBTEvent_getIdentifier(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return NULL;
-}
-
-jboolean Java_jau_direct_1bt_DBTEvent_executeCallback(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return JNI_FALSE;
-}
-
-jboolean Java_jau_direct_1bt_DBTEvent_hasCallback(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return JNI_FALSE;
-}
-
-void Java_jau_direct_1bt_DBTEvent_init(JNIEnv *env, jobject obj, jobject type, jstring name,
- jstring identifier, jobject parent, jobject callback,
- jobject arg_data)
-{
- (void)env;
- (void)obj;
- (void)type;
- (void)name;
- (void)identifier;
- (void)parent;
- (void)callback;
- (void)arg_data;
-}
-
-void Java_jau_direct_1bt_DBTEvent_delete(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-}
-
diff --git a/java/jni/direct_bt/DBTGattService.cxx b/java/jni/direct_bt/DBTGattService.cxx
index 085ef1a1..43539077 100644
--- a/java/jni/direct_bt/DBTGattService.cxx
+++ b/java/jni/direct_bt/DBTGattService.cxx
@@ -60,7 +60,9 @@ void Java_jau_direct_1bt_DBTGattService_deleteImpl(JNIEnv *env, jobject obj, jlo
}
}
-static const std::string _characteristicClazzCtorArgs("(JLjau/direct_bt/DBTGattService;S[Ljava/lang/String;ZZLjava/lang/String;SI)V");
+static const std::string _characteristicClazzCtorArgs("(JLjau/direct_bt/DBTGattService;SLorg/direct_bt/GattCharPropertySet;Ljava/lang/String;SI)V");
+static const std::string _gattCharPropSetClassName("org/direct_bt/GattCharPropertySet");
+static const std::string _gattCharPropSetClazzCtorArgs("(B)V");
jobject Java_jau_direct_1bt_DBTGattService_getCharsImpl(JNIEnv *env, jobject obj) {
try {
@@ -69,57 +71,60 @@ jobject Java_jau_direct_1bt_DBTGattService_getCharsImpl(JNIEnv *env, jobject obj
jau::darray<std::shared_ptr<BTGattChar>> & characteristics = service->characteristicList;
- // BTGattChar(final long nativeInstance, final BTGattService service,
- // final short handle, final String[] properties,
- // final boolean hasNotify, final boolean hasIndicate,
- // final String value_type_uuid, final short value_handle,
- // final int clientCharacteristicsConfigIndex)
-
+ jclass gattCharPropSetClazz;
+ jmethodID gattCharPropSetClazzCtor;
+ // gattCharPropSetClazzRef, gattCharPropSetClazzCtor
+ {
+ gattCharPropSetClazz = jau::search_class(env, _gattCharPropSetClassName.c_str());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
+ if( nullptr == gattCharPropSetClazz ) {
+ throw jau::InternalError("BTDevice::java_class not found: "+_gattCharPropSetClassName, E_FILE_LINE);
+ }
+ }
+ gattCharPropSetClazzCtor = jau::search_method(env, gattCharPropSetClazz, "<init>", _gattCharPropSetClazzCtorArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
+ if( nullptr == gattCharPropSetClazzCtor ) {
+ throw jau::InternalError("GattCharPropertySet ctor not found: "+_gattCharPropSetClassName+".<init>"+_gattCharPropSetClazzCtorArgs, E_FILE_LINE);
+ }
+
+ /**
+ DBTGattChar(final long nativeInstance, final DBTGattService service,
+ final short handle, final GattCharPropertySet properties,
+ final String value_type_uuid, final short value_handle,
+ final int clientCharacteristicsConfigIndex)
+ */
std::function<jobject(JNIEnv*, jclass, jmethodID, BTGattChar *)> ctor_char =
- [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTGattChar *characteristic)->jobject {
+ [&gattCharPropSetClazz, &gattCharPropSetClazzCtor](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTGattChar *characteristic)->jobject {
// prepare adapter ctor
std::shared_ptr<BTGattService> _service = characteristic->getServiceChecked();
JavaGlobalObj::check(_service->getJavaObject(), E_FILE_LINE);
jobject jservice = JavaGlobalObj::GetObject(_service->getJavaObject());
- jau::darray<std::unique_ptr<std::string>> props = BTGattChar::getPropertiesStringList(characteristic->properties);
- size_t props_size = props.size();
-
- jobjectArray jproperties;
- {
- jclass string_class = search_class(env_, "java/lang/String");
- jproperties = env_->NewObjectArray((jsize)props_size, string_class, 0);
- java_exception_check_and_throw(env_, E_FILE_LINE);
- env_->DeleteLocalRef(string_class);
- }
- for (size_t i = 0; i < props_size; ++i) {
- jobject elem = from_string_to_jstring(env_, *props[i].get());
- env_->SetObjectArrayElement(jproperties, (jsize)i, elem);
- env_->DeleteLocalRef(elem);
- }
+ jobject jGattCharPropSet = env_->NewObject(gattCharPropSetClazz, gattCharPropSetClazzCtor, (jbyte)characteristic->properties);
+ jau::java_exception_check_and_throw(env_, E_FILE_LINE);
+ JNIGlobalRef::check(jGattCharPropSet, E_FILE_LINE);
java_exception_check_and_throw(env_, E_FILE_LINE);
- const bool hasNotify = characteristic->hasProperties(BTGattChar::PropertyBitVal::Notify);
- const bool hasIndicate = characteristic->hasProperties(BTGattChar::PropertyBitVal::Indicate);
-
const jstring uuid = from_string_to_jstring(env_,
directBTJNISettings.getUnifyUUID128Bit() ? characteristic->value_type->toUUID128String() :
characteristic->value_type->toString());
java_exception_check_and_throw(env_, E_FILE_LINE);
jobject jcharVal = env_->NewObject(clazz, clazz_ctor, (jlong)characteristic, jservice,
- characteristic->handle, jproperties, hasNotify, hasIndicate,
+ characteristic->handle, jGattCharPropSet,
uuid, characteristic->value_handle, characteristic->clientCharConfigIndex);
java_exception_check_and_throw(env_, E_FILE_LINE);
JNIGlobalRef::check(jcharVal, E_FILE_LINE);
std::shared_ptr<JavaAnon> jCharRef = characteristic->getJavaObject(); // GlobalRef
JavaGlobalObj::check(jCharRef, E_FILE_LINE);
- env_->DeleteLocalRef(jproperties);
+ env_->DeleteLocalRef(jGattCharPropSet);
env_->DeleteLocalRef(jcharVal);
return JavaGlobalObj::GetObject(jCharRef);
};
- return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<BTGattChar>>, BTGattChar>(
+ jobject jres = convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<BTGattChar>>, BTGattChar>(
env, characteristics, _characteristicClazzCtorArgs.c_str(), ctor_char);
+ env->DeleteLocalRef(gattCharPropSetClazz);
+ return jres;
} catch(...) {
rethrow_and_raise_java_exception(env);
}
diff --git a/java/jni/direct_bt/helper_dbt.hpp b/java/jni/direct_bt/helper_dbt.hpp
index 584e842d..8c7a45b5 100644
--- a/java/jni/direct_bt/helper_dbt.hpp
+++ b/java/jni/direct_bt/helper_dbt.hpp
@@ -41,7 +41,7 @@ namespace direct_bt {
* Enables or disables uuid128_t consolidation
* for native uuid16_t and uuid32_t values before string conversion.
* <p>
- * Default is {@code true}, as this represent compatibility with original TinyB D-Bus behavior.
+ * Default is {@code true}.
* </p>
*/
bool getUnifyUUID128Bit() { return unifyUUID128Bit; }
diff --git a/java/jni/helper_base.cxx b/java/jni/helper_base.cxx
index c08c9280..84a6e4c2 100644
--- a/java/jni/helper_base.cxx
+++ b/java/jni/helper_base.cxx
@@ -50,10 +50,6 @@ void raise_java_exception(JNIEnv *env, const direct_bt::BTException &e, const ch
jau::print_native_caught_exception_fwd2java(e, file, line);
env->ThrowNew(env->FindClass("org/direct_bt/BTException"), e.what());
}
-void raise_java_exception(JNIEnv *env, const tinyb::BluetoothException &e, const char* file, int line) {
- jau::print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("org/direct_bt/BTException"), e.what());
-}
static std::string _unknown_exception_type_msg("Unknown exception type");
@@ -80,8 +76,6 @@ void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char* file, int li
jau::raise_java_exception(env, e, file, line);
} catch (const direct_bt::BTException &e) {
raise_java_exception(env, e, file, line);
- } catch (const tinyb::BluetoothException &e) {
- raise_java_exception(env, e, file, line);
} catch (const jau::RuntimeException &e) {
jau::raise_java_exception(env, e, file, line);
} catch (const std::runtime_error &e) {
diff --git a/java/jni/helper_base.hpp b/java/jni/helper_base.hpp
index 05293108..2e678236 100644
--- a/java/jni/helper_base.hpp
+++ b/java/jni/helper_base.hpp
@@ -37,12 +37,10 @@
#include <jau/jni/helper_jni.hpp>
#include "direct_bt/BTTypes0.hpp"
-#include "tinyb/BluetoothException.hpp"
jobject get_bluetooth_type(JNIEnv *env, const char *field_name);
void raise_java_exception(JNIEnv *env, const direct_bt::BTException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const tinyb::BluetoothException &e, const char* file, int line);
/**
* Re-throw current exception and raise respective java exception
diff --git a/java/jni/tinyb/CMakeLists.txt b/java/jni/tinyb/CMakeLists.txt
deleted file mode 100644
index 0e98beb3..00000000
--- a/java/jni/tinyb/CMakeLists.txt
+++ /dev/null
@@ -1,64 +0,0 @@
-find_package(JNI REQUIRED)
-
-if (JNI_FOUND)
- message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
- message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
-endif (JNI_FOUND)
-
-set (tinyb_LIB_INCLUDE_DIRS
- ${PROJECT_SOURCE_DIR}/jaulib/include
- ${PROJECT_SOURCE_DIR}/api
- ${PROJECT_SOURCE_DIR}/api/direct_bt
- ${PROJECT_SOURCE_DIR}/api/tinyb
- ${PROJECT_SOURCE_DIR}/include
- ${PROJECT_SOURCE_DIR}/java/jni
-)
-
-include_directories(
- ${JNI_INCLUDE_DIRS}
- ${tinyb_LIB_INCLUDE_DIRS}
- ${JNI_HEADER_PATH}
-)
-
-set (tinyb_JNI_SRCS
- ${PROJECT_SOURCE_DIR}/jaulib/java_jni/jni/jni_mem.cxx
- ${PROJECT_SOURCE_DIR}/jaulib/java_jni/jni/helper_jni.cxx
- ${PROJECT_SOURCE_DIR}/jaulib/src/basic_types.cpp
- ${PROJECT_SOURCE_DIR}/java/jni/helper_base.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/BTFactory.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/BTUtils.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/helper_tinyb.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusAdapter.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusDevice.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusEvent.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusGattCharacteristic.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusGattDescriptor.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusGattService.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusManager.cxx
- ${PROJECT_SOURCE_DIR}/java/jni/tinyb/DBusObject.cxx
-)
-
-set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
-
-add_library (javatinyb SHARED ${tinyb_JNI_SRCS})
-target_link_libraries(javatinyb ${JNI_LIBRARIES} tinyb)
-
-if(USE_STRIP)
-add_custom_command(TARGET javatinyb POST_BUILD
- COMMAND ${STRIP} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}javatinyb${CMAKE_SHARED_LIBRARY_SUFFIX}.${tinyb_VERSION_STRING}
- COMMENT "stripping javatinyb"
- VERBATIM
- )
-endif(USE_STRIP)
-
-set_target_properties(
- javatinyb
- PROPERTIES
- SOVERSION ${tinyb_VERSION_MAJOR}
- VERSION ${tinyb_VERSION_STRING}
-)
-
-install(TARGETS javatinyb LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
-
-add_dependencies(javatinyb tinyb direct_bt_jar)
-
diff --git a/java/jni/tinyb/DBusAdapter.cxx b/java/jni/tinyb/DBusAdapter.cxx
deleted file mode 100644
index 531a046e..00000000
--- a/java/jni/tinyb/DBusAdapter.cxx
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothAdapter.hpp"
-#include "tinyb/BluetoothDevice.hpp"
-#include "tinyb/BluetoothObject.hpp"
-
-#include "tinyb_dbus_DBusAdapter.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusAdapter_getBluetoothType(JNIEnv *env, jobject obj)
-{
- try {
- (void)obj;
-
- return get_bluetooth_type(env, "ADAPTER");
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusAdapter_clone(JNIEnv *env, jobject obj)
-{
- try {
- return generic_clone<BluetoothAdapter>(env, obj);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_startDiscovery(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return obj_adapter->start_discovery() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return obj_adapter->stop_discovery() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jobject Java_tinyb_dbus_DBusAdapter_getDiscoveredDevices(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::vector<std::unique_ptr<BluetoothDevice>> array = obj_adapter->get_devices();
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothDevice>>, BluetoothDevice>(
- env, array, "(J)V");
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jint Java_tinyb_dbus_DBusAdapter_removeDiscoveredDevices(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::vector<std::unique_ptr<tinyb::BluetoothDevice>> array = obj_adapter->get_devices();
-
- for (unsigned int i =0;i<array.size();i++) {
- std::unique_ptr<tinyb::BluetoothDevice> *obj_device = &array.at(i);
- std::string path = obj_device->get()->get_object_path();
- // printf("PATH:%s\n", path.c_str());
- // fflush(stdout);
- obj_adapter->remove_device(path.c_str());
-
- }
- return array.size();
-
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jstring Java_tinyb_dbus_DBusAdapter_getAddressString(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::string address = obj_adapter->get_address();
-
- return env->NewStringUTF((const char *)address.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusAdapter_getName(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::string name = obj_adapter->get_name();
-
- return env->NewStringUTF((const char *)name.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusAdapter_getAlias(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::string alias = obj_adapter->get_alias();
-
- return env->NewStringUTF((const char *)alias.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusAdapter_setAlias(JNIEnv *env, jobject obj, jstring str)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- const std::string string_to_write = from_jstring_to_string(env, str);
-
- obj_adapter->set_alias(string_to_write);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jlong Java_tinyb_dbus_DBusAdapter_getBluetoothClass(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return (jlong)obj_adapter->get_class();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_getPoweredState(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return obj_adapter->get_powered() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_setPowered(JNIEnv *env, jobject obj, jboolean val)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- bool val_to_write = from_jboolean_to_bool(val);
- obj_adapter->set_powered(val_to_write);
- return JNI_TRUE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusAdapter_enablePoweredNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_adapter->enable_powered_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusAdapter_disablePoweredNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- obj_adapter->disable_powered_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_getDiscoverable(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return obj_adapter->get_discoverable() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_setDiscoverable(JNIEnv *env, jobject obj, jboolean val)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- bool val_to_write = from_jboolean_to_bool(val);
- obj_adapter->set_discoverable(val_to_write);
- return JNI_TRUE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusAdapter_enableDiscoverableNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_adapter->enable_discoverable_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusAdapter_disableDiscoverableNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- obj_adapter->disable_discoverable_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jlong Java_tinyb_dbus_DBusAdapter_getDiscoverableTimeout(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return (jlong)obj_adapter->get_discoverable_timeout();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_setDiscoverableTimout(JNIEnv *env, jobject obj, jlong timeout)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- if (timeout < 0)
- {
- throw std::invalid_argument("timeout argument is negative\n");
- }
- obj_adapter->set_discoverable_timeout((unsigned int)timeout);
- return JNI_TRUE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_getPairable(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return obj_adapter->get_pairable() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusAdapter_enablePairableNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_adapter->enable_pairable_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusAdapter_disablePairableNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- obj_adapter->disable_pairable_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_setPairable(JNIEnv *env, jobject obj, jboolean val)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- bool val_to_write = from_jboolean_to_bool(val);
- obj_adapter->set_pairable(val_to_write);
- return JNI_TRUE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jlong Java_tinyb_dbus_DBusAdapter_getPairableTimeout(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return (jlong)obj_adapter->get_pairable_timeout();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_setPairableTimeout(JNIEnv *env, jobject obj, jlong timeout)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- if (timeout < 0)
- {
- throw std::invalid_argument("timeout argument is negative\n");
- }
- obj_adapter->set_pairable_timeout((unsigned int)timeout);
- return JNI_TRUE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusAdapter_getDiscovering(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- return obj_adapter->get_discovering() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusAdapter_enableDiscoveringNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_adapter->enable_discovering_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusAdapter_disableDiscoveringNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter =
- getInstance<BluetoothAdapter>(env, obj);
- obj_adapter->disable_discovering_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jobjectArray Java_tinyb_dbus_DBusAdapter_getUUIDs(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::vector<std::string> uuids = obj_adapter->get_uuids();
- unsigned int uuids_size = uuids.size();
-
- jclass string_class = search_class(env, "Ljava/lang/String;");
- jobjectArray result = env->NewObjectArray(uuids_size, string_class, 0);
- if (!result)
- {
- throw std::bad_alloc();
- }
-
- for (unsigned int i = 0; i < uuids_size; ++i)
- {
- std::string str_elem = uuids.at(i);
- jobject elem = env->NewStringUTF((const char *)str_elem.c_str());
- env->SetObjectArrayElement(result, i, elem);
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusAdapter_getModalias(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
- std::unique_ptr<std::string> modalias = obj_adapter->get_modalias();
- if(modalias == nullptr)
- return nullptr;
-
- return env->NewStringUTF((const char *)modalias->c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusAdapter_delete(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothAdapter *adapter = getInstance<BluetoothAdapter>(env, obj);
- delete adapter;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusAdapter_setDiscoveryFilter(JNIEnv *env, jobject obj, jobject uuids, jint rssi, jint pathloss, jint transportType)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- jclass cList = env->FindClass("java/util/List");
-
- jmethodID mSize = env->GetMethodID(cList, "size", "()I");
- jmethodID mGet = env->GetMethodID(cList, "get", "(I)Ljava/lang/Object;");
-
- jint size = env->CallIntMethod(uuids, mSize);
- std::vector<BluetoothUUID> native_uuids;
-
- for (jint i = 0; i < size; i++) {
- jstring strObj = (jstring) env->CallObjectMethod(uuids, mGet, i);
- const char * chr = env->GetStringUTFChars(strObj, NULL);
- BluetoothUUID uuid(chr);
- native_uuids.push_back(uuid);
- env->ReleaseStringUTFChars(strObj, chr);
- }
-
- TransportType t_type = from_int_to_transport_type((int) transportType);
-
- obj_adapter->set_discovery_filter(native_uuids, (int16_t) rssi, (uint16_t) pathloss, t_type);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jobject Java_tinyb_dbus_DBusAdapter_connectDeviceImpl(JNIEnv *env, jobject obj, jstring jaddress, jstring jaddressType)
-{
- try {
- BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
-
- const std::string address = from_jstring_to_string(env, jaddress);
- const std::string addressType = from_jstring_to_string(env, jaddressType);
-
- fprintf(stderr, "connectDeviceJ.0\n"); fflush(stderr);
- std::unique_ptr<tinyb::BluetoothDevice> b_device = obj_adapter->connect_device(address, addressType);
- fprintf(stderr, "connectDeviceJ.1\n"); fflush(stderr);
-
- BluetoothDevice *b_device_naked = b_device.release();
- fprintf(stderr, "connectDeviceJ.2\n"); fflush(stderr);
- if (!b_device_naked)
- {
- return nullptr;
- }
- jclass clazz = search_class(env, *b_device_naked);
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", "(J)V", false);
-
- jobject result = env->NewObject(clazz, clazz_ctor, (jlong)b_device_naked);
- fprintf(stderr, "connectDeviceJ.X\n"); fflush(stderr);
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return NULL;
-}
-
diff --git a/java/jni/tinyb/DBusDevice.cxx b/java/jni/tinyb/DBusDevice.cxx
deleted file mode 100644
index aa5c804d..00000000
--- a/java/jni/tinyb/DBusDevice.cxx
+++ /dev/null
@@ -1,883 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothAdapter.hpp"
-#include "tinyb/BluetoothDevice.hpp"
-#include "tinyb/BluetoothGattService.hpp"
-#include "tinyb/BluetoothObject.hpp"
-
-#include "tinyb_dbus_DBusDevice.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusDevice_getBluetoothType(JNIEnv *env, jobject obj)
-{
- try {
- (void)obj;
-
- return get_bluetooth_type(env, "DEVICE");
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusDevice_clone(JNIEnv *env, jobject obj)
-{
- try {
- return generic_clone<BluetoothDevice>(env, obj);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_disconnectImpl(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->disconnect() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusDevice_connectAsyncStart(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- obj_device->connect_async_start();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_connectAsyncFinish(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->connect_async_finish() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_connectImpl(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->connect() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_connectProfile(JNIEnv *env, jobject obj, jstring str)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- const std::string string_to_write = from_jstring_to_string(env, str);
-
- return obj_device->connect_profile(string_to_write) ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_disconnectProfile(JNIEnv *env, jobject obj, jstring str)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- const std::string string_to_write = from_jstring_to_string(env, str);
-
- return obj_device->disconnect_profile(string_to_write) ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_pair(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->pair() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_remove(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->remove_device() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_cancelPairing(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->cancel_pairing() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jobject Java_tinyb_dbus_DBusDevice_getServices(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::vector<std::unique_ptr<BluetoothGattService>> array = obj_device->get_services();
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothGattService>>, BluetoothGattService>(
- env, array, "(J)V");
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusDevice_getAddressString(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::string address = obj_device->get_address();
-
- return env->NewStringUTF((const char *)address.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusDevice_getName(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::string name = obj_device->get_name();
-
- return env->NewStringUTF((const char *)name.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusDevice_getAlias(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::string alias = obj_device->get_alias();
-
- return env->NewStringUTF((const char *)alias.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusDevice_setAlias(JNIEnv *env, jobject obj, jstring str)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- const std::string string_to_write = from_jstring_to_string(env, str);
-
- obj_device->set_alias(string_to_write);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jint Java_tinyb_dbus_DBusDevice_getBluetoothClass(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return (jlong)obj_device->get_class();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jshort Java_tinyb_dbus_DBusDevice_getAppearance(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return (jshort)obj_device->get_appearance();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jstring Java_tinyb_dbus_DBusDevice_getIcon(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::unique_ptr<std::string> icon = obj_device->get_icon();
- if (icon == nullptr)
- return nullptr;
-
- return env->NewStringUTF((const char *)icon->c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_getPaired(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->get_paired() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusDevice_enablePairedNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_paired_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disablePairedNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_paired_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_getTrusted(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->get_trusted() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusDevice_setTrusted(JNIEnv *env, jobject obj, jboolean val)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- bool val_to_write = from_jboolean_to_bool(val);
- obj_device->set_trusted(val_to_write);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_enableTrustedNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_trusted_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableTrustedNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_trusted_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_getBlocked(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->get_blocked() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusDevice_setBlocked(JNIEnv *env, jobject obj, jboolean val)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- bool val_to_write = from_jboolean_to_bool(val);
- obj_device->set_blocked(val_to_write);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_enableBlockedNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_blocked_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableBlockedNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_blocked_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_getLegacyPairing(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->get_legacy_pairing() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jshort Java_tinyb_dbus_DBusDevice_getRSSI(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return (jshort)obj_device->get_rssi();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-void Java_tinyb_dbus_DBusDevice_enableRSSINotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_rssi_notifications([ callback_ptr ] (int16_t v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass short_cls = search_class(*jni_env, "java/lang/Short");
- jmethodID constructor = search_method(*jni_env, short_cls, "<init>", "(S)V", false);
-
- jobject result = jni_env->NewObject(short_cls, constructor, (jshort) v);
- jni_env->DeleteLocalRef(short_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableRSSINotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_rssi_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_getConnected(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->get_connected() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusDevice_enableConnectedNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_connected_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableConnectedNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_connected_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jobjectArray Java_tinyb_dbus_DBusDevice_getUUIDs(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::vector<std::string> uuids = obj_device->get_uuids();
- unsigned int uuids_size = uuids.size();
-
- jclass string_class = search_class(env, "Ljava/lang/String;");
- jobjectArray result = env->NewObjectArray(uuids_size, string_class, 0);
-
- for (unsigned int i = 0; i < uuids_size; ++i)
- {
- std::string str_elem = uuids.at(i);
- jobject elem = env->NewStringUTF((const char *)str_elem.c_str());
- env->SetObjectArrayElement(result, i, elem);
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusDevice_getModalias(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- std::unique_ptr<std::string> modalias = obj_device->get_modalias();
- if (modalias == nullptr)
- return nullptr;
-
- return env->NewStringUTF((const char *)modalias->c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusDevice_getAdapter(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- BluetoothAdapter *obj_adapter = obj_device->get_adapter().clone();
-
- jclass b_adapter_class = search_class(env, *obj_adapter);
- jmethodID b_adapter_ctor = search_method(env, b_adapter_class, "<init>",
- "(J)V", false);
- jobject result = env->NewObject(b_adapter_class, b_adapter_ctor, (jlong)obj_adapter);
- if (!result)
- {
- throw std::bad_alloc();
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusDevice_getManufacturerData(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- auto mdata = obj_device->get_manufacturer_data();
-
- jclass map_cls = search_class(env, "java/util/HashMap");
- jmethodID map_ctor = search_method(env, map_cls, "<init>",
- "(I)V", false);
- jmethodID map_put = search_method(env, map_cls, "put",
- "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
- false);
-
- jclass short_cls = search_class(env, "java/lang/Short");
- jmethodID short_ctor = search_method(env, short_cls, "<init>",
- "(S)V", false);
-
- jobject result = env->NewObject(map_cls, map_ctor, mdata.size());
-
- for (auto it: mdata) {
- jbyteArray arr = env->NewByteArray(it.second.size());
- env->SetByteArrayRegion(arr, 0, it.second.size(), (const jbyte *)it.second.data());
- jobject key = env->NewObject(short_cls, short_ctor, it.first);
- env->CallObjectMethod(result, map_put, key, arr);
-
- env->DeleteLocalRef(arr);
- env->DeleteLocalRef(key);
- }
-
- if (!result)
- {
- throw std::bad_alloc();
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusDevice_enableManufacturerDataNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_manufacturer_data_notifications([ callback_ptr ] (std::map<uint16_t, std::vector<uint8_t>> v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass map_cls = search_class(*jni_env, "java/util/HashMap");
- jmethodID map_ctor = search_method(*jni_env, map_cls, "<init>",
- "(I)V", false);
- jmethodID map_put = search_method(*jni_env, map_cls, "put",
- "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
- false);
-
- jclass short_cls = search_class(*jni_env, "java/lang/Short");
- jmethodID short_ctor = search_method(*jni_env, short_cls, "<init>",
- "(S)V", false);
-
- jobject result = jni_env->NewObject(map_cls, map_ctor, v.size());
- jni_env->DeleteLocalRef(map_cls);
- for (auto it: v) {
- jbyteArray arr = jni_env->NewByteArray(it.second.size());
- jni_env->SetByteArrayRegion(arr, 0, it.second.size(), (const jbyte *)it.second.data());
- jobject key = jni_env->NewObject(short_cls, short_ctor, it.first);
- jni_env->CallObjectMethod(result, map_put, key, arr);
-
- jni_env->DeleteLocalRef(arr);
- jni_env->DeleteLocalRef(key);
- }
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
- jni_env->DeleteLocalRef(short_cls);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableManufacturerDataNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_service_data_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jobject Java_tinyb_dbus_DBusDevice_getServiceData(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
- auto mdata = obj_device->get_service_data();
-
- jclass map_cls = search_class(env, "java/util/HashMap");
- jmethodID map_ctor = search_method(env, map_cls, "<init>",
- "(I)V", false);
- jmethodID map_put = search_method(env, map_cls, "put",
- "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
- false);
-
- jobject result = env->NewObject(map_cls, map_ctor, mdata.size());
-
- for (auto it: mdata) {
- jbyteArray arr = env->NewByteArray(it.second.size());
- env->SetByteArrayRegion(arr, 0, it.second.size(), (const jbyte *)it.second.data());
- jobject key = env->NewStringUTF(it.first.c_str());
- env->CallObjectMethod(result, map_put, key, arr);
-
- env->DeleteLocalRef(arr);
- env->DeleteLocalRef(key);
- }
-
- if (!result)
- {
- throw std::bad_alloc();
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusDevice_enableServiceDataNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_service_data_notifications([ callback_ptr ] (std::map<std::string, std::vector<uint8_t>> v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass map_cls = search_class(*jni_env, "java/util/HashMap");
- jmethodID map_ctor = search_method(*jni_env, map_cls, "<init>",
- "(I)V", false);
- jmethodID map_put = search_method(*jni_env, map_cls, "put",
- "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
- false);
-
- jobject result = jni_env->NewObject(map_cls, map_ctor, v.size());
- jni_env->DeleteLocalRef(map_cls);
-
- for (auto it: v) {
- jbyteArray arr = jni_env->NewByteArray(it.second.size());
- jni_env->SetByteArrayRegion(arr, 0, it.second.size(), (const jbyte *)it.second.data());
- jobject key = jni_env->NewStringUTF(it.first.c_str());
- jni_env->CallObjectMethod(result, map_put, key, arr);
-
- jni_env->DeleteLocalRef(arr);
- jni_env->DeleteLocalRef(key);
- }
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableServiceDataNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_service_data_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-
-
-jshort Java_tinyb_dbus_DBusDevice_getTxPower(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return (jshort)obj_device->get_tx_power();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return 0;
-}
-
-jboolean Java_tinyb_dbus_DBusDevice_getServicesResolved(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
-
- return obj_device->get_services_resolved() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusDevice_enableServicesResolvedNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_device->enable_services_resolved_notifications([ callback_ptr ] (bool v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
-
- jclass boolean_cls = search_class(*jni_env, "java/lang/Boolean");
- jmethodID constructor = search_method(*jni_env, boolean_cls, "<init>", "(Z)V", false);
-
- jobject result = jni_env->NewObject(boolean_cls, constructor, v ? JNI_TRUE : JNI_FALSE);
- jni_env->DeleteLocalRef(boolean_cls);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusDevice_disableServicesResolvedNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *obj_device =
- getInstance<BluetoothDevice>(env, obj);
- obj_device->disable_services_resolved_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-
-
-void Java_tinyb_dbus_DBusDevice_delete(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothDevice *b_device = getInstance<BluetoothDevice>(env, obj);
- delete b_device;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
diff --git a/java/jni/tinyb/DBusEvent.cxx b/java/jni/tinyb/DBusEvent.cxx
deleted file mode 100644
index 14b6431c..00000000
--- a/java/jni/tinyb/DBusEvent.cxx
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb_dbus_DBusEvent.h"
-
-jobject Java_tinyb_dbus_DBusEvent_getType(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return NULL;
-}
-
-jstring Java_tinyb_dbus_DBusEvent_getName(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return NULL;
-}
-
-jstring Java_tinyb_dbus_DBusEvent_getIdentifier(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return NULL;
-}
-
-jboolean Java_tinyb_dbus_DBusEvent_executeCallback(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusEvent_hasCallback(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusEvent_init(JNIEnv *env, jobject obj, jobject type, jstring name,
- jstring identifier, jobject parent, jobject callback,
- jobject arg_data)
-{
- (void)env;
- (void)obj;
- (void)type;
- (void)name;
- (void)identifier;
- (void)parent;
- (void)callback;
- (void)arg_data;
-}
-
-void Java_tinyb_dbus_DBusEvent_delete(JNIEnv *env, jobject obj)
-{
- (void)env;
- (void)obj;
-}
-
diff --git a/java/jni/tinyb/DBusGattCharacteristic.cxx b/java/jni/tinyb/DBusGattCharacteristic.cxx
deleted file mode 100644
index 0becc560..00000000
--- a/java/jni/tinyb/DBusGattCharacteristic.cxx
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothGattCharacteristic.hpp"
-#include "tinyb/BluetoothGattDescriptor.hpp"
-#include "tinyb/BluetoothGattService.hpp"
-#include "tinyb/BluetoothObject.hpp"
-
-#include "tinyb_dbus_DBusGattCharacteristic.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusGattCharacteristic_getBluetoothType(JNIEnv *env, jobject obj)
-{
- try {
- (void)obj;
-
- return get_bluetooth_type(env, "GATT_CHARACTERISTIC");
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattCharacteristic_clone(JNIEnv *env, jobject obj)
-{
- try {
- return generic_clone<BluetoothGattCharacteristic>(env, obj);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jbyteArray Java_tinyb_dbus_DBusGattCharacteristic_readValue(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- std::vector<unsigned char> array = obj_gatt_char->read_value();
- unsigned int array_size = array.size();
-
- jbyteArray result = env->NewByteArray((jsize)array_size);
- env->SetByteArrayRegion(result, 0, (jsize)array_size, (const jbyte *)&array[0]);
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusGattCharacteristic_writeValue(JNIEnv *env, jobject obj, jbyteArray argValue)
-{
- try {
- if (!argValue)
- {
- throw std::invalid_argument("byte array is null");
- return JNI_FALSE;
- }
-
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
-
- jboolean is_copy = false;
- jbyte *native_array = env->GetByteArrayElements(argValue, &is_copy);
- jsize native_array_length = env->GetArrayLength(argValue);
-
- std::vector<unsigned char> array(native_array, native_array + native_array_length);
-
- return obj_gatt_char->write_value(array) ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusGattCharacteristic_enableValueNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_gatt_char->enable_value_notifications([ callback_ptr ] (std::vector<unsigned char> &v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
- unsigned int size = v.size();
-
- jbyteArray result = jni_env->NewByteArray((jsize)size);
- jni_env->SetByteArrayRegion(result, 0, (jsize)size, (const jbyte *)&v[0]);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusGattCharacteristic_disableValueNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- obj_gatt_char->disable_value_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jstring Java_tinyb_dbus_DBusGattCharacteristic_getUUID(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- std::string uuid = obj_gatt_char->get_uuid();
-
- return env->NewStringUTF((const char *)uuid.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattCharacteristic_getService(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- BluetoothGattService *obj_gatt_serv = obj_gatt_char->get_service().clone();
-
- jclass b_gatt_serv_class = search_class(env, *obj_gatt_serv);
- jmethodID b_gatt_serv_ctor = search_method(env, b_gatt_serv_class, "<init>",
- "(J)V", false);
- jobject result = env->NewObject(b_gatt_serv_class, b_gatt_serv_ctor, (jlong)obj_gatt_serv);
- if (result == NULL)
- {
- throw std::runtime_error("cannot create instance of class\n");
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jbyteArray Java_tinyb_dbus_DBusGattCharacteristic_getValue(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- std::vector<unsigned char> array = obj_gatt_char->get_value();
- unsigned int array_size = array.size();
-
- jbyteArray result = env->NewByteArray((jsize)array_size);
- env->SetByteArrayRegion(result, 0, (jsize)array_size, (const jbyte *)&array[0]);
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusGattCharacteristic_getNotifying(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- return obj_gatt_char->get_notifying() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jobjectArray Java_tinyb_dbus_DBusGattCharacteristic_getFlags(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- std::vector<std::string> flags = obj_gatt_char->get_flags();
- unsigned int flags_size = flags.size();
-
- jclass string_class = search_class(env, "Ljava/lang/String;");
- jobjectArray result = env->NewObjectArray(flags_size, string_class, 0);
-
- for (unsigned int i = 0; i < flags_size; ++i)
- {
- std::string str_elem = flags.at(i);
- jobject elem = env->NewStringUTF((const char *)str_elem.c_str());
- env->SetObjectArrayElement(result, i, elem);
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattCharacteristic_getDescriptors(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- std::vector<std::unique_ptr<BluetoothGattDescriptor>> array = obj_gatt_char->get_descriptors();
-
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothGattDescriptor>>, BluetoothGattDescriptor>(
- env, array, "(J)V");
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusGattCharacteristic_delete(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattCharacteristic *obj_gatt_char =
- getInstance<BluetoothGattCharacteristic>(env, obj);
- delete obj_gatt_char;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
diff --git a/java/jni/tinyb/DBusGattDescriptor.cxx b/java/jni/tinyb/DBusGattDescriptor.cxx
deleted file mode 100644
index a1cc7606..00000000
--- a/java/jni/tinyb/DBusGattDescriptor.cxx
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothGattCharacteristic.hpp"
-#include "tinyb/BluetoothGattDescriptor.hpp"
-#include "tinyb/BluetoothObject.hpp"
-
-#include "tinyb_dbus_DBusGattDescriptor.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusGattDescriptor_getBluetoothType(JNIEnv *env, jobject obj)
-{
- try {
- (void)obj;
-
- return get_bluetooth_type(env, "GATT_DESCRIPTOR");
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattDescriptor_clone(JNIEnv *env, jobject obj)
-{
- try {
- return generic_clone<BluetoothGattDescriptor>(env, obj);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jbyteArray Java_tinyb_dbus_DBusGattDescriptor_readValue(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
- std::vector<unsigned char> array = obj_gatt_desc->read_value();
- unsigned int array_size = array.size();
-
- jbyteArray result = env->NewByteArray((jsize)array_size);
- env->SetByteArrayRegion(result, 0, (jsize)array_size, (const jbyte *)&array[0]);
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusGattDescriptor_writeValue(JNIEnv *env, jobject obj, jbyteArray argValue)
-{
- try {
- if (!argValue)
- {
- throw std::invalid_argument("byte array is null");
- }
-
- BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
-
- jboolean is_copy = false;
- jbyte *native_array = env->GetByteArrayElements(argValue, &is_copy);
- jsize native_array_length = env->GetArrayLength(argValue);
-
- std::vector<unsigned char> array(native_array, native_array + native_array_length);
-
- return obj_gatt_desc->write_value(array) ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jstring Java_tinyb_dbus_DBusGattDescriptor_getUUID(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
- std::string uuid = obj_gatt_desc->get_uuid();
-
- return env->NewStringUTF((const char *)uuid.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattDescriptor_getCharacteristic(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
- BluetoothGattCharacteristic *obj_gatt_char = obj_gatt_desc->get_characteristic().clone();
-
- jclass b_gatt_char_class = search_class(env, *obj_gatt_char);
- jmethodID b_gatt_char_ctor = search_method(env, b_gatt_char_class, "<init>",
- "(J)V", false);
- jobject result = env->NewObject(b_gatt_char_class, b_gatt_char_ctor, (jlong)obj_gatt_char);
- if (result == NULL)
- {
- throw std::runtime_error("cannot create instance of class\n");
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jbyteArray Java_tinyb_dbus_DBusGattDescriptor_getValue(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
- std::vector<unsigned char> array = obj_gatt_desc->get_value();
- unsigned int array_size = array.size();
-
- jbyteArray result = env->NewByteArray((jsize)array_size);
- env->SetByteArrayRegion(result, 0, (jsize)array_size, (const jbyte *)&array[0]);
-
- return result;
-
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusGattDescriptor_enableValueNotifications(JNIEnv *env, jobject obj, jobject callback)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc =
- getInstance<BluetoothGattDescriptor>(env, obj);
- std::shared_ptr<JNIGlobalRef> callback_ptr(new JNIGlobalRef(callback));
- obj_gatt_desc->enable_value_notifications([ callback_ptr ] (std::vector<unsigned char> &v)
- {
- jclass notification = search_class(*jni_env, **callback_ptr);
- jmethodID method = search_method(*jni_env, notification, "run", "(Ljava/lang/Object;)V", false);
- jni_env->DeleteLocalRef(notification);
- unsigned int size = v.size();
-
- jbyteArray result = jni_env->NewByteArray((jsize)size);
- jni_env->SetByteArrayRegion(result, 0, (jsize)size, (const jbyte *)&v[0]);
-
- jni_env->CallVoidMethod(**callback_ptr, method, result);
- jni_env->DeleteLocalRef(result);
-
- });
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusGattDescriptor_disableValueNotifications(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc =
- getInstance<BluetoothGattDescriptor>(env, obj);
- obj_gatt_desc->disable_value_notifications();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-
-void Java_tinyb_dbus_DBusGattDescriptor_delete(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattDescriptor *obj_gatt_desc = getInstance<BluetoothGattDescriptor>(env, obj);
- delete obj_gatt_desc;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
diff --git a/java/jni/tinyb/DBusGattService.cxx b/java/jni/tinyb/DBusGattService.cxx
deleted file mode 100644
index f621df2d..00000000
--- a/java/jni/tinyb/DBusGattService.cxx
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothDevice.hpp"
-#include "tinyb/BluetoothGattService.hpp"
-#include "tinyb/BluetoothGattCharacteristic.hpp"
-#include "tinyb/BluetoothObject.hpp"
-
-#include "tinyb_dbus_DBusGattService.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusGattService_getBluetoothType(JNIEnv *env, jobject obj)
-{
- try {
- (void)obj;
-
- return get_bluetooth_type(env, "GATT_SERVICE");
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattService_clone(JNIEnv *env, jobject obj)
-{
- try {
- return generic_clone<BluetoothGattService>(env, obj);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jstring Java_tinyb_dbus_DBusGattService_getUUID(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj);
- std::string uuid = obj_gatt_serv->get_uuid();
-
- return env->NewStringUTF((const char *)uuid.c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusGattService_getDevice(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj);
- BluetoothDevice *obj_device = obj_gatt_serv->get_device().clone();
-
- jclass b_device_class = search_class(env, *obj_device);
- jmethodID b_device_ctor = search_method(env, b_device_class, "<init>",
- "(J)V", false);
- jobject result = env->NewObject(b_device_class, b_device_ctor, (jlong)obj_device);
- if (result == NULL)
- {
- throw std::runtime_error("cannot create instance of class\n");
- }
-
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusGattService_getPrimary(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj);
-
- return obj_gatt_serv->get_primary() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jobject Java_tinyb_dbus_DBusGattService_getChars(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj);
- std::vector<std::unique_ptr<BluetoothGattCharacteristic>> array =
- obj_gatt_serv->get_characteristics();
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothGattCharacteristic>>, BluetoothGattCharacteristic>(
- env, array, "(J)V");
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-void Java_tinyb_dbus_DBusGattService_delete(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothGattService *obj_gatt_serv = getInstance<BluetoothGattService>(env, obj);
- delete obj_gatt_serv;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
diff --git a/java/jni/tinyb/DBusManager.cxx b/java/jni/tinyb/DBusManager.cxx
deleted file mode 100644
index e3abf7ba..00000000
--- a/java/jni/tinyb/DBusManager.cxx
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothAdapter.hpp"
-#include "tinyb/BluetoothDevice.hpp"
-#include "tinyb/BluetoothGattService.hpp"
-#include "tinyb/BluetoothManager.hpp"
-
-#include "tinyb_dbus_DBusManager.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusManager_getBluetoothType(JNIEnv *env, jobject obj)
-{
- try {
- (void)obj;
-
- return get_bluetooth_type(env, "NONE");
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-static void getObject_setter(JNIEnv *env,
- jstring name, std::string **name_to_write,
- jstring identifier, std::string **identifier_to_write,
- jobject parent, BluetoothObject **b_parent)
-{
- try {
- if (!parent)
- {
- *b_parent = nullptr;
- }
- else
- {
- *b_parent = getInstance<BluetoothObject>(env, parent);
- }
-
- if (!name)
- {
- *name_to_write = nullptr;
- }
- else
- {
- *name_to_write = new std::string(from_jstring_to_string(env, name));
- }
-
- if (!identifier)
- {
- *identifier_to_write = nullptr;
- }
- else
- {
- *identifier_to_write = new std::string(from_jstring_to_string(env, identifier));
- }
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-static void getObject_cleaner(std::string *name_to_write, std::string *identifier_to_write)
-{
- if (name_to_write != nullptr)
- delete name_to_write;
-
- if (identifier_to_write != nullptr)
- delete identifier_to_write;
-}
-
-jobject Java_tinyb_dbus_DBusManager_find(JNIEnv *env, jobject obj, jint type,
- jstring name, jstring identifier, jobject parent,
- jlong milliseconds)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- BluetoothObject *b_parent;
- BluetoothType b_type;
- std::string *name_to_write;
- std::string *identifier_to_write;
-
- getObject_setter(env,
- name, &name_to_write,
- identifier, &identifier_to_write,
- parent, &b_parent);
-
- b_type = from_int_to_btype((int)type);
- std::unique_ptr<BluetoothObject> b_object = manager->find(b_type, name_to_write,
- identifier_to_write,
- b_parent,
- std::chrono::milliseconds(milliseconds));
- getObject_cleaner(name_to_write, identifier_to_write);
-
- BluetoothObject *b_object_naked = b_object.release();
- if (!b_object_naked)
- {
- return nullptr;
- }
- jclass clazz = search_class(env, *b_object_naked);
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", "(J)V", false);
-
- jobject result = env->NewObject(clazz, clazz_ctor, (jlong)b_object_naked);
-
- return result;
-
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-
-jobject Java_tinyb_dbus_DBusManager_getObject(JNIEnv *env, jobject obj, jint type,
- jstring name, jstring identifier, jobject parent)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- BluetoothObject *b_parent;
- BluetoothType b_type;
- std::string *name_to_write;
- std::string *identifier_to_write;
-
- getObject_setter(env,
- name, &name_to_write,
- identifier, &identifier_to_write,
- parent, &b_parent);
-
- b_type = from_int_to_btype((int)type);
- std::unique_ptr<BluetoothObject> b_object = manager->get_object(b_type, name_to_write,
- identifier_to_write,
- b_parent);
- getObject_cleaner(name_to_write, identifier_to_write);
-
- BluetoothObject *b_object_naked = b_object.release();
- if (!b_object_naked)
- {
- return nullptr;
- }
- jclass clazz = search_class(env, *b_object_naked);
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", "(J)V", false);
-
- jobject result = env->NewObject(clazz, clazz_ctor, (jlong)b_object_naked);
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusManager_getObjects(JNIEnv *env, jobject obj, jint type,
- jstring name, jstring identifier, jobject parent)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- BluetoothObject *b_parent;
- BluetoothType b_type;
- std::string *name_to_write;
- std::string *identifier_to_write;
-
- getObject_setter(env,
- name, &name_to_write,
- identifier, &identifier_to_write,
- parent, &b_parent);
-
- b_type = from_int_to_btype((int)type);
- std::vector<std::unique_ptr<BluetoothObject>> array = manager->get_objects(b_type,
- name_to_write,
- identifier_to_write,
- b_parent);
- getObject_cleaner(name_to_write, identifier_to_write);
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothObject>>, BluetoothObject>(
- env, array, "(J)V");
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusManager_getAdapters(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
-
- std::vector<std::unique_ptr<BluetoothAdapter>> array = manager->get_adapters();
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothAdapter>>, BluetoothAdapter>(
- env, array, "(J)V");
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusManager_getDevices(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
-
- std::vector<std::unique_ptr<BluetoothDevice>> array = manager->get_devices();
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothDevice>>, BluetoothDevice>(
- env, array, "(J)V");
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jobject Java_tinyb_dbus_DBusManager_getServices(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
-
- std::vector<std::unique_ptr<BluetoothGattService>> array = manager->get_services();
- jobject result = convert_vector_uniqueptr_to_jarraylist<std::vector<std::unique_ptr<BluetoothGattService>>, BluetoothGattService>(
- env, array, "(J)V");
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
-
-jboolean Java_tinyb_dbus_DBusManager_setDefaultAdapter(JNIEnv *env, jobject obj, jobject adapter)
-{
- try {
- if (adapter == nullptr)
- throw std::invalid_argument("adapter argument is null\n");
-
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- BluetoothAdapter *b_adapter = getInstance<BluetoothAdapter>(env, adapter);
-
- return manager->set_default_adapter(*b_adapter);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jobject Java_tinyb_dbus_DBusManager_getDefaultAdapter(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
-
- std::unique_ptr<tinyb::BluetoothAdapter> b_adapter = manager->get_default_adapter();
- BluetoothAdapter *b_adapter_naked = b_adapter.release();
- if (!b_adapter_naked)
- {
- return nullptr;
- }
- jclass clazz = search_class(env, *b_adapter_naked);
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", "(J)V", false);
-
- jobject result = env->NewObject(clazz, clazz_ctor, (jlong)b_adapter_naked);
- return result;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return NULL;
-}
-
-jboolean Java_tinyb_dbus_DBusManager_startDiscovery(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- return manager->start_discovery() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusManager_stopDiscoveryImpl(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- return manager->start_discovery() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_tinyb_dbus_DBusManager_getDiscovering(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- return manager->get_discovering() ? JNI_TRUE : JNI_FALSE;
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-void Java_tinyb_dbus_DBusManager_init(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = BluetoothManager::get_bluetooth_manager();
- setInstance<BluetoothManager>(env, obj, manager);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-void Java_tinyb_dbus_DBusManager_delete(JNIEnv *env, jobject obj)
-{
- try {
- BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
- (void) manager;
- // delete manager; // Should not be called!
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
-}
-
-jstring Java_tinyb_dbus_DBusManager_getNativeAPIVersion(JNIEnv *env, jclass clazz)
-{
- try {
- (void) clazz;
-
- BluetoothManager *manager = BluetoothManager::get_bluetooth_manager();
- return env->NewStringUTF(manager->get_api_version().c_str());
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return nullptr;
-}
diff --git a/java/jni/tinyb/DBusObject.cxx b/java/jni/tinyb/DBusObject.cxx
deleted file mode 100644
index 1ab749f6..00000000
--- a/java/jni/tinyb/DBusObject.cxx
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "tinyb/BluetoothObject.hpp"
-
-#include "tinyb_dbus_DBusObject.h"
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-using namespace jau;
-
-jobject Java_tinyb_dbus_DBusObject_getBluetoothType(JNIEnv *env, jobject obj)
-{
- (void)obj;
-
- return get_bluetooth_type(env, "NONE");
-}
-
-jobject Java_tinyb_dbus_DBusObject_clone(JNIEnv *env, jobject obj)
-{
- return generic_clone<BluetoothObject>(env, obj);
-}
-
-void Java_tinyb_dbus_DBusObject_delete(JNIEnv *env, jobject obj)
-{
- BluetoothObject *obj_b = getInstance<BluetoothObject>(env, obj);
-
- delete obj_b;
-}
-
-jboolean Java_tinyb_dbus_DBusObject_operatorEqual(JNIEnv *env, jobject obj, jobject other)
-{
- if (!other)
- {
- return JNI_FALSE;
- }
- BluetoothObject *obj_b = getInstance<BluetoothObject>(env, obj);
- BluetoothObject *obj_other = getInstance<BluetoothObject>(env, other);
-
- return (*obj_b) == (*obj_other);
-}
-
-jstring Java_tinyb_dbus_DBusObject_getObjectPath(JNIEnv *env, jobject obj)
-{
- BluetoothObject *obj_b = getInstance<BluetoothObject>(env, obj);
-
- return env->NewStringUTF(obj_b->get_object_path().c_str());
-}
-
diff --git a/java/jni/tinyb/helper_tinyb.cxx b/java/jni/tinyb/helper_tinyb.cxx
deleted file mode 100644
index 8777f024..00000000
--- a/java/jni/tinyb/helper_tinyb.cxx
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Author: Sven Gothel <[email protected]>
- * Copyright (c) 2020 Gothel Software e.K.
- * Copyright (c) 2020 ZAFENA AB
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <jni.h>
-#include <memory>
-#include <stdexcept>
-#include <vector>
-
-#include "helper_tinyb.hpp"
-
-using namespace tinyb;
-
-jclass tinyb::search_class(JNIEnv *env, BluetoothObject &object)
-{
- return jau::search_class(env, object.get_java_class().c_str());
-}
-
-BluetoothType tinyb::from_int_to_btype(int type)
-{
- BluetoothType result = BluetoothType::NONE;
-
- switch (type)
- {
- case 0:
- result = BluetoothType::NONE;
- break;
-
- case 1:
- result = BluetoothType::ADAPTER;
- break;
-
- case 2:
- result = BluetoothType::DEVICE;
- break;
-
- case 3:
- result = BluetoothType::GATT_SERVICE;
- break;
-
- case 4:
- result = BluetoothType::GATT_CHARACTERISTIC;
- break;
-
- case 5:
- result = BluetoothType::GATT_CHARACTERISTIC;
- break;
-
- default:
- result = BluetoothType::NONE;
- break;
- }
-
- return result;
-}
-
-TransportType tinyb::from_int_to_transport_type(int type)
-{
- TransportType result = TransportType::AUTO;
-
- switch (type)
- {
- case 0:
- result = TransportType::AUTO;
- break;
-
- case 1:
- result = TransportType::BREDR;
- break;
-
- case 2:
- result = TransportType::LE;
- break;
-
- default:
- result = TransportType::AUTO;
- break;
- }
-
- return result;
-}
-
-void tinyb::raise_java_bluetooth_exception(JNIEnv *env, BluetoothException &e)
-{
- env->ThrowNew(env->FindClass("org/direct_bt/BTException"), e.what());
-}
-
diff --git a/java/jni/tinyb/helper_tinyb.hpp b/java/jni/tinyb/helper_tinyb.hpp
deleted file mode 100644
index cdfad29c..00000000
--- a/java/jni/tinyb/helper_tinyb.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Author: Andrei Vasiliu <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Author: Sven Gothel <[email protected]>
- * Copyright (c) 2020 Gothel Software e.K.
- * Copyright (c) 2020 ZAFENA AB
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#pragma once
-
-#include "helper_base.hpp"
-
-#include "tinyb/BluetoothObject.hpp"
-#include "tinyb/BluetoothException.hpp"
-
-namespace tinyb {
-
- jclass search_class(JNIEnv *env, BluetoothObject &object);
- BluetoothType from_int_to_btype(int type);
- TransportType from_int_to_transport_type(int type);
-
- void raise_java_bluetooth_exception(JNIEnv *env, BluetoothException &e);
-
-} // namespace tinyb