Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
joth
2012/02/14 00:46:49
2012 ?
bulach
2012/02/14 02:12:32
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 // This file is autogenerated by base/android/jni_generator/jni_generator_tests. py | |
| 7 // For com/android/example/jni_generator/SampleForTests | |
| 8 | |
| 9 #ifndef com_android_example_jni_generator_SampleForTests_JNI | |
| 10 #define com_android_example_jni_generator_SampleForTests_JNI | |
|
joth
2012/02/14 00:46:49
so this will be org_chromium_...
bulach
2012/02/14 02:12:32
Done.
| |
| 11 | |
| 12 #include <jni.h> | |
| 13 | |
| 14 #include "base/android/jni_android.h" | |
| 15 #include "base/android/scoped_java_ref.h" | |
| 16 #include "base/basictypes.h" | |
| 17 #include "base/logging.h" | |
| 18 | |
| 19 using base::android::ScopedJavaLocalRef; | |
| 20 | |
| 21 // Step 1: forward declarations. | |
| 22 namespace { | |
| 23 const char* const kInnerClassClassPath = "com/android/example/jni_generator/Samp leForTests$InnerClass"; | |
| 24 const char* const kSampleForTestsClassPath = "com/android/example/jni_generator/ SampleForTests"; | |
| 25 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | |
| 26 base::android::ScopedJavaGlobalRef<jclass>& | |
| 27 g_InnerClass_clazz = *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 28 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | |
| 29 base::android::ScopedJavaGlobalRef<jclass>& | |
| 30 g_SampleForTests_clazz = *(new base::android::ScopedJavaGlobalRef<jclass>()) ; | |
| 31 } // namespace | |
| 32 | |
| 33 static jint Init(JNIEnv* env, jobject obj); | |
| 34 | |
| 35 | |
| 36 static jdouble GetDoubleFunction(JNIEnv* env, jobject obj); | |
| 37 | |
| 38 | |
| 39 static jfloat GetFloatFunction(JNIEnv* env, jclass clazz); | |
| 40 | |
| 41 | |
| 42 static void SetNonPODDatatype(JNIEnv* env, jobject obj, | |
| 43 jobject rect); | |
| 44 | |
| 45 | |
| 46 static jobject GetNonPODDatatype(JNIEnv* env, jobject obj); | |
| 47 | |
| 48 | |
| 49 static jint InnerFunction(JNIEnv* env, jclass clazz); | |
| 50 | |
| 51 | |
| 52 // Step 2: method stubs. | |
| 53 static void Destroy(JNIEnv* env, jobject obj, | |
| 54 jint nativeCPPClass) { | |
| 55 DCHECK(nativeCPPClass) << "Destroy"; | |
| 56 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 57 return native->Destroy(env, obj); | |
| 58 } | |
| 59 | |
| 60 static jint Method(JNIEnv* env, jobject obj, | |
| 61 jint nativeCPPClass) { | |
| 62 DCHECK(nativeCPPClass) << "Method"; | |
| 63 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 64 return native->Method(env, obj); | |
| 65 } | |
| 66 | |
| 67 static jdouble MethodOtherP0(JNIEnv* env, jobject obj, | |
| 68 jint nativeCPPClass) { | |
| 69 DCHECK(nativeCPPClass) << "MethodOtherP0"; | |
| 70 cpp_namespace::CPPClass* native = reinterpret_cast<cpp_namespace::CPPClass*>(n ativeCPPClass); | |
| 71 return native->MethodOtherP0(env, obj); | |
| 72 } | |
| 73 | |
| 74 static jstring InnerMethod(JNIEnv* env, jobject obj, | |
| 75 jint nativeCPPClass) { | |
| 76 DCHECK(nativeCPPClass) << "InnerMethod"; | |
| 77 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 78 return native->InnerMethod(env, obj).Release(); | |
| 79 } | |
| 80 | |
| 81 | |
| 82 static jmethodID g_SampleForTests_javaMethod = 0; | |
| 83 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, | |
| 84 jint bar) { | |
| 85 DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ | |
| 86 DCHECK(g_SampleForTests_javaMethod); | |
| 87 jint ret = | |
| 88 env->CallIntMethod(obj, | |
| 89 g_SampleForTests_javaMethod, foo, bar); | |
| 90 base::android::CheckException(env); | |
| 91 return ret; | |
| 92 } | |
| 93 | |
| 94 static jmethodID g_SampleForTests_staticJavaMethod = 0; | |
| 95 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { | |
| 96 DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ | |
| 97 DCHECK(g_SampleForTests_staticJavaMethod); | |
| 98 jboolean ret = | |
| 99 env->CallStaticBooleanMethod(g_SampleForTests_clazz.obj(), | |
| 100 g_SampleForTests_staticJavaMethod); | |
| 101 base::android::CheckException(env); | |
| 102 return ret; | |
| 103 } | |
| 104 | |
| 105 static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0; | |
| 106 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject ob j) { | |
| 107 DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ | |
| 108 DCHECK(g_SampleForTests_packagePrivateJavaMethod); | |
| 109 | |
| 110 env->CallVoidMethod(obj, | |
| 111 g_SampleForTests_packagePrivateJavaMethod); | |
| 112 base::android::CheckException(env); | |
| 113 | |
| 114 } | |
| 115 | |
| 116 static jmethodID g_SampleForTests_methodThatThrowsException = 0; | |
| 117 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject o bj) { | |
| 118 DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ | |
| 119 DCHECK(g_SampleForTests_methodThatThrowsException); | |
| 120 | |
| 121 env->CallVoidMethod(obj, | |
| 122 g_SampleForTests_methodThatThrowsException); | |
| 123 | |
| 124 | |
| 125 } | |
| 126 | |
| 127 static jmethodID g_InnerClass_JavaInnerMethod = 0; | |
| 128 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) { | |
| 129 DCHECK(!g_InnerClass_clazz.is_null()); /* Must call RegisterNativesImpl() */ | |
| 130 DCHECK(g_InnerClass_JavaInnerMethod); | |
| 131 jfloat ret = | |
| 132 env->CallFloatMethod(obj, | |
| 133 g_InnerClass_JavaInnerMethod); | |
| 134 base::android::CheckException(env); | |
| 135 return ret; | |
| 136 } | |
| 137 | |
| 138 static jmethodID g_InnerClass_javaInnerFunction = 0; | |
| 139 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) { | |
| 140 DCHECK(!g_InnerClass_clazz.is_null()); /* Must call RegisterNativesImpl() */ | |
| 141 DCHECK(g_InnerClass_javaInnerFunction); | |
| 142 | |
| 143 env->CallStaticVoidMethod(g_InnerClass_clazz.obj(), | |
| 144 g_InnerClass_javaInnerFunction); | |
| 145 base::android::CheckException(env); | |
| 146 | |
| 147 } | |
| 148 | |
| 149 // Step 3: GetMethodIDs and RegisterNatives. | |
| 150 | |
| 151 | |
| 152 static void GetMethodIDsImpl(JNIEnv* env) { | |
| 153 g_InnerClass_clazz.Reset(base::android::GetClass(env, kInnerClassClassPath)); | |
| 154 g_SampleForTests_clazz.Reset(base::android::GetClass(env, kSampleForTestsClass Path)); | |
| 155 g_SampleForTests_javaMethod = base::android::GetMethodID( | |
| 156 env, g_SampleForTests_clazz, | |
| 157 "javaMethod", | |
| 158 "(II)I"); | |
| 159 | |
| 160 g_SampleForTests_staticJavaMethod = base::android::GetStaticMethodID( | |
| 161 env, g_SampleForTests_clazz, | |
| 162 "staticJavaMethod", | |
| 163 "()Z"); | |
| 164 | |
| 165 g_SampleForTests_packagePrivateJavaMethod = base::android::GetMethodID( | |
| 166 env, g_SampleForTests_clazz, | |
| 167 "packagePrivateJavaMethod", | |
| 168 "()V"); | |
| 169 | |
| 170 g_SampleForTests_methodThatThrowsException = base::android::GetMethodID( | |
| 171 env, g_SampleForTests_clazz, | |
| 172 "methodThatThrowsException", | |
| 173 "()V"); | |
| 174 | |
| 175 g_InnerClass_JavaInnerMethod = base::android::GetMethodID( | |
| 176 env, g_InnerClass_clazz, | |
| 177 "JavaInnerMethod", | |
| 178 "()F"); | |
| 179 | |
| 180 g_InnerClass_javaInnerFunction = base::android::GetStaticMethodID( | |
| 181 env, g_InnerClass_clazz, | |
| 182 "javaInnerFunction", | |
| 183 "()V"); | |
| 184 | |
| 185 } | |
| 186 | |
| 187 static bool RegisterNativesImpl(JNIEnv* env) { | |
| 188 GetMethodIDsImpl(env); | |
| 189 | |
| 190 static const JNINativeMethod kMethodsInnerClass[] = { | |
| 191 { "nativeInnerFunction", "()I", reinterpret_cast<void*>(InnerFunction) }, | |
| 192 { "nativeInnerMethod", "(I)Ljava/lang/String;", reinterpret_cast<void*>(Inne rMethod) }, | |
| 193 }; | |
| 194 const int kMethodsInnerClassSize = arraysize(kMethodsInnerClass); | |
| 195 | |
| 196 if (env->RegisterNatives(g_InnerClass_clazz.obj(), | |
| 197 kMethodsInnerClass, | |
| 198 kMethodsInnerClassSize) < 0) { | |
| 199 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
| 200 return false; | |
| 201 } | |
| 202 | |
| 203 static const JNINativeMethod kMethodsSampleForTests[] = { | |
| 204 { "nativeInit", "()I", reinterpret_cast<void*>(Init) }, | |
| 205 { "nativeDestroy", "(I)V", reinterpret_cast<void*>(Destroy) }, | |
| 206 { "nativeGetDoubleFunction", "()D", reinterpret_cast<void*>(GetDoubleFunctio n) }, | |
| 207 { "nativeGetFloatFunction", "()F", reinterpret_cast<void*>(GetFloatFunction) }, | |
| 208 { "nativeSetNonPODDatatype", "(Landroid/graphics/Rect;)V", reinterpret_cast< void*>(SetNonPODDatatype) }, | |
| 209 { "nativeGetNonPODDatatype", "()Ljava/lang/Object;", reinterpret_cast<void*> (GetNonPODDatatype) }, | |
| 210 { "nativeMethod", "(I)I", reinterpret_cast<void*>(Method) }, | |
| 211 { "nativeMethodOtherP0", "(I)D", reinterpret_cast<void*>(MethodOtherP0) }, | |
| 212 }; | |
| 213 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); | |
| 214 | |
| 215 if (env->RegisterNatives(g_SampleForTests_clazz.obj(), | |
| 216 kMethodsSampleForTests, | |
| 217 kMethodsSampleForTestsSize) < 0) { | |
| 218 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
| 219 return false; | |
| 220 } | |
| 221 | |
| 222 return true; | |
| 223 } | |
| 224 | |
| 225 #endif // com_android_example_jni_generator_SampleForTests_JNI | |
| OLD | NEW |