diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index 96ae760c3475a8..86df18e5432fee 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -268,14 +268,14 @@ CHIP_ERROR MdnsContexts::Has(GenericContext * context) return CHIP_ERROR_KEY_NOT_FOUND; } -CHIP_ERROR MdnsContexts::GetRegisterContextOfType(const char * type, RegisterContext ** context) +CHIP_ERROR MdnsContexts::GetRegisterContextOfTypeAndName(const char * type, const char * name, RegisterContext ** context) { bool found = false; std::vector::iterator iter; for (iter = mContexts.begin(); iter != mContexts.end(); iter++) { - if ((*iter)->type == ContextType::Register && (static_cast(*iter))->matches(type)) + if ((*iter)->type == ContextType::Register && (static_cast(*iter))->matches(type, name)) { *context = static_cast(*iter); found = true; diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index e08fbb178bb094..eb2ebb205e1b31 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -152,7 +152,7 @@ CHIP_ERROR Register(void * context, DnssdPublishCallback callback, uint32_t inte StringOrNullMarker(name), StringOrNullMarker(hostname), port, StringOrNullMarker(type), interfaceId); RegisterContext * sdCtx = nullptr; - if (CHIP_NO_ERROR == MdnsContexts::GetInstance().GetRegisterContextOfType(type, &sdCtx)) + if (CHIP_NO_ERROR == MdnsContexts::GetInstance().GetRegisterContextOfTypeAndName(type, name, &sdCtx)) { auto err = DNSServiceUpdateRecord(sdCtx->serviceRef, nullptr, kRegisterFlags, record.size(), record.data(), 0 /* ttl */); VerifyOrReturnError(kDNSServiceErr_NoError == err, sdCtx->Finalize(err)); diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index 1dd6319222599e..0f724747da2fd2 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -82,12 +82,13 @@ class MdnsContexts * Example: * _matterc._udp,_V65521,_S15,_L3840,_CM * _matter._tcp,_I4CEEAD044CC35B63 + * @param[in] name The instance name for the service. * @param[out] context A reference to the context previously registered * * @return On success, the context parameter will point to the previously * registered context. */ - CHIP_ERROR GetRegisterContextOfType(const char * type, RegisterContext ** context); + CHIP_ERROR GetRegisterContextOfTypeAndName(const char * type, const char * name, RegisterContext ** context); /** * Return a pointer to an existing ResolveContext for the given @@ -146,7 +147,7 @@ struct RegisterContext : public GenericContext void DispatchFailure(const char * errorStr, CHIP_ERROR err) override; void DispatchSuccess() override; - bool matches(const char * sType) { return mType.compare(sType) == 0; } + bool matches(const char * type, const char * name) { return mType == type && mInstanceName == name; } }; struct BrowseHandler : public GenericContext