Skip to content

Commit

Permalink
[chip-tool][ICD]Remove icd entry in icd client storage after unregist…
Browse files Browse the repository at this point in the history
…erClient in ICDManagemenet is triggered (#33671)

* Remove icd entry in icd client storage after unregisterClient is
triggered

* Restyled by clang-format

* address comments

* Update ModelCommand.cpp

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
yunhanw-google and restyled-commits authored May 30, 2024
1 parent 17c5a00 commit 452cad3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ 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)
Expand Down Expand Up @@ -109,6 +118,11 @@ 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))
{
ModelCommand::ClearICDEntry(mScopedNodeId);
}
}

virtual void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override
Expand Down Expand Up @@ -208,7 +222,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
private:
chip::ClusterId mClusterId;
chip::CommandId mCommandId;

chip::ScopedNodeId mScopedNodeId;
CHIP_ERROR mError = CHIP_NO_ERROR;
CustomArgument mPayload;
};
9 changes: 9 additions & 0 deletions examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ModelCommand : public CHIPCommand

virtual CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) { return CHIP_ERROR_BAD_REQUEST; };

virtual void ClearICDEntry(const chip::ScopedNodeId & nodeId);

void Shutdown() override;

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ void ModelCommand::Shutdown()
mOnDeviceConnectionFailureCallback.Cancel();
}

void ModelCommand::ClearICDEntry(const chip::ScopedNodeId & nodeId)
{
ChipLogError(chipTool, "ClearICDEntry is not implemented in tv-casting-app");
}

bool ModelCommand::IsPeerLIT()
{
// Does not support tv-casting-app
Expand Down

0 comments on commit 452cad3

Please sign in to comment.