[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / EventsProvider.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of EventsProvider */
12 public interface EventsProviderInterface {
13         /**Processes any events generated since the last call using the given event handler.
14          * 
15          * See the trait-level documentation for requirements.
16          */
17         void process_pending_events(EventHandler handler);
18 }
19
20 /**
21  * A trait indicating an object may generate events.
22  * 
23  * Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
24  * 
25  * Implementations of this trait may also feature an async version of event handling, as shown with
26  * [`ChannelManager::process_pending_events_async`] and
27  * [`ChainMonitor::process_pending_events_async`].
28  * 
29  * # Requirements
30  * 
31  * When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
32  * event since the last invocation.
33  * 
34  * In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
35  * and replay any unhandled events on startup. An [`Event`] is considered handled when
36  * [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
37  * relevant changes to disk *before* returning.
38  * 
39  * Further, because an application may crash between an [`Event`] being handled and the
40  * implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
41  * effect, [`Event`]s may be replayed.
42  * 
43  * Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
44  * consult the provider's documentation on the implication of processing events and how a handler
45  * may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
46  * [`ChainMonitor::process_pending_events`]).
47  * 
48  * (C-not implementable) As there is likely no reason for a user to implement this trait on their
49  * own type(s).
50  * 
51  * [`process_pending_events`]: Self::process_pending_events
52  * [`handle_event`]: EventHandler::handle_event
53  * [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
54  * [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
55  * [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
56  * [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
57  */
58 public class EventsProvider : CommonBase {
59         internal bindings.LDKEventsProvider bindings_instance;
60         internal long instance_idx;
61
62         internal EventsProvider(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
63         ~EventsProvider() {
64                 if (ptr != 0) { bindings.EventsProvider_free(ptr); }
65         }
66
67         private class LDKEventsProviderHolder { internal EventsProvider held; }
68         private class LDKEventsProviderImpl : bindings.LDKEventsProvider {
69                 internal LDKEventsProviderImpl(EventsProviderInterface arg, LDKEventsProviderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
70                 private EventsProviderInterface arg;
71                 private LDKEventsProviderHolder impl_holder;
72                 public void process_pending_events(long _handler) {
73                         EventHandler ret_hu_conv = new EventHandler(null, _handler);
74                         if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
75                         arg.process_pending_events(ret_hu_conv);
76                                 GC.KeepAlive(arg);
77                 }
78         }
79
80         /** Creates a new instance of EventsProvider from a given implementation */
81         public static EventsProvider new_impl(EventsProviderInterface arg) {
82                 LDKEventsProviderHolder impl_holder = new LDKEventsProviderHolder();
83                 LDKEventsProviderImpl impl = new LDKEventsProviderImpl(arg, impl_holder);
84                 long[] ptr_idx = bindings.LDKEventsProvider_new(impl);
85
86                 impl_holder.held = new EventsProvider(null, ptr_idx[0]);
87                 impl_holder.held.instance_idx = ptr_idx[1];
88                 impl_holder.held.bindings_instance = impl;
89                 return impl_holder.held;
90         }
91
92         /**
93          * Processes any events generated since the last call using the given event handler.
94          * 
95          * See the trait-level documentation for requirements.
96          */
97         public void process_pending_events(org.ldk.structs.EventHandler handler) {
98                 bindings.EventsProvider_process_pending_events(this.ptr, handler.ptr);
99                 GC.KeepAlive(this);
100                 GC.KeepAlive(handler);
101                 if (this != null) { this.ptrs_to.AddLast(handler); };
102         }
103
104 }
105 } } }