Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / ErrorAction.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
11  * Used to put an error message in a LightningError
12  */
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 {
18                 super.finalize();
19                 if (ptr != 0) { bindings.ErrorAction_free(ptr); }
20         }
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);
25                 }
26                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) {
27                         return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
28                 }
29                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
30                         return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
31                 }
32                 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
33                         return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
34                 }
35                 assert false; return null; // Unreachable without extending the (internal) bindings interface
36         }
37
38         /**
39          * The peer took some action which made us think they were useless. Disconnect them.
40          */
41         public final static class DisconnectPeer extends ErrorAction {
42                 /**
43                  * An error message which we should make an effort to send before we disconnect.
44                  * 
45                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
46                 */
47                 @Nullable public final ErrorMessage msg;
48                 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
49                         super(null, ptr);
50                         long msg = obj.msg;
51                         ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
52                         msg_hu_conv.ptrs_to.add(this);
53                         this.msg = msg_hu_conv;
54                 }
55         }
56         /**
57          * The peer did something harmless that we weren't able to process, just log and ignore
58          */
59         public final static class IgnoreError extends ErrorAction {
60                 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
61                         super(null, ptr);
62                 }
63         }
64         /**
65          * The peer did something harmless that we weren't able to meaningfully process.
66          * If the error is logged, log it at the given level.
67          */
68         public final static class IgnoreAndLog extends ErrorAction {
69                 public final Level ignore_and_log;
70                 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
71                         super(null, ptr);
72                         this.ignore_and_log = obj.ignore_and_log;
73                 }
74         }
75         /**
76          * The peer did something incorrect. Tell them.
77          */
78         public final static class SendErrorMessage extends ErrorAction {
79                 /**
80                  * The message to send.
81                 */
82                 public final ErrorMessage msg;
83                 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
84                         super(null, ptr);
85                         long msg = obj.msg;
86                         ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
87                         msg_hu_conv.ptrs_to.add(this);
88                         this.msg = msg_hu_conv;
89                 }
90         }
91         long clone_ptr() {
92                 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
93                 return ret;
94         }
95
96         /**
97          * Creates a copy of the ErrorAction
98          */
99         public ErrorAction clone() {
100                 long ret = bindings.ErrorAction_clone(this.ptr);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
103                 ret_hu_conv.ptrs_to.add(this);
104                 return ret_hu_conv;
105         }
106
107         /**
108          * Utility method to constructs a new DisconnectPeer-variant ErrorAction
109          */
110         public static ErrorAction disconnect_peer(ErrorMessage msg) {
111                 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1);
112                 if (ret >= 0 && ret <= 4096) { return null; }
113                 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
114                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
115                 return ret_hu_conv;
116         }
117
118         /**
119          * Utility method to constructs a new IgnoreError-variant ErrorAction
120          */
121         public static ErrorAction ignore_error() {
122                 long ret = bindings.ErrorAction_ignore_error();
123                 if (ret >= 0 && ret <= 4096) { return null; }
124                 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
125                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
126                 return ret_hu_conv;
127         }
128
129         /**
130          * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
131          */
132         public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
133                 long ret = bindings.ErrorAction_ignore_and_log(a);
134                 if (ret >= 0 && ret <= 4096) { return null; }
135                 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
136                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Utility method to constructs a new SendErrorMessage-variant ErrorAction
142          */
143         public static ErrorAction send_error_message(ErrorMessage msg) {
144                 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
147                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
148                 return ret_hu_conv;
149         }
150
151 }