Skip to content

Commit c5fba0c

Browse files
Add domain names matching the DnssdServices stored in Browse Context (project-chip#32740)
* Add domain names matching the DnssdServices stored in Browse Context This is needed to pass the domain returned from a call to Browse to the Resolve. * Restyled by clang-format * Add the domain names to the services vector * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 22adb08 commit c5fba0c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/platform/Darwin/DnssdContexts.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,12 @@ void BrowseContext::DispatchSuccess()
368368
void BrowseContext::DispatchPartialSuccess()
369369
{
370370
sContextDispatchingSuccess = this;
371-
callback(context, services.data(), services.size(), false, CHIP_NO_ERROR);
371+
std::vector<DnssdService> dnsServices;
372+
for (auto iter : services)
373+
{
374+
dnsServices.push_back(std::move(iter.first));
375+
}
376+
callback(context, dnsServices.data(), dnsServices.size(), false, CHIP_NO_ERROR);
372377
sContextDispatchingSuccess = nullptr;
373378
services.clear();
374379
}
@@ -390,7 +395,7 @@ void BrowseContext::OnBrowseAdd(const char * name, const char * type, const char
390395

391396
VerifyOrReturn(IsLocalDomain(domain));
392397
auto service = GetService(name, type, protocol, interfaceId);
393-
services.push_back(service);
398+
services.push_back(std::make_pair(std::move(service), std::string(domain)));
394399
}
395400

396401
void BrowseContext::OnBrowseRemove(const char * name, const char * type, const char * domain, uint32_t interfaceId)
@@ -402,9 +407,10 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c
402407
VerifyOrReturn(IsLocalDomain(domain));
403408

404409
services.erase(std::remove_if(services.begin(), services.end(),
405-
[name, type, interfaceId](const DnssdService & service) {
406-
return strcmp(name, service.mName) == 0 && type == GetFullType(&service) &&
407-
service.mInterface == chip::Inet::InterfaceId(interfaceId);
410+
[name, type, interfaceId, domain](const auto & service) {
411+
return strcmp(name, service.first.mName) == 0 && type == GetFullType(&service.first) &&
412+
service.first.mInterface == chip::Inet::InterfaceId(interfaceId) &&
413+
strcmp(domain, service.second.c_str()) == 0;
408414
}),
409415
services.end());
410416
}

src/platform/Darwin/DnssdImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ struct BrowseHandler : public GenericContext
167167
struct BrowseContext : public BrowseHandler
168168
{
169169
DnssdBrowseCallback callback;
170-
std::vector<DnssdService> services;
170+
std::vector<std::pair<DnssdService, std::string>> services;
171171

172172
BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol);
173173

0 commit comments

Comments
 (0)