7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of EventHandler */
12 public interface EventHandlerInterface {
13 /**Handles the given [`Event`].
15 * See [`EventsProvider`] for details that must be considered when implementing this method.
17 void handle_event(Event _event);
21 * A trait implemented for objects handling events from [`EventsProvider`].
23 * An async variation also exists for implementations of [`EventsProvider`] that support async
24 * event handling. The async event handler should satisfy the generic bounds: `F:
25 * core::future::Future, H: Fn(Event) -> F`.
27 public class EventHandler : CommonBase {
28 internal bindings.LDKEventHandler bindings_instance;
29 internal long instance_idx;
31 internal EventHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
33 if (ptr != 0) { bindings.EventHandler_free(ptr); }
36 private class LDKEventHandlerHolder { internal EventHandler held; }
37 private class LDKEventHandlerImpl : bindings.LDKEventHandler {
38 internal LDKEventHandlerImpl(EventHandlerInterface arg, LDKEventHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
39 private EventHandlerInterface arg;
40 private LDKEventHandlerHolder impl_holder;
41 public void handle_event(long _event) {
42 org.ldk.structs.Event _event_hu_conv = org.ldk.structs.Event.constr_from_ptr(_event);
43 if (_event_hu_conv != null) { _event_hu_conv.ptrs_to.AddLast(this); };
44 arg.handle_event(_event_hu_conv);
49 /** Creates a new instance of EventHandler from a given implementation */
50 public static EventHandler new_impl(EventHandlerInterface arg) {
51 LDKEventHandlerHolder impl_holder = new LDKEventHandlerHolder();
52 LDKEventHandlerImpl impl = new LDKEventHandlerImpl(arg, impl_holder);
53 long[] ptr_idx = bindings.LDKEventHandler_new(impl);
55 impl_holder.held = new EventHandler(null, ptr_idx[0]);
56 impl_holder.held.instance_idx = ptr_idx[1];
57 impl_holder.held.bindings_instance = impl;
58 return impl_holder.held;
62 * Handles the given [`Event`].
64 * See [`EventsProvider`] for details that must be considered when implementing this method.
66 public void handle_event(org.ldk.structs.Event _event) {
67 bindings.EventHandler_handle_event(this.ptr, _event.ptr);
70 if (this != null) { this.ptrs_to.AddLast(_event); };