Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jniutil.h
Go to the documentation of this file.
1 
18 #ifndef ION_PORT_ANDROID_JNIUTIL_H_
19 #define ION_PORT_ANDROID_JNIUTIL_H_
20 
21 #include <jni.h>
22 #include <string>
23 
24 namespace ion {
25 namespace port {
26 namespace android {
27 
33 void SetJVM(JavaVM* jvm);
34 JavaVM* GetJVM();
35 jclass FindClassGlobal(JNIEnv* env, const char* class_name);
36 jmethodID GetStaticMethod(JNIEnv* env, jclass clazz, const char* class_name,
37  const char* name, const char* signature);
38 jmethodID GetMethod(JNIEnv* env, jclass clazz, const char* class_name,
39  const char* name, const char* signature);
40 jfieldID GetStaticMember(JNIEnv* env, jclass clazz, const char* class_name,
41  const char* name, const char* type);
42 jfieldID GetMember(JNIEnv* env, jclass clazz, const char* class_name,
43  const char* name, const char* type);
44 jfieldID GetIntMember(
45  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
46 jfieldID GetLongMember(
47  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
48 jfieldID GetStringMember(
49  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
50 jfieldID GetBooleanMember(
51  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
52 jfieldID GetIntArrayMember(
53  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
54 jfieldID GetStaticIntMember(
55  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
56 jfieldID GetStaticLongMember(
57  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
58 jfieldID GetStaticStringMember(
59  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
60 jfieldID GetStaticBooleanMember(
61  JNIEnv* env, jclass clazz, const char* class_name, const char* name);
62 jstring JavaString(JNIEnv* env, const std::string& s);
63 jobjectArray JavaStringArray(JNIEnv* env, int length);
64 jbyteArray JavaByteArray(JNIEnv* env, const std::string& bytes);
65 jbyteArray JavaByteArray(JNIEnv* env, const jbyte* data, jsize size);
66 
67 void JavaGetByteArray(JNIEnv* env, jbyteArray array,
68  jsize first, jsize size, char* out);
69 
71 class LocalFrame {
72  public:
74  explicit LocalFrame(JNIEnv* env);
76  ~LocalFrame();
77  private:
78  JNIEnv* env_;
79 };
80 
84  public:
85  explicit ScopedJObject(JNIEnv* env, jobject* obj): env_(env), obj_(obj) {}
86  ~ScopedJObject() { env_->DeleteLocalRef(*obj_); }
87  private:
88  JNIEnv* env_;
89  jobject* obj_;
90 };
91 
92 } // namespace android
93 } // namespace port
94 } // namespace ion
95 
96 #endif // ION_PORT_ANDROID_JNIUTIL_H_
void JavaGetByteArray(JNIEnv *env, jbyteArray array, jsize first, jsize size, char *out)
Definition: jniutil.cc:190
JavaVM * GetJVM()
Definition: jniutil.cc:30
jfieldID GetStaticStringMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:94
std::string type
Definition: printer.cc:353
jbyteArray JavaByteArray(JNIEnv *env, const std::string &bytes)
Definition: jniutil.cc:176
void SetJVM(JavaVM *jvm)
Set the pointer to the JavaVM.
Definition: jniutil.cc:34
jfieldID GetStaticLongMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:104
jfieldID GetStringMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:129
uint32 length
jfieldID GetIntMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:114
Pushes and pops a JNI local reference frame.
Definition: jniutil.h:71
jclass FindClassGlobal(JNIEnv *env, const char *class_name)
Definition: jniutil.cc:44
jmethodID GetStaticMethod(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *signature)
Definition: jniutil.cc:66
LocalFrame(JNIEnv *env)
Pushes a local reference frame frame with env->PushLocalFrame(0).
Definition: jniutil.cc:206
jstring JavaString(JNIEnv *env, const std::string &s)
Definition: jniutil.cc:172
jfieldID GetStaticBooleanMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:109
Stack-allocate this to clean up a jobject at end of scope.
Definition: jniutil.h:83
jfieldID GetMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *type)
Definition: jniutil.cc:153
std::string name
Definition: printer.cc:324
jobjectArray JavaStringArray(JNIEnv *env, int length)
Definition: jniutil.cc:167
ScopedJObject(JNIEnv *env, jobject *obj)
Definition: jniutil.h:85
jfieldID GetLongMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:119
jmethodID GetMethod(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *signature)
Definition: jniutil.cc:80
jfieldID GetStaticMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name, const char *type)
Definition: jniutil.cc:139
jfieldID GetBooleanMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:124
jfieldID GetStaticIntMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:99
jfieldID GetIntArrayMember(JNIEnv *env, jclass clazz, const char *class_name, const char *name)
Definition: jniutil.cc:134
~LocalFrame()
Pops a local reference frame with env->PopLocalFrame(NULL);.
Definition: jniutil.cc:214