aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-18 06:50:15 +0200
committerSven Gothel <[email protected]>2020-06-18 06:50:15 +0200
commitb899d56e49d06ce9fe955eb903f84f1e47644056 (patch)
tree690a147cc819042416d8f8cbc1b9c050b7a05c94
parentacdce5a21b676b6b83b62a48b11d2000895ca9eb (diff)
Direct-BT: API doc and clarify interface JavaAnonObj, JavaUplink and JavaAnonObj implementation JavaGlobalObj
JavaAnonObj is now a full virtual interface. JavaGlobalObj gets default spec for copy and move ctor and assignment.
-rw-r--r--api/direct_bt/JavaUplink.hpp14
-rw-r--r--java/jni/direct_bt/helper_dbt.hpp10
2 files changed, 22 insertions, 2 deletions
diff --git a/api/direct_bt/JavaUplink.hpp b/api/direct_bt/JavaUplink.hpp
index bea38e4..601bafd 100644
--- a/api/direct_bt/JavaUplink.hpp
+++ b/api/direct_bt/JavaUplink.hpp
@@ -33,15 +33,27 @@ namespace direct_bt {
#define JAVA_DBT_PACKAGE "direct_bt/tinyb/"
+ /**
+ * Pure virtual JavaAnonObj, hiding Java JNI details from API,
+ * to be implemented by JNI module.
+ * <p>
+ * One implementation is JavaGlobalObj within the JNI module,
+ * wrapping a JNIGlobalRef instance.
+ * </p>
+ */
class JavaAnonObj {
public:
virtual ~JavaAnonObj() { }
virtual std::string toString() const { return "JavaAnonObj[???]"; }
/** Clears the java reference, i.e. nulling it, without deleting the global reference via JNI. */
- virtual void clear() { }
+ virtual void clear() = 0;
};
+ /**
+ * Sharing the anonymous Java object (JavaAnonObj),
+ * i.e. exposing the Java object uplink to the C++ implementation.
+ */
class JavaUplink {
private:
std::shared_ptr<JavaAnonObj> javaObjectRef;
diff --git a/java/jni/direct_bt/helper_dbt.hpp b/java/jni/direct_bt/helper_dbt.hpp
index b2f002d..40e2c60 100644
--- a/java/jni/direct_bt/helper_dbt.hpp
+++ b/java/jni/direct_bt/helper_dbt.hpp
@@ -52,6 +52,10 @@ namespace direct_bt {
};
extern DirectBTJNISettings directBTJNISettings;
+ /**
+ * Implementation for JavaAnonObj,
+ * by simply wrapping a JNIGlobalRef instance.
+ */
class JavaGlobalObj : public JavaAnonObj {
private:
JNIGlobalRef javaObjectRef;
@@ -77,7 +81,11 @@ namespace direct_bt {
return true;
}
JavaGlobalObj(jobject obj) : javaObjectRef(obj) { }
- ~JavaGlobalObj() override { }
+
+ JavaGlobalObj(const JavaGlobalObj &o) noexcept = default;
+ JavaGlobalObj(JavaGlobalObj &&o) noexcept = default;
+ JavaGlobalObj& operator=(const JavaGlobalObj &o) noexcept = default;
+ JavaGlobalObj& operator=(JavaGlobalObj &&o) noexcept = default;
std::string toString() const override {
const uint64_t ref = (uint64_t)(void*)javaObjectRef.getObject();