aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-10 23:20:36 +0100
committerfiaxh <git@mx.ax.lt>2017-03-10 23:20:36 +0100
commit95e8d126db06a183918b4db4e84013ff28f8b1f7 (patch)
tree05c0d3f6d538a95f984fb6108d7d3938d6731044 /xmpp-vala/src/core
parent24b55d83a1f9e21b028c8d5ac9778e75565f417d (diff)
parentd8e102a160f316369c99d3dc2df7d7d54f5bc955 (diff)
downloaddino-95e8d126db06a183918b4db4e84013ff28f8b1f7.tar.gz
dino-95e8d126db06a183918b4db4e84013ff28f8b1f7.zip
Merge branch 'master' of github.com:dino/dino
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);