theKernel 10.0
Loading...
Searching...
No Matches
LibMkKernel_jv.c
Go to the documentation of this file.
1
9/* LABEL-NO */
10
11#include "jni_h/jvmkkernel_MkKernel.h"
12#include "LibMkKernel_private_jv.h"
13
15JavaVM *MK(cached_jvm) = NULL;
16
20
21#define defDebug0
22#define defClass(v,n) jclass v;
23#define defOAtr(v,c,n,s) jfieldID v;
24#define defSAtr(v,c,n,s) jfieldID v;
25#define defOMth(v,c,n,s) jmethodID v;
26#define defSMth(v,c,n,s) jmethodID v;
27
28#include "MkDefs_jv.h"
29
30#undef defDebug0
31#undef defClass
32#undef defOAtr
33#undef defSAtr
34#undef defOMth
35#undef defSMth
36
37static void NS(sMkRuntimeCallback) ( MK_RT_ARGS_ONLY ) {
38 // BEGIN-INIT - created by 'jv_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
39
40 NS(MkBufferListC_Init) (MK_RT_CALL_ONLY) ;
41 NS(MkBufferC_Init) (MK_RT_CALL_ONLY) ;
42 NS(MkBufferStreamC_Init) (MK_RT_CALL_ONLY) ;
43 NS(MkErrorC_Init) (MK_RT_CALL_ONLY) ;
44 NS(MkLogFileC_Init) (MK_RT_CALL_ONLY) ;
45 NS(MkObjectC_Init) (MK_RT_CALL_ONLY) ;
46 NS(MkRuntimeC_Init) (MK_RT_CALL_ONLY) ;
47
48 // END-INIT - created by 'jv_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
49}
50
51static struct MkRuntimeCallbackS NS(sMkRuntimeCallbackData) = {0};
52
53#define MkCleanupTmpl()
54#define MkSetupTmpl()
55
56// BEGIN-MkKernel - created by 'jv_MqC.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
57
61
62// doc-key: MkKernel,MkKernel-Enum,sco
63
65JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_ErrorE_1FromInt (JNIEnv *env, jclass class, jint value) {
67 enum MkErrorE value_out;
68 enum MkErrorE errVal = MkErrorE_FromInt(value, &value_out);
69 MkErrorC_Check(NULL, errVal)
70 jobject __retVal__S = MK(pGetEnumFromString)(env,MK(Class_MkErrorE),"Ljvmkkernel/MkErrorE;",MkErrorE_ToString(value_out));
71 return __retVal__S;
72error:
73 return 0;
74}
75
77JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_IdSE_1FromInt (JNIEnv *env, jclass class, jint value) {
79 enum MkIdSE value_out;
80 enum MkErrorE errVal = MkIdSE_FromInt(value, &value_out);
81 MkErrorC_Check(NULL, errVal)
82 jobject __retVal__S = MK(pGetEnumFromString)(env,MK(Class_MkIdSE),"Ljvmkkernel/MkIdSE;",MkIdSE_ToString(value_out));
83 return __retVal__S;
84error:
85 return 0;
86}
87
89JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_TimeoutE_1FromInt (JNIEnv *env, jclass class, jint value) {
91 enum MkTimeoutE value_out;
92 enum MkErrorE errVal = MkTimeoutE_FromInt(value, &value_out);
93 MkErrorC_Check(NULL, errVal)
94 jobject __retVal__S = MK(pGetEnumFromString)(env,MK(Class_MkTimeoutE),"Ljvmkkernel/MkTimeoutE;",MkTimeoutE_ToString(value_out));
95 return __retVal__S;
96error:
97 return 0;
98}
99
101JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_TypeE_1FromInt (JNIEnv *env, jclass class, jint value) {
103 enum MkTypeE value_out;
104 enum MkErrorE errVal = MkTypeE_FromInt(value, &value_out);
105 MkErrorC_Check(NULL, errVal)
106 jobject __retVal__S = MK(pGetEnumFromString)(env,MK(Class_MkTypeE),"Ljvmkkernel/MkTypeE;",MkTypeE_ToString(value_out));
107 return __retVal__S;
108error:
109 return 0;
110}
111
112// doc-key: MkKernel,MkKernel-Enum,sm_
113
115JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_ErrorE_1ToInt (JNIEnv *env, jclass class, jobject value) {
117 enum MkErrorE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkErrorE), value);
118 JavaErrorCheck;
119 MK_I32 __retVal__L = MkErrorE_ToInt(value_e);
120 jint __retVal__S = __retVal__L;
121 return __retVal__S;
122error:
123 return 0;
124}
125
127JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_ErrorE_1ToString (JNIEnv *env, jclass class, jobject value) {
129 enum MkErrorE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkErrorE), value);
130 JavaErrorCheck;
131 MK_STRN __retVal__L = MkErrorE_ToString(value_e);
132 jstring __retVal__S = JC2O(env,__retVal__L);
133 return __retVal__S;
134error:
135 return 0;
136}
137
139JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_IdSE_1ToInt (JNIEnv *env, jclass class, jobject value) {
141 enum MkIdSE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkIdSE), value);
142 JavaErrorCheck;
143 MK_I32 __retVal__L = MkIdSE_ToInt(value_e);
144 jint __retVal__S = __retVal__L;
145 return __retVal__S;
146error:
147 return 0;
148}
149
151JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_IdSE_1ToString (JNIEnv *env, jclass class, jobject value) {
153 enum MkIdSE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkIdSE), value);
154 JavaErrorCheck;
155 MK_STRN __retVal__L = MkIdSE_ToString(value_e);
156 jstring __retVal__S = JC2O(env,__retVal__L);
157 return __retVal__S;
158error:
159 return 0;
160}
161
163JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_TimeoutE_1ToInt (JNIEnv *env, jclass class, jobject value) {
165 enum MkTimeoutE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkTimeoutE), value);
166 JavaErrorCheck;
167 MK_I32 __retVal__L = MkTimeoutE_ToInt(value_e);
168 jint __retVal__S = __retVal__L;
169 return __retVal__S;
170error:
171 return 0;
172}
173
175JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_TimeoutE_1ToString (JNIEnv *env, jclass class, jobject value) {
177 enum MkTimeoutE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkTimeoutE), value);
178 JavaErrorCheck;
179 MK_STRN __retVal__L = MkTimeoutE_ToString(value_e);
180 jstring __retVal__S = JC2O(env,__retVal__L);
181 return __retVal__S;
182error:
183 return 0;
184}
185
187JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_TypeE_1ToInt (JNIEnv *env, jclass class, jobject value) {
189 enum MkTypeE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkTypeE), value);
190 JavaErrorCheck;
191 MK_I32 __retVal__L = MkTypeE_ToInt(value_e);
192 jint __retVal__S = __retVal__L;
193 return __retVal__S;
194error:
195 return 0;
196}
197
199JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_TypeE_1ToString (JNIEnv *env, jclass class, jobject value) {
201 enum MkTypeE value_e = MK(pGetEnumFromObj)(env, NS(Class_MkTypeE), value);
202 JavaErrorCheck;
203 MK_STRN __retVal__L = MkTypeE_ToString(value_e);
204 jstring __retVal__S = JC2O(env,__retVal__L);
205 return __retVal__S;
206error:
207 return 0;
208}
209
211// MkKernel_Enum_JV_API
212
216
217// doc-key: MkKernel,MkKernel-Setup-libmkkernel,sm_
218
220JNIEXPORT void JNICALL Java_jvmkkernel_MkKernel_Cleanup (JNIEnv *env, jclass class) {
223}
224
226JNIEXPORT void JNICALL Setup (JNIEnv *env, jclass class) {
228 MkSetupTmpl();
229}
230
232// MkKernel_Setup_libmkkernel_JV_API
233
234// END-MkKernel - created by 'jv_MqC.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
235
236// https://stackoverflow.com/questions/30026030/what-is-the-best-way-to-save-jnienv
237enum MkErrorE MK(GetJniEnv)(MK_RT_ARGS JNIEnv **env) {
238 enum MkErrorE did_attach_thread = MK_OK;
239 *env = NULL;
240 // Check if the current thread is attached to the VM
241 jint get_env_result = (*MK(cached_jvm))->GetEnv(MK(cached_jvm), (void**)env, JNI_VERSION_1_6);
242 if (get_env_result == JNI_EDETACHED) {
243 JavaVMAttachArgs args = {JNI_VERSION_10, "libmqmsgque", NULL};
244 //if ((*MK(cached_jvm))->AttachCurrentThreadAsDaemon(MK(cached_jvm), (void**)env, &args) == JNI_OK) {
245 if ((*MK(cached_jvm))->AttachCurrentThread(MK(cached_jvm), (void**)env, &args) == JNI_OK) {
246 did_attach_thread = MK_OK;
247 } else {
248 // Failed to attach thread. Throw an exception if you want to.
249 did_attach_thread = MkErrorSetC_1E ("Failed to attach thread");
250 }
251 } else if (get_env_result == JNI_EVERSION) {
252 // Unsupported JNI version. Throw an exception if you want to.
253 did_attach_thread = MkErrorSetC_1E ("Unsupported JNI version");
254 }
255 if (*env == NULL) {
256 did_attach_thread = MkErrorSetC_1E ("unable to retrieve 'JNIEnv'");
257 } else if ((**env)->ExceptionCheck(*env)) {
258 did_attach_thread = MkErrorSetC_1E ("exception during retrieving of 'JNIEnv'");
259 }
260 return did_attach_thread;
261}
262
263
265// MODULE
266
268
269JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
270{
271 JNIEnv *env;
272 MK(cached_jvm) = jvm; /* cache the JavaVM pointer */
273
274 JavaErrorCheck0 ((*jvm)->GetEnv(jvm, (void*) &env, JNI_VERSION_1_6));
275
276 // init "LibMqMsgque"
277 MkSetup();
279
280 //MkSysPipeHandler(MK_PIPE_KEEP);
281
282 JavaErrorCheck0 ((*env)->EnsureLocalCapacity(env, 50));
283
284 jclass cls;
285
286#define check(v,c) if ((v=(c))==NULL) return JNI_ERR
287#define defClass(v,n) check(cls, (*env)->FindClass(env, n));\
288 JavaErrorCheck; \
289 check(v, (*env)->NewGlobalRef(env, cls)); \
290 JavaErrorCheck;
291#define defOAtr(v,c,n,s) check(v, (*env)->GetFieldID(env,c,n,s)); \
292 JavaErrorCheck;
293#define defSAtr(v,c,n,s) check(v, (*env)->GetStaticFieldID(env,c,n,s)); \
294 JavaErrorCheck;
295#define defOMth(v,c,n,s) check(v, (*env)->GetMethodID(env,c,n,s)); \
296 JavaErrorCheck;
297#define defSMth(v,c,n,s) check(v, (*env)->GetStaticMethodID(env,c,n,s)); \
298 JavaErrorCheck;
299#define defDebug0 MA
300
301#include "MkDefs_jv.h"
302
303#undef defDebug0
304#undef defClass
305#undef defOAtr
306#undef defSAtr
307#undef defOMth
308#undef defSMth
309
310 // class specific initialization
311 MkRuntimeCallbackAdd( MK_RT_CALL &NS(sMkRuntimeCallbackData), NS(sMkRuntimeCallback), "JvKernel" );
312
313 return JNI_VERSION_10;
314error:
315 return JNI_ERR; /* JNI version not supported */
316}
317
318JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
319{
320 JNIEnv *env;
321 void *val;
322 if ((*jvm)->GetEnv(jvm, &val, JNI_VERSION_1_6)) {
323 return;
324 }
325
327
328 // cleanup global variables
329 env = (JNIEnv*) val;
330
331#define defDebug0
332#define defClass(v,n) (*env)->DeleteGlobalRef(env, v);
333#define defOAtr(v,c,n,s)
334#define defSAtr(v,c,n,s)
335#define defOMth(v,c,n,s)
336#define defSMth(v,c,n,s)
337
338#include "MkDefs_jv.h"
339
340#undef defDebug0
341#undef defClass
342#undef defOAtr
343#undef defSAtr
344#undef defOMth
345#undef defSMth
346
347 MkRuntimeCallbackDel( MK_RT_CALL &NS(sMkRuntimeCallbackData) );
348
349 MkCleanup();
350
351 return;
352}
#define MkCleanupTmpl()
jfieldID jfieldID_List
jclass jclass_List
#define MkSetupTmpl()
jmethodID jmethodID_List
tag: nhi1-release-250425
#define MkErrorSetC_1E(message)
MK_STRN MkTimeoutE_ToString(enum MkTimeoutE value)
return the MkTimeoutE as string …
MkTimeoutE
Predefined Timeout values …
enum MkErrorE MkIdSE_FromInt(MK_I32 const value, enum MkIdSE *value_out)
return the MkIdSE from integer …
static MK_I32 MkTypeE_ToInt(enum MkTypeE value)
return the MkTypeE as integer …
static MK_I32 MkErrorE_ToInt(enum MkErrorE value)
return the MkErrorE as integer …
static MK_I32 MkTimeoutE_ToInt(enum MkTimeoutE value)
return the MkTimeoutE as integer …
enum MkErrorE MkTypeE_FromInt(MK_I32 const value, enum MkTypeE *value_out)
return the MkTypeE from integer …
MK_STRN MkIdSE_ToString(enum MkIdSE value)
return the MkIdSE as string …
static MK_I32 MkIdSE_ToInt(enum MkIdSE value)
return the MkIdSE as integer …
enum MkErrorE MkErrorE_FromInt(MK_I32 const value, enum MkErrorE *value_out)
return the MkErrorE from integer …
enum MkErrorE MkTimeoutE_FromInt(MK_I32 const value, enum MkTimeoutE *value_out)
return the MkTimeoutE from integer …
MK_STRN MkTypeE_ToString(enum MkTypeE value)
return the MkTypeE as string …
MkErrorE
collection for the different error-codes …
MkTypeE
basic data-types supported by Programming-Language-Micro-Kernel (PLMK) …
MK_STRN MkErrorE_ToString(enum MkErrorE value)
return the MkErrorE as string …
@ MK_OK
(persistent) everything is OK.
JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_IdSE_1ToString(JNIEnv *env, jclass class, jobject value)
Java: [static] String IdSE_ToString(MkIdSE value) → C-API return the MkIdSE as string …
JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_IdSE_1ToInt(JNIEnv *env, jclass class, jobject value)
Java: [static] int IdSE_ToInt(MkIdSE value) → C-API return the MkIdSE as integer …
JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_ErrorE_1ToInt(JNIEnv *env, jclass class, jobject value)
Java: [static] int ErrorE_ToInt(MkErrorE value) → C-API return the MkErrorE as integer …
JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_ErrorE_1ToString(JNIEnv *env, jclass class, jobject value)
Java: [static] String ErrorE_ToString(MkErrorE value) → C-API return the MkErrorE as string …
JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_IdSE_1FromInt(JNIEnv *env, jclass class, jint value)
Java: [static] MkIdSE IdSE_FromInt(int value) → C-API return the MkIdSE from integer …
JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_ErrorE_1FromInt(JNIEnv *env, jclass class, jint value)
Java: [static] MkErrorE ErrorE_FromInt(int value) → C-API return the MkErrorE from integer …
JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_TypeE_1ToString(JNIEnv *env, jclass class, jobject value)
Java: [static] String TypeE_ToString(MkTypeE value) → C-API return the MkTypeE as string …
JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_TypeE_1ToInt(JNIEnv *env, jclass class, jobject value)
Java: [static] int TypeE_ToInt(MkTypeE value) → C-API return the MkTypeE as integer …
JNIEXPORT jint JNICALL Java_jvmkkernel_MkKernel_TimeoutE_1ToInt(JNIEnv *env, jclass class, jobject value)
Java: [static] int TimeoutE_ToInt(MkTimeoutE value) → C-API return the MkTimeoutE as integer …
JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_TypeE_1FromInt(JNIEnv *env, jclass class, jint value)
Java: [static] MkTypeE TypeE_FromInt(int value) → C-API return the MkTypeE from integer …
JNIEXPORT jstring JNICALL Java_jvmkkernel_MkKernel_TimeoutE_1ToString(JNIEnv *env, jclass class, jobject value)
Java: [static] String TimeoutE_ToString(MkTimeoutE value) → C-API return the MkTimeoutE as strin...
JNIEXPORT jobject JNICALL Java_jvmkkernel_MkKernel_TimeoutE_1FromInt(JNIEnv *env, jclass class, jint value)
Java: [static] MkTimeoutE TimeoutE_FromInt(int value) → C-API return the MkTimeoutE from integer...
void MkSetup(void)
setup jvmkkernel internal memory …
void MkCleanup(void)
cleanup jvmkkernel internal memory …
JNIEXPORT void JNICALL Java_jvmkkernel_MkKernel_Cleanup(JNIEnv *env, jclass class)
Java: [static] Cleanup() → C-API cleanup jvmkkernel internal memory …
JNIEXPORT void JNICALL Setup(JNIEnv *env, jclass class)
Java: [static] Setup() → C-API setup jvmkkernel internal memory …
const MK_STRB * MK_STRN
constant string pointer data-type
signed int MK_I32
4 byte integer data-type
MkIdSE
signal type of the MkIdS data val …
bool MkRuntimeSysPipeHandlerUse
block SIGPIPE ignore handlern default=true, Java require this
size_t MkRuntimeCallbackAdd(MK_RT mkrt, MkRuntimeCallbackS *cbdata, MkRuntimeInitF rt_callback, MK_STRN ident)
add a callback to the runtime …
void MkRuntimeCallbackDel(MK_RT mkrt, MkRuntimeCallbackS *cbdata)
delete a callback from the runtime …
#define MK_RT_CALL
#define MK_RT_CALL_ONLY
#define MK_RT_ARGS
#define MkRtSetup_NULL
#define MK_RT_ARGS_ONLY
keep callback related data …