summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/LinkLocal/LinkLocalConnector.cpp')
-rw-r--r--Swiften/LinkLocal/LinkLocalConnector.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/Swiften/LinkLocal/LinkLocalConnector.cpp b/Swiften/LinkLocal/LinkLocalConnector.cpp
new file mode 100644
index 0000000..af521b0
--- /dev/null
+++ b/Swiften/LinkLocal/LinkLocalConnector.cpp
@@ -0,0 +1,57 @@
+#include "Swiften/LinkLocal/LinkLocalConnector.h"
+
+#include <boost/bind.hpp>
+
+#include "Swiften/Network/Connection.h"
+#include "Swiften/Network/ConnectionFactory.h"
+#include "Swiften/Network/HostAddress.h"
+#include "Swiften/Network/HostAddressPort.h"
+#include "Swiften/LinkLocal/DNSSDService.h"
+
+namespace Swift {
+
+LinkLocalConnector::LinkLocalConnector(
+ const JID& remoteJID,
+ const String& hostname,
+ int port,
+ boost::shared_ptr<DNSSDService> resolver,
+ boost::shared_ptr<Connection> connection) :
+ remoteJID_(remoteJID),
+ hostname_(hostname),
+ port_(port),
+ resolver_(resolver),
+ connection_(connection),
+ resolving_(false) {
+}
+
+void LinkLocalConnector::connect() {
+ resolving_ = true;
+ resolver_->onHostnameResolved.connect(boost::bind(&LinkLocalConnector::handleHostnameResolved, boost::dynamic_pointer_cast<LinkLocalConnector>(shared_from_this()), _1, _2));
+ resolver_->resolveHostname(hostname_);
+}
+
+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::handleConnected(bool error) {
+ onConnectFinished(error);
+}
+
+void LinkLocalConnector::queueElement(boost::shared_ptr<Element> element) {
+ queuedElements_.push_back(element);
+}
+
+
+}