• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>& callback);
33
34JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv*
35    env, jclass jcaller,
36    jobject callback) {
37  return DoSomething(env, base::android::JavaParamRef<jclass>(env, jcaller),
38      base::android::JavaParamRef<jobject>(env, callback));
39}
40
41static base::subtle::AtomicWord g_Foo_calledByNative = 0;
42static void Java_Foo_calledByNative(JNIEnv* env, const
43    base::android::JavaRefOrBare<jobject>& callback) {
44  CHECK_CLAZZ(env, Foo_clazz(env),
45      Foo_clazz(env));
46  jmethodID method_id =
47      base::android::MethodID::LazyGet<
48      base::android::MethodID::TYPE_STATIC>(
49      env, Foo_clazz(env),
50      "calledByNative",
51"("
52"Lorg/chromium/foo/Bar$Callback;"
53")"
54"V",
55      &g_Foo_calledByNative);
56
57     env->CallStaticVoidMethod(Foo_clazz(env),
58          method_id, callback.obj());
59  jni_generator::CheckException(env);
60}
61
62// Step 3: RegisterNatives.
63
64static const JNINativeMethod kMethodsFoo[] = {
65    { "nativeDoSomething",
66"("
67"Lorg/chromium/foo/Bar$Callback;"
68")"
69"V", reinterpret_cast<void*>(Java_org_chromium_foo_Foo_nativeDoSomething) },
70};
71
72static bool RegisterNativesImpl(JNIEnv* env) {
73  if (jni_generator::ShouldSkipJniRegistration(false))
74    return true;
75
76  const int kMethodsFooSize = arraysize(kMethodsFoo);
77
78  if (env->RegisterNatives(Foo_clazz(env),
79                           kMethodsFoo,
80                           kMethodsFooSize) < 0) {
81    jni_generator::HandleRegistrationError(
82        env, Foo_clazz(env), __FILE__);
83    return false;
84  }
85
86  return true;
87}
88
89#endif  // org_chromium_foo_Foo_JNI
90