summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-26 08:21:20 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-26 14:52:17 (GMT)
commit26d623d3cfd8937fb52acf76ef33d230f5010538 (patch)
treeade8246f719fa4dee9de1daaa2ba3f7b6c324e53 /Swiften/LinkLocal/DNSSD/Bonjour
parent2833b8f09c9aef09004662a2a89eefbaee1e4247 (diff)
downloadswift-contrib-26d623d3cfd8937fb52acf76ef33d230f5010538.zip
swift-contrib-26d623d3cfd8937fb52acf76ef33d230f5010538.tar.bz2
Implement fake DNSSD querier.
Diffstat (limited to 'Swiften/LinkLocal/DNSSD/Bonjour')
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h13
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp7
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h14
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h9
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h9
5 files changed, 37 insertions, 15 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h
index 62d8606..8e3181e 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h
@@ -14,14 +14,17 @@ namespace Swift {
&sdRef, 0, 0, "_presence._tcp", 0,
&BonjourBrowseQuery::handleServiceDiscoveredStatic, this);
if (result != kDNSServiceErr_NoError) {
- std::cout << "Error" << std::endl;
- // TODO
+ sdRef = NULL;
}
}
void startBrowsing() {
- assert(sdRef);
- run();
+ if (!sdRef) {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onError)), shared_from_this());
+ }
+ else {
+ run();
+ }
}
void stopBrowsing() {
@@ -35,7 +38,7 @@ namespace Swift {
void handleServiceDiscovered(DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain) {
if (errorCode != kDNSServiceErr_NoError) {
- return;
+ MainEventLoop::postEvent(boost::bind(boost::ref(onError)), shared_from_this());
}
else {
DNSSDServiceID service(name, type, domain, interfaceIndex);
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
index c065d4d..70fbc7c 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
@@ -22,7 +22,7 @@ BonjourQuerier::BonjourQuerier() : stopRequested(false), thread(0) {
}
BonjourQuerier::~BonjourQuerier() {
- stop();
+ assert(!thread);
}
boost::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() {
@@ -64,18 +64,19 @@ void BonjourQuerier::interruptSelect() {
}
void BonjourQuerier::start() {
- stop();
+ assert(!thread);
thread = new boost::thread(boost::bind(&BonjourQuerier::run, shared_from_this()));
}
void BonjourQuerier::stop() {
if (thread) {
stopRequested = true;
- runningQueries.clear(); // TODO: Is this the right thing to do?
+ assert(runningQueries.empty());
runningQueriesAvailableEvent.notify_one();
interruptSelect();
thread->join();
delete thread;
+ thread = NULL;
stopRequested = false;
}
}
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
index 9c4db13..41e5831 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
@@ -18,13 +18,21 @@ namespace Swift {
txtRecord.getSize(), txtRecord.getData(),
&BonjourRegisterQuery::handleServiceRegisteredStatic, this);
if (result != kDNSServiceErr_NoError) {
- // TODO
- std::cerr << "Error creating service registration" << std::endl;
+ sdRef = NULL;
}
}
void registerService() {
- run();
+ if (sdRef) {
+ run();
+ }
+ else {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ }
+ }
+
+ void unregisterService() {
+ stop();
}
void updateServiceInfo(const LinkLocalServiceInfo& info) {
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
index 58c6588..6e2a852 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
@@ -19,13 +19,18 @@ namespace Swift {
hostname.getUTF8Data(),
&BonjourResolveHostnameQuery::handleHostnameResolvedStatic, this);
if (result != kDNSServiceErr_NoError) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>()), shared_from_this());
+ sdRef = NULL;
}
}
//void DNSSDResolveHostnameQuery::run() {
void run() {
- BonjourQuery::run();
+ if (sdRef) {
+ BonjourQuery::run();
+ }
+ else {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>()), shared_from_this());
+ }
}
private:
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h
index 1ebd487..8b3f7ec 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h
@@ -18,12 +18,17 @@ namespace Swift {
service.getDomain().getUTF8Data(),
&BonjourResolveServiceQuery::handleServiceResolvedStatic, this);
if (result != kDNSServiceErr_NoError) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ sdRef = NULL;
}
}
void start() {
- run();
+ if (sdRef) {
+ run();
+ }
+ else {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ }
}
void stop() {