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

#include <boost/enable_shared_from_this.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <dns_sd.h>

#include "Swiften/LinkLocal/DNSSDService.h"
#include "Swiften/EventLoop/EventOwner.h"

namespace Swift {
	class AppleDNSSDService : public DNSSDService, public EventOwner, public boost::enable_shared_from_this<AppleDNSSDService> {
		public:
			AppleDNSSDService();
			~AppleDNSSDService();

			virtual void registerService(const String& name, int port, const LinkLocalServiceInfo&);
			virtual void unregisterService();
			virtual void start();
			virtual void stop();

		private:
			void doStart();
			void interruptSelect();

			static void handleServiceDiscoveredGlobal(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType, const char *, const char *, const char *, void*);
			void handleServiceDiscovered(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType, const char *, const char *, const char *);
			static void handleServiceRegisteredGlobal(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType, const char *, const char *, const char *, void *);
			void handleServiceRegistered(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType, const char *, const char *, const char *);

		private:
			boost::thread* thread;
			bool stopRequested;
			int interruptSelectReadSocket;
			int interruptSelectWriteSocket;
			boost::mutex sdRefsMutex;
			DNSServiceRef browseSDRef;
			DNSServiceRef registerSDRef;
	};
}