summaryrefslogtreecommitdiffstats
blob: 2c491859c1d688f0ba72257a7d0f9be7caec0b3a (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
/*
 * Copyright (c) 2010-2016 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/LinkLocal/LinkLocalService.h>
#include <Swiften/Network/Connection.h>

namespace Swift {
    class ConnectionFactory;
    class HostAddress;
    class ToplevelElement;
    class PayloadParserFactoryCollection;
    class PayloadSerializerCollection;
    class DNSSDQuerier;
    class DNSSDResolveHostnameQuery;

    class SWIFTEN_API LinkLocalConnector : public std::enable_shared_from_this<LinkLocalConnector> {
        public:
            LinkLocalConnector(
                    const LinkLocalService& service,
                    std::shared_ptr<DNSSDQuerier> querier,
                    std::shared_ptr<Connection> connection);
            ~LinkLocalConnector();

            const LinkLocalService& getService() const {
                return service;
            }

            void connect();
            void cancel();
            void queueElement(std::shared_ptr<ToplevelElement> element);

            const std::vector<std::shared_ptr<ToplevelElement> >& getQueuedElements() const {
                return queuedElements;
            }

            std::shared_ptr<Connection> getConnection() const {
                return connection;
            }

            boost::signals2::signal<void (bool)> onConnectFinished;

        private:
            void handleHostnameResolved(const boost::optional<HostAddress>& address);
            void handleConnected(bool error);

        private:
            LinkLocalService service;
            std::shared_ptr<DNSSDQuerier> querier;
            std::shared_ptr<DNSSDResolveHostnameQuery> resolveQuery;
            boost::signals2::connection resolveQueryHostNameResolvedConnection;
            std::shared_ptr<Connection> connection;
            boost::signals2::connection connectionConnectFinishedConnection;
            std::vector<std::shared_ptr<ToplevelElement> > queuedElements;
    };
}