1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Used to put an error message in a LightningError
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class ErrorAction extends CommonBase {
15 private ErrorAction(Object _dummy, long ptr) { super(ptr); }
16 @Override @SuppressWarnings("deprecation")
17 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.ErrorAction_free(ptr); }
21 static ErrorAction constr_from_ptr(long ptr) {
22 bindings.LDKErrorAction raw_val = bindings.LDKErrorAction_ref_from_ptr(ptr);
23 if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeer.class) {
24 return new DisconnectPeer(ptr, (bindings.LDKErrorAction.DisconnectPeer)raw_val);
26 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) {
27 return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
29 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
30 return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
32 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
33 return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
35 assert false; return null; // Unreachable without extending the (internal) bindings interface
38 public final static class DisconnectPeer extends ErrorAction {
40 * An error message which we should make an effort to send before we disconnect.
42 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
44 @Nullable public final ErrorMessage msg;
45 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
48 ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
49 msg_hu_conv.ptrs_to.add(this);
50 this.msg = msg_hu_conv;
53 public final static class IgnoreError extends ErrorAction {
54 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
58 public final static class IgnoreAndLog extends ErrorAction {
59 public final Level ignore_and_log;
60 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
62 this.ignore_and_log = obj.ignore_and_log;
65 public final static class SendErrorMessage extends ErrorAction {
67 * The message to send.
69 public final ErrorMessage msg;
70 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
73 ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
74 msg_hu_conv.ptrs_to.add(this);
75 this.msg = msg_hu_conv;
79 * Creates a copy of the ErrorAction
81 public ErrorAction clone() {
82 long ret = bindings.ErrorAction_clone(this.ptr);
83 if (ret < 1024) { return null; }
84 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
85 ret_hu_conv.ptrs_to.add(this);
90 * Utility method to constructs a new DisconnectPeer-variant ErrorAction
92 public static ErrorAction disconnect_peer(ErrorMessage msg) {
93 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1);
94 if (ret < 1024) { return null; }
95 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
96 ret_hu_conv.ptrs_to.add(ret_hu_conv);
97 ret_hu_conv.ptrs_to.add(msg);
102 * Utility method to constructs a new IgnoreError-variant ErrorAction
104 public static ErrorAction ignore_error() {
105 long ret = bindings.ErrorAction_ignore_error();
106 if (ret < 1024) { return null; }
107 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
108 ret_hu_conv.ptrs_to.add(ret_hu_conv);
113 * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
115 public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
116 long ret = bindings.ErrorAction_ignore_and_log(a);
117 if (ret < 1024) { return null; }
118 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
119 ret_hu_conv.ptrs_to.add(ret_hu_conv);
124 * Utility method to constructs a new SendErrorMessage-variant ErrorAction
126 public static ErrorAction send_error_message(ErrorMessage msg) {
127 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1);
128 if (ret < 1024) { return null; }
129 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
130 ret_hu_conv.ptrs_to.add(ret_hu_conv);
131 ret_hu_conv.ptrs_to.add(msg);