summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/LinkLocal/DNSSD')
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h10
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h12
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h8
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h12
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp10
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h3
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp2
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h10
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h10
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h10
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp24
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp7
-rw-r--r--Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h10
16 files changed, 77 insertions, 63 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h
index f8ec795..3bee907 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiBrowseQuery.h
@@ -10,7 +10,7 @@
#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class AvahiQuerier;
@@ -27,7 +27,7 @@ namespace Swift {
browser = avahi_service_browser_new(querier->getClient(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_presence._tcp", NULL, static_cast<AvahiLookupFlags>(0), &handleServiceDiscoveredStatic, this);
if (!browser) {
std::cout << "Error" << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onError)), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this());
}
avahi_threaded_poll_unlock(querier->getThreadedPoll());
}
@@ -49,18 +49,18 @@ namespace Swift {
switch (event) {
case AVAHI_BROWSER_FAILURE:
std::cout << "Service browse error" << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onError)), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this());
break;
case AVAHI_BROWSER_NEW: {
DNSSDServiceID service(name, domain, type, interfaceIndex);
std::cout << "Service discovered " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this());
break;
}
case AVAHI_BROWSER_REMOVE: {
std::cout << "Service went away " << name << " " << domain << " " << type << " " << interfaceIndex << std::endl;
DNSSDServiceID service(name, domain, type, interfaceIndex);
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this());
break;
}
case AVAHI_BROWSER_ALL_FOR_NOW:
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
index 2045328..3e5a758 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
@@ -11,7 +11,7 @@
#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h"
#include "Swiften/Base/ByteArray.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class AvahiQuerier;
@@ -29,7 +29,7 @@ namespace Swift {
group = avahi_entry_group_new(querier->getClient(), handleEntryGroupChange, this);
if (!group) {
std::cout << "Error ceating entry group" << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
}
@@ -61,7 +61,7 @@ namespace Swift {
int result = avahi_entry_group_add_service_strlst(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name.getUTF8Data(), "_presence._tcp", NULL, NULL, port, txtList);
if (result < 0) {
std::cout << "Error registering service: " << avahi_strerror(result) << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
result = avahi_entry_group_commit(group);
if (result < 0) {
@@ -78,7 +78,7 @@ namespace Swift {
switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED :
// Domain is a hack!
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, "local", "_presence._tcp", 0))), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, "local", "_presence._tcp", 0))), shared_from_this());
std::cout << "Entry group established" << std::endl;
break;
case AVAHI_ENTRY_GROUP_COLLISION : {
@@ -106,7 +106,7 @@ namespace Swift {
if (result != kDNSServiceErr_NoError) {
sdRef = NULL;
}*/
- //MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ //eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
}
@@ -117,7 +117,7 @@ namespace Swift {
void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) {
if (errorCode != kDNSServiceErr_NoError) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
else {
}
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h
index e069629..6803fd0 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveHostnameQuery.h
@@ -9,7 +9,7 @@
#include "Swiften/Base/String.h"
#include "Swiften/LinkLocal/DNSSD/Avahi/AvahiQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/Network/HostAddress.h"
#include <netinet/in.h>
@@ -24,7 +24,7 @@ namespace Swift {
}
void run() {
- MainEventLoop::postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>(HostAddress(hostname))), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>(HostAddress(hostname))), shared_from_this());
}
void finish() {
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h
index 4709677..402f84f 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiResolveServiceQuery.h
@@ -10,7 +10,7 @@
#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h"
#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"
#include "Swiften/Base/ByteArray.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class AvahiQuerier;
@@ -27,7 +27,7 @@ namespace Swift {
resolver = avahi_service_resolver_new(querier->getClient(), service.getNetworkInterfaceID(), AVAHI_PROTO_UNSPEC, service.getName().getUTF8Data(), service.getType().getUTF8Data(), service.getDomain().getUTF8Data(), AVAHI_PROTO_UNSPEC, static_cast<AvahiLookupFlags>(0), handleServiceResolvedStatic, this);
if (!resolver) {
std::cout << "Error starting resolver" << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
}
avahi_threaded_poll_unlock(querier->getThreadedPoll());
}
@@ -50,7 +50,7 @@ namespace Swift {
switch(event) {
case AVAHI_RESOLVER_FAILURE:
std::cout << "Resolve error " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(resolver))) << std::endl;
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
break;
case AVAHI_RESOLVER_FOUND: {
std::cout << "Success" << std::endl;
@@ -64,7 +64,7 @@ namespace Swift {
// FIXME: Probably not accurate
String fullname = String(name) + "." + String(type) + "." + String(domain) + ".";
std::cout << "Result: " << fullname << "->" << String(a) << ":" << port << std::endl;
- MainEventLoop::postEvent(
+ eventLoop->postEvent(
boost::bind(
boost::ref(onServiceResolved),
Result(fullname, String(a), port, txtRecord)),
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h
index bfecea9..52c47d7 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h
@@ -8,14 +8,14 @@
#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class BonjourQuerier;
class BonjourBrowseQuery : public DNSSDBrowseQuery, public BonjourQuery {
public:
- BonjourBrowseQuery(boost::shared_ptr<BonjourQuerier> q) : BonjourQuery(q) {
+ BonjourBrowseQuery(boost::shared_ptr<BonjourQuerier> q, EventLoop* eventLoop) : BonjourQuery(q, eventLoop) {
DNSServiceErrorType result = DNSServiceBrowse(
&sdRef, 0, 0, "_presence._tcp", 0,
&BonjourBrowseQuery::handleServiceDiscoveredStatic, this);
@@ -26,7 +26,7 @@ namespace Swift {
void startBrowsing() {
if (!sdRef) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onError)), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this());
}
else {
run();
@@ -44,16 +44,16 @@ namespace Swift {
void handleServiceDiscovered(DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain) {
if (errorCode != kDNSServiceErr_NoError) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onError)), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this());
}
else {
//std::cout << "Discovered service: name:" << name << " domain:" << domain << " type: " << type << std::endl;
DNSSDServiceID service(name, domain, type, interfaceIndex);
if (flags & kDNSServiceFlagsAdd) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this());
}
else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this());
}
}
}
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
index 55c64c4..03271d6 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
@@ -18,7 +18,7 @@
namespace Swift {
-BonjourQuerier::BonjourQuerier() : stopRequested(false), thread(0) {
+BonjourQuerier::BonjourQuerier(EventLoop* eventLoop) : eventLoop(eventLoop), stopRequested(false), thread(0) {
int fds[2];
int result = pipe(fds);
assert(result == 0);
@@ -32,19 +32,19 @@ BonjourQuerier::~BonjourQuerier() {
}
boost::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() {
- return boost::shared_ptr<DNSSDBrowseQuery>(new BonjourBrowseQuery(shared_from_this()));
+ return boost::shared_ptr<DNSSDBrowseQuery>(new BonjourBrowseQuery(shared_from_this(), eventLoop));
}
boost::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const String& name, int port, const ByteArray& info) {
- return boost::shared_ptr<DNSSDRegisterQuery>(new BonjourRegisterQuery(name, port, info, shared_from_this()));
+ return boost::shared_ptr<DNSSDRegisterQuery>(new BonjourRegisterQuery(name, port, info, shared_from_this(), eventLoop));
}
boost::shared_ptr<DNSSDResolveServiceQuery> BonjourQuerier::createResolveServiceQuery(const DNSSDServiceID& service) {
- return boost::shared_ptr<DNSSDResolveServiceQuery>(new BonjourResolveServiceQuery(service, shared_from_this()));
+ return boost::shared_ptr<DNSSDResolveServiceQuery>(new BonjourResolveServiceQuery(service, shared_from_this(), eventLoop));
}
boost::shared_ptr<DNSSDResolveHostnameQuery> BonjourQuerier::createResolveHostnameQuery(const String& hostname, int interfaceIndex) {
- return boost::shared_ptr<DNSSDResolveHostnameQuery>(new BonjourResolveHostnameQuery(hostname, interfaceIndex, shared_from_this()));
+ return boost::shared_ptr<DNSSDResolveHostnameQuery>(new BonjourResolveHostnameQuery(hostname, interfaceIndex, shared_from_this(), eventLoop));
}
void BonjourQuerier::addRunningQuery(boost::shared_ptr<BonjourQuery> query) {
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h
index a6c7d4d..916acc3 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h
@@ -22,7 +22,7 @@ namespace Swift {
public DNSSDQuerier,
public boost::enable_shared_from_this<BonjourQuerier> {
public:
- BonjourQuerier();
+ BonjourQuerier(EventLoop* eventLoop);
~BonjourQuerier();
boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
@@ -45,6 +45,7 @@ namespace Swift {
void run();
private:
+ EventLoop* eventLoop;
bool stopRequested;
boost::thread* thread;
boost::mutex runningQueriesMutex;
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp
index c496072..d7ff5d5 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp
@@ -9,7 +9,7 @@
namespace Swift {
-BonjourQuery::BonjourQuery(boost::shared_ptr<BonjourQuerier> q) : querier(q), sdRef(0) {
+BonjourQuery::BonjourQuery(boost::shared_ptr<BonjourQuerier> q, EventLoop* eventLoop) : eventLoop(eventLoop), querier(q), sdRef(0) {
}
BonjourQuery::~BonjourQuery() {
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h
index e13883e..e3cd9a5 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h
@@ -15,12 +15,13 @@
namespace Swift {
class BonjourQuerier;
+ class EventLoop;
class BonjourQuery :
public EventOwner,
public boost::enable_shared_from_this<BonjourQuery> {
public:
- BonjourQuery(boost::shared_ptr<BonjourQuerier>);
+ BonjourQuery(boost::shared_ptr<BonjourQuerier>, EventLoop* eventLoop);
virtual ~BonjourQuery();
void processResult();
@@ -31,6 +32,7 @@ namespace Swift {
void finish();
protected:
+ EventLoop* eventLoop;
boost::shared_ptr<BonjourQuerier> querier;
mutable boost::mutex sdRefMutex;
DNSServiceRef sdRef;
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
index 8155a33..9d8516b 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
@@ -9,14 +9,14 @@
#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h"
#include "Swiften/Base/ByteArray.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class BonjourQuerier;
class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery {
public:
- BonjourRegisterQuery(const String& name, int port, const ByteArray& txtRecord, boost::shared_ptr<BonjourQuerier> querier) : BonjourQuery(querier) {
+ BonjourRegisterQuery(const String& name, int port, const ByteArray& txtRecord, boost::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) {
DNSServiceErrorType result = DNSServiceRegister(
&sdRef, 0, 0, name.getUTF8Data(), "_presence._tcp", NULL, NULL, port,
txtRecord.getSize(), txtRecord.getData(),
@@ -31,7 +31,7 @@ namespace Swift {
run();
}
else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
}
@@ -51,10 +51,10 @@ namespace Swift {
void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) {
if (errorCode != kDNSServiceErr_NoError) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, domain, regtype, 0))), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<DNSSDServiceID>(DNSSDServiceID(name, domain, regtype, 0))), shared_from_this());
}
}
};
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
index de52321..16e9be6 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
@@ -11,7 +11,7 @@
#include "Swiften/Base/String.h"
#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/Network/HostAddress.h"
#include <netinet/in.h>
@@ -21,7 +21,7 @@ namespace Swift {
class BonjourResolveHostnameQuery : public DNSSDResolveHostnameQuery, public BonjourQuery {
public:
- BonjourResolveHostnameQuery(const String& hostname, int interfaceIndex, boost::shared_ptr<BonjourQuerier> querier) : BonjourQuery(querier) {
+ BonjourResolveHostnameQuery(const String& hostname, int interfaceIndex, boost::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) {
DNSServiceErrorType result = DNSServiceGetAddrInfo(
&sdRef, 0, interfaceIndex, kDNSServiceProtocol_IPv4,
hostname.getUTF8Data(),
@@ -37,7 +37,7 @@ namespace Swift {
BonjourQuery::run();
}
else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onHostnameResolved), boost::optional<HostAddress>()), shared_from_this());
}
}
@@ -52,7 +52,7 @@ namespace Swift {
void handleHostnameResolved(DNSServiceErrorType errorCode, const struct sockaddr *rawAddress) {
if (errorCode) {
- MainEventLoop::postEvent(
+ eventLoop->postEvent(
boost::bind(boost::ref(onHostnameResolved),
boost::optional<HostAddress>()),
shared_from_this());
@@ -61,7 +61,7 @@ namespace Swift {
assert(rawAddress->sa_family == AF_INET);
const sockaddr_in* sa = reinterpret_cast<const sockaddr_in*>(rawAddress);
uint32_t address = ntohl(sa->sin_addr.s_addr);
- MainEventLoop::postEvent(boost::bind(
+ eventLoop->postEvent(boost::bind(
boost::ref(onHostnameResolved),
HostAddress(reinterpret_cast<unsigned char*>(&address), 4)),
shared_from_this());
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h
index 38121ca..136b366 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveServiceQuery.h
@@ -10,14 +10,14 @@
#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h"
#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"
#include "Swiften/Base/ByteArray.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
class BonjourQuerier;
class BonjourResolveServiceQuery : public DNSSDResolveServiceQuery, public BonjourQuery {
public:
- BonjourResolveServiceQuery(const DNSSDServiceID& service, boost::shared_ptr<BonjourQuerier> querier) : BonjourQuery(querier) {
+ BonjourResolveServiceQuery(const DNSSDServiceID& service, boost::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) {
DNSServiceErrorType result = DNSServiceResolve(
&sdRef, 0, service.getNetworkInterfaceID(),
service.getName().getUTF8Data(), service.getType().getUTF8Data(),
@@ -33,7 +33,7 @@ namespace Swift {
run();
}
else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
}
}
@@ -48,11 +48,11 @@ namespace Swift {
void handleServiceResolved(DNSServiceErrorType errorCode, const char* fullName, const char* host, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord) {
if (errorCode != kDNSServiceErr_NoError) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
}
else {
//std::cout << "Service resolved: name:" << fullName << " host:" << host << " port:" << port << std::endl;
- MainEventLoop::postEvent(
+ eventLoop->postEvent(
boost::bind(
boost::ref(onServiceResolved),
Result(String(fullName), String(host), port,
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
index d8e7acf..0bcdba1 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
@@ -12,11 +12,11 @@
#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h"
#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveServiceQuery.h"
#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h"
-#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/EventLoop.h"
namespace Swift {
-FakeDNSSDQuerier::FakeDNSSDQuerier(const String& domain) : domain(domain) {
+FakeDNSSDQuerier::FakeDNSSDQuerier(const String& domain, EventLoop* eventLoop) : domain(domain), eventLoop(eventLoop) {
}
FakeDNSSDQuerier::~FakeDNSSDQuerier() {
@@ -46,24 +46,24 @@ void FakeDNSSDQuerier::addRunningQuery(boost::shared_ptr<FakeDNSSDQuery> query)
allQueriesEverRun.push_back(query);
if (boost::shared_ptr<FakeDNSSDBrowseQuery> browseQuery = boost::dynamic_pointer_cast<FakeDNSSDBrowseQuery>(query)) {
foreach(const DNSSDServiceID& service, services) {
- MainEventLoop::postEvent(boost::bind(boost::ref(browseQuery->onServiceAdded), service), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(browseQuery->onServiceAdded), service), shared_from_this());
}
}
else if (boost::shared_ptr<FakeDNSSDResolveServiceQuery> resolveQuery = boost::dynamic_pointer_cast<FakeDNSSDResolveServiceQuery>(query)) {
for(ServiceInfoMap::const_iterator i = serviceInfo.begin(); i != serviceInfo.end(); ++i) {
if (i->first == resolveQuery->service) {
- MainEventLoop::postEvent(boost::bind(boost::ref(resolveQuery->onServiceResolved), i->second), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(resolveQuery->onServiceResolved), i->second), shared_from_this());
}
}
}
else if (boost::shared_ptr<FakeDNSSDRegisterQuery> registerQuery = boost::dynamic_pointer_cast<FakeDNSSDRegisterQuery>(query)) {
DNSSDServiceID service(registerQuery->name, domain);
- MainEventLoop::postEvent(boost::bind(boost::ref(registerQuery->onRegisterFinished), service), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(registerQuery->onRegisterFinished), service), shared_from_this());
}
else if (boost::shared_ptr<FakeDNSSDResolveHostnameQuery> resolveHostnameQuery = boost::dynamic_pointer_cast<FakeDNSSDResolveHostnameQuery>(query)) {
std::map<String,boost::optional<HostAddress> >::const_iterator i = addresses.find(resolveHostnameQuery->hostname);
if (i != addresses.end()) {
- MainEventLoop::postEvent(
+ eventLoop->postEvent(
boost::bind(
boost::ref(resolveHostnameQuery->onHostnameResolved), i->second),
shared_from_this());
@@ -79,7 +79,7 @@ void FakeDNSSDQuerier::removeRunningQuery(boost::shared_ptr<FakeDNSSDQuery> quer
void FakeDNSSDQuerier::addService(const DNSSDServiceID& id) {
services.insert(id);
foreach(const boost::shared_ptr<FakeDNSSDBrowseQuery>& query, getQueries<FakeDNSSDBrowseQuery>()) {
- MainEventLoop::postEvent(boost::bind(boost::ref(query->onServiceAdded), id), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(query->onServiceAdded), id), shared_from_this());
}
}
@@ -87,7 +87,7 @@ void FakeDNSSDQuerier::removeService(const DNSSDServiceID& id) {
services.erase(id);
serviceInfo.erase(id);
foreach(const boost::shared_ptr<FakeDNSSDBrowseQuery>& query, getQueries<FakeDNSSDBrowseQuery>()) {
- MainEventLoop::postEvent(boost::bind(boost::ref(query->onServiceRemoved), id), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(query->onServiceRemoved), id), shared_from_this());
}
}
@@ -98,7 +98,7 @@ void FakeDNSSDQuerier::setServiceInfo(const DNSSDServiceID& id, const DNSSDResol
}
foreach(const boost::shared_ptr<FakeDNSSDResolveServiceQuery>& query, getQueries<FakeDNSSDResolveServiceQuery>()) {
if (query->service == id) {
- MainEventLoop::postEvent(boost::bind(boost::ref(query->onServiceResolved), info), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(query->onServiceResolved), info), shared_from_this());
}
}
}
@@ -114,13 +114,13 @@ bool FakeDNSSDQuerier::isServiceRegistered(const String& name, int port, const B
void FakeDNSSDQuerier::setBrowseError() {
foreach(const boost::shared_ptr<FakeDNSSDBrowseQuery>& query, getQueries<FakeDNSSDBrowseQuery>()) {
- MainEventLoop::postEvent(boost::ref(query->onError), shared_from_this());
+ eventLoop->postEvent(boost::ref(query->onError), shared_from_this());
}
}
void FakeDNSSDQuerier::setRegisterError() {
foreach(const boost::shared_ptr<FakeDNSSDRegisterQuery>& query, getQueries<FakeDNSSDRegisterQuery>()) {
- MainEventLoop::postEvent(boost::bind(boost::ref(query->onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(query->onRegisterFinished), boost::optional<DNSSDServiceID>()), shared_from_this());
}
}
@@ -128,7 +128,7 @@ void FakeDNSSDQuerier::setAddress(const String& hostname, boost::optional<HostAd
addresses[hostname] = address;
foreach(const boost::shared_ptr<FakeDNSSDResolveHostnameQuery>& query, getQueries<FakeDNSSDResolveHostnameQuery>()) {
if (query->hostname == hostname) {
- MainEventLoop::postEvent(boost::bind(
+ eventLoop->postEvent(boost::bind(
boost::ref(query->onHostnameResolved), address), shared_from_this());
}
}
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
index f08ab68..9338dd4 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
@@ -22,13 +22,14 @@ namespace Swift {
class ByteArray;
class FakeDNSSDQuery;
class FakeDNSSDBrowseQuery;
+ class EventLoop;
class FakeDNSSDQuerier :
public DNSSDQuerier,
public EventOwner,
public boost::enable_shared_from_this<FakeDNSSDQuerier> {
public:
- FakeDNSSDQuerier(const String& domain);
+ FakeDNSSDQuerier(const String& domain, EventLoop* eventLoop);
~FakeDNSSDQuerier();
void start() {}
@@ -84,6 +85,7 @@ namespace Swift {
private:
String domain;
+ EventLoop* eventLoop;
std::list< boost::shared_ptr<FakeDNSSDQuery> > runningQueries;
std::list< boost::shared_ptr<FakeDNSSDQuery> > allQueriesEverRun;
std::set<DNSSDServiceID> services;
diff --git a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp
index 56128f0..7a42129 100644
--- a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp
+++ b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.cpp
@@ -15,11 +15,14 @@
namespace Swift {
+PlatformDNSSDQuerierFactory::PlatformDNSSDQuerierFactory(EventLoop* eventLoop) : eventLoop(eventLoop) {
+}
+
boost::shared_ptr<DNSSDQuerier> PlatformDNSSDQuerierFactory::createQuerier() {
#if defined(HAVE_BONJOUR)
- return boost::shared_ptr<DNSSDQuerier>(new BonjourQuerier());
+ return boost::shared_ptr<DNSSDQuerier>(new BonjourQuerier(eventLoop));
#elif defined(HAVE_AVAHI)
- return boost::shared_ptr<DNSSDQuerier>(new AvahiQuerier());
+ return boost::shared_ptr<DNSSDQuerier>(new AvahiQuerier(eventLoop));
#else
return boost::shared_ptr<DNSSDQuerier>();
#endif
diff --git a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h
index 674c13a..ca5570f 100644
--- a/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h
+++ b/Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h
@@ -10,11 +10,17 @@
namespace Swift {
class DNSSDQuerier;
+ class EventLoop;
class PlatformDNSSDQuerierFactory {
public:
- boost::shared_ptr<DNSSDQuerier> createQuerier();
+ PlatformDNSSDQuerierFactory(EventLoop* eventLoop);
- bool canCreate();
+ boost::shared_ptr<DNSSDQuerier> createQuerier();
+
+ bool canCreate();
+
+ private:
+ EventLoop* eventLoop;
};
}