OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "base/android/jni_generator/sample_for_tests.h" | 5 #include "base/android/jni_generator/sample_for_tests.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 // Generated file for JNI bindings from C++ to Java @CalledByNative methods. | 10 // Generated file for JNI bindings from C++ to Java @CalledByNative methods. |
11 // Only to be included in one .cc file. | 11 // Only to be included in one .cc file. |
12 // Name is based on the java file name: *.java -> jni/*_jni.h | 12 // Name is based on the java file name: *.java -> jni/*_jni.h |
13 #include "jni/SampleForTests_jni.h" // Generated by JNI. | 13 #include "jni/SampleForTests_jni.h" // Generated by JNI. |
14 | 14 |
15 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
16 using base::android::ScopedJavaLocalRef; | 16 using base::android::ScopedJavaLocalRef; |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 namespace android { | 19 namespace android { |
20 | 20 |
21 jdouble CPPClass::InnerClass::MethodOtherP0(JNIEnv* env, jobject obj) { | 21 jdouble CPPClass::InnerClass::MethodOtherP0(JNIEnv* env, jobject caller) { |
22 return 0.0; | 22 return 0.0; |
23 } | 23 } |
24 | 24 |
25 CPPClass::CPPClass() { | 25 CPPClass::CPPClass() { |
26 } | 26 } |
27 | 27 |
28 CPPClass::~CPPClass() { | 28 CPPClass::~CPPClass() { |
29 } | 29 } |
30 | 30 |
31 // static | 31 // static |
32 bool CPPClass::RegisterJNI(JNIEnv* env) { | 32 bool CPPClass::RegisterJNI(JNIEnv* env) { |
33 return RegisterNativesImpl(env); // Generated in SampleForTests_jni.h | 33 return RegisterNativesImpl(env); // Generated in SampleForTests_jni.h |
34 } | 34 } |
35 | 35 |
36 void CPPClass::Destroy(JNIEnv* env, jobject obj) { | 36 void CPPClass::Destroy(JNIEnv* env, jobject caller) { |
37 delete this; | 37 delete this; |
38 } | 38 } |
39 | 39 |
40 jint CPPClass::Method(JNIEnv* env, jobject obj) { | 40 jint CPPClass::Method(JNIEnv* env, jobject caller) { |
41 return 0; | 41 return 0; |
42 } | 42 } |
43 | 43 |
44 void CPPClass::AddStructB(JNIEnv* env, jobject obj, jobject structb) { | 44 void CPPClass::AddStructB(JNIEnv* env, jobject caller, jobject structb) { |
45 long key = Java_InnerStructB_getKey(env, structb); | 45 long key = Java_InnerStructB_getKey(env, structb); |
46 std::string value = ConvertJavaStringToUTF8( | 46 std::string value = ConvertJavaStringToUTF8( |
47 env, Java_InnerStructB_getValue(env, structb).obj()); | 47 env, Java_InnerStructB_getValue(env, structb).obj()); |
48 map_[key] = value; | 48 map_[key] = value; |
49 } | 49 } |
50 | 50 |
51 void CPPClass::IterateAndDoSomethingWithStructB(JNIEnv* env, jobject obj) { | 51 void CPPClass::IterateAndDoSomethingWithStructB(JNIEnv* env, jobject caller) { |
52 // Iterate over the elements and do something with them. | 52 // Iterate over the elements and do something with them. |
53 for (std::map<long, std::string>::const_iterator it = map_.begin(); | 53 for (std::map<long, std::string>::const_iterator it = map_.begin(); |
54 it != map_.end(); ++it) { | 54 it != map_.end(); ++it) { |
55 long key = it->first; | 55 long key = it->first; |
56 std::string value = it->second; | 56 std::string value = it->second; |
57 } | 57 } |
58 map_.clear(); | 58 map_.clear(); |
59 } | 59 } |
60 | 60 |
61 base::android::ScopedJavaLocalRef<jstring> CPPClass::ReturnAString( | 61 base::android::ScopedJavaLocalRef<jstring> CPPClass::ReturnAString( |
62 JNIEnv* env, jobject obj) { | 62 JNIEnv* env, |
| 63 jobject caller) { |
63 base::android::ScopedJavaLocalRef<jstring> ret = ConvertUTF8ToJavaString( | 64 base::android::ScopedJavaLocalRef<jstring> ret = ConvertUTF8ToJavaString( |
64 env, "test"); | 65 env, "test"); |
65 return ret; | 66 return ret; |
66 } | 67 } |
67 | 68 |
68 // Static free functions declared and called directly from java. | 69 // Static free functions declared and called directly from java. |
69 static jlong Init(JNIEnv* env, jobject obj, jstring param) { | 70 static jlong Init(JNIEnv* env, jobject caller, jstring param) { |
70 return 0; | 71 return 0; |
71 } | 72 } |
72 | 73 |
73 static jdouble GetDoubleFunction(JNIEnv*, jobject) { | 74 static jdouble GetDoubleFunction(JNIEnv*, jobject) { |
74 return 0; | 75 return 0; |
75 } | 76 } |
76 | 77 |
77 static jfloat GetFloatFunction(JNIEnv*, jclass) { | 78 static jfloat GetFloatFunction(JNIEnv*, jclass) { |
78 return 0; | 79 return 0; |
79 } | 80 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 ScopedJavaLocalRef<jobject> struct_a = | 112 ScopedJavaLocalRef<jobject> struct_a = |
112 base::android::Java_InnerStructA_create( | 113 base::android::Java_InnerStructA_create( |
113 env, 0, 1, | 114 env, 0, 1, |
114 base::android::ConvertUTF8ToJavaString(env, "test").obj()); | 115 base::android::ConvertUTF8ToJavaString(env, "test").obj()); |
115 base::android::Java_SampleForTests_addStructA( | 116 base::android::Java_SampleForTests_addStructA( |
116 env, my_java_object, struct_a.obj()); | 117 env, my_java_object, struct_a.obj()); |
117 } | 118 } |
118 base::android::Java_SampleForTests_iterateAndDoSomething(env, my_java_object); | 119 base::android::Java_SampleForTests_iterateAndDoSomething(env, my_java_object); |
119 return 0; | 120 return 0; |
120 } | 121 } |
OLD | NEW |