aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/core')
-rw-r--r--xmpp-vala/src/core/xmpp_stream.vala25
1 files changed, 21 insertions, 4 deletions
diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala
index 2cba2b54..38b4abb4 100644
--- a/xmpp-vala/src/core/xmpp_stream.vala
+++ b/xmpp-vala/src/core/xmpp_stream.vala
@@ -126,11 +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) {
- return module;
- }
+ if (identity.matches(module)) return identity.cast(module);
}
return null;
}
@@ -231,6 +230,24 @@ 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 bool matches(XmppStreamModule module) {
+ return module.get_ns() == ns && module.get_id() == id;
+ }
+}
+
public abstract class XmppStreamModule : Object {
public abstract void attach(XmppStream stream);
public abstract void detach(XmppStream stream);