From 4374185f2a13aede495e576df3e43c26d2d2c0e4 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 15 Mar 2022 17:10:11 -0400 Subject: [PATCH] Ensure ResolverProxy maintains callbacks until init is called. Ensure server app always initializes the global resolver (#16230) --- src/app/server/Server.cpp | 2 ++ src/lib/dnssd/ResolverProxy.h | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 229b4786c648a0..949affe999294d 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -197,6 +197,8 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint err = chip::app::InteractionModelEngine::GetInstance()->Init(&mExchangeMgr); SuccessOrExit(err); + chip::Dnssd::Resolver::Instance().Init(DeviceLayer::UDPEndPointManager()); + #if CHIP_CONFIG_ENABLE_SERVER_IM_EVENT // Initialize event logging subsystem { diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h index 00bb397a9cd4f0..57690c2dbb7920 100644 --- a/src/lib/dnssd/ResolverProxy.h +++ b/src/lib/dnssd/ResolverProxy.h @@ -86,6 +86,24 @@ class ResolverProxy : public Resolver ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(udpEndPoint)); VerifyOrReturnError(mDelegate == nullptr, CHIP_ERROR_INCORRECT_STATE); mDelegate = chip::Platform::New(); + + if (mDelegate != nullptr) + { + if (mPreInitOperationalDelegate != nullptr) + { + ChipLogProgress(Discovery, "Setting operational delegate post init"); + mDelegate->SetOperationalDelegate(mPreInitOperationalDelegate); + mPreInitOperationalDelegate = nullptr; + } + + if (mPreInitCommissioningDelegate != nullptr) + { + ChipLogProgress(Discovery, "Setting commissioning delegate post init"); + mDelegate->SetCommissioningDelegate(mPreInitCommissioningDelegate); + mPreInitCommissioningDelegate = nullptr; + } + } + return mDelegate != nullptr ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; } @@ -97,7 +115,8 @@ class ResolverProxy : public Resolver } else { - ChipLogError(Discovery, "Failed to proxy operational discovery: missing delegate"); + ChipLogProgress(Discovery, "Delaying proxy of operational discovery: missing delegate"); + mPreInitOperationalDelegate = delegate; } } @@ -109,7 +128,8 @@ class ResolverProxy : public Resolver } else { - ChipLogError(Discovery, "Failed to proxy commissioning discovery: missing delegate"); + ChipLogError(Discovery, "Delaying proxy of commissioning discovery: missing delegate"); + mPreInitCommissioningDelegate = delegate; } } @@ -127,7 +147,9 @@ class ResolverProxy : public Resolver CHIP_ERROR FindCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; private: - ResolverDelegateProxy * mDelegate = nullptr; + ResolverDelegateProxy * mDelegate = nullptr; + OperationalResolveDelegate * mPreInitOperationalDelegate = nullptr; + CommissioningResolveDelegate * mPreInitCommissioningDelegate = nullptr; }; } // namespace Dnssd