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

#pragma once

#include <string>
#include <vector>

#include <boost/optional.hpp>

#include <Swiften/Base/API.h>
#include <Swiften/Elements/JingleDescription.h>
#include <Swiften/Elements/JingleTransportPayload.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/JID/JID.h>

namespace Swift {
    class SWIFTEN_API JingleContentPayload : public Payload {
        public:
            typedef std::shared_ptr<JingleContentPayload> ref;

            enum Creator {
                UnknownCreator,
                InitiatorCreator,
                ResponderCreator
            };

            JingleContentPayload() : creator(UnknownCreator) {
            }

            /*enum Senders {
                NoSenders,
                InitiatorSender,
                ResponderSender,
                BothSenders,
            };*/

            Creator getCreator() const {
                return creator;
            }

            void setCreator(Creator creator) {
                this->creator = creator;
            }

            const std::string& getName() const {
                return name;
            }

            void setName(const std::string& name) {
                this->name = name;
            }

            const std::vector<JingleDescription::ref>& getDescriptions() const {
                return descriptions;
            }

            void addDescription(JingleDescription::ref description) {
                descriptions.push_back(description);
            }

            const std::vector<std::shared_ptr<JingleTransportPayload> >& getTransports() const {
                return transports;
            }

            void addTransport(std::shared_ptr<JingleTransportPayload>  transport) {
                transports.push_back(transport);
            }

            template<typename T>
            std::shared_ptr<T> getDescription() const {
                for (const auto& description : descriptions) {
                    std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(description));
                    if (result) {
                        return result;
                    }
                }
                return std::shared_ptr<T>();
            }

            template<typename T>
            std::shared_ptr<T> getTransport() const {
                for (const auto& transport : transports) {
                    std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(transport));
                    if (result) {
                        return result;
                    }
                }
                return std::shared_ptr<T>();
            }

        private:
            Creator creator;
            std::string name;
            //Senders senders;
            std::vector<JingleDescription::ref> descriptions;
            std::vector<std::shared_ptr<JingleTransportPayload> > transports;
    };
}