summaryrefslogtreecommitdiffstats
blob: 62185442b7af307fc129cd8e4b6a2d47841daada (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Copyright (c) 2011 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2013-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <memory>
#include <string>
#include <vector>

#include <boost/signals2.hpp>
#include <boost/variant.hpp>

#include <Swiften/Base/API.h>
#include <Swiften/Base/Override.h>
#include <Swiften/Base/SimpleIDGenerator.h>
#include <Swiften/Elements/JinglePayload.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Jingle/JingleContentID.h>
#include <Swiften/Jingle/JingleSession.h>

namespace Swift {
    class JingleContentID;

    class SWIFTEN_API FakeJingleSession : public JingleSession {
        public:
        struct InitiateCall {
            InitiateCall(JingleContentID contentId, JingleDescription::ref desc, JingleTransportPayload::ref payL) : id(contentId), description(desc), payload(payL) {}
            JingleContentID id;
            JingleDescription::ref description;
            JingleTransportPayload::ref payload;
        };

        struct  TerminateCall {
            TerminateCall(JinglePayload::Reason::Type r) : reason(r) {}
            JinglePayload::Reason::Type reason;
        };

        struct InfoCall {
            InfoCall(std::shared_ptr<Payload> info) : payload(info) {}
            std::shared_ptr<Payload> payload;
        };

        struct AcceptCall {
            AcceptCall(JingleContentID contentId, JingleDescription::ref desc, JingleTransportPayload::ref payL) : id(contentId), description(desc), payload(payL) {}
            JingleContentID id;
            JingleDescription::ref description;
            JingleTransportPayload::ref payload;
        };

        struct InfoTransportCall {
            InfoTransportCall(JingleContentID contentId, JingleTransportPayload::ref payL) : id(contentId), payload(payL) {}
            JingleContentID id;
            JingleTransportPayload::ref payload;
        };

        struct AcceptTransportCall {
            AcceptTransportCall(JingleContentID contentId, JingleTransportPayload::ref payL) : id(contentId), payload(payL) {}
            JingleContentID id;
            JingleTransportPayload::ref payload;
        };

        struct RejectTransportCall {
            RejectTransportCall(JingleContentID contentId, JingleTransportPayload::ref payL) : id(contentId), payload(payL) {}
            JingleContentID id;
            JingleTransportPayload::ref payload;
        };

        struct ReplaceTransportCall {
            ReplaceTransportCall(JingleContentID contentId, JingleTransportPayload::ref payL) : id(contentId), payload(payL) {}
            JingleContentID id;
            JingleTransportPayload::ref payload;
        };

        typedef boost::variant<InitiateCall, TerminateCall, AcceptCall, InfoCall, InfoTransportCall, AcceptTransportCall, RejectTransportCall, ReplaceTransportCall> Command;

        public:
            typedef std::shared_ptr<FakeJingleSession> ref;

            FakeJingleSession(const JID& initiator, const std::string& id);
            virtual ~FakeJingleSession();

            virtual void sendInitiate(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
            virtual void sendTerminate(JinglePayload::Reason::Type reason) SWIFTEN_OVERRIDE;
            virtual void sendInfo(std::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
            virtual void sendAccept(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref = JingleTransportPayload::ref()) SWIFTEN_OVERRIDE;
            virtual std::string sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
            virtual void sendTransportAccept(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
            virtual void sendTransportReject(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
            virtual void sendTransportReplace(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;

            void handleSessionTerminateReceived(boost::optional<JinglePayload::Reason>);
            void handleSessionAcceptReceived(const JingleContentID&, std::shared_ptr<JingleDescription>, std::shared_ptr<JingleTransportPayload>);
            void handleSessionInfoReceived(std::shared_ptr<JinglePayload>);

            void handleTransportReplaceReceived(const JingleContentID&, JingleTransportPayload::ref);
            void handleTransportAcceptReceived(const JingleContentID&, std::shared_ptr<JingleTransportPayload>);
            void handleTransportInfoReceived(const JingleContentID&, std::shared_ptr<JingleTransportPayload>);
            void handleTransportRejectReceived(const JingleContentID&, std::shared_ptr<JingleTransportPayload>);
            void handleTransportInfoAcknowledged(const std::string& id);

        public:
            std::vector<Command> calledCommands;
            SimpleIDGenerator idGenerator;
    };
}