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

// FIXME: This example is not complete yet

#include <iostream>

#include <Swiften/EventLoop/SimpleEventLoop.h>
#include <Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h>
#include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h>
#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h>
#include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h>

using namespace Swift;

int main(int argc, char* argv[]) {
    if (argc < 2) {
        std::cerr << "Invalid parameters" << std::endl;
        return -1;
    }

    SimpleEventLoop eventLoop;
    PlatformDNSSDQuerierFactory factory(&eventLoop);
    std::shared_ptr<DNSSDQuerier> querier = factory.createQuerier();
    querier->start();

    if (std::string(argv[1]) == "browse") {
        std::shared_ptr<DNSSDBrowseQuery> browseQuery = querier->createBrowseQuery();
        browseQuery->startBrowsing();
        eventLoop.run();
        browseQuery->stopBrowsing();
    }
    else if (std::string(argv[1]) == "resolve-service") {
        if (argc < 5) {
            std::cerr << "Invalid parameters" << std::endl;
            return -1;
        }
        std::shared_ptr<DNSSDResolveServiceQuery> resolveQuery = querier->createResolveServiceQuery(DNSSDServiceID(argv[2], argv[3], argv[4]));
        resolveQuery->start();
        eventLoop.run();
        std::cerr << "Done running" << std::endl;
        resolveQuery->stop();
    }

    querier->stop();
}