Skip to content

Commit

Permalink
Ensure ResolverProxy maintains callbacks until init is called. Ensure…
Browse files Browse the repository at this point in the history
… server app always initializes the global resolver (#16230)
  • Loading branch information
andy31415 authored and pull[bot] committed Jun 7, 2022
1 parent 4cc2c12 commit 4374185
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
28 changes: 25 additions & 3 deletions src/lib/dnssd/ResolverProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolverDelegateProxy>();

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;
}

Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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
Expand Down

0 comments on commit 4374185

Please sign in to comment.