1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This file is autogenerated by 6// base/android/jni_generator/jni_generator.py 7// For 8// org/chromium/foo/Foo 9 10#ifndef org_chromium_foo_Foo_JNI 11#define org_chromium_foo_Foo_JNI 12 13#include <jni.h> 14 15#include "base/android/jni_generator/jni_generator_helper.h" 16 17#include "base/android/jni_int_wrapper.h" 18 19// Step 1: forward declarations. 20namespace { 21const char kFooClassPath[] = "org/chromium/foo/Foo"; 22// Leaking this jclass as we cannot use LazyInstance from some threads. 23base::subtle::AtomicWord g_Foo_clazz __attribute__((unused)) = 0; 24#define Foo_clazz(env) base::android::LazyGetClass(env, kFooClassPath, &g_Foo_clazz) 25 26} // namespace 27 28// Step 2: method stubs. 29 30static void DoSomething(JNIEnv* env, const base::android::JavaParamRef<jclass>& 31 jcaller, 32 const base::android::JavaParamRef<jobject>& callback1, 33 const base::android::JavaParamRef<jobject>& callback2); 34 35JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* 36 env, jclass jcaller, 37 jobject callback1, 38 jobject callback2) { 39 return DoSomething(env, base::android::JavaParamRef<jclass>(env, jcaller), 40 base::android::JavaParamRef<jobject>(env, callback1), 41 base::android::JavaParamRef<jobject>(env, callback2)); 42} 43 44static base::subtle::AtomicWord g_Foo_calledByNative = 0; 45static void Java_Foo_calledByNative(JNIEnv* env, const 46 base::android::JavaRefOrBare<jobject>& callback1, 47 const base::android::JavaRefOrBare<jobject>& callback2) { 48 CHECK_CLAZZ(env, Foo_clazz(env), 49 Foo_clazz(env)); 50 jmethodID method_id = 51 base::android::MethodID::LazyGet< 52 base::android::MethodID::TYPE_STATIC>( 53 env, Foo_clazz(env), 54 "calledByNative", 55"(" 56"Lorg/chromium/foo/Bar1$Callback;" 57"Lorg/chromium/foo/Bar2$Callback;" 58")" 59"V", 60 &g_Foo_calledByNative); 61 62 env->CallStaticVoidMethod(Foo_clazz(env), 63 method_id, callback1.obj(), callback2.obj()); 64 jni_generator::CheckException(env); 65} 66 67// Step 3: RegisterNatives. 68 69static const JNINativeMethod kMethodsFoo[] = { 70 { "nativeDoSomething", 71"(" 72"Lorg/chromium/foo/Bar1$Callback;" 73"Lorg/chromium/foo/Bar2$Callback;" 74")" 75"V", reinterpret_cast<void*>(Java_org_chromium_foo_Foo_nativeDoSomething) }, 76}; 77 78static bool RegisterNativesImpl(JNIEnv* env) { 79 if (jni_generator::ShouldSkipJniRegistration(false)) 80 return true; 81 82 const int kMethodsFooSize = arraysize(kMethodsFoo); 83 84 if (env->RegisterNatives(Foo_clazz(env), 85 kMethodsFoo, 86 kMethodsFooSize) < 0) { 87 jni_generator::HandleRegistrationError( 88 env, Foo_clazz(env), __FILE__); 89 return false; 90 } 91 92 return true; 93} 94 95#endif // org_chromium_foo_Foo_JNI 96