X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FSocketDescriptor.ts;h=a2207ae78e8a1592b05d84d30629b6b7d1c839f0;hb=22f5f4208b1f3b5542292250f1612b944f5cd7fd;hp=cb5a21ed64d25a4f5db3400936afcccc8409e748;hpb=56e9910ffaa7fccf2cb777dc9cf55e01a9681543;p=ldk-java diff --git a/ts/structs/SocketDescriptor.ts b/ts/structs/SocketDescriptor.ts index cb5a21ed..a2207ae7 100644 --- a/ts/structs/SocketDescriptor.ts +++ b/ts/structs/SocketDescriptor.ts @@ -1,5 +1,77 @@ - public long send_data(byte[] data, boolean resume_read) { - long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read); + + +import CommonBase from './CommonBase'; +import * as bindings from '../bindings' // TODO: figure out location + + + + export class SocketDescriptor extends CommonBase { + + bindings_instance?: bindings.LDKSocketDescriptor; + + constructor(ptr?: number, arg?: bindings.LDKSocketDescriptor) { + if (Number.isFinite(ptr)) { + super(ptr); + this.bindings_instance = null; + } else { + // TODO: private constructor instantiation + super(bindings.LDKSocketDescriptor_new(arg)); + this.ptrs_to.push(arg); + + } + } + + protected finalize() { + if (this.ptr != 0) { + bindings.SocketDescriptor_free(this.ptr); + } + super.finalize(); + } + + static new_impl(arg: SocketDescriptorInterface): SocketDescriptor { + const impl_holder: LDKSocketDescriptorHolder = new LDKSocketDescriptorHolder(); + let structImplementation = { + // todo: in-line interface filling + send_data (data: Uint8Array, resume_read: boolean): number { + number ret = arg.send_data(data, resume_read); + return ret; + }, + + disconnect_socket (): void { + arg.disconnect_socket(); + }, + + eq (other_arg: number): boolean { + SocketDescriptor ret_hu_conv = new SocketDescriptor(null, other_arg); + ret_hu_conv.ptrs_to.add(this); + boolean ret = arg.eq(ret_hu_conv); + return ret; + }, + + hash (): number { + number ret = arg.hash(); + return ret; + }, + + + }; + impl_holder.held = new SocketDescriptor (null, structImplementation); + } + } + + export interface SocketDescriptorInterface { + send_data(data: Uint8Array, resume_read: boolean): number; + disconnect_socket(): void; + eq(other_arg: SocketDescriptor): boolean; + hash(): number; + + } + + class LDKSocketDescriptorHolder { + held: SocketDescriptor; + } + public number send_data(Uint8Array data, boolean resume_read) { + number ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read); return ret; } @@ -7,13 +79,13 @@ bindings.SocketDescriptor_disconnect_socket(this.ptr); } - public long hash() { - long ret = bindings.SocketDescriptor_hash(this.ptr); + public number hash() { + number ret = bindings.SocketDescriptor_hash(this.ptr); return ret; } public SocketDescriptor clone() { - uint32_t ret = bindings.SocketDescriptor_clone(this.ptr); + number ret = bindings.SocketDescriptor_clone(this.ptr); SocketDescriptor ret_hu_conv = new SocketDescriptor(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv;