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

#include <boost/signal.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <map>
#include <vector>

#include "Swiften/Base/String.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h"
#include "Swiften/LinkLocal/LinkLocalService.h"
#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"

namespace Swift {
	class LinkLocalServiceBrowser {
		public:
			LinkLocalServiceBrowser(boost::shared_ptr<DNSSDQuerier> querier);
			~LinkLocalServiceBrowser();

			void start();
			void stop();
			bool isRunning() const;
			bool hasError() const;

			void registerService(const String& name, int port, const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
			void unregisterService();
			bool isRegistered() const;

			std::vector<LinkLocalService> getServices() const;

			boost::signal<void (const LinkLocalService&)> onServiceAdded;
			boost::signal<void (const LinkLocalService&)> onServiceChanged;
			boost::signal<void (const LinkLocalService&)> onServiceRemoved;
			boost::signal<void (bool)> onStopped;

		private:
			void handleServiceAdded(const DNSSDServiceID&);
			void handleServiceRemoved(const DNSSDServiceID&);
			void handleServiceResolved(const DNSSDServiceID& service, const boost::optional<DNSSDResolveServiceQuery::Result>& result);
			void handleRegisterFinished(const boost::optional<DNSSDServiceID>&);
			void handleBrowseError();

		private:
			boost::shared_ptr<DNSSDQuerier> querier;
			boost::optional<DNSSDServiceID> selfService;
			boost::shared_ptr<DNSSDBrowseQuery> browseQuery;
			boost::shared_ptr<DNSSDRegisterQuery> registerQuery;
			typedef std::map<DNSSDServiceID, boost::shared_ptr<DNSSDResolveServiceQuery> > ResolveQueryMap;
			ResolveQueryMap resolveQueries;
			typedef std::map<DNSSDServiceID, DNSSDResolveServiceQuery::Result> ServiceMap;
			ServiceMap services;
			bool haveError;
	};
}