-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaModule.cpp
More file actions
93 lines (72 loc) · 1.93 KB
/
Copy pathJavaModule.cpp
File metadata and controls
93 lines (72 loc) · 1.93 KB
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
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <jni.h>
#include "gridlabd.h"
//#include "myclass.h"
#define MODULENAME "JavaModule"
#define MAJOR 1
#define MINOR 0
static JNIEnv *jnienv = NULL;
EXPORT CLASS *javainit(CALLBACKS *fntable, MODULE *module, int argc, char *argv[], JNIEnv *env)
{
// set the GridLAB core API callback table
callback = fntable;
// set the JNI Environment pointer
jnienv = env;
jclass cls = jnienv->FindClass(MODULENAME);
// init is int (*)(long, int, String[])
jmethodID init_mid = env->GetStaticMethodID(cls, "init", "(JI[Ljava/lang/String;)I");
if(cls == NULL)
return NULL;
if(init_mid == NULL)
return NULL;
jobjectArray args = env->NewObjectArray(argc, jnienv->FindClass("[Ljava/lang/String;"), NULL);
if(args == NULL)
return NULL;
jstring jargv[argc];
for(int i = 0; i < argc; ++i){
jargv[i] = env->NewStringUTF(argv[i]);
jnienv->SetObjectArrayElement(jargv[i], i, args);
}
jnienv->CallStaticIntMethod(cls, init_mid, (long long)module, argc, jargv);
// TODO: register each object class by creating its first instance
//new myclass(module);
// always return the first class registered
//return myclass::oclass;
// JNI cleanup
jnienv->DeleteLocalRef(jobjectArray);
for(int i = 0; i < argc; ++i)
; /* delete the strings */
return NULL;
}
CDECL int do_kill()
{
// if anything needs to be deleted or freed, this is a good time to do it
return 0;
}
#if 0
public static int check(){
return 0;
}
public static int import_file(String filename){
return 0;
}
public static int export_file(String filename){
return 0;
}
public static int setvar(String varname, String value){
return 0;
}
public static int module_test(int argc, String[] argv){
return 0;
}
public static int cmdargs(int argc, String[] argv){
return 0;
}
/* returns a string to fprintf into the C-side stub */
public static String kmldump(long object_addr){
return "";
}
#endif
/* EOF */