From 9cdc3619bd172a731333b8152ee561eed76e77f8 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 10 Mar 2017 21:13:35 +0100 Subject: Add typed identity to stream modules --- xmpp-vala/src/core/xmpp_stream.vala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'xmpp-vala/src/core') diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 2cba2b54..18256119 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -126,9 +126,10 @@ public class XmppStream { foreach (XmppStreamModule module in modules) module.detach(this); } - public XmppStreamModule? get_module(string ns, string id) { + public T? get_module(ModuleIdentity? identity) { + if (identity == null) return null; foreach (var module in modules) { - if (module.get_ns() == ns && module.get_id() == id) { + if (module.get_ns() == identity.ns && module.get_id() == identity.id) { return module; } } @@ -231,6 +232,20 @@ public abstract class XmppStreamFlag { public abstract string get_id(); } +public class ModuleIdentity : Object { + public string ns { get; private set; } + public string id { get; private set; } + + public ModuleIdentity(string ns, string id) { + this.ns = ns; + this.id = id; + } + + public T? cast(XmppStreamModule module) { + return (T?) module; + } +} + public abstract class XmppStreamModule : Object { public abstract void attach(XmppStream stream); public abstract void detach(XmppStream stream); -- cgit v1.2.3-54-g00ecf