Index: base/android/jni_generator/golden_sample_for_tests_jni.h |
diff --git a/base/android/jni_generator/golden_sample_for_tests_jni.h b/base/android/jni_generator/golden_sample_for_tests_jni.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..47be127a0f8510a50f865dab4b84383b37e7bcf6 |
--- /dev/null |
+++ b/base/android/jni_generator/golden_sample_for_tests_jni.h |
@@ -0,0 +1,225 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+ |
+// This file is autogenerated by base/android/jni_generator/jni_generator_tests.py |
+// For org/chromium/example/jni_generator/SampleForTests |
+ |
+#ifndef org_chromium_example_jni_generator_SampleForTests_JNI |
+#define org_chromium_example_jni_generator_SampleForTests_JNI |
+ |
+#include <jni.h> |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/scoped_java_ref.h" |
+#include "base/basictypes.h" |
+#include "base/logging.h" |
+ |
+using base::android::ScopedJavaLocalRef; |
joth
2012/02/16 18:32:23
shouldn't have using in a .h file. (and it doesn't
|
+ |
+// Step 1: forward declarations. |
+namespace { |
+const char* const kInnerClassClassPath = "org/chromium/example/jni_generator/SampleForTests$InnerClass"; |
+const char* const kSampleForTestsClassPath = "org/chromium/example/jni_generator/SampleForTests"; |
+// Leaking this JavaRef as we cannot use LazyInstance from some threads. |
+base::android::ScopedJavaGlobalRef<jclass>& |
+ g_InnerClass_clazz = *(new base::android::ScopedJavaGlobalRef<jclass>()); |
+// Leaking this JavaRef as we cannot use LazyInstance from some threads. |
+base::android::ScopedJavaGlobalRef<jclass>& |
+ g_SampleForTests_clazz = *(new base::android::ScopedJavaGlobalRef<jclass>()); |
+} // namespace |
+ |
+static jint Init(JNIEnv* env, jobject obj); |
+ |
+ |
+static jdouble GetDoubleFunction(JNIEnv* env, jobject obj); |
+ |
+ |
+static jfloat GetFloatFunction(JNIEnv* env, jclass clazz); |
+ |
+ |
+static void SetNonPODDatatype(JNIEnv* env, jobject obj, |
+ jobject rect); |
+ |
+ |
+static jobject GetNonPODDatatype(JNIEnv* env, jobject obj); |
joth
2012/02/16 18:32:23
In the java it said this would be declared to retu
|
+ |
+ |
+static jint InnerFunction(JNIEnv* env, jclass clazz); |
+ |
+ |
+// Step 2: method stubs. |
+static void Destroy(JNIEnv* env, jobject obj, |
+ jint nativeCPPClass) { |
+ DCHECK(nativeCPPClass) << "Destroy"; |
+ CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); |
+ return native->Destroy(env, obj); |
+} |
+ |
+static jint Method(JNIEnv* env, jobject obj, |
+ jint nativeCPPClass) { |
+ DCHECK(nativeCPPClass) << "Method"; |
+ CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); |
+ return native->Method(env, obj); |
+} |
+ |
+static jdouble MethodOtherP0(JNIEnv* env, jobject obj, |
+ jint nativeCPPClass) { |
+ DCHECK(nativeCPPClass) << "MethodOtherP0"; |
+ cpp_namespace::CPPClass* native = reinterpret_cast<cpp_namespace::CPPClass*>(nativeCPPClass); |
+ return native->MethodOtherP0(env, obj); |
+} |
+ |
+static jstring InnerMethod(JNIEnv* env, jobject obj, |
+ jint nativeCPPClass) { |
+ DCHECK(nativeCPPClass) << "InnerMethod"; |
+ CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); |
+ return native->InnerMethod(env, obj).Release(); |
+} |
+ |
+ |
+static jmethodID g_SampleForTests_javaMethod = 0; |
+static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, |
+ jint bar) { |
+ DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ |
+ DCHECK(g_SampleForTests_javaMethod); |
+ jint ret = |
+ env->CallIntMethod(obj, |
+ g_SampleForTests_javaMethod, foo, bar); |
+ base::android::CheckException(env); |
+ return ret; |
+} |
+ |
+static jmethodID g_SampleForTests_staticJavaMethod = 0; |
+static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { |
+ DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ |
+ DCHECK(g_SampleForTests_staticJavaMethod); |
+ jboolean ret = |
+ env->CallStaticBooleanMethod(g_SampleForTests_clazz.obj(), |
+ g_SampleForTests_staticJavaMethod); |
+ base::android::CheckException(env); |
+ return ret; |
+} |
+ |
+static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0; |
+static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject obj) { |
+ DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ |
+ DCHECK(g_SampleForTests_packagePrivateJavaMethod); |
+ |
+ env->CallVoidMethod(obj, |
+ g_SampleForTests_packagePrivateJavaMethod); |
+ base::android::CheckException(env); |
+ |
+} |
+ |
+static jmethodID g_SampleForTests_methodThatThrowsException = 0; |
+static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject obj) { |
+ DCHECK(!g_SampleForTests_clazz.is_null()); /* Must call RegisterNativesImpl() */ |
+ DCHECK(g_SampleForTests_methodThatThrowsException); |
+ |
+ env->CallVoidMethod(obj, |
+ g_SampleForTests_methodThatThrowsException); |
+ |
+ |
+} |
+ |
+static jmethodID g_InnerClass_JavaInnerMethod = 0; |
+static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) { |
+ DCHECK(!g_InnerClass_clazz.is_null()); /* Must call RegisterNativesImpl() */ |
+ DCHECK(g_InnerClass_JavaInnerMethod); |
+ jfloat ret = |
+ env->CallFloatMethod(obj, |
+ g_InnerClass_JavaInnerMethod); |
+ base::android::CheckException(env); |
+ return ret; |
+} |
+ |
+static jmethodID g_InnerClass_javaInnerFunction = 0; |
+static void Java_InnerClass_javaInnerFunction(JNIEnv* env) { |
+ DCHECK(!g_InnerClass_clazz.is_null()); /* Must call RegisterNativesImpl() */ |
+ DCHECK(g_InnerClass_javaInnerFunction); |
+ |
+ env->CallStaticVoidMethod(g_InnerClass_clazz.obj(), |
+ g_InnerClass_javaInnerFunction); |
+ base::android::CheckException(env); |
+ |
+} |
+ |
+// Step 3: GetMethodIDs and RegisterNatives. |
+ |
+ |
+static void GetMethodIDsImpl(JNIEnv* env) { |
+ g_InnerClass_clazz.Reset(base::android::GetClass(env, kInnerClassClassPath)); |
+ g_SampleForTests_clazz.Reset(base::android::GetClass(env, kSampleForTestsClassPath)); |
+ g_SampleForTests_javaMethod = base::android::GetMethodID( |
+ env, g_SampleForTests_clazz, |
+ "javaMethod", |
+ "(II)I"); |
+ |
+ g_SampleForTests_staticJavaMethod = base::android::GetStaticMethodID( |
+ env, g_SampleForTests_clazz, |
+ "staticJavaMethod", |
+ "()Z"); |
+ |
+ g_SampleForTests_packagePrivateJavaMethod = base::android::GetMethodID( |
+ env, g_SampleForTests_clazz, |
+ "packagePrivateJavaMethod", |
+ "()V"); |
+ |
+ g_SampleForTests_methodThatThrowsException = base::android::GetMethodID( |
+ env, g_SampleForTests_clazz, |
+ "methodThatThrowsException", |
+ "()V"); |
+ |
+ g_InnerClass_JavaInnerMethod = base::android::GetMethodID( |
+ env, g_InnerClass_clazz, |
+ "JavaInnerMethod", |
+ "()F"); |
+ |
+ g_InnerClass_javaInnerFunction = base::android::GetStaticMethodID( |
+ env, g_InnerClass_clazz, |
+ "javaInnerFunction", |
+ "()V"); |
+ |
+} |
+ |
+static bool RegisterNativesImpl(JNIEnv* env) { |
+ GetMethodIDsImpl(env); |
+ |
+ static const JNINativeMethod kMethodsInnerClass[] = { |
+ { "nativeInnerFunction", "()I", reinterpret_cast<void*>(InnerFunction) }, |
+ { "nativeInnerMethod", "(I)Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) }, |
+ }; |
+ const int kMethodsInnerClassSize = arraysize(kMethodsInnerClass); |
+ |
+ if (env->RegisterNatives(g_InnerClass_clazz.obj(), |
+ kMethodsInnerClass, |
+ kMethodsInnerClassSize) < 0) { |
+ LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
+ return false; |
+ } |
+ |
+ static const JNINativeMethod kMethodsSampleForTests[] = { |
+ { "nativeInit", "()I", reinterpret_cast<void*>(Init) }, |
+ { "nativeDestroy", "(I)V", reinterpret_cast<void*>(Destroy) }, |
+ { "nativeGetDoubleFunction", "()D", reinterpret_cast<void*>(GetDoubleFunction) }, |
+ { "nativeGetFloatFunction", "()F", reinterpret_cast<void*>(GetFloatFunction) }, |
+ { "nativeSetNonPODDatatype", "(Landroid/graphics/Rect;)V", reinterpret_cast<void*>(SetNonPODDatatype) }, |
+ { "nativeGetNonPODDatatype", "()Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype) }, |
+ { "nativeMethod", "(I)I", reinterpret_cast<void*>(Method) }, |
+ { "nativeMethodOtherP0", "(I)D", reinterpret_cast<void*>(MethodOtherP0) }, |
+ }; |
+ const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); |
+ |
+ if (env->RegisterNatives(g_SampleForTests_clazz.obj(), |
+ kMethodsSampleForTests, |
+ kMethodsSampleForTestsSize) < 0) { |
+ LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+#endif // org_chromium_example_jni_generator_SampleForTests_JNI |