summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/LinkLocal/DNSSD/Bonjour')
-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
8 files changed, 32 insertions, 29 deletions
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,