diff options
author | Marvin W <git@larma.de> | 2017-03-10 21:13:35 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-03-10 21:15:06 +0100 |
commit | 9cdc3619bd172a731333b8152ee561eed76e77f8 (patch) | |
tree | 9261c5addf903d43daf6c2d5b6203e551cb13648 /xmpp-vala/src/core | |
parent | 29ca70a6d534e1cd79963718c793ae740318cff1 (diff) | |
download | dino-9cdc3619bd172a731333b8152ee561eed76e77f8.tar.gz dino-9cdc3619bd172a731333b8152ee561eed76e77f8.zip |
Add typed identity to stream modules
Diffstat (limited to 'xmpp-vala/src/core')
-rw-r--r-- | xmpp-vala/src/core/xmpp_stream.vala | 19 |
1 files changed, 17 insertions, 2 deletions
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<T>(ModuleIdentity<T>? 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<T> : 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); |