theKernel 10.0
Loading...
Searching...
No Matches
MkKernel.java
Go to the documentation of this file.
1
9/* LABEL-NO */
10package jvmkkernel;
11
12import java.lang.reflect.Array;
13import java.lang.reflect.Field;
14import java.util.Deque;
15import java.util.ArrayDeque;
16import java.lang.reflect.Constructor;
17
18// #######################################################################
19// -----------------------------------------------------------------------
20// documentation order
35
46
58
70
80
92
100
112
122
128
133final public class MkKernel {
134
135 private MkKernel() {};
136
137 private static boolean first = false;
138
160 static private void SetupTmpl() {
161 if (first) return;
162 first = true;
163
164 System.loadLibrary("jvmkkernel");
165 }
166
167 // INTERNAL
168
169 static ThreadLocal<StackTraceElement> stack_t = new ThreadLocal<>();
170
172 static void getCallerStack() {
173 Integer stack_il;
174 StackTraceElement[] stack_tl = Thread.currentThread().getStackTrace();
175 if (stack_tl.length > 2) {
176 String mark = stack_tl[2].getMethodName();
177 for (stack_il=3; stack_il<stack_tl.length; stack_il++) {
178 if (stack_tl[stack_il].getMethodName() != mark) break;
179 }
180 } else {
181 stack_il = stack_tl.length-1;
182 }
183 stack_t.set(stack_tl[stack_il]);
184 }
185
187 static String getCallerProc() {
188 var mn = stack_t.get().getMethodName();
189 return (mn == "Callback" ? stack_t.get().getClassName() : mn);
190 }
191
193 static String getCallerFile() {
194 return stack_t.get().getFileName();
195 }
196
198 static int getCallerLine() {
199 return stack_t.get().getLineNumber();
200 }
201
202 // PUBLIC
203
204 // BEGIN-MkKernel - created by 'jv_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
205
209
210 // doc-key: MkKernel,MkKernel-Enum,sco
211
213 public native static MkErrorE ErrorE_FromInt (int value);
214
216 public native static MkIdSE IdSE_FromInt (int value);
217
219 public native static MkTimeoutE TimeoutE_FromInt (int value);
220
222 public native static MkTypeE TypeE_FromInt (int value);
223
224 // doc-key: MkKernel,MkKernel-Enum,sm_
225
227 public native static int ErrorE_ToInt (MkErrorE value);
228
230 public native static String ErrorE_ToString (MkErrorE value);
231
233 public native static int IdSE_ToInt (MkIdSE value);
234
236 public native static String IdSE_ToString (MkIdSE value);
237
239 public native static int TimeoutE_ToInt (MkTimeoutE value);
240
242 public native static String TimeoutE_ToString (MkTimeoutE value);
243
245 public native static int TypeE_ToInt (MkTypeE value);
246
248 public native static String TypeE_ToString (MkTypeE value);
249
251 // MkKernel_Enum_JV_API
252
256
257 // doc-key: MkKernel,MkKernel-Setup-libmkkernel,sm_
258
260 public native static void Cleanup ();
261
263 public static void Setup () {
264 SetupTmpl();
265 }
266
268 // MkKernel_Setup_libmkkernel_JV_API
269
270 // END-MkKernel - created by 'jv_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
271
272 private static class SpaceBuffer {
273 private StringBuffer val = null;
274 private Deque<Integer> stack = null;
275
276 public SpaceBuffer (String sp) {
277 val = new StringBuffer(sp);
278 stack = new ArrayDeque<Integer>();
279 }
280
281 public SpaceBuffer push (String space) {
282 stack.push(val.length());
283 val.append(space);
284 return this;
285 }
286
287 public void pop () {
288 val.delete(stack.pop(),val.length());
289 }
290
291 public String toString() {
292 return val.toString();
293 }
294 }
295
296 public static void dumpln(Object o) {
297 System.err.println(dump(o, new SpaceBuffer("")));
298 }
299 public static String dump(Object o) {
300 return dump(o, new SpaceBuffer(""));
301 }
302
303 private static String dump(Object o, SpaceBuffer sp) {
304 StringBuffer buffer = new StringBuffer();
305 if (o == null) {
306 buffer.append(sp.toString() + "NULL");
307 } else {
308 Class<?> oClass = o.getClass();
309 if (oClass.isArray()) {
310 buffer.append(sp.toString() + "Array: ");
311 buffer.append("[");
312 for (int i = 0; i < Array.getLength(o); i++) {
313 Object value = Array.get(o, i);
314 if (value.getClass().isPrimitive() ||
315 value.getClass() == java.lang.Long.class ||
316 value.getClass() == java.lang.Integer.class ||
317 value.getClass() == java.lang.Boolean.class ||
318 value.getClass() == java.lang.String.class ||
319 value.getClass() == java.lang.Double.class ||
320 value.getClass() == java.lang.Short.class ||
321 value.getClass() == java.lang.Byte.class
322 ) {
323 buffer.append(value);
324 if(i != (Array.getLength(o)-1)) buffer.append(",");
325 } else {
326 buffer.append(dump(value));
327 }
328 }
329 buffer.append("]\n");
330 } else {
331 buffer.append(sp.toString() + "Class: " + oClass.getName());
332 buffer.append(" {\n");
333 sp.push(" ");
334 while (oClass != null) {
335 Field[] fields = oClass.getDeclaredFields();
336 for (int i = 0; i < fields.length; i++) {
337 fields[i].setAccessible(true);
338 buffer.append(sp.toString() + fields[i].getName());
339 buffer.append("=");
340 try {
341 Object value = fields[i].get(o);
342 if (value != null) {
343 if (value.getClass().isPrimitive() ||
344 value.getClass() == java.lang.Long.class ||
345 value.getClass() == java.lang.String.class ||
346 value.getClass() == java.lang.Integer.class ||
347 value.getClass() == java.lang.Boolean.class ||
348 value.getClass() == java.lang.Double.class ||
349 value.getClass() == java.lang.Short.class ||
350 value.getClass() == java.lang.Byte.class
351 ) {
352 buffer.append(value);
353 } else {
354 buffer.append(dump(value, sp));
355 }
356 }
357 } catch (IllegalAccessException e) {
358 buffer.append(e.getMessage());
359 }
360 buffer.append("\n");
361 }
362 oClass = oClass.getSuperclass();
363 }
364 sp.pop();
365 buffer.append("}\n");
366 }
367 }
368 return buffer.toString();
369 }
370}
371
MkKernel PACKAGE - The package is the toplevel structure of the Programming-Language-Micro-Kernel (PL...
static String dump(Object o)
static void dumpln(Object o)
Java: enum MkErrorE → C-API
Definition MkErrorE.java:16
Java: enum MkIdSE → C-API
Definition MkIdSE.java:16
Java: enum MkTimeoutE → C-API
Java: enum MkTypeE → C-API
Definition MkTypeE.java:16
static native int TimeoutE_ToInt(MkTimeoutE value)
Java: [static] int TimeoutE_ToInt(MkTimeoutE value) → C-API return the MkTimeoutE as integer …
static native String ErrorE_ToString(MkErrorE value)
Java: [static] String ErrorE_ToString(MkErrorE value) → C-API return the MkErrorE as string …
static native String TimeoutE_ToString(MkTimeoutE value)
Java: [static] String TimeoutE_ToString(MkTimeoutE value) → C-API return the MkTimeoutE as strin...
static native MkIdSE IdSE_FromInt(int value)
Java: [static] MkIdSE IdSE_FromInt(int value) → C-API return the MkIdSE from integer …
static native int ErrorE_ToInt(MkErrorE value)
Java: [static] int ErrorE_ToInt(MkErrorE value) → C-API return the MkErrorE as integer …
static native String TypeE_ToString(MkTypeE value)
Java: [static] String TypeE_ToString(MkTypeE value) → C-API return the MkTypeE as string …
static native String IdSE_ToString(MkIdSE value)
Java: [static] String IdSE_ToString(MkIdSE value) → C-API return the MkIdSE as string …
static native int IdSE_ToInt(MkIdSE value)
Java: [static] int IdSE_ToInt(MkIdSE value) → C-API return the MkIdSE as integer …
static native MkTypeE TypeE_FromInt(int value)
Java: [static] MkTypeE TypeE_FromInt(int value) → C-API return the MkTypeE from integer …
static native int TypeE_ToInt(MkTypeE value)
Java: [static] int TypeE_ToInt(MkTypeE value) → C-API return the MkTypeE as integer …
static native MkTimeoutE TimeoutE_FromInt(int value)
Java: [static] MkTimeoutE TimeoutE_FromInt(int value) → C-API return the MkTimeoutE from integer...
static native MkErrorE ErrorE_FromInt(int value)
Java: [static] MkErrorE ErrorE_FromInt(int value) → C-API return the MkErrorE from integer …
static void Setup()
Java: [static] Setup() → C-API setup jvmkkernel internal memory …
static native void Cleanup()
Java: [static] Cleanup() → C-API cleanup jvmkkernel internal memory …