aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core/module_flag.vala
blob: 76ae4dc1b51b917dc11125646eb880c9573384e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace Xmpp {

    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 flag) {
#if VALA_0_56_11
        // We can't typecheck due to compiler bug
        return (T) module;
#else
            return flag.get_type().is_a(typeof(T)) ? (T?) flag : null;
#endif
        }

        public bool matches(XmppStreamFlag module) {
            return module.get_ns() == ns && module.get_id() == id;
        }
    }

    public abstract class XmppStreamFlag : Object {
        public abstract string get_ns();

        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) {
#if VALA_0_56_11
        // We can't typecheck due to compiler bug
        return (T) module;
#else
            return module.get_type().is_a(typeof(T)) ? (T?) module : null;
#endif
        }

        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);

        public abstract string get_ns();

        public abstract string get_id();
    }

    public abstract class XmppStreamNegotiationModule : XmppStreamModule {
        public abstract bool mandatory_outstanding(XmppStream stream);

        public abstract bool negotiation_active(XmppStream stream);
    }

}