diff options
-rw-r--r-- | api/direct_bt/JavaUplink.hpp | 14 | ||||
-rw-r--r-- | java/jni/direct_bt/helper_dbt.hpp | 10 |
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(); |