Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
helper_jni.hpp
Go to the documentation of this file.
1 /*
2  * Author: Sven Gothel <sgothel@jausoft.com>
3  * Copyright (c) 2020 Gothel Software e.K.
4  * Copyright (c) 2020 ZAFENA AB
5  *
6  * Author: Andrei Vasiliu <andrei.vasiliu@intel.com>
7  * Copyright (c) 2016 Intel Corporation.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 
29 #ifndef JAU_HELPER_JNI_HPP_
30 #define JAU_HELPER_JNI_HPP_
31 
32 #include <vector>
33 #include <memory>
34 #include <functional>
35 #include <jni.h>
36 
37 #include <jau/java_uplink.hpp>
38 #include <jau/basic_types.hpp>
39 #include <jau/darray.hpp>
40 #include <jau/basic_algos.hpp>
41 
42 #include <jau/jni/jni_mem.hpp>
43 
44 namespace jau {
45 
46  //
47  // C++ <-> java exceptions
48  //
49 
50  /**
51  * Return true if a java exception occurred, otherwise false.
52  * <p>
53  * In case of an exception, the information might be logged to stderr.
54  * </p>
55  * <p>
56  * In case of an exception, user shall release resourced in their JNI code
57  * and leave immediately.
58  * </p>
59  */
60  bool java_exception_check(JNIEnv *env, const char* file, int line);
61 
62  /**
63  * Throws a C++ exception if a java exception occurred, otherwise do nothing.
64  * <p>
65  * In case of an exception, the information might be logged to stderr.
66  * </p>
67  * <p>
68  * In case of an exception and hence thrown C++ exception,
69  * might want to catch all and handle it via {@link #rethrow_and_raise_java_exception(JNIEnv*)}.
70  * </p>
71  */
72  void java_exception_check_and_throw(JNIEnv *env, const char* file, int line);
73 
74  void print_native_caught_exception_fwd2java(const std::exception &e, const char* file, int line);
75  void print_native_caught_exception_fwd2java(const std::string &msg, const char* file, int line);
76  void print_native_caught_exception_fwd2java(const char * cmsg, const char* file, int line);
77 
78  void raise_java_exception(JNIEnv *env, const std::exception &e, const char* file, int line);
79  void raise_java_exception(JNIEnv *env, const std::runtime_error &e, const char* file, int line);
80  void raise_java_exception(JNIEnv *env, const jau::RuntimeException &e, const char* file, int line);
81  void raise_java_exception(JNIEnv *env, const jau::InternalError &e, const char* file, int line);
82  void raise_java_exception(JNIEnv *env, const jau::NullPointerException &e, const char* file, int line);
83  void raise_java_exception(JNIEnv *env, const jau::IllegalArgumentException &e, const char* file, int line);
84  void raise_java_exception(JNIEnv *env, const std::invalid_argument &e, const char* file, int line);
85  void raise_java_exception(JNIEnv *env, const jau::IllegalStateException &e, const char* file, int line);
86  void raise_java_exception(JNIEnv *env, const jau::UnsupportedOperationException &e, const char* file, int line);
87  void raise_java_exception(JNIEnv *env, const jau::IndexOutOfBoundsException &e, const char* file, int line);
88  void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line);
89  void raise_java_exception(JNIEnv *env, const jau::OutOfMemoryError &e, const char* file, int line);
90 
91  /**
92  * Re-throw current exception and raise respective java exception
93  * using any matching function above.
94  */
95  void rethrow_and_raise_java_exception_jauimpl(JNIEnv *env, const char* file, int line);
96 
97  /**
98  * Re-throw current exception and raise respective java exception
99  * using any matching function above.
100  */
101  #define rethrow_and_raise_java_exception_jau(E) rethrow_and_raise_java_exception_jauimpl((E), __FILE__, __LINE__)
102  // inline void rethrow_and_raise_java_exception_jau(JNIEnv *env) { rethrow_and_raise_java_exception_jauimpl(env, __FILE__, __LINE__); }
103 
104  //
105  // Basic
106  //
107 
108  jfieldID getField(JNIEnv *env, jobject obj, const char* field_name, const char* field_signature);
109  inline jfieldID getInstanceField(JNIEnv *env, jobject obj) {
110  return getField(env, obj, "nativeInstance", "J");
111  }
112 
113  jclass search_class(JNIEnv *env, const char *clazz_name);
114  jclass search_class(JNIEnv *env, jobject obj);
115  jclass search_class(JNIEnv *env, JavaUplink &object);
116 
117  jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name,
118  const char *prototype, bool is_static);
119  jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name,
120  const char *type, bool is_static);
121 
122  bool from_jboolean_to_bool(jboolean val);
123  std::string from_jstring_to_string(JNIEnv *env, jstring str);
124  jstring from_string_to_jstring(JNIEnv *env, const std::string & str);
125 
126  jobject get_new_arraylist(JNIEnv *env, jsize size, jmethodID *add);
127 
128  //
129  // C++ JavaAnon implementation
130  //
131 
132  /**
133  * Implementation for JavaAnon,
134  * by simply wrapping a JNIGlobalRef instance.
135  */
136  class JavaGlobalObj : public JavaAnon {
137  private:
138  JNIGlobalRef javaObjectRef;
139  jmethodID mNotifyDeleted;
140 
141  public:
142  static inline void check(const std::shared_ptr<JavaAnon> & shref, const char* file, int line) {
143  if( nullptr == shref ) {
144  throw RuntimeException("JavaGlobalObj::check: Null shared-JavaAnonObj", file, line);
145  }
146  if( 0 == shref.use_count() ) { // safe-guard for concurrent dtor
147  throw RuntimeException("JavaGlobalObj::check: Empty shared-JavaAnonObj", file, line);
148  }
149  const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject();
150  if( nullptr == obj ) {
151  throw RuntimeException("JavaGlobalObj::check: Null object", file, line);
152  }
153  }
154  static bool isValid(const std::shared_ptr<JavaAnon> & shref) noexcept {
155  if( nullptr == shref || 0 == shref.use_count() ) {
156  return false;
157  }
158  const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject();
159  if( nullptr == obj ) {
160  return false;
161  }
162  return true;
163  }
164  JavaGlobalObj(jobject obj, jmethodID mNotifyDeleted_) noexcept
165  : javaObjectRef(obj), mNotifyDeleted(mNotifyDeleted_) { }
166 
167  JavaGlobalObj(const JavaGlobalObj &o) noexcept = default;
168  JavaGlobalObj(JavaGlobalObj &&o) noexcept = default;
169  JavaGlobalObj& operator=(const JavaGlobalObj &o) noexcept = default;
170  JavaGlobalObj& operator=(JavaGlobalObj &&o) noexcept = default;
171 
172  virtual ~JavaGlobalObj() noexcept;
173 
174  std::string toString() const noexcept override {
175  const uint64_t ref = (uint64_t)(void*)javaObjectRef.getObject();
176  return "JavaGlobalObj["+to_hexstring(ref)+"]";
177  }
178 
179  /** Clears the java reference, i.e. nulling it, without deleting the global reference via JNI. */
180  void clear() noexcept override { javaObjectRef.clear(); }
181 
182  JNIGlobalRef & getJavaObject() noexcept { return javaObjectRef; }
183 
184  /* Provides access to the stored GlobalRef as an jobject. */
185  jobject getObject() const noexcept { return javaObjectRef.getObject(); }
186  /* Provides access to the stored GlobalRef as a jclass. */
187  jclass getClass() const noexcept { return javaObjectRef.getClass(); }
188 
189  /* Provides access to the stored GlobalRef as an getJavaObject. */
190  static JNIGlobalRef GetJavaObject(const std::shared_ptr<JavaAnon> & shref) noexcept {
191  return static_cast<JavaGlobalObj*>(shref.get())->getJavaObject();
192  }
193  /* Provides access to the stored GlobalRef as an jobject. */
194  static jobject GetObject(const std::shared_ptr<JavaAnon> & shref) noexcept {
195  return static_cast<JavaGlobalObj*>(shref.get())->getObject();
196  }
197 
198  /* Provides access to the stored GlobalRef as a jclass. */
199  static jclass GetClass(const std::shared_ptr<JavaAnon> & shref) noexcept {
200  return static_cast<JavaGlobalObj*>(shref.get())->getClass();
201  }
202  };
203 
204  //
205  // C++ JavaUplink <-> java access, assuming it implementats JavaUplink: field "long nativeInstance" and native method 'void checkValid()' etc
206  //
207 
208  template <typename T>
209  T *getJavaUplinkObject(JNIEnv *env, jobject obj)
210  {
211  jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
212  T *t = reinterpret_cast<T *>(instance);
213  if (t == nullptr) {
214  throw jau::RuntimeException("Trying to acquire null NativeObject", E_FILE_LINE);
215  }
216  t->checkValid();
217  return t;
218  }
219 
220  template <typename T>
221  T *getJavaUplinkObjectUnchecked(JNIEnv *env, jobject obj)
222  {
223  jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
224  return reinterpret_cast<T *>(instance);
225  }
226 
227  template <typename T>
228  void setJavaUplinkObject(JNIEnv *env, jobject obj, T *t)
229  {
230  if (t == nullptr) {
231  throw jau::RuntimeException("Trying to create null NativeObject", E_FILE_LINE);
232  }
233  jlong instance = reinterpret_cast<jlong>(t);
234  env->SetLongField(obj, getInstanceField(env, obj), instance);
235  }
236 
237  //
238  // C++ JavaAnon <-> java access, all generic
239  //
240 
241  template <typename T>
242  T *castInstance(jlong instance)
243  {
244  T *t = reinterpret_cast<T *>(instance);
245  if (t == nullptr) {
246  throw jau::RuntimeException("Trying to cast null object", E_FILE_LINE);
247  }
248  return t;
249  }
250 
251  template <typename T>
252  T *getObjectRef(JNIEnv *env, jobject obj, const char* field_name)
253  {
254  jlong jobj = env->GetLongField(obj, getField(env, obj, field_name, "J"));
256  return reinterpret_cast<T *>(jobj);
257  }
258 
259  template <typename T>
260  void setObjectRef(JNIEnv *env, jobject obj, T *t, const char* field_name)
261  {
262  jlong jobj = reinterpret_cast<jlong>(t);
263  env->SetLongField(obj, getField(env, obj, field_name, "J"), jobj);
265  }
266 
267  template <typename T>
268  T *getInstance(JNIEnv *env, jobject obj)
269  {
270  jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
271  T *t = reinterpret_cast<T *>(instance);
272  if (t == nullptr) {
273  throw jau::RuntimeException("Trying to acquire null object", E_FILE_LINE);
274  }
275  return t;
276  }
277 
278  template <typename T>
279  T *getInstanceUnchecked(JNIEnv *env, jobject obj)
280  {
281  jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
282  return reinterpret_cast<T *>(instance);
283  }
284 
285  template <typename T>
286  void setInstance(JNIEnv *env, jobject obj, T *t)
287  {
288  if (t == nullptr) {
289  throw jau::RuntimeException("Trying to create null object", E_FILE_LINE);
290  }
291  jlong instance = reinterpret_cast<jlong>(t);
292  env->SetLongField(obj, getInstanceField(env, obj), instance);
293  }
294 
295  inline void clearInstance(JNIEnv *env, jobject obj) {
296  env->SetLongField(obj, getInstanceField(env, obj), 0);
297  }
298 
299  template <typename T>
300  jobject generic_clone(JNIEnv *env, jobject obj)
301  {
302  T *obj_generic = getInstance<T>(env, obj);
303  T *copy_generic = obj_generic->clone();
304 
305  jclass generic_class = search_class(env, *copy_generic);
306  jmethodID generic_ctor = search_method(env, generic_class, "<init>", "(J)V", false);
307 
308  jobject result = env->NewObject(generic_class, generic_ctor, (jlong)copy_generic);
309  if (!result)
310  {
311  throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE);
312  }
313 
314  return result;
315  }
316 
317  //
318  // C++ <-> java type mapping
319  //
320 
321  template <typename T>
322  jobject convert_instance_to_jobject(JNIEnv *env, T *elem,
323  const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, T*)> ctor)
324  {
325  jclass clazz = search_class(env, T::java_class().c_str());
326  jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
327 
328  jobject object = ctor(env, clazz, clazz_ctor, elem);
329  if (!object)
330  {
331  throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE);
332  }
334 
335  return object;
336  }
337 
338  template <typename T>
339  jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T& array)
340  {
341  nsize_t array_size = array.size();
342 
343  jmethodID arraylist_add;
344  jobject result = get_new_arraylist(env, (jsize)array_size, &arraylist_add);
345 
346  if (0 == array_size) {
347  return result;
348  }
349 
350  jau::for_each(array.begin(), array.end(), [&](typename T::value_type & elem){
351  std::shared_ptr<JavaAnon> objref = elem->getJavaObject();
352  if ( nullptr == objref ) {
353  throw InternalError("JavaUplink element of array has no valid java-object: "+elem->toString(), E_FILE_LINE);
354  }
355  env->CallBooleanMethod(result, arraylist_add, JavaGlobalObj::GetObject(objref));
356  });
357  return result;
358  }
359 
360  template <typename T, typename U>
361  jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, T& array, const char *ctor_prototype)
362  {
363  unsigned int array_size = array.size();
364 
365  jmethodID arraylist_add;
366  jobject result = get_new_arraylist(env, array_size, &arraylist_add);
367 
368  if (array_size == 0)
369  {
370  return result;
371  }
372 
373  jclass clazz = search_class(env, U::java_class().c_str());
374  jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
375 
376  for (unsigned int i = 0; i < array_size; ++i)
377  {
378  U *elem = array[i].release();
379  jobject object = env->NewObject(clazz, clazz_ctor, (jlong)elem);
380  if (!object)
381  {
382  throw jau::InternalError("cannot create instance of class", E_FILE_LINE);
383  }
384  env->CallBooleanMethod(result, arraylist_add, object);
386  }
387  return result;
388  }
389 
390  template <typename T, typename U>
391  jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, T& array,
392  const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, U*)> ctor)
393  {
394  unsigned int array_size = array.size();
395 
396  jmethodID arraylist_add;
397  jobject result = get_new_arraylist(env, array_size, &arraylist_add);
398 
399  if (array_size == 0)
400  {
401  return result;
402  }
403 
404  jclass clazz = search_class(env, U::java_class().c_str());
405  jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
406 
407  for (unsigned int i = 0; i < array_size; ++i)
408  {
409  U *elem = array[i].release();
410  jobject object = ctor(env, clazz, clazz_ctor, elem);
411  if (!object)
412  {
413  throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE);
414  }
415  env->CallBooleanMethod(result, arraylist_add, object);
417  }
418  return result;
419  }
420 
421  template <typename T, typename U>
422  jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T& array,
423  const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, U*)> ctor)
424  {
425  unsigned int array_size = array.size();
426 
427  jmethodID arraylist_add;
428  jobject result = get_new_arraylist(env, array_size, &arraylist_add);
429 
430  if (array_size == 0)
431  {
432  return result;
433  }
434 
435  jclass clazz = search_class(env, U::java_class().c_str());
436  jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
437 
438  for (unsigned int i = 0; i < array_size; ++i)
439  {
440  U *elem = array[i].get();
441  jobject object = ctor(env, clazz, clazz_ctor, elem);
442  if (!object)
443  {
444  throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE);
445  }
446  env->CallBooleanMethod(result, arraylist_add, object);
448  }
449  return result;
450  }
451 
452 } // namespace direct_bt
453 
454 #endif /* JAU_HELPER_JNI_HPP_ */
jau::JavaGlobalObj::operator=
JavaGlobalObj & operator=(const JavaGlobalObj &o) noexcept=default
jau::JavaGlobalObj::~JavaGlobalObj
virtual ~JavaGlobalObj() noexcept
jau::from_jstring_to_string
std::string from_jstring_to_string(JNIEnv *env, jstring str)
jau::castInstance
T * castInstance(jlong instance)
Definition: helper_jni.hpp:242
JNIGlobalRef::clear
void clear() noexcept
Clears the java reference, i.e.
jau::setObjectRef
void setObjectRef(JNIEnv *env, jobject obj, T *t, const char *field_name)
Definition: helper_jni.hpp:260
jau::convert_vector_sharedptr_to_jarraylist
jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T &array)
Definition: helper_jni.hpp:339
jau::getField
jfieldID getField(JNIEnv *env, jobject obj, const char *field_name, const char *field_signature)
jau::search_class
jclass search_class(JNIEnv *env, JavaUplink &object)
darray.hpp
jau::getJavaUplinkObjectUnchecked
T * getJavaUplinkObjectUnchecked(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:221
jau::getObjectRef
T * getObjectRef(JNIEnv *env, jobject obj, const char *field_name)
Definition: helper_jni.hpp:252
basic_algos.hpp
jau::JavaGlobalObj::isValid
static bool isValid(const std::shared_ptr< JavaAnon > &shref) noexcept
Definition: helper_jni.hpp:154
jau::IllegalArgumentException
Definition: basic_types.hpp:111
jau::convert_vector_uniqueptr_to_jarraylist
jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, T &array, const char *ctor_prototype, std::function< jobject(JNIEnv *, jclass, jmethodID, U *)> ctor)
Definition: helper_jni.hpp:391
jau::from_string_to_jstring
jstring from_string_to_jstring(JNIEnv *env, const std::string &str)
jau::JavaGlobalObj::getJavaObject
JNIGlobalRef & getJavaObject() noexcept
Definition: helper_jni.hpp:182
jau::setJavaUplinkObject
void setJavaUplinkObject(JNIEnv *env, jobject obj, T *t)
Definition: helper_jni.hpp:228
jau::IndexOutOfBoundsException
Definition: basic_types.hpp:129
JNIGlobalRef::getObject
jobject getObject() const noexcept
Definition: jni_mem.hpp:108
jau::print_native_caught_exception_fwd2java
void print_native_caught_exception_fwd2java(const std::exception &e, const char *file, int line)
jau::InternalError
Definition: basic_types.hpp:93
JNIGlobalRef
Definition: jni_mem.hpp:75
jau::getInstanceUnchecked
T * getInstanceUnchecked(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:279
jau::java_exception_check
bool java_exception_check(JNIEnv *env, const char *file, int line)
Return true if a java exception occurred, otherwise false.
jau::for_each
constexpr UnaryFunction for_each(InputIt first, InputIt last, UnaryFunction f)
Like std::for_each() of 'algorithm'.
Definition: basic_algos.hpp:163
jau
Definition: basic_algos.hpp:34
jau::JavaGlobalObj::JavaGlobalObj
JavaGlobalObj(const JavaGlobalObj &o) noexcept=default
jau::JavaGlobalObj::JavaGlobalObj
JavaGlobalObj(JavaGlobalObj &&o) noexcept=default
jau::search_class
jclass search_class(JNIEnv *env, const char *clazz_name)
jau::java_exception_check_and_throw
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.
jni_mem.hpp
jau::convert_vector_sharedptr_to_jarraylist
jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T &array, const char *ctor_prototype, std::function< jobject(JNIEnv *, jclass, jmethodID, U *)> ctor)
Definition: helper_jni.hpp:422
E_FILE_LINE
#define E_FILE_LINE
Definition: basic_types.hpp:64
jau::JavaAnon
Pure virtual JavaAnon, hiding Java JNI details from API, to be implemented by JNI module.
Definition: java_uplink.hpp:44
jau::JavaGlobalObj::clear
void clear() noexcept override
Clears the java reference, i.e.
Definition: helper_jni.hpp:180
jau::search_method
jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
jau::rethrow_and_raise_java_exception_jauimpl
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.
jau::getJavaUplinkObject
T * getJavaUplinkObject(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:209
jau::JavaGlobalObj::toString
std::string toString() const noexcept override
Definition: helper_jni.hpp:174
jau::generic_clone
jobject generic_clone(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:300
jau::get_new_arraylist
jobject get_new_arraylist(JNIEnv *env, jsize size, jmethodID *add)
jau::JavaGlobalObj::JavaGlobalObj
JavaGlobalObj(jobject obj, jmethodID mNotifyDeleted_) noexcept
Definition: helper_jni.hpp:164
jau::raise_java_exception
void raise_java_exception(JNIEnv *env, const std::exception &e, const char *file, int line)
jau::setInstance
void setInstance(JNIEnv *env, jobject obj, T *t)
Definition: helper_jni.hpp:286
jau::JavaGlobalObj::operator=
JavaGlobalObj & operator=(JavaGlobalObj &&o) noexcept=default
jau::JavaGlobalObj::check
static void check(const std::shared_ptr< JavaAnon > &shref, const char *file, int line)
Definition: helper_jni.hpp:142
jau::JavaGlobalObj::GetJavaObject
static JNIGlobalRef GetJavaObject(const std::shared_ptr< JavaAnon > &shref) noexcept
Definition: helper_jni.hpp:190
jau::RuntimeException
Definition: basic_types.hpp:66
jau::clearInstance
void clearInstance(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:295
jau::JavaGlobalObj::GetObject
static jobject GetObject(const std::shared_ptr< JavaAnon > &shref) noexcept
Definition: helper_jni.hpp:194
jau::JavaGlobalObj::getObject
jobject getObject() const noexcept
Definition: helper_jni.hpp:185
jau::JavaGlobalObj
Implementation for JavaAnon, by simply wrapping a JNIGlobalRef instance.
Definition: helper_jni.hpp:136
jau::IllegalStateException
Definition: basic_types.hpp:117
jau::to_hexstring
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
Definition: string_util.hpp:104
jau::nsize_t
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
Definition: int_types.hpp:44
jau::JavaGlobalObj::GetClass
static jclass GetClass(const std::shared_ptr< JavaAnon > &shref) noexcept
Definition: helper_jni.hpp:199
jau::getInstance
T * getInstance(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:268
jau::convert_instance_to_jobject
jobject convert_instance_to_jobject(JNIEnv *env, T *elem, const char *ctor_prototype, std::function< jobject(JNIEnv *, jclass, jmethodID, T *)> ctor)
Definition: helper_jni.hpp:322
jau::OutOfMemoryError
Definition: basic_types.hpp:99
jau::search_field
jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name, const char *type, bool is_static)
basic_types.hpp
jau::UnsupportedOperationException
Definition: basic_types.hpp:123
JNIGlobalRef::getClass
jclass getClass() const noexcept
Definition: jni_mem.hpp:110
jau::from_jboolean_to_bool
bool from_jboolean_to_bool(jboolean val)
jau::JavaGlobalObj::getClass
jclass getClass() const noexcept
Definition: helper_jni.hpp:187
jau::getInstanceField
jfieldID getInstanceField(JNIEnv *env, jobject obj)
Definition: helper_jni.hpp:109
jau::NullPointerException
Definition: basic_types.hpp:105