jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Classes | Namespaces | Macros | Typedefs | Functions
helper_jni.hpp File Reference
#include <limits>
#include <vector>
#include <memory>
#include <jni.h>
#include <jau/java_uplink.hpp>
#include <jau/basic_algos.hpp>
#include <jau/basic_types.hpp>
#include <jau/darray.hpp>
#include <jau/io_util.hpp>
#include <jau/functional.hpp>
#include <jau/jni/jni_mem.hpp>
Include dependency graph for helper_jni.hpp:

Go to the source code of this file.

Classes

class  jau::jni::JavaGlobalObj
 Implementation for JavaAnon, by simply wrapping a JNIGlobalRef instance. More...
 
class  jau::jni::shared_ptr_ref< T >
 A std::shared_ptr<T> storage instance to be copied from and released into a java object's long nativeInstance field. More...
 

Namespaces

namespace  jau
 __pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
 
namespace  jau::jni
 

Macros

#define rethrow_and_raise_java_exception_jau(E)   jau::jni::rethrow_and_raise_java_exception_jauimpl((E), __FILE__, __LINE__)
 Re-throw current exception and raise respective java exception using any matching function above. More...
 

Typedefs

typedef std::shared_ptr< JavaGlobalObj > jau::jni::JavaGlobalObjRef
 

Functions

template<typename T >
std::shared_ptr< T > * jau::jni::castInstance (jlong instance, const bool throw_on_nullptr=true)
 Returns the cast shared_ptr<T> pointer from the java object's long nativeInstance field. More...
 
template<typename T >
void jau::jni::clearInstance (JNIEnv *env, jobject obj)
 Deletes the std::shared_ptr<T> storage of the java object if exists and write nullptr into its long nativeInstance field. More...
 
template<class byte_container_type , std::enable_if_t< std::is_integral_v< typename byte_container_type::value_type > &&std::is_convertible_v< typename byte_container_type::value_type, jbyte >, bool > = true>
jbyteArray jau::jni::convert_bytes_to_jbytearray (JNIEnv *env, const byte_container_type &data)
 
template<typename T >
jobject jau::jni::convert_instance_to_jobject (JNIEnv *env, const std::shared_ptr< T > &elem, const char *ctor_prototype, jau::function< jobject(JNIEnv *, jclass, jmethodID, const std::shared_ptr< T > &)> ctor)
 
template<typename T >
jobject jau::jni::convert_instance_to_jobject (JNIEnv *env, jclass clazz, const char *ctor_prototype, jau::function< jobject(JNIEnv *, jclass, jmethodID, const std::shared_ptr< T > &)> ctor, const std::shared_ptr< T > &elem)
 
std::vector< std::string > jau::jni::convert_jlist_string_to_vector (JNIEnv *env, jobject jlist)
 
jobject jau::jni::convert_vector_bytes_to_jarraylist (JNIEnv *env, const std::vector< std::vector< uint8_t > > &array)
 
template<typename T >
jobject jau::jni::convert_vector_sharedptr_to_jarraylist (JNIEnv *env, T &array)
 
template<typename T , typename U >
jobject jau::jni::convert_vector_sharedptr_to_jarraylist (JNIEnv *env, T &array, const char *ctor_prototype, jau::function< jobject(JNIEnv *, jclass, jmethodID, const std::shared_ptr< U > &)> ctor)
 
template<typename T , typename U >
jobject jau::jni::convert_vector_sharedptr_to_jarraylist (JNIEnv *env, T &array, jau::function< jobject(JNIEnv *, const std::shared_ptr< U > &)> ctor)
 
jobject jau::jni::convert_vector_string_to_jarraylist (JNIEnv *env, const std::vector< std::string > &array)
 
jobject jau::jni::convert_vector_stringview_to_jarraylist (JNIEnv *env, const std::vector< std::string_view > &array)
 
template<typename T , typename U >
jobject jau::jni::convert_vector_to_jarraylist (JNIEnv *env, T &array, jau::function< jobject(JNIEnv *, const U &)> ctor)
 
