-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathComputeIntensiveClass.cpp
203 lines (162 loc) · 6.4 KB
/
ComputeIntensiveClass.cpp
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
195
196
197
198
199
/**
* File generated by Jenny -- https://github.com/LanderlYoung/Jenny
*
* For bug report, please refer to github issue tracker https://github.com/LanderlYoung/Jenny/issues,
* or contact author [email protected].
*/
#include <CallbackProxy.h>
#include <NestedClassProxy.h>
#include "ComputeIntensiveClass.h"
#include "gen/jenny_fusion_proxies.h"
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public int addInNative(int a, int b)
* Signature: (II)I
*/
jint ComputeIntensiveClass::addInNative(JNIEnv* env, jobject thiz, jint a, jint b) {
jint c = a + b;
return c;
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static void computeSomething(byte[] sth)
* Signature: ([B)V
*/
void ComputeIntensiveClass::computeSomething(JNIEnv *env, jclass clazz, jbyteArray sth) {
return;
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static java.lang.String greet()
* Signature: ()Ljava/lang/String;
*/
jstring ComputeIntensiveClass::greet(JNIEnv *env, jclass clazz) {
return env->NewStringUTF("Hello From Jenny");
}
/*
* 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 ComputeIntensiveClass::testParamParse(JNIEnv *env, jobject thiz, jint a, jstring b, jlongArray c, jobjectArray d, jthrowable e, jclass f, jobject g) {
return;
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static long returnsLong()
* Signature: ()J
*/
jlong ComputeIntensiveClass::returnsLong(JNIEnv *env, jclass clazz) {
return 0;
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static boolean returnsBool()
* Signature: ()Z
*/
jboolean ComputeIntensiveClass::returnsBool(JNIEnv *env, jclass clazz) {
return JNI_FALSE;
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static java.lang.Object returnsObject()
* Signature: ()Ljava/lang/Object;
*/
jobject ComputeIntensiveClass::returnsObject(JNIEnv *env, jclass clazz) {
return nullptr;
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static void testOverload()
* Signature: ()V
*/
void ComputeIntensiveClass::testOverload__(JNIEnv *env, jclass clazz) {
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public static void testOverload(int i)
* Signature: (I)V
*/
void ComputeIntensiveClass::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 ComputeIntensiveClass::httpGet(JNIEnv *env, jclass clazz, jstring _url) {
#define __ \
if (env->ExceptionCheck()) { \
env->ExceptionClear(); \
return nullptr; \
}
using namespace java::okhttp;
jenny::LocalRef<jstring> url(_url, false);
OkHttpClientProxy client = OkHttpClientProxy::newInstance(); __
BuilderProxy builder = BuilderProxy::newInstance().url(url); __
RequestProxy request = builder.build(); __
CallProxy call = client.newCall(request.getThis()); __
ResponseProxy response = call.execute(); __
ResponseBodyProxy body = response.body(); __
return body.string().release();
#undef __
/*
* equivalent java code to {@link ComputeIntensiveClass#httpGet(String)}
String run(String url) throws IOException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
*/
}
void ComputeIntensiveClass::runJniHelperTest(JNIEnv* env, jclass clazz) {
jenny::internal::jniHelperUnitTest(env);
}
/*
* Class: io.github.landerlyoung.jennysampleapp.ComputeIntensiveClass
* Method: public int computeThenCallback(io.github.landerlyoung.jennysampleapp.Callback listener)
* Signature: (Lio/github/landerlyoung/jennysampleapp/Callback;)I
*/
jint ComputeIntensiveClass::computeThenCallback(JNIEnv* env, jobject thiz, jobject listener) {
static int count = 0;
bool useJniHelper = count++ % 2 == 0;
if (useJniHelper) {
CallbackProxy proxy{listener, false};
auto name = proxy.getName();
auto newInstance = CallbackProxy::newInstance();
proxy.setLock(newInstance.getThis(false));
proxy.onJobProgress(20);
auto nestedClass = NestedClassProxy::newInstance(proxy.getThis(false));
proxy.setLock(nestedClass.getThis(false));
proxy.onJobProgress(50);
CallbackProxy::setAStaticField(nullptr);
proxy.setCount(100);
proxy.setLock(proxy.getThis(false));
proxy.onJobProgress(100);
auto str = jenny::toJavaString("Yes, callback from jni w/ jnihelper");
proxy.onJobDone(JNI_TRUE, str);
} else {
CallbackProxy::onJobStart(env, listener);
auto name = CallbackProxy::getName(env, listener);
auto newInstance = CallbackProxy::newInstance(env);
CallbackProxy::setLock(env, listener, newInstance);
CallbackProxy::onJobProgress(env, listener, 20);
auto nestedClass = NestedClassProxy::newInstance(env, listener);
CallbackProxy::setLock(env, newInstance, nestedClass);
CallbackProxy::onJobProgress(env, listener, 50);
CallbackProxy::setAStaticField(env, nullptr);
CallbackProxy::setCount(env, listener, 100);
CallbackProxy::setLock(env, listener, listener);
CallbackProxy::onJobProgress(env, listener, 100);
jstring str = env->NewStringUTF("Yes, callback from jni w/o jnihelper");
CallbackProxy::onJobDone(env, listener, JNI_TRUE, str);
env->DeleteLocalRef(name);
env->DeleteLocalRef(str);
env->DeleteLocalRef(newInstance);
env->DeleteLocalRef(nestedClass);
}
return 0;
}