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

#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <list>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>

#include "Swiften/EventLoop/EventOwner.h"
#include "Swiften/LinkLocal/DNSSDBrowseQuery.h"
#include "Swiften/LinkLocal/DNSSDPublishQuery.h"
#include "Swiften/LinkLocal/BonjourQuery.h"

namespace Swift {
	class LinkLocalServiceInfo;

	class BonjourQuerier : 
			public boost::enable_shared_from_this<BonjourQuerier>, 
			public EventOwner {
		public:
			BonjourQuerier();
			~BonjourQuerier();

			boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
			boost::shared_ptr<DNSSDPublishQuery> createPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info);

			void start();
			void stop();

		private:
			friend class BonjourQuery;

			void addRunningQuery(boost::shared_ptr<BonjourQuery>);
			void removeRunningQuery(boost::shared_ptr<BonjourQuery>);
		
		private:
			void interruptSelect();
			void run();

		private:
			bool stopRequested;
			boost::thread* thread;
			boost::mutex runningQueriesMutex;
			std::list< boost::shared_ptr<BonjourQuery> > runningQueries;
			int interruptSelectReadSocket;
			int interruptSelectWriteSocket;
			boost::condition_variable runningQueriesAvailableEvent;
	};
}