bool jau::jni::from_jboolean_to_bool (const jboolean val)
 
jau::io::secure_string jau::jni::from_jbytebuffer_to_sstring (JNIEnv *env, jobject jbytebuffer)
 
std::string jau::jni::from_jstring_to_string (JNIEnv *env, jstring str)
 
jstring jau::jni::from_string_to_jstring (JNIEnv *env, const std::string &str)
 
jobject jau::jni::get_new_arraylist (JNIEnv *env, jsize size, jmethodID *add)
 
jfieldID jau::jni::getField (JNIEnv *env, jobject obj, const char *field_name, const char *field_signature)
 
template<typename T >
std::shared_ptr< T > * jau::jni::getInstance (JNIEnv *env, jobject obj, const bool throw_on_nullptr=true)
 Returns the cast shared_ptr<T> pointer from the java object's long nativeInstance field. More...
 
jfieldID jau::jni::getInstanceField (JNIEnv *env, jobject obj)
 
jint jau::jni::getIntFieldValue (JNIEnv *env, jobject obj, const char *field_name)
 
jlong jau::jni::getLongFieldValue (JNIEnv *env, jobject obj, const char *field_name)
 
jobject jau::jni::getObjectFieldValue (JNIEnv *env, jobject obj, const char *field_name, const char *field_signature)
 
template<typename T >
T * jau::jni::getObjectRef (JNIEnv *env, jobject obj, const char *field_name)
 
std::string jau::jni::getStringFieldValue (JNIEnv *env, jobject obj, const char *field_name)
 
bool jau::jni::java_exception_check (JNIEnv *env, const char *file, int line)
 Return true if a java exception occurred, otherwise false. More...
 
void jau::jni::java_exception_check_and_throw (JNIEnv *env, const char *file, int line)
 Throws a C++ exception if a java exception occurred, otherwise do nothing. More...
 
void jau::jni::print_native_caught_exception_fwd2java (const char *cmsg, const char *file, int line)
 
void jau::jni::print_native_caught_exception_fwd2java (const jau::OutOfMemoryError &e, const char *file, int line)
 
void jau::jni::print_native_caught_exception_fwd2java (const jau::RuntimeException &e, const char *file, int line)
 
void jau::jni::print_native_caught_exception_fwd2java (const std::exception &e, const char *file, int line)
 
void jau::jni::print_native_caught_exception_fwd2java (const std::string &msg, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::IllegalArgumentException &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::IllegalStateException &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::IndexOutOfBoundsException &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::InternalError &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::NullPointerException &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::OutOfMemoryError &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::RuntimeException &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const jau::UnsupportedOperationException &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const std::bad_alloc &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const std::exception &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const std::invalid_argument &e, const char *file, int line)
 
void jau::jni::raise_java_exception (JNIEnv *env, const std::runtime_error &e, const char *file, int line)
 
void jau::jni::rethrow_and_raise_java_exception_jauimpl (JNIEnv *env, const char *file, int line)
 Re-throw current exception and raise respective java exception using any matching function above. More...
 
jclass jau::jni::search_class (JNIEnv *env, const char *clazz_name)
 
jclass jau::jni::search_class (JNIEnv *env, JavaUplink &object)
 
jclass jau::jni::search_class (JNIEnv *env, jobject obj)
 
jfieldID jau::jni::search_field (JNIEnv *env, jclass clazz, const char *field_name, const char *type, bool is_static)
 
jmethodID jau::jni::search_method (JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
 
template<typename T >
void jau::jni::setInstance (JNIEnv *env, jobject obj, const std::shared_ptr< T > &t)
 Deletes the std::shared_ptr<T> storage of the java object if exists first and writes the given std::shared_ptr<T> storage pointer into its long nativeInstance field. More...
 
template<typename T >
void jau::jni::setObjectRef (JNIEnv *env, jobject obj, T *t, const char *field_name)