-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstage3.cpp
50 lines (37 loc) · 1.21 KB
/
stage3.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
#include "stage3.hpp"
#include <cstring>
#include <jni.h>
extern "C" Stage3 *stage3_create() {
return new Stage3();
}
extern "C" void stage3_delete(Stage3 *st) {
delete st;
}
extern "C" const char *stage3_blep(Stage3 *st, char *foo) {
return strdup(st->blep(foo).c_str());
}
std::string Stage3::blep(std::string foo) {
JavaVM *jvm = NULL;
JNIEnv *env = NULL;
printf("Stage 3: %s\n", foo.c_str());
JNI_GetCreatedJavaVMs(&jvm, 1, NULL);
jvm->AttachCurrentThread((void **)&env, NULL);
jclass stage4 = env->FindClass("Stage4");
jmethodID blep_id = env->GetStaticMethodID(stage4, "blep", "(Ljava/lang/String;)Ljava/lang/String;");
jstring jfoo = env->NewStringUTF(foo.c_str());
jstring jres = static_cast<jstring>(env->CallStaticObjectMethod(stage4, blep_id, jfoo));
const char *cfoo = env->GetStringUTFChars(jres, 0);
const char *rv = strdup(cfoo);
env->ReleaseStringUTFChars(jfoo, cfoo);
jvm->DetachCurrentThread();
printf("Return value[3]: %s\n", rv);
return rv;
}
int main(int argc, const char *argv[]) {
if (argc < 2)
return 1;
Stage3 *st = new Stage3();
printf("%s\n", st->blep(argv[1]).c_str());
delete st;
return 0;
}