From 3727078b55528fc0a79d3d21015fb31a0011432b Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 19 Mar 2024 02:14:05 +0000 Subject: [PATCH] call OnActiveModeNotification out from onCheckInComplete (#32159) --- examples/chip-tool/commands/common/CHIPCommand.cpp | 6 ++++-- src/app/icd/client/CheckInHandler.cpp | 9 +++++++-- src/app/icd/client/CheckInHandler.h | 6 ++++-- src/app/icd/client/DefaultCheckInDelegate.cpp | 11 ++++------- src/app/icd/client/DefaultCheckInDelegate.h | 7 +++++-- src/app/icd/client/RefreshKeySender.cpp | 13 +++++++++---- src/app/icd/client/RefreshKeySender.h | 7 ++++--- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 78abff12ada208..125ab46433e0ef 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -149,9 +149,11 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack() ReturnErrorOnFailure(GetAttestationTrustStore(mPaaTrustStorePath.ValueOr(nullptr), &sTrustStore)); - ReturnLogErrorOnFailure(sCheckInDelegate.Init(&sICDClientStorage)); + auto engine = chip::app::InteractionModelEngine::GetInstance(); + VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INCORRECT_STATE); + ReturnLogErrorOnFailure(sCheckInDelegate.Init(&sICDClientStorage, engine)); ReturnLogErrorOnFailure(sCheckInHandler.Init(DeviceControllerFactory::GetInstance().GetSystemState()->ExchangeMgr(), - &sICDClientStorage, &sCheckInDelegate)); + &sICDClientStorage, &sCheckInDelegate, engine)); CommissionerIdentity nullIdentity{ kIdentityNull, chip::kUndefinedNodeId }; ReturnLogErrorOnFailure(InitializeCommissioner(nullIdentity, kIdentityNullFabricId)); diff --git a/src/app/icd/client/CheckInHandler.cpp b/src/app/icd/client/CheckInHandler.cpp index 165301c45480fd..f6ef50a0019d66 100644 --- a/src/app/icd/client/CheckInHandler.cpp +++ b/src/app/icd/client/CheckInHandler.cpp @@ -22,6 +22,8 @@ * */ +#include +#include #include #include #include @@ -44,7 +46,7 @@ inline constexpr uint32_t kKeyRefreshLimit = (1U << 31); CheckInHandler::CheckInHandler() {} CHIP_ERROR CheckInHandler::Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage, - CheckInDelegate * delegate) + CheckInDelegate * delegate, InteractionModelEngine * engine) { VerifyOrReturnError(exchangeManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(clientStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -54,7 +56,7 @@ CHIP_ERROR CheckInHandler::Init(Messaging::ExchangeManager * exchangeManager, IC mpExchangeManager = exchangeManager; mpICDClientStorage = clientStorage; mpCheckInDelegate = delegate; - + mpImEngine = engine; return mpExchangeManager->RegisterUnsolicitedMessageHandlerForType(Protocols::SecureChannel::MsgType::ICD_CheckIn, this); } @@ -127,6 +129,9 @@ CHIP_ERROR CheckInHandler::OnMessageReceived(Messaging::ExchangeContext * ec, co else { mpCheckInDelegate->OnCheckInComplete(clientInfo); +#if CHIP_CONFIG_ENABLE_READ_CLIENT + mpImEngine->OnActiveModeNotification(clientInfo.peer_node); +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT } return CHIP_NO_ERROR; diff --git a/src/app/icd/client/CheckInHandler.h b/src/app/icd/client/CheckInHandler.h index 22170a1b332694..b2489aaac34812 100644 --- a/src/app/icd/client/CheckInHandler.h +++ b/src/app/icd/client/CheckInHandler.h @@ -36,12 +36,13 @@ namespace chip { namespace app { - +class InteractionModelEngine; class CheckInHandler : public Messaging::ExchangeDelegate, public Messaging::UnsolicitedMessageHandler { public: - CHIP_ERROR Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage, CheckInDelegate * delegate); + CHIP_ERROR Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage, CheckInDelegate * delegate, + InteractionModelEngine * engine); void Shutdown(); CheckInHandler(); @@ -87,6 +88,7 @@ class CheckInHandler : public Messaging::ExchangeDelegate, public Messaging::Uns Messaging::ExchangeManager * mpExchangeManager = nullptr; CheckInDelegate * mpCheckInDelegate = nullptr; ICDClientStorage * mpICDClientStorage = nullptr; + InteractionModelEngine * mpImEngine = nullptr; }; } // namespace app diff --git a/src/app/icd/client/DefaultCheckInDelegate.cpp b/src/app/icd/client/DefaultCheckInDelegate.cpp index 8df98006f6e9e0..e967138310c0f4 100644 --- a/src/app/icd/client/DefaultCheckInDelegate.cpp +++ b/src/app/icd/client/DefaultCheckInDelegate.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ -#include #include #include #include @@ -25,11 +24,12 @@ namespace chip { namespace app { -CHIP_ERROR DefaultCheckInDelegate::Init(ICDClientStorage * storage) +CHIP_ERROR DefaultCheckInDelegate::Init(ICDClientStorage * storage, InteractionModelEngine * engine) { VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(mpStorage == nullptr, CHIP_ERROR_INCORRECT_STATE); - mpStorage = storage; + mpStorage = storage; + mpImEngine = engine; return CHIP_NO_ERROR; } @@ -38,9 +38,6 @@ void DefaultCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo) ChipLogProgress( ICD, "Check In Message processing complete: start_counter=%" PRIu32 " offset=%" PRIu32 " nodeid=" ChipLogFormatScopedNodeId, clientInfo.start_icd_counter, clientInfo.offset, ChipLogValueScopedNodeId(clientInfo.peer_node)); -#if CHIP_CONFIG_ENABLE_READ_CLIENT - InteractionModelEngine::GetInstance()->OnActiveModeNotification(clientInfo.peer_node); -#endif } RefreshKeySender * DefaultCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage) @@ -55,7 +52,7 @@ RefreshKeySender * DefaultCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & cl return nullptr; } - auto refreshKeySender = Platform::New(this, clientInfo, clientStorage, newKey); + auto refreshKeySender = Platform::New(this, clientInfo, clientStorage, mpImEngine, newKey); if (refreshKeySender == nullptr) { return nullptr; diff --git a/src/app/icd/client/DefaultCheckInDelegate.h b/src/app/icd/client/DefaultCheckInDelegate.h index e7b856677734bd..5465994ef1bda0 100644 --- a/src/app/icd/client/DefaultCheckInDelegate.h +++ b/src/app/icd/client/DefaultCheckInDelegate.h @@ -26,18 +26,21 @@ namespace app { using namespace std; +class InteractionModelEngine; + /// Callbacks for check in protocol class DefaultCheckInDelegate : public CheckInDelegate { public: virtual ~DefaultCheckInDelegate() {} - CHIP_ERROR Init(ICDClientStorage * storage); + CHIP_ERROR Init(ICDClientStorage * storage, InteractionModelEngine * engine); void OnCheckInComplete(const ICDClientInfo & clientInfo) override; RefreshKeySender * OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage) override; void OnKeyRefreshDone(RefreshKeySender * refreshKeySender, CHIP_ERROR error) override; private: - ICDClientStorage * mpStorage = nullptr; + ICDClientStorage * mpStorage = nullptr; + InteractionModelEngine * mpImEngine = nullptr; }; } // namespace app diff --git a/src/app/icd/client/RefreshKeySender.cpp b/src/app/icd/client/RefreshKeySender.cpp index 45cbbd9c987a68..f0fbdbae7721d8 100644 --- a/src/app/icd/client/RefreshKeySender.cpp +++ b/src/app/icd/client/RefreshKeySender.cpp @@ -19,6 +19,7 @@ #include "CheckInDelegate.h" #include "controller/InvokeInteraction.h" #include +#include #include #include #include @@ -28,10 +29,11 @@ namespace chip { namespace app { RefreshKeySender::RefreshKeySender(CheckInDelegate * checkInDelegate, const ICDClientInfo & icdClientInfo, - ICDClientStorage * icdClientStorage, const RefreshKeyBuffer & refreshKeyBuffer) : - mICDClientInfo(icdClientInfo), - mpICDClientStorage(icdClientStorage), mpCheckInDelegate(checkInDelegate), mOnConnectedCallback(HandleDeviceConnected, this), - mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) + ICDClientStorage * icdClientStorage, InteractionModelEngine * engine, + const RefreshKeyBuffer & refreshKeyBuffer) : + mpCheckInDelegate(checkInDelegate), + mICDClientInfo(icdClientInfo), mpICDClientStorage(icdClientStorage), mpImEngine(engine), + mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) { mNewKey = refreshKeyBuffer; @@ -64,6 +66,9 @@ CHIP_ERROR RefreshKeySender::RegisterClientWithNewKey(Messaging::ExchangeManager } mpCheckInDelegate->OnCheckInComplete(mICDClientInfo); +#if CHIP_CONFIG_ENABLE_READ_CLIENT + mpImEngine->OnActiveModeNotification(mICDClientInfo.peer_node); +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT mpCheckInDelegate->OnKeyRefreshDone(this, CHIP_NO_ERROR); }; diff --git a/src/app/icd/client/RefreshKeySender.h b/src/app/icd/client/RefreshKeySender.h index a0cf822fa446f9..a92345fbe8ab83 100644 --- a/src/app/icd/client/RefreshKeySender.h +++ b/src/app/icd/client/RefreshKeySender.h @@ -34,7 +34,7 @@ namespace chip { namespace app { class CheckInDelegate; - +class InteractionModelEngine; /** * @brief RefreshKeySender contains all the data and methods needed for key refresh and re-registration of an ICD client. */ @@ -44,7 +44,7 @@ class RefreshKeySender typedef Crypto::SensitiveDataBuffer RefreshKeyBuffer; RefreshKeySender(CheckInDelegate * checkInDelegate, const ICDClientInfo & icdClientInfo, ICDClientStorage * icdClientStorage, - const RefreshKeyBuffer & refreshKeyBuffer); + InteractionModelEngine * engine, const RefreshKeyBuffer & refreshKeyBuffer); /** * @brief Sets up a CASE session to the peer for re-registering a client with the peer when a key refresh is required to avoid @@ -82,9 +82,10 @@ class RefreshKeySender */ CHIP_ERROR RegisterClientWithNewKey(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle); + CheckInDelegate * mpCheckInDelegate = nullptr; ICDClientInfo mICDClientInfo; ICDClientStorage * mpICDClientStorage = nullptr; - CheckInDelegate * mpCheckInDelegate = nullptr; + InteractionModelEngine * mpImEngine = nullptr; RefreshKeyBuffer mNewKey; Callback::Callback mOnConnectedCallback; Callback::Callback mOnConnectionFailureCallback;