aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core/xmpp_stream.vala
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/core/xmpp_stream.vala')
-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();