From 2b749bb5665adf893188faec1c299e23dd9c6c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 25 Jul 2009 19:38:11 +0200 Subject: Remove obsolete DNSSD factories. 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 - -namespace Swift { - class DNSSDService; - - class DNSSDServiceFactory { - public: - virtual ~DNSSDServiceFactory(); - virtual bool canCreate() const = 0; - - virtual boost::shared_ptr 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 #include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" +#include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h" #include "Swiften/Network/HostAddress.h" namespace Swift { LinkLocalServiceBrowser::LinkLocalServiceBrowser(boost::shared_ptr 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 LinkLocalServiceBrowser::getServices() const { std::vector 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 resolveQuery = querier->createResolveServiceQuery(service); + resolveQuery->onServiceResolved.connect( + boost::bind(&LinkLocalServiceBrowser::handleServiceResolved, this, service, _1)); + std::pair 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 r = services.insert(std::make_pair(service, result)); - if (r.second) { - onServiceAdded(service); +void LinkLocalServiceBrowser::handleServiceResolved(const DNSSDServiceID& service, const boost::optional& result) { + if (!result) { + // TODO + std::cerr << "Error resolving" << std::endl; } else { - r.first->second = result; - onServiceChanged(service); + std::pair 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 #include #include #include #include #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 querier); + ~LinkLocalServiceBrowser(); - std::vector getServices() const; + /*std::vector getServices() const;*/ boost::signal onServiceAdded; boost::signal onServiceChanged; boost::signal 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& result); private: boost::shared_ptr querier; - //typedef std::map ServiceMap; - //ServiceMap services; + boost::shared_ptr browseQuery; + typedef std::map > ResolveQueryMap; + ResolveQueryMap resolveQueries; + typedef std::map 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 - -#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 PlatformDNSSDServiceFactory::createDNSSDService() { -#if defined(HAVE_AVAHI) - return boost::shared_ptr(new AvahiDNSSDService()); -#elif defined(HAVE_BONJOUR) - return boost::shared_ptr(new AppleDNSSDService()); -#else - assert(false); - return boost::shared_ptr(); -#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 createDNSSDService(); - }; -} -- cgit v0.10.2-6-g49f6