aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-19 12:55:36 +0100
committerfiaxh <git@mx.ax.lt>2017-03-20 22:28:27 +0100
commitdb57a973534f099af2b150f1a1307d1948553d9f (patch)
tree238ae1d4e53412a33e3febd07318dfd38b0eb2f8 /xmpp-vala/src/core
parent233f2b35d033cd20d1ac648bf2d723bcb7a918fc (diff)
downloaddino-db57a973534f099af2b150f1a1307d1948553d9f.tar.gz
dino-db57a973534f099af2b150f1a1307d1948553d9f.zip
Add typed identity to manager modules and stream flags
Diffstat (limited to 'xmpp-vala/src/core')
-rw-r--r--xmpp-vala/src/core/xmpp_stream.vala29
1 files changed, 25 insertions, 4 deletions
diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala
index 57eafe45..f3be115d 100644
--- a/xmpp-vala/src/core/xmpp_stream.vala
+++ b/xmpp-vala/src/core/xmpp_stream.vala
@@ -101,11 +101,14 @@ public class XmppStream {
flags.add(flag);
}
- public XmppStreamFlag? get_flag(string ns, string id) {
+ public bool has_flag<T>(FlagIdentity<T>? identity) {
+ return get_flag(identity) != null;
+ }
+
+ public T? get_flag<T>(FlagIdentity<T>? identity) {
+ if (identity == null) return null;
foreach (var flag in flags) {
- if (flag.get_ns() == ns && flag.get_id() == id) {
- return flag;
- }
+ if (identity.matches(flag)) return identity.cast(flag);
}
return null;
}
@@ -225,6 +228,24 @@ public class XmppStream {
}
}
+public class FlagIdentity<T> : Object {
+ public string ns { get; private set; }
+ public string id { get; private set; }
+
+ public FlagIdentity(string ns, string id) {
+ this.ns = ns;
+ this.id = id;
+ }
+
+ public T? cast(XmppStreamFlag module) {
+ return (T?) module;
+ }
+
+ public bool matches(XmppStreamFlag module) {
+ return module.get_ns() == ns && module.get_id() == id;
+ }
+}
+
public abstract class XmppStreamFlag {
public abstract string get_ns();
public abstract string get_id();