summaryrefslogtreecommitdiffstats
blob: f67a0fe944b9297e647c7dd2ad064acfe7bf9749 (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
/*
 * Copyright (c) 2011-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <map>
#include <memory>

#include <boost/signals2.hpp>

#include <Swiften/Base/API.h>
#include <Swiften/Jingle/JingleSessionImpl.h>

namespace Swift {
    class IQRouter;
    class JingleResponder;
    class IncomingJingleSessionHandler;

    class SWIFTEN_API JingleSessionManager {
            friend class JingleResponder;
        public:
            JingleSessionManager(IQRouter* router);
            ~JingleSessionManager();

            JingleSessionImpl::ref getSession(const JID& jid, const std::string& id) const;

            void addIncomingSessionHandler(IncomingJingleSessionHandler* handler);
            void removeIncomingSessionHandler(IncomingJingleSessionHandler* handler);

            void registerOutgoingSession(const JID& initiator, JingleSessionImpl::ref);
        protected:
            void handleIncomingSession(const JID& initiator, const JID& recipient, JingleSessionImpl::ref, const std::vector<JingleContentPayload::ref>& contents);

        private:
            IQRouter* router;
            JingleResponder* responder;
            std::vector<IncomingJingleSessionHandler*> incomingSessionHandlers;
            struct JIDSession {
                JIDSession(const JID& initiator, const std::string& session) : initiator(initiator), session(session) {}
                bool operator<(const JIDSession& o) const {
                    return initiator == o.initiator ? session < o.session : initiator < o.initiator;
                }
                JID initiator;
                std::string session;
            };
            typedef std::map<JIDSession, JingleSessionImpl::ref> SessionMap;
            SessionMap sessions;
    };
}