From f40a34bdc1995e656b09cc1252a8dcce685e373f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 11 Mar 2017 23:04:58 +0100 Subject: Use delegates + object storage instead of listener objects --- xmpp-vala/src/module/iq/module.vala | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'xmpp-vala/src/module/iq') diff --git a/xmpp-vala/src/module/iq/module.vala b/xmpp-vala/src/module/iq/module.vala index c3bb81ff..693f1da3 100644 --- a/xmpp-vala/src/module/iq/module.vala +++ b/xmpp-vala/src/module/iq/module.vala @@ -12,14 +12,15 @@ namespace Xmpp.Iq { private HashMap responseListeners = new HashMap(); private HashMap> namespaceRegistrants = new HashMap>(); - public void send_iq(XmppStream stream, Iq.Stanza iq, ResponseListener? listener = null) { + [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, Iq.Stanza iq, Object reference); + public void send_iq(XmppStream stream, Iq.Stanza iq, OnResult? listener = null, Object? reference = null) { try { stream.write(iq.stanza); } catch (IOStreamError e) { print(@"$(e.message)\n"); } if (listener != null) { - responseListeners.set(iq.id, listener); + responseListeners[iq.id] = new ResponseListener(listener, reference); } } @@ -56,7 +57,7 @@ namespace Xmpp.Iq { if (responseListeners.has_key(iq.id)) { ResponseListener? listener = responseListeners.get(iq.id); if (listener != null) { - listener.on_result(stream, iq); + listener.on_result(stream, iq, listener.reference); } responseListeners.unset(iq.id); } @@ -77,6 +78,16 @@ namespace Xmpp.Iq { } } } + + private class ResponseListener { + public OnResult on_result { get; private set; } + public Object? reference { get; private set; } + + public ResponseListener(OnResult on_result, Object? reference = null) { + this.on_result = on_result; + this.reference = reference; + } + } } public interface Handler : Object { @@ -84,7 +95,4 @@ namespace Xmpp.Iq { public abstract void on_iq_set(XmppStream stream, Iq.Stanza iq); } - public interface ResponseListener : Object { - public abstract void on_result(XmppStream stream, Iq.Stanza iq); - } } -- cgit v1.2.3-70-g09d2