aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-01-31 07:00:18 +0100
committerSven Gothel <[email protected]>2020-01-31 07:00:18 +0100
commitb88401a0bd3043e6ecf5bfdc5a99a10cf36b31d6 (patch)
tree5f7533a3b95c643a00dfbf5cf4e776667da78bcb
parent031145ae81daa3583ddc2bb04b7b730d48cd67c8 (diff)
Expose BluetoothDevice async calls: device1_call_connect(..) / device1_call_connect_finish via Java connectAsyncStart() and connectAsyncFinish()
-rw-r--r--api/tinyb/BluetoothDevice.hpp9
-rw-r--r--java/BluetoothDevice.java10
-rw-r--r--java/jni/BluetoothDevice.cxx39
-rw-r--r--src/BluetoothDevice.cpp23
4 files changed, 81 insertions, 0 deletions
diff --git a/api/tinyb/BluetoothDevice.hpp b/api/tinyb/BluetoothDevice.hpp
index cef30504..e3300b56 100644
--- a/api/tinyb/BluetoothDevice.hpp
+++ b/api/tinyb/BluetoothDevice.hpp
@@ -106,6 +106,15 @@ public:
bool disconnect (
);
+ /** An asynchronous connection to this device is initiated,
+ * connecting each profile flagged as auto-connectable.
+ */
+ void connect_async_start ();
+
+ /** Completion of the initiated asynchronous connection.
+ */
+ bool connect_async_finish ();
+
/** A connection to this device is established, connecting each profile
* flagged as auto-connectable.
* @return TRUE if the device connected
diff --git a/java/BluetoothDevice.java b/java/BluetoothDevice.java
index fa7b1fe0..da077117 100644
--- a/java/BluetoothDevice.java
+++ b/java/BluetoothDevice.java
@@ -75,6 +75,16 @@ public class BluetoothDevice extends BluetoothObject
*/
public native boolean disconnect() throws BluetoothException;
+ /** An asynchronous connection to this device is initiated,
+ * connecting each profile flagged as auto-connectable.
+ */
+ public native void connectAsyncStart() throws BluetoothException;
+
+ /** Completion of the initiated asynchronous connection.
+ * @return TRUE if the device connected
+ */
+ public native boolean connectAsyncFinish() throws BluetoothException;
+
/** A connection to this device is established, connecting each profile
* flagged as auto-connectable.
* @return TRUE if the device connected
diff --git a/java/jni/BluetoothDevice.cxx b/java/jni/BluetoothDevice.cxx
index 387c9559..5f9dcf41 100644
--- a/java/jni/BluetoothDevice.cxx
+++ b/java/jni/BluetoothDevice.cxx
@@ -92,6 +92,45 @@ jboolean Java_tinyb_BluetoothDevice_disconnect(JNIEnv *env, jobject obj)
return JNI_FALSE;
}
+void Java_tinyb_BluetoothDevice_connectAsyncStart(JNIEnv *env, jobject obj)
+{
+ try {
+ BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
+
+ obj_device->connect_async_start();
+ } catch (std::bad_alloc &e) {
+ raise_java_oom_exception(env, e);
+ } catch (BluetoothException &e) {
+ raise_java_bluetooth_exception(env, e);
+ } catch (std::runtime_error &e) {
+ raise_java_runtime_exception(env, e);
+ } catch (std::invalid_argument &e) {
+ raise_java_invalid_arg_exception(env, e);
+ } catch (std::exception &e) {
+ raise_java_exception(env, e);
+ }
+}
+
+jboolean Java_tinyb_BluetoothDevice_connectAsyncFinish(JNIEnv *env, jobject obj)
+{
+ try {
+ BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
+
+ return obj_device->connect_async_finish() ? JNI_TRUE : JNI_FALSE;
+ } catch (std::bad_alloc &e) {
+ raise_java_oom_exception(env, e);
+ } catch (BluetoothException &e) {
+ raise_java_bluetooth_exception(env, e);
+ } catch (std::runtime_error &e) {
+ raise_java_runtime_exception(env, e);
+ } catch (std::invalid_argument &e) {
+ raise_java_invalid_arg_exception(env, e);
+ } catch (std::exception &e) {
+ raise_java_exception(env, e);
+ }
+ return JNI_FALSE;
+}
+
jboolean Java_tinyb_BluetoothDevice_connect(JNIEnv *env, jobject obj)
{
try {
diff --git a/src/BluetoothDevice.cpp b/src/BluetoothDevice.cpp
index d860f8ab..31a9736d 100644
--- a/src/BluetoothDevice.cpp
+++ b/src/BluetoothDevice.cpp
@@ -242,6 +242,29 @@ bool BluetoothDevice::disconnect ()
return result;
}
+void BluetoothDevice::connect_async_start ()
+{
+ device1_call_connect (
+ object, // Device1 *proxy,
+ NULL, // GCancellable *cancellable,
+ NULL, // GAsyncReadyCallback callback,
+ NULL // gpointer user_data)
+ );
+}
+
+bool BluetoothDevice::connect_async_finish ()
+{
+ GError *error = NULL;
+ bool result;
+ result = device1_call_connect_finish (
+ object, // Device1 *proxy,
+ NULL, // GAsyncResult *res,
+ &error // GError **error)
+ );
+ handle_error(error);
+ return result;
+}
+
bool BluetoothDevice::connect ()
{
GError *error = NULL;