From 24b692a82111d144a909e5193f087a04a37dbd6f Mon Sep 17 00:00:00 2001 From: yunhanw Date: Mon, 20 May 2024 09:44:16 -0700 Subject: [PATCH 1/5] Remove icd entry in icd client storage after unregisterClient is triggered --- .../chip-tool/commands/clusters/ClusterCommand.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 792588a886dffb..65235c5bb1c0a5 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -59,6 +59,8 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub chip::CommandId commandId, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsRequest::Type & value) { + mPeerNodeId = device->GetDeviceId(); + mFabricIndex = device->GetSecureSession().Value()->GetFabricIndex(); ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value)); if (value.transferFileDesignator.HasValue() && @@ -109,6 +111,15 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub return; } } + if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) && (path.mCommandId == chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Id)) + { + CHIP_ERROR deleteEntryError = + CHIPCommand::sICDClientStorage.DeleteEntry(chip::ScopedNodeId(mPeerNodeId, mFabricIndex)); + if (deleteEntryError != CHIP_NO_ERROR) + { + ChipLogError(chipTool, "Failed to delete ICD entry: %s", chip::ErrorStr(deleteEntryError)); + } + } } virtual void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override @@ -208,7 +219,8 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub private: chip::ClusterId mClusterId; chip::CommandId mCommandId; - + chip::FabricIndex mFabricIndex = 0; + chip::NodeId mPeerNodeId = 0; CHIP_ERROR mError = CHIP_NO_ERROR; CustomArgument mPayload; }; From 32d3fa2c408ca7afadf25d13eaa0dfc3ff66f578 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 29 May 2024 21:27:14 +0000 Subject: [PATCH 2/5] Restyled by clang-format --- .../chip-tool/commands/clusters/ClusterCommand.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 65235c5bb1c0a5..7f46023f7bc2a4 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -59,7 +59,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub chip::CommandId commandId, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsRequest::Type & value) { - mPeerNodeId = device->GetDeviceId(); + mPeerNodeId = device->GetDeviceId(); mFabricIndex = device->GetSecureSession().Value()->GetFabricIndex(); ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value)); @@ -111,10 +111,10 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub return; } } - if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) && (path.mCommandId == chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Id)) + if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) && + (path.mCommandId == chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Id)) { - CHIP_ERROR deleteEntryError = - CHIPCommand::sICDClientStorage.DeleteEntry(chip::ScopedNodeId(mPeerNodeId, mFabricIndex)); + CHIP_ERROR deleteEntryError = CHIPCommand::sICDClientStorage.DeleteEntry(chip::ScopedNodeId(mPeerNodeId, mFabricIndex)); if (deleteEntryError != CHIP_NO_ERROR) { ChipLogError(chipTool, "Failed to delete ICD entry: %s", chip::ErrorStr(deleteEntryError)); @@ -220,7 +220,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub chip::ClusterId mClusterId; chip::CommandId mCommandId; chip::FabricIndex mFabricIndex = 0; - chip::NodeId mPeerNodeId = 0; - CHIP_ERROR mError = CHIP_NO_ERROR; + chip::NodeId mPeerNodeId = 0; + CHIP_ERROR mError = CHIP_NO_ERROR; CustomArgument mPayload; }; From 46dba2357297359d55fd9214eccb2e795b7961f3 Mon Sep 17 00:00:00 2001 From: yunhanw Date: Wed, 29 May 2024 20:13:05 -0700 Subject: [PATCH 3/5] address comments --- examples/chip-tool/commands/clusters/ClusterCommand.h | 6 +----- examples/chip-tool/commands/clusters/ModelCommand.cpp | 9 +++++++++ examples/chip-tool/commands/clusters/ModelCommand.h | 2 ++ .../tv-casting-common/commands/clusters/ModelCommand.cpp | 5 +++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 7f46023f7bc2a4..18de0768be4037 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -114,11 +114,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) && (path.mCommandId == chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Id)) { - CHIP_ERROR deleteEntryError = CHIPCommand::sICDClientStorage.DeleteEntry(chip::ScopedNodeId(mPeerNodeId, mFabricIndex)); - if (deleteEntryError != CHIP_NO_ERROR) - { - ChipLogError(chipTool, "Failed to delete ICD entry: %s", chip::ErrorStr(deleteEntryError)); - } + ModelCommand::ClearICDEntry(chip::ScopedNodeId(mPeerNodeId, mFabricIndex)); } } diff --git a/examples/chip-tool/commands/clusters/ModelCommand.cpp b/examples/chip-tool/commands/clusters/ModelCommand.cpp index c908f9fa71b548..fcb137ac103707 100644 --- a/examples/chip-tool/commands/clusters/ModelCommand.cpp +++ b/examples/chip-tool/commands/clusters/ModelCommand.cpp @@ -76,6 +76,15 @@ void ModelCommand::Shutdown() CHIPCommand::Shutdown(); } +void ModelCommand::ClearICDEntry(const chip::ScopedNodeId & nodeId) +{ + CHIP_ERROR deleteEntryError = CHIPCommand::sICDClientStorage.DeleteEntry(nodeId); + if (deleteEntryError != CHIP_NO_ERROR) + { + ChipLogError(chipTool, "Failed to delete ICD entry: %" CHIP_ERROR_FORMAT, deleteEntryError.Format()); + } +} + void ModelCommand::CheckPeerICDType() { if (mIsPeerLIT.HasValue()) diff --git a/examples/chip-tool/commands/clusters/ModelCommand.h b/examples/chip-tool/commands/clusters/ModelCommand.h index 9561932c9b74e0..c9406fea7e1a8c 100644 --- a/examples/chip-tool/commands/clusters/ModelCommand.h +++ b/examples/chip-tool/commands/clusters/ModelCommand.h @@ -67,6 +67,8 @@ class ModelCommand : public CHIPCommand virtual CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) { return CHIP_ERROR_BAD_REQUEST; }; + void ClearICDEntry(const chip::ScopedNodeId & nodeId) override; + void Shutdown() override; protected: diff --git a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp index bc14214af4cce9..82db1db4827d5d 100644 --- a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp +++ b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp @@ -81,3 +81,8 @@ void ModelCommand::Shutdown() mOnDeviceConnectedCallback.Cancel(); mOnDeviceConnectionFailureCallback.Cancel(); } + +void ClearICDEntry(const chip::ScopedNodeId & nodeId); +{ + ChipLogError(chipTool, "ClearICDEntry is not implemented"); +} From d57d9e4643f120e1aa382f541ed194e965cdae7a Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Thu, 30 May 2024 07:50:49 -0700 Subject: [PATCH 4/5] Update ModelCommand.cpp --- .../chip-tool/commands/clusters/ClusterCommand.h | 16 +++++++++++----- .../chip-tool/commands/clusters/ModelCommand.h | 2 +- .../commands/clusters/ModelCommand.cpp | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 18de0768be4037..9f50d1225623bb 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -55,12 +55,19 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub return InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value); } + CHIP_ERROR SendCommand(chip::DeviceProxy * device, chip::EndpointId endpointId, chip::ClusterId clusterId, + chip::CommandId commandId, + const chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Type & value) + { + ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value)); + mScopedNodeId = chip::ScopedNodeId(value.checkInNodeID,device->GetSecureSession().Value()->GetFabricIndex()); + return CHIP_NO_ERROR; + } + CHIP_ERROR SendCommand(chip::DeviceProxy * device, chip::EndpointId endpointId, chip::ClusterId clusterId, chip::CommandId commandId, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsRequest::Type & value) { - mPeerNodeId = device->GetDeviceId(); - mFabricIndex = device->GetSecureSession().Value()->GetFabricIndex(); ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value)); if (value.transferFileDesignator.HasValue() && @@ -114,7 +121,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) && (path.mCommandId == chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Id)) { - ModelCommand::ClearICDEntry(chip::ScopedNodeId(mPeerNodeId, mFabricIndex)); + ModelCommand::ClearICDEntry(mScopedNodeId); } } @@ -215,8 +222,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub private: chip::ClusterId mClusterId; chip::CommandId mCommandId; - chip::FabricIndex mFabricIndex = 0; - chip::NodeId mPeerNodeId = 0; + chip::ScopedNodeId mScopedNodeId; CHIP_ERROR mError = CHIP_NO_ERROR; CustomArgument mPayload; }; diff --git a/examples/chip-tool/commands/clusters/ModelCommand.h b/examples/chip-tool/commands/clusters/ModelCommand.h index 2708a92c9b93a6..79c31cf865930d 100644 --- a/examples/chip-tool/commands/clusters/ModelCommand.h +++ b/examples/chip-tool/commands/clusters/ModelCommand.h @@ -67,7 +67,7 @@ class ModelCommand : public CHIPCommand virtual CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) { return CHIP_ERROR_BAD_REQUEST; }; - void ClearICDEntry(const chip::ScopedNodeId & nodeId) override; + virtual void ClearICDEntry(const chip::ScopedNodeId & nodeId); void Shutdown() override; diff --git a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp index d031388d48820d..dafa11f2381fed 100644 --- a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp +++ b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp @@ -61,7 +61,7 @@ void ModelCommand::OnDeviceConnectedFn(void * context, Messaging::ExchangeManage VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnDeviceConnectedFn: context is null")); OperationalDeviceProxy device(&exchangeMgr, sessionHandle); - CHIP_ERROR err = command->SendCommand(&device, command->minEndPointId); + CHIP_ERROR err = command->SendCommand(&device, command->mEndPointId); VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err)); } @@ -82,7 +82,7 @@ void ModelCommand::Shutdown() mOnDeviceConnectionFailureCallback.Cancel(); } -void ClearICDEntry(const chip::ScopedNodeId & nodeId); +void ModelCommand::ClearICDEntry(const chip::ScopedNodeId & nodeId) { ChipLogError(chipTool, "ClearICDEntry is not implemented in tv-casting-app"); } From fc0e4bb371737c8435da4280a2f7fd2b1c4ffd34 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 30 May 2024 20:45:06 +0000 Subject: [PATCH 5/5] Restyled by clang-format --- examples/chip-tool/commands/clusters/ClusterCommand.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 9f50d1225623bb..171c664481c9dd 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -60,7 +60,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub const chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Type & value) { ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value)); - mScopedNodeId = chip::ScopedNodeId(value.checkInNodeID,device->GetSecureSession().Value()->GetFabricIndex()); + mScopedNodeId = chip::ScopedNodeId(value.checkInNodeID, device->GetSecureSession().Value()->GetFabricIndex()); return CHIP_NO_ERROR; } @@ -223,6 +223,6 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub chip::ClusterId mClusterId; chip::CommandId mCommandId; chip::ScopedNodeId mScopedNodeId; - CHIP_ERROR mError = CHIP_NO_ERROR; + CHIP_ERROR mError = CHIP_NO_ERROR; CustomArgument mPayload; };