Chromium Code Reviews| 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..cad3f7b4b419ae060da0fbe771bc917ce95389af |
| --- /dev/null |
| +++ b/base/android/jni_generator/golden_sample_for_tests_jni.h |
| @@ -0,0 +1,225 @@ |
| +// 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.
|
| +// 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 com/android/example/jni_generator/SampleForTests |
| + |
| +#ifndef com_android_example_jni_generator_SampleForTests_JNI |
| +#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.
|
| + |
| +#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; |
| + |
| +// Step 1: forward declarations. |
| +namespace { |
| +const char* const kInnerClassClassPath = "com/android/example/jni_generator/SampleForTests$InnerClass"; |
| +const char* const kSampleForTestsClassPath = "com/android/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); |
| + |
| + |
| +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 // com_android_example_jni_generator_SampleForTests_JNI |