diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-07-25 17:38:11 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-07-25 18:02:22 (GMT) |
commit | 2b749bb5665adf893188faec1c299e23dd9c6c9f (patch) | |
tree | a64e1ca10d592ae68baa6ccf56a385a576a00575 /Swiften/LinkLocal/LinkLocalServiceBrowser.cpp | |
parent | 9f51e6c6279ae7fb541774ac4bf9debfa61395c1 (diff) | |
download | swift-2b749bb5665adf893188faec1c299e23dd9c6c9f.zip swift-2b749bb5665adf893188faec1c299e23dd9c6c9f.tar.bz2 |
Remove obsolete DNSSD factories.
Diffstat (limited to 'Swiften/LinkLocal/LinkLocalServiceBrowser.cpp')
-rw-r--r-- | Swiften/LinkLocal/LinkLocalServiceBrowser.cpp | 56 |
1 files changed, 38 insertions, 18 deletions
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); + } } } -*/ } |