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

#pragma once

#include <memory>
#include <vector>

#include <boost/signals2.hpp>

#include <Swiften/Base/API.h>
#include <Swiften/Elements/Stanza.h>

namespace Swift {
    class HighLayer;
    class LowLayer;
    class StreamLayer;

    class SWIFTEN_API StreamStack {
        public:
            StreamStack(std::unique_ptr<HighLayer> topLayer, std::unique_ptr<LowLayer> bottomLayer);
            ~StreamStack();

            void addLayer(std::unique_ptr<StreamLayer> /* streamLayer */);

            HighLayer* getTopLayer() const {
                return topLayer_.get();
            }

            template<typename T> T* getLayer() const {
                for (const auto& i : layers_) {
                    T* layer = dynamic_cast<T*>(i.get());
                    if (layer) {
                        return layer;
                    }
                }
                if (T* layer = dynamic_cast<T*>(topLayer_.get())) {
                    return layer;
                }
                if (T* layer = dynamic_cast<T*>(bottomLayer_.get())) {
                    return layer;
                }
                return nullptr;
            }

        private:
            std::unique_ptr<HighLayer> topLayer_;
            std::unique_ptr<LowLayer> bottomLayer_;
            std::vector<std::unique_ptr<StreamLayer>> layers_;
    };
}