seq_android.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. #ifndef __GO_SEQ_ANDROID_HDR__
  5. #define __GO_SEQ_ANDROID_HDR__
  6. #include <stdint.h>
  7. #include <android/log.h>
  8. // For abort()
  9. #include <stdlib.h>
  10. #include <jni.h>
  11. #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, "go/Seq", __VA_ARGS__)
  12. #define LOG_FATAL(...) \
  13. { \
  14. __android_log_print(ANDROID_LOG_FATAL, "go/Seq", __VA_ARGS__); \
  15. abort(); \
  16. }
  17. // Platform specific types
  18. typedef struct nstring {
  19. // UTF16 or UTF8 Encoded string. When converting from Java string to Go
  20. // string, UTF16. When converting from Go to Java, UTF8.
  21. void *chars;
  22. // length in bytes, regardless of encoding
  23. jsize len;
  24. } nstring;
  25. typedef struct nbyteslice {
  26. void *ptr;
  27. jsize len;
  28. } nbyteslice;
  29. typedef jlong nint;
  30. extern void go_seq_dec_ref(int32_t ref);
  31. extern void go_seq_inc_ref(int32_t ref);
  32. // go_seq_unwrap takes a reference number to a Java wrapper and returns
  33. // a reference number to its wrapped Go object.
  34. extern int32_t go_seq_unwrap(jint refnum);
  35. extern int32_t go_seq_to_refnum(JNIEnv *env, jobject o);
  36. extern int32_t go_seq_to_refnum_go(JNIEnv *env, jobject o);
  37. extern jobject go_seq_from_refnum(JNIEnv *env, int32_t refnum, jclass proxy_class, jmethodID proxy_cons);
  38. extern void go_seq_maybe_throw_exception(JNIEnv *env, jobject msg);
  39. // go_seq_get_exception returns any pending exception and clears the exception status.
  40. extern jobject go_seq_get_exception(JNIEnv *env);
  41. extern jbyteArray go_seq_to_java_bytearray(JNIEnv *env, nbyteslice s, int copy);
  42. extern nbyteslice go_seq_from_java_bytearray(JNIEnv *env, jbyteArray s, int copy);
  43. extern void go_seq_release_byte_array(JNIEnv *env, jbyteArray arr, jbyte* ptr);
  44. extern jstring go_seq_to_java_string(JNIEnv *env, nstring str);
  45. extern nstring go_seq_from_java_string(JNIEnv *env, jstring s);
  46. // push_local_frame retrieves or creates the JNIEnv* for the current thread
  47. // and pushes a JNI reference frame. Must be matched with call to pop_local_frame.
  48. extern JNIEnv *go_seq_push_local_frame(jint cap);
  49. // Pop the current local frame, releasing all JNI local references in it
  50. extern void go_seq_pop_local_frame(JNIEnv *env);
  51. // Return a global reference to the given class. Return NULL and clear exception if not found.
  52. extern jclass go_seq_find_class(const char *name);
  53. extern jmethodID go_seq_get_static_method_id(jclass clazz, const char *name, const char *sig);
  54. extern jmethodID go_seq_get_method_id(jclass clazz, const char *name, const char *sig);
  55. extern int go_seq_isinstanceof(jint refnum, jclass clazz);
  56. #endif // __GO_SEQ_ANDROID_HDR__