X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=java_strings.py;h=2e9ae67052d7d06fe6873065da9004d0a72fc4a2;hb=56b390596670c976a82419933a7206eb93cd1484;hp=b66157eb80be4580e1f857b2a979925227074e05;hpb=739c980d19c6c04538b739c680024c5083a10585;p=ldk-java diff --git a/java_strings.py b/java_strings.py index b66157eb..2e9ae670 100644 --- a/java_strings.py +++ b/java_strings.py @@ -1,7 +1,54 @@ from bindingstypes import * class Consts: - def __init__(self, DEBUG): + def __init__(self, DEBUG: bool, **kwargs): + + self.c_type_map = dict( + uint8_t = ['byte'], + uint16_t = ['short'], + uint32_t = ['int'], + long = ['long'], + ) + + self.to_hu_conv_templates = dict( + ptr = '{human_type} {var_name}_hu_conv = new {human_type}(null, {var_name});', + default = '{human_type} {var_name}_hu_conv = new {human_type}(null, {var_name});' + ) + + self.bindings_header = """package org.ldk.impl; +import org.ldk.enums.*; + +public class bindings { + public static class VecOrSliceDef { + public long dataptr; + public long datalen; + public long stride; + public VecOrSliceDef(long dataptr, long datalen, long stride) { + this.dataptr = dataptr; this.datalen = datalen; this.stride = stride; + } + } + static { + System.loadLibrary(\"lightningjni\"); + init(java.lang.Enum.class, VecOrSliceDef.class); + init_class_cache(); + } + static native void init(java.lang.Class c, java.lang.Class slicedef); + static native void init_class_cache(); + + public static native boolean deref_bool(long ptr); + public static native long deref_long(long ptr); + public static native void free_heap_ptr(long ptr); + public static native byte[] read_bytes(long ptr, long len); + public static native byte[] get_u8_slice_bytes(long slice_ptr); + public static native long bytes_to_u8_vec(byte[] bytes); + public static native long new_txpointer_copy_data(byte[] txdata); + public static native void txpointer_free(long ptr); + public static native byte[] txpointer_get_buffer(long ptr); + public static native long vec_slice_len(long vec); + public static native long new_empty_slice_vec(); + +""" + self.common_base = """package org.ldk.structs; import java.util.LinkedList; class CommonBase { @@ -738,3 +785,21 @@ import java.util.Arrays; out_c += ("\t}\n}\n") out_java_enum += ("}\n") return (out_java, out_java_enum, out_c) + + def map_opaque_struct(self, struct_name): + out_opaque_struct_human = "" + out_opaque_struct_human += self.hu_struct_file_prefix + out_opaque_struct_human += ("public class " + struct_name.replace("LDK","") + " extends CommonBase") + if struct_name.startswith("LDKLocked"): + out_opaque_struct_human += (" implements AutoCloseable") + out_opaque_struct_human += (" {\n") + out_opaque_struct_human += ("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n") + if struct_name.startswith("LDKLocked"): + out_opaque_struct_human += ("\t@Override public void close() {\n") + else: + out_opaque_struct_human += ("\t@Override @SuppressWarnings(\"deprecation\")\n") + out_opaque_struct_human += ("\tprotected void finalize() throws Throwable {\n") + out_opaque_struct_human += ("\t\tsuper.finalize();\n") + out_opaque_struct_human += ("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n") + out_opaque_struct_human += ("\t}\n\n") + return out_opaque_struct_human