summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/LinkLocal/DNSSDServiceFactory.cpp8
-rw-r--r--Swiften/LinkLocal/DNSSDServiceFactory.h15
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.cpp56
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.h21
-rw-r--r--Swiften/LinkLocal/Makefile.inc4
-rw-r--r--Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp38
-rw-r--r--Swiften/LinkLocal/PlatformDNSSDServiceFactory.h13
7 files changed, 52 insertions, 103 deletions
diff --git a/Swiften/LinkLocal/DNSSDServiceFactory.cpp b/Swiften/LinkLocal/DNSSDServiceFactory.cpp
deleted file mode 100644
index f53660a..0000000
--- a/Swiften/LinkLocal/DNSSDServiceFactory.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
-
-namespace Swift {
-
-DNSSDServiceFactory::~DNSSDServiceFactory() {
-}
-
-}
diff --git a/Swiften/LinkLocal/DNSSDServiceFactory.h b/Swiften/LinkLocal/DNSSDServiceFactory.h
deleted file mode 100644
index 6296165..0000000
--- a/Swiften/LinkLocal/DNSSDServiceFactory.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include <boost/shared_ptr.hpp>
-
-namespace Swift {
- class DNSSDService;
-
- class DNSSDServiceFactory {
- public:
- virtual ~DNSSDServiceFactory();
- virtual bool canCreate() const = 0;
-
- virtual boost::shared_ptr<DNSSDService> createDNSSDService() = 0;
- };
-}
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
index ab56695..6634a0a 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
@@ -2,48 +2,68 @@
#include <iostream>
#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h"
+#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h"
#include "Swiften/Network/HostAddress.h"
namespace Swift {
LinkLocalServiceBrowser::LinkLocalServiceBrowser(boost::shared_ptr<DNSSDQuerier> querier) : querier(querier) {
- /*dnsSDService = factory->createDNSSDService();
- dnsSDService->onServiceAdded.connect(
+ browseQuery = querier->createBrowseQuery();
+ browseQuery->onServiceAdded.connect(
boost::bind(&LinkLocalServiceBrowser::handleServiceAdded, this, _1));
- dnsSDService->onServiceRemoved.connect(
+ browseQuery->onServiceRemoved.connect(
boost::bind(&LinkLocalServiceBrowser::handleServiceRemoved, this, _1));
- dnsSDService->onServiceResolved.connect(
- boost::bind(&LinkLocalServiceBrowser::handleServiceResolved, this, _1, _2));*/
+ browseQuery->startBrowsing();
}
+LinkLocalServiceBrowser::~LinkLocalServiceBrowser() {
+ browseQuery->stopBrowsing();
+}
+
+/*
std::vector<LinkLocalService> LinkLocalServiceBrowser::getServices() const {
std::vector<LinkLocalService> result;
- /*for (ServiceMap::const_iterator i = services.begin(); i != services.end(); ++i) {
+ for (ServiceMap::const_iterator i = services.begin(); i != services.end(); ++i) {
result.push_back(LinkLocalService(i->first, i->second));
- }*/
+ }
return result;
}
+*/
-/*void LinkLocalServiceBrowser::handleServiceAdded(const DNSSDServiceID& service) {
- dnsSDService->startResolvingService(service);
+void LinkLocalServiceBrowser::handleServiceAdded(const DNSSDServiceID& service) {
+ boost::shared_ptr<DNSSDResolveServiceQuery> resolveQuery = querier->createResolveServiceQuery(service);
+ resolveQuery->onServiceResolved.connect(
+ boost::bind(&LinkLocalServiceBrowser::handleServiceResolved, this, service, _1));
+ std::pair<ResolveQueryMap::iterator, bool> r = resolveQueries.insert(std::make_pair(service, resolveQuery));
+ if (!r.second) {
+ r.first->second = resolveQuery;
+ }
+ resolveQuery->start();
}
void LinkLocalServiceBrowser::handleServiceRemoved(const DNSSDServiceID& service) {
- dnsSDService->stopResolvingService(service);
- services.erase(service);
+ ResolveQueryMap::iterator i = resolveQueries.find(service);
+ assert(i != resolveQueries.end());
+ i->second->stop();
+ resolveQueries.erase(i);
onServiceRemoved(service);
}
-void LinkLocalServiceBrowser::handleServiceResolved(const DNSSDServiceID& service, const DNSSDService::ResolveResult& result) {
- std::pair<ServiceMap::iterator, bool> r = services.insert(std::make_pair(service, result));
- if (r.second) {
- onServiceAdded(service);
+void LinkLocalServiceBrowser::handleServiceResolved(const DNSSDServiceID& service, const boost::optional<DNSSDResolveServiceQuery::Result>& result) {
+ if (!result) {
+ // TODO
+ std::cerr << "Error resolving" << std::endl;
}
else {
- r.first->second = result;
- onServiceChanged(service);
+ std::pair<ServiceMap::iterator, bool> r = services.insert(std::make_pair(service, *result));
+ if (r.second) {
+ onServiceAdded(service);
+ }
+ else {
+ r.first->second = *result;
+ onServiceChanged(service);
+ }
}
}
-*/
}
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.h b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
index 10b12b7..5bd9bf0 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.h
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
@@ -1,36 +1,41 @@
#pragma once
+#include <boost/signal.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <map>
#include <vector>
#include "Swiften/Base/String.h"
-#include "Swiften/LinkLocal/LinkLocalService.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDQuerier.h"
+#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h"
#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h"
namespace Swift {
- class HostAddress;
+ //class HostAddress;
class LinkLocalServiceBrowser {
public:
LinkLocalServiceBrowser(boost::shared_ptr<DNSSDQuerier> querier);
+ ~LinkLocalServiceBrowser();
- std::vector<LinkLocalService> getServices() const;
+ /*std::vector<LinkLocalService> getServices() const;*/
boost::signal<void (const DNSSDServiceID&)> onServiceAdded;
boost::signal<void (const DNSSDServiceID&)> onServiceChanged;
boost::signal<void (const DNSSDServiceID&)> onServiceRemoved;
private:
- //void handleServiceAdded(const DNSSDServiceID&);
- //void handleServiceRemoved(const DNSSDServiceID&);
- //void handleServiceResolved(const DNSSDServiceID& service, const DNSSDService::ResolveResult& result);
+ void handleServiceAdded(const DNSSDServiceID&);
+ void handleServiceRemoved(const DNSSDServiceID&);
+ void handleServiceResolved(const DNSSDServiceID& service, const boost::optional<DNSSDResolveServiceQuery::Result>& result);
private:
boost::shared_ptr<DNSSDQuerier> querier;
- //typedef std::map<DNSSDServiceID, DNSSDService::ResolveResult> ServiceMap;
- //ServiceMap services;
+ boost::shared_ptr<DNSSDBrowseQuery> browseQuery;
+ typedef std::map<DNSSDServiceID, boost::shared_ptr<DNSSDResolveServiceQuery> > ResolveQueryMap;
+ ResolveQueryMap resolveQueries;
+ typedef std::map<DNSSDServiceID, DNSSDResolveServiceQuery::Result> ServiceMap;
+ ServiceMap services;
};
}
diff --git a/Swiften/LinkLocal/Makefile.inc b/Swiften/LinkLocal/Makefile.inc
index 0980194..ac3d2a2 100644
--- a/Swiften/LinkLocal/Makefile.inc
+++ b/Swiften/LinkLocal/Makefile.inc
@@ -1,13 +1,11 @@
SWIFTEN_SOURCES += \
- Swiften/LinkLocal/DNSSDServiceFactory.cpp \
+ Swiften/LinkLocal/LinkLocalServiceBrowser.cpp \
Swiften/LinkLocal/DNSSDService.cpp \
- Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp \
Swiften/LinkLocal/LinkLocalRoster.cpp \
Swiften/LinkLocal/LinkLocalServiceInfo.cpp \
Swiften/LinkLocal/IncomingLinkLocalSession.cpp \
Swiften/LinkLocal/OutgoingLinkLocalSession.cpp \
Swiften/LinkLocal/LinkLocalConnector.cpp
-#Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
ifeq ($(HAVE_BONJOUR),yes)
SWIFTEN_SOURCES += \
diff --git a/Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp b/Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp
deleted file mode 100644
index df70506..0000000
--- a/Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "Swiften/LinkLocal/PlatformDNSSDServiceFactory.h"
-
-#include <cassert>
-
-#ifdef HAVE_SWIFTEN_CONFIG_H
-#include "Swiften/config.h"
-#endif
-#if defined(HAVE_AVAHI)
-#include "Swiften/LinkLocal/AvahiDNSSDService.h"
-#elif defined(HAVE_BONJOUR)
-#include "Swiften/LinkLocal/AppleDNSSDService.h"
-#endif
-
-namespace Swift {
-
-PlatformDNSSDServiceFactory::PlatformDNSSDServiceFactory() {
-}
-
-bool PlatformDNSSDServiceFactory::canCreate() const {
-#if defined(HAVE_AVAHI) || defined(HAVE_BONJOUR)
- return true;
-#else
- return false;
-#endif
-}
-
-boost::shared_ptr<DNSSDService> PlatformDNSSDServiceFactory::createDNSSDService() {
-#if defined(HAVE_AVAHI)
- return boost::shared_ptr<DNSSDService>(new AvahiDNSSDService());
-#elif defined(HAVE_BONJOUR)
- return boost::shared_ptr<DNSSDService>(new AppleDNSSDService());
-#else
- assert(false);
- return boost::shared_ptr<DNSSDService>();
-#endif
-}
-
-}
diff --git a/Swiften/LinkLocal/PlatformDNSSDServiceFactory.h b/Swiften/LinkLocal/PlatformDNSSDServiceFactory.h
deleted file mode 100644
index 9c4e4e6..0000000
--- a/Swiften/LinkLocal/PlatformDNSSDServiceFactory.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-
-#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
-
-namespace Swift {
- class PlatformDNSSDServiceFactory : public DNSSDServiceFactory {
- public:
- PlatformDNSSDServiceFactory();
-
- bool canCreate() const;
- virtual boost::shared_ptr<DNSSDService> createDNSSDService();
- };
-}