aboutsummaryrefslogtreecommitdiffstats
path: root/sample-android-qt/src/main/cpp/ComputeIntensiveClass.h
blob: 08d6924bed05766cc0c57755f9a906cf276951b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
 * File generated by Jenny -- https://github.com/LanderlYoung/Jenny
 *
 * DO NOT EDIT THIS FILE.
 *
 * For bug report, please refer to github issue tracker https://github.com/LanderlYoung/Jenny/issues.
 */

/* C++ header file for class io/github/landerlyoung/jennysampleapp/ComputeIntensiveClass */
#pragma once

#include <jni.h>


namespace ComputeIntensiveClass {

// DO NOT modify
static constexpr auto FULL_CLASS_NAME = u8"io/github/landerlyoung/jennysampleapp/ComputeIntensiveClass";

static constexpr auto LOG_TAG = u8"ComputeIntensiveClass";
static constexpr auto KEY_WHERE_ARE_YOUT_FROM = u8"where_are_you_from";
static constexpr jint IDEL = -1;
static constexpr jint BUSY = 1;

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public int addInNative(int a, int b)
 * Signature: (II)I
 */
jint JNICALL addInNative(JNIEnv* env, jobject thiz, jint a, jint b);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static void computeSomething(byte[] sth)
 * Signature: ([B)V
 */
void JNICALL computeSomething(JNIEnv* env, jclass clazz, jbyteArray sth);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static java.lang.String greet()
 * Signature: ()Ljava/lang/String;
 */
jstring JNICALL greet(JNIEnv* env, jclass clazz);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public final void testParamParse(int a, java.lang.String b, long[] c, float[][] d, java.lang.Exception e, java.lang.Class<java.lang.String> f, java.util.HashMap<?,?> g)
 * Signature: (ILjava/lang/String;[J[[FLjava/lang/Exception;Ljava/lang/Class;Ljava/util/HashMap;)V
 */
void JNICALL testParamParse(JNIEnv* env, jobject thiz, jint a, jstring b, jlongArray c, jobjectArray d, jthrowable e, jclass f, jobject g);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static long returnsLong()
 * Signature: ()J
 */
jlong JNICALL returnsLong(JNIEnv* env, jclass clazz);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static boolean returnsBool()
 * Signature: ()Z
 */
jboolean JNICALL returnsBool(JNIEnv* env, jclass clazz);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static java.lang.Object returnsObject()
 * Signature: ()Ljava/lang/Object;
 */
jobject JNICALL returnsObject(JNIEnv* env, jclass clazz);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static void testOverload()
 * Signature: ()V
 */
void JNICALL testOverload__(JNIEnv* env, jclass clazz);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static void testOverload(int i)
 * Signature: (I)V
 */
void JNICALL testOverload__I(JNIEnv* env, jclass clazz, jint i);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static java.lang.String httpGet(java.lang.String url)
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
 */
jstring JNICALL httpGet(JNIEnv* env, jclass clazz, jstring url);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public int computeThenCallback(io.github.landerlyoung.jennysampleapp.Callback listener)
 * Signature: (Lio/github/landerlyoung/jennysampleapp/Callback;)I
 */
jint JNICALL computeThenCallback(JNIEnv* env, jobject thiz, jobject listener);

/*
 * Class:     io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
 * Method:    public static void runJniHelperTest()
 * Signature: ()V
 */
void JNICALL runJniHelperTest(JNIEnv* env, jclass clazz);

/**
* register Native functions
* @returns success or not
*/
inline bool registerNativeFunctions(JNIEnv* env) {
// 1. C++20 has u8"" string as char8_t type, we should cast them.
// 2. jni.h has JNINativeMethod::name as char* type not const char*. (while Android does)
#define jenny_u8cast(u8) const_cast<char *>(reinterpret_cast<const char *>(u8))
   const JNINativeMethod gsNativeMethods[] = {
       {
           /* method name      */ jenny_u8cast(u8"addInNative"),
           /* method signature */ jenny_u8cast(u8"(II)I"),
           /* function pointer */ reinterpret_cast<void *>(addInNative)
       },
       {
           /* method name      */ jenny_u8cast(u8"computeSomething"),
           /* method signature */ jenny_u8cast(u8"([B)V"),
           /* function pointer */ reinterpret_cast<void *>(computeSomething)
       },
       {
           /* method name      */ jenny_u8cast(u8"greet"),
           /* method signature */ jenny_u8cast(u8"()Ljava/lang/String;"),
           /* function pointer */ reinterpret_cast<void *>(greet)
       },
       {
           /* method name      */ jenny_u8cast(u8"testParamParse"),
           /* method signature */ jenny_u8cast(u8"(ILjava/lang/String;[J[[FLjava/lang/Exception;Ljava/lang/Class;Ljava/util/HashMap;)V"),
           /* function pointer */ reinterpret_cast<void *>(testParamParse)
       },
       {
           /* method name      */ jenny_u8cast(u8"returnsLong"),
           /* method signature */ jenny_u8cast(u8"()J"),
           /* function pointer */ reinterpret_cast<void *>(returnsLong)
       },
       {
           /* method name      */ jenny_u8cast(u8"returnsBool"),
           /* method signature */ jenny_u8cast(u8"()Z"),
           /* function pointer */ reinterpret_cast<void *>(returnsBool)
       },
       {
           /* method name      */ jenny_u8cast(u8"returnsObject"),
           /* method signature */ jenny_u8cast(u8"()Ljava/lang/Object;"),
           /* function pointer */ reinterpret_cast<void *>(returnsObject)
       },
       {
           /* method name      */ jenny_u8cast(u8"testOverload"),
           /* method signature */ jenny_u8cast(u8"()V"),
           /* function pointer */ reinterpret_cast<void *>(testOverload__)
       },
       {
           /* method name      */ jenny_u8cast(u8"testOverload"),
           /* method signature */ jenny_u8cast(u8"(I)V"),
           /* function pointer */ reinterpret_cast<void *>(testOverload__I)
       },
       {
           /* method name      */ jenny_u8cast(u8"httpGet"),
           /* method signature */ jenny_u8cast(u8"(Ljava/lang/String;)Ljava/lang/String;"),
           /* function pointer */ reinterpret_cast<void *>(httpGet)
       },
       {
           /* method name      */ jenny_u8cast(u8"computeThenCallback"),
           /* method signature */ jenny_u8cast(u8"(Lio/github/landerlyoung/jennysampleapp/Callback;)I"),
           /* function pointer */ reinterpret_cast<void *>(computeThenCallback)
       },
       {
           /* method name      */ jenny_u8cast(u8"runJniHelperTest"),
           /* method signature */ jenny_u8cast(u8"()V"),
           /* function pointer */ reinterpret_cast<void *>(runJniHelperTest)
       }
   };

   const int gsMethodCount = sizeof(gsNativeMethods) / sizeof(JNINativeMethod);

   bool success = false;
   jclass clazz = env->FindClass(jenny_u8cast(FULL_CLASS_NAME));
   if (clazz != nullptr) {
       success = !env->RegisterNatives(clazz, gsNativeMethods, gsMethodCount);
       env->DeleteLocalRef(clazz);
   }
   return success;
#undef jenny_u8cast
}

} // endof namespace ComputeIntensiveClass