diff options
author | fiaxh <git@mx.ax.lt> | 2017-03-11 23:04:58 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-03-11 23:09:57 +0100 |
commit | f40a34bdc1995e656b09cc1252a8dcce685e373f (patch) | |
tree | d56684122d0a2f0e13ee9d94e6e8675bae1b4c52 /xmpp-vala/src/module/xep/0199_ping.vala | |
parent | 0ea4ac7e20674e3e6a8d1b3d4b53702dace72907 (diff) | |
download | dino-f40a34bdc1995e656b09cc1252a8dcce685e373f.tar.gz dino-f40a34bdc1995e656b09cc1252a8dcce685e373f.zip |
Use delegates + object storage instead of listener objects
Diffstat (limited to 'xmpp-vala/src/module/xep/0199_ping.vala')
-rw-r--r-- | xmpp-vala/src/module/xep/0199_ping.vala | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/xmpp-vala/src/module/xep/0199_ping.vala b/xmpp-vala/src/module/xep/0199_ping.vala index a4157e99..35cad26c 100644 --- a/xmpp-vala/src/module/xep/0199_ping.vala +++ b/xmpp-vala/src/module/xep/0199_ping.vala @@ -9,20 +9,10 @@ namespace Xmpp.Xep.Ping { public const string ID = "0199_ping"; public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); - public void send_ping(XmppStream stream, string jid, ResponseListener? listener = null) { + public void send_ping(XmppStream stream, string jid, ResponseListener listener) { Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("ping", NS_URI).add_self_xmlns()); iq.to = jid; - stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, listener == null? null : new IqResponseListenerImpl(listener)); - } - - private class IqResponseListenerImpl : Iq.ResponseListener, Object { - ResponseListener listener; - public IqResponseListenerImpl(ResponseListener listener) { - this.listener = listener; - } - public void on_result(XmppStream stream, Iq.Stanza iq) { - listener.on_result(stream); - } + stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_ping_response, listener); } public override void attach(XmppStream stream) { @@ -45,6 +35,11 @@ namespace Xmpp.Xep.Ping { } public void on_iq_set(XmppStream stream, Iq.Stanza iq) { } } + + private static void on_ping_response(XmppStream stream, Iq.Stanza iq, Object o) { + ResponseListener listener = o as ResponseListener; + listener.on_result(stream); + } } public interface ResponseListener : Object { |