blob: 904f8f006559d0a79ac6ce619516df9405841ed5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <boost/bind.hpp>
#include <iostream>
#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h"
#include "Swiften/Network/HostAddress.h"
namespace Swift {
LinkLocalServiceBrowser::LinkLocalServiceBrowser(DNSSDServiceFactory* factory) {
dnsSDService = factory->createDNSSDService();
dnsSDService->onServiceAdded.connect(
boost::bind(&LinkLocalServiceBrowser::handleServiceAdded, this, _1));
dnsSDService->onServiceRemoved.connect(
boost::bind(&LinkLocalServiceBrowser::handleServiceRemoved, this, _1));
dnsSDService->onServiceResolved.connect(
boost::bind(&LinkLocalServiceBrowser::handleServiceResolved, this, _1, _2));
}
std::vector<LinkLocalService> LinkLocalServiceBrowser::getServices() const {
std::vector<LinkLocalService> result;
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 LinkLocalServiceID& service) {
dnsSDService->startResolvingService(service);
}
void LinkLocalServiceBrowser::handleServiceRemoved(const LinkLocalServiceID& service) {
dnsSDService->stopResolvingService(service);
services.erase(service);
onServiceRemoved(service);
}
void LinkLocalServiceBrowser::handleServiceResolved(const LinkLocalServiceID& service, const DNSSDService::ResolveResult& result) {
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);
}
}
}
|