summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-31 16:38:15 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-31 16:38:15 (GMT)
commitaa60aa80d2d170a536c246ef6c221f92de7dd8ed (patch)
tree04a03dbe10024cbb21c42dffc73560d3cba0329d /Swiften/LinkLocal
parentd0f250d26bd1bdb405b2232159e7f84741d13e52 (diff)
downloadswift-aa60aa80d2d170a536c246ef6c221f92de7dd8ed.zip
swift-aa60aa80d2d170a536c246ef6c221f92de7dd8ed.tar.bz2
Adapt LinkLocalConnector to new LinkLocal infrastructure.
Diffstat (limited to 'Swiften/LinkLocal')
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h1
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h4
-rw-r--r--Swiften/LinkLocal/LinkLocalConnector.cpp49
-rw-r--r--Swiften/LinkLocal/LinkLocalConnector.h25
5 files changed, 49 insertions, 36 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
index 6e2a852..7b5f19a 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h
@@ -12,7 +12,7 @@ namespace Swift {
class BonjourQuerier;
class BonjourResolveHostnameQuery : public DNSSDResolveHostnameQuery, public BonjourQuery {
- public:
+ public:
BonjourResolveHostnameQuery(const String& hostname, int interfaceIndex, boost::shared_ptr<BonjourQuerier> querier) : BonjourQuery(querier) {
DNSServiceErrorType result = DNSServiceGetAddrInfo(
&sdRef, 0, interfaceIndex, kDNSServiceProtocol_IPv4,
@@ -33,6 +33,10 @@ namespace Swift {
}
}
+ void finish() {
+ BonjourQuery::finish();
+ }
+
private:
static void handleHostnameResolvedStatic(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char*, const struct sockaddr *address, uint32_t, void *context) {
static_cast<BonjourResolveHostnameQuery*>(context)->handleHostnameResolved(errorCode, address);
diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h
index a2e218c..1b9f291 100644
--- a/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h
+++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h
@@ -11,6 +11,7 @@ namespace Swift {
virtual ~DNSSDResolveHostnameQuery();
virtual void run() = 0;
+ virtual void finish() = 0;
boost::signal<void (const boost::optional<HostAddress>&)> onHostnameResolved;
};
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h
index 2ff84d3..1f9d7f1 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDResolveHostnameQuery.h
@@ -19,6 +19,10 @@ namespace Swift {
FakeDNSSDQuery::run();
}
+ void finish() {
+ FakeDNSSDQuery::finish();
+ }
+
String hostname;
int interfaceIndex;
};
diff --git a/Swiften/LinkLocal/LinkLocalConnector.cpp b/Swiften/LinkLocal/LinkLocalConnector.cpp
index 28107ed..18b5d6a 100644
--- a/Swiften/LinkLocal/LinkLocalConnector.cpp
+++ b/Swiften/LinkLocal/LinkLocalConnector.cpp
@@ -7,52 +7,53 @@
#include "Swiften/Network/HostAddress.h"
#include "Swiften/Network/HostAddressPort.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h"
+#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h"
namespace Swift {
LinkLocalConnector::LinkLocalConnector(
const JID& remoteJID,
const String& hostname,
+ int interfaceIndex,
int port,
boost::shared_ptr<DNSSDQuerier> querier,
boost::shared_ptr<Connection> connection) :
- remoteJID_(remoteJID),
- hostname_(hostname),
- port_(port),
- querier_(querier),
- connection_(connection),
- resolving_(false) {
+ remoteJID(remoteJID),
+ hostname(hostname),
+ interfaceIndex(interfaceIndex),
+ port(port),
+ querier(querier),
+ connection(connection) {
}
void LinkLocalConnector::connect() {
- resolving_ = true;
- //querier_->onHostnameResolved.connect(boost::bind(&LinkLocalConnector::handleHostnameResolved, boost::dynamic_pointer_cast<LinkLocalConnector>(shared_from_this()), _1, _2));
- //querier_->resolveHostname(hostname_);
+ resolveQuery = querier->createResolveHostnameQuery(hostname, interfaceIndex);
+ resolveQuery->onHostnameResolved.connect(boost::bind(
+ &LinkLocalConnector::handleHostnameResolved,
+ boost::dynamic_pointer_cast<LinkLocalConnector>(shared_from_this()),
+ _1));
+ resolveQuery->run();
}
-/*
-void LinkLocalConnector::handleHostnameResolved(const String& hostname, const boost::optional<HostAddress>& address) {
- if (resolving_) {
- if (hostname == hostname_) {
- resolving_ = false;
- if (address) {
- connection_->onConnectFinished.connect(boost::bind(boost::ref(onConnectFinished), _1));
- connection_->connect(HostAddressPort(*address, port_));
- }
- else {
- onConnectFinished(false);
- }
- }
+void LinkLocalConnector::handleHostnameResolved(const boost::optional<HostAddress>& address) {
+ if (address) {
+ resolveQuery->finish();
+ resolveQuery.reset();
+ connection->onConnectFinished.connect(
+ boost::bind(boost::ref(onConnectFinished), _1));
+ connection->connect(HostAddressPort(*address, port));
+ }
+ else {
+ onConnectFinished(false);
}
}
-*/
void LinkLocalConnector::handleConnected(bool error) {
onConnectFinished(error);
}
void LinkLocalConnector::queueElement(boost::shared_ptr<Element> element) {
- queuedElements_.push_back(element);
+ queuedElements.push_back(element);
}
diff --git a/Swiften/LinkLocal/LinkLocalConnector.h b/Swiften/LinkLocal/LinkLocalConnector.h
index 2ddb5b8..134656c 100644
--- a/Swiften/LinkLocal/LinkLocalConnector.h
+++ b/Swiften/LinkLocal/LinkLocalConnector.h
@@ -16,44 +16,47 @@ namespace Swift {
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
class DNSSDQuerier;
+ class DNSSDResolveHostnameQuery;
class LinkLocalConnector : public boost::enable_shared_from_this<LinkLocalConnector> {
public:
LinkLocalConnector(
const JID& remoteJID,
const String& hostname,
+ int interfaceIndex,
int port,
boost::shared_ptr<DNSSDQuerier> querier,
boost::shared_ptr<Connection> connection);
const JID& getRemoteJID() const {
- return remoteJID_;
+ return remoteJID;
}
void connect();
void queueElement(boost::shared_ptr<Element> element);
const std::vector<boost::shared_ptr<Element> >& getQueuedElements() const {
- return queuedElements_;
+ return queuedElements;
}
boost::shared_ptr<Connection> getConnection() const {
- return connection_;
+ return connection;
}
boost::signal<void (bool)> onConnectFinished;
private:
- //void handleHostnameResolved(const String& hostname, const boost::optional<HostAddress>& address);
+ void handleHostnameResolved(const boost::optional<HostAddress>& address);
void handleConnected(bool error);
private:
- JID remoteJID_;
- String hostname_;
- int port_;
- boost::shared_ptr<DNSSDQuerier> querier_;
- boost::shared_ptr<Connection> connection_;
- bool resolving_;
- std::vector<boost::shared_ptr<Element> > queuedElements_;
+ JID remoteJID;
+ String hostname;
+ int interfaceIndex;
+ int port;
+ boost::shared_ptr<DNSSDQuerier> querier;
+ boost::shared_ptr<DNSSDResolveHostnameQuery> resolveQuery;
+ boost::shared_ptr<Connection> connection;
+ std::vector<boost::shared_ptr<Element> > queuedElements;
};
}