diff options
author | Sven Gothel <[email protected]> | 2020-04-20 07:21:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-04-20 07:21:35 +0200 |
commit | de9058b333219c060aa2a61d8ff40ed084adac28 (patch) | |
tree | d0781f9429e1385db02ad926ab1fc475cf41d86c /java/jni/JNIMem.hpp | |
parent | 1ddeb84eac79894642be5b382c21126fe55d8df0 (diff) |
Initial working Java binding for the direct_bt C++ module
Example ScannerTinyB01 demonstrates efficient scanning devices using the new BluetoothDeviceDiscoveryListener interface.
The C++ HCIObject extends JavaUplink, which handles the java object references
via 'std::shared_ptr<JavaAnonObj>', where JavaAnonObj relies on later polymorph specialization.
JavaAnonObj gets derived in the java/jni of direct_bt, where the JNI header + libraries are available.
+++
The java inplementing NativeDownlink implementations
store the nativeInstance to the C++ instances
as well as handle their java references within the native instances.
The C++ JavaUplink and Java NativeDownlink interfaces are complete
the cross referencing java <-> native.
+++
Native libraries are now split into pairs:
- tinyb + javatinyb
- direct_bt + javadirect_bt
TODO: BluetoothFactory must chose the proper bundle!
+++
The Java Adapter received a BluetoothDeviceDiscoveryListener hook,
matching C++ Adapter's HCIDeviceDiscoveryListener.
Since the Java Adapter implements its own discovery thread,
using the BluetoothDeviceDiscoveryListener is more efficient then polling
over a list of Devices fetched.
++++
TODO: Align Java and C++ class names, foremost in the C++ direct_bt space.
TODO: Bind the whole C++ GATT functionality
More testing.
Diffstat (limited to 'java/jni/JNIMem.hpp')
-rw-r--r-- | java/jni/JNIMem.hpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/java/jni/JNIMem.hpp b/java/jni/JNIMem.hpp index 389a915..a133bd9 100644 --- a/java/jni/JNIMem.hpp +++ b/java/jni/JNIMem.hpp @@ -2,6 +2,10 @@ * Author: Petre Eftime <[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 @@ -22,10 +26,14 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef JNIMEM__HPP_ +#define JNIMEM__HPP_ + #include <jni.h> #include <stdexcept> +#include "BasicTypes.hpp" + extern JavaVM* vm; @@ -67,12 +75,26 @@ private: jobject object; public: + static inline void check(jobject object, const char* file, int line) { + if( nullptr == object ) { + throw direct_bt::RuntimeException("JNIGlobalRef::check: Null jobject", file, line); + } + } + /* Creates a GlobalRef from an object passed to it */ JNIGlobalRef(jobject object); + /* Deletes the stored GlobalRef */ ~JNIGlobalRef(); - /* Provides access to the stored GlobalRef */ - jobject operator*(); + /* Provides access to the stored GlobalRef as an jobject. */ + jobject operator*() { return object; } + + /* Provides access to the stored GlobalRef as an jobject. */ + jobject getObject() const { return object; } + /* Provides access to the stored GlobalRef as a jclass. */ + jclass getClass() const { return (jclass)object; } }; +#endif /* JNIMEM__HPP_ */ + |