summaryrefslogtreecommitdiffstats
blob: 9689352705fbb83de78dcdbb40a3a79e7b927b89 (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
#pragma once

#include <boost/signal.hpp>
#include <map>

#include "Swiften/Base/String.h"
#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"

namespace Swift {
	class LinkLocalServiceInfo;
	class HostAddress;

	class DNSSDService {
		public:
			struct Service {
				Service(const String& name, const String& type, const String& domain, int networkInterface) : name(name), type(type), domain(domain), networkInterface(networkInterface) {}
				bool operator==(const Service& o) const {
					return name == o.name && type == o.type && domain == o.domain && (networkInterface != 0 && o.networkInterface != 0 ? networkInterface == o.networkInterface : true);
				}
				bool operator<(const Service& o) const {
					if (o.name == name) {
						if (o.type == type) {
							if (o.domain == domain) {
								return networkInterface < o.networkInterface;
							}
							else {
								return domain < o.domain;
							}
						}
						else {
							return type < o.type;
						}
					}
					else {
						return o.name < name;
					}
				}

				String name;
				String type;
				String domain;
				int networkInterface;
			};

			struct ResolveResult {
				ResolveResult(const String& host, int port, const LinkLocalServiceInfo& info) : host(host), port(port), info(info) {}
				String host;
				int port;
				LinkLocalServiceInfo info;
			};

			virtual ~DNSSDService();

			virtual void start() = 0;
			virtual void stop() = 0;

			virtual void registerService(const String& name, int port, const LinkLocalServiceInfo&) = 0;
			virtual void updateService(const LinkLocalServiceInfo&) = 0;
			virtual void unregisterService() = 0;

			virtual void startResolvingService(const Service&) = 0;
			virtual void stopResolvingService(const Service&) = 0;
			
			virtual void resolveHostname(const String& hostname, int interfaceIndex = 0) = 0;

			boost::signal<void ()> onStarted;
			boost::signal<void (bool)> onStopped;
			boost::signal<void (const Service&)> onServiceAdded;
			boost::signal<void (const Service&)> onServiceRemoved;
			boost::signal<void (const Service&)> onServiceRegistered;
			boost::signal<void (const Service&, const ResolveResult&)> onServiceResolved;
			boost::signal<void (const String&, const boost::optional<HostAddress>&)> onHostnameResolved;
	};
}