jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Classes | Typedefs | Functions | Variables
jau::jni Namespace Reference

Classes

class  JavaAnon
 Pure virtual JavaAnon, hiding Java JNI details from API, to be implemented by JNI module. More...
 
class  JavaGlobalObj
 Implementation for JavaAnon, by simply wrapping a JNIGlobalRef instance. More...
 
class  JavaUplink
 Sharing the anonymous Java object (JavaAnon), i.e. More...
 
class  JNICriticalArray
 
class  JNIEnvContainer
 
class  JNIGlobalRef
 
class  shared_ptr_ref
 A std::shared_ptr<T> storage instance to be copied from and released into a java object's long nativeInstance field. More...
 

Typedefs

typedef std::shared_ptr< JavaAnonJavaAnonRef
 
typedef std::shared_ptr< JavaGlobalObjJavaGlobalObjRef
 
typedef std::shared_ptr< JavaUplinkJavaUplinkRef
 

Functions

template<typename T >
std::shared_ptr< T > * 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 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 convert_bytes_to_jbytearray (JNIEnv *env, const byte_container_type &data)
 
template<typename T >
jobject 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 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 > convert_jlist_string_to_vector (JNIEnv *env, jobject jlist)
 
jobject convert_vector_bytes_to_jarraylist (JNIEnv *env, const std::vector< std::vector< uint8_t > > &array)
 
template<typename T >
jobject convert_vector_sharedptr_to_jarraylist (JNIEnv *env, T &array)
 
template<typename T , typename U >
jobject 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 convert_vector_sharedptr_to_jarraylist (JNIEnv *env, T &array, jau::function< jobject(JNIEnv *, const std::shared_ptr< U > &)> ctor)
 
jobject convert_vector_string_to_jarraylist (JNIEnv *env, const std::vector< std::string > &array)
 
jobject convert_vector_stringview_to_jarraylist (JNIEnv *env, const std::vector< std::string_view > &array)
 
template<typename T , typename U >
jobject convert_vector_to_jarraylist (JNIEnv *env, T &array, jau::function< jobject(JNIEnv *, const U &)> ctor)
 
bool from_jboolean_to_bool (const jboolean val)
 
jau::io::secure_string from_jbytebuffer_to_sstring (JNIEnv *env, jobject jbytebuffer)
 
std::string from_jstring_to_string (JNIEnv *env, jstring str)
 
jstring from_string_to_jstring (JNIEnv *env, const std::string &str)
 
jobject get_new_arraylist (JNIEnv *env, jsize size, jmethodID *add)
 
jfieldID getField (JNIEnv *env, jobject obj, const char *field_name, const char *field_signature)
 
template<typename T >
std::shared_ptr< T > * 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 getInstanceField (JNIEnv *env, jobject obj)
 
jint getIntFieldValue (JNIEnv *env, jobject obj, const char *field_name)
 
jlong getLongFieldValue (JNIEnv *env, jobject obj, const char *field_name)
 
jobject getObjectFieldValue (JNIEnv *env, jobject obj, const char *field_name, const char *field_signature)
 
template<typename T >
T * getObjectRef (JNIEnv *env, jobject obj, const char *field_name)
 
std::string getStringFieldValue (JNIEnv *env, jobject obj, const char *field_name)
 
bool java_exception_check (JNIEnv *env, const char *file, int line)
 Return true if a java exception occurred, otherwise false. More...
 
void 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 print_native_caught_exception_fwd2java (const char *cmsg, const char *file, int line)
 
void print_native_caught_exception_fwd2java (const jau::OutOfMemoryError &e, const char *file, int line)
 
void print_native_caught_exception_fwd2java (const jau::RuntimeException &e, const char *file, int line)
 
void print_native_caught_exception_fwd2java (const std::exception &e, const char *file, int line)
 
void print_native_caught_exception_fwd2java (const std::string &msg, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::IllegalArgumentException &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::IllegalStateException &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::IndexOutOfBoundsException &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::InternalError &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::NullPointerException &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::OutOfMemoryError &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::RuntimeException &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const jau::UnsupportedOperationException &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const std::bad_alloc &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const std::exception &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const std::invalid_argument &e, const char *file, int line)
 
void raise_java_exception (JNIEnv *env, const std::runtime_error &e, const char *file, int line)
 
void 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 search_class (JNIEnv *env, const char *clazz_name)
 
jclass search_class (JNIEnv *env, JavaUplink &object)
 
jclass search_class (JNIEnv *env, jobject obj)
 
jfieldID search_field (JNIEnv *env, jclass clazz, const char *field_name, const char *type, bool is_static)
 
jmethodID search_method (JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
 
template<typename T >
void 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 setObjectRef (JNIEnv *env, jobject obj, T *t, const char *field_name)
 

Variables

thread_local JNIEnvContainer jni_env
 
JavaVM * vm