| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.example.jni_generator; | 5 package org.chromium.example.jni_generator; |
| 6 | 6 |
| 7 import android.graphics.Rect; | 7 import android.graphics.Rect; |
| 8 | 8 |
| 9 import org.chromium.base.annotations.AccessedByNative; | 9 import org.chromium.base.annotations.AccessedByNative; |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| 11 import org.chromium.base.annotations.CalledByNativeUnchecked; | 11 import org.chromium.base.annotations.CalledByNativeUnchecked; |
| 12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
| 13 import org.chromium.base.annotations.NativeClassQualifiedName; | 13 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 14 | 14 |
| 15 import java.util.ArrayList; | 15 import java.util.ArrayList; |
| 16 import java.util.Iterator; | 16 import java.util.Iterator; |
| 17 import java.util.List; | 17 import java.util.List; |
| 18 | 18 |
| 19 // This class serves as a reference test for the bindings generator, and as exam
ple documentation | 19 // This class serves as a reference test for the bindings generator, and as exam
ple documentation |
| 20 // for how to use the jni generator. | 20 // for how to use the jni generator. |
| 21 // The C++ counter-part is sample_for_tests.cc. | 21 // The C++ counter-part is sample_for_tests.cc. |
| 22 // jni_generator.gyp has a jni_generator_tests target that will: | 22 // jni_generator/BUILD.gn has a jni_generator_tests target that will: |
| 23 // * Generate a header file for the JNI bindings based on this file. | 23 // * Generate a header file for the JNI bindings based on this file. |
| 24 // * Compile sample_for_tests.cc using the generated header file. | 24 // * Compile sample_for_tests.cc using the generated header file. |
| 25 // * link a native executable to prove the generated header + cc file are self
-contained. | 25 // * link a native executable to prove the generated header + cc file are self
-contained. |
| 26 // All comments are informational only, and are ignored by the jni generator. | 26 // All comments are informational only, and are ignored by the jni generator. |
| 27 // | 27 // |
| 28 // Binding C/C++ with Java is not trivial, specially when ownership and object l
ifetime | 28 // Binding C/C++ with Java is not trivial, specially when ownership and object l
ifetime |
| 29 // semantics needs to be managed across boundaries. | 29 // semantics needs to be managed across boundaries. |
| 30 // Following a few guidelines will make the code simpler and less buggy: | 30 // Following a few guidelines will make the code simpler and less buggy: |
| 31 // | 31 // |
| 32 // - Never write any JNI "by hand". Rely on the bindings generator to have a thi
n | 32 // - Never write any JNI "by hand". Rely on the bindings generator to have a thi
n |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // Now, do something with element. | 295 // Now, do something with element. |
| 296 nativeAddStructB(mNativeCPPObject, element); | 296 nativeAddStructB(mNativeCPPObject, element); |
| 297 } | 297 } |
| 298 nativeIterateAndDoSomethingWithStructB(mNativeCPPObject); | 298 nativeIterateAndDoSomethingWithStructB(mNativeCPPObject); |
| 299 } | 299 } |
| 300 | 300 |
| 301 native void nativeAddStructB(long nativeCPPClass, InnerStructB b); | 301 native void nativeAddStructB(long nativeCPPClass, InnerStructB b); |
| 302 native void nativeIterateAndDoSomethingWithStructB(long nativeCPPClass); | 302 native void nativeIterateAndDoSomethingWithStructB(long nativeCPPClass); |
| 303 native String nativeReturnAString(long nativeCPPClass); | 303 native String nativeReturnAString(long nativeCPPClass); |
| 304 } | 304 } |
| OLD | NEW |