Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed May 7, 2024
1 parent 4a89ee8 commit ca3501c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "CHIPCommand.h"

#include <commands/icd/ICDCommand.h>
#include <controller/CHIPDeviceControllerFactory.h>
#include <credentials/attestation_verifier/FileAttestationTrustStore.h>
#include <lib/core/CHIPConfig.h>
Expand Down Expand Up @@ -52,7 +53,6 @@ chip::Credentials::GroupDataProviderImpl CHIPCommand::sGroupDataProvider{ kMaxGr
// All fabrics share the same ICD client storage.
chip::app::DefaultICDClientStorage CHIPCommand::sICDClientStorage;
chip::Crypto::RawKeySessionKeystore CHIPCommand::sSessionKeystore;
chip::app::DefaultCheckInDelegate CHIPCommand::sCheckInDelegate;
chip::app::CheckInHandler CHIPCommand::sCheckInHandler;

namespace {
Expand Down Expand Up @@ -153,9 +153,9 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()

auto engine = chip::app::InteractionModelEngine::GetInstance();
VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnLogErrorOnFailure(sCheckInDelegate.Init(&sICDClientStorage, engine));
ReturnLogErrorOnFailure(chipToolCheckInDelegate()->Init(&sICDClientStorage, engine));
ReturnLogErrorOnFailure(sCheckInHandler.Init(DeviceControllerFactory::GetInstance().GetSystemState()->ExchangeMgr(),
&sICDClientStorage, &sCheckInDelegate, engine));
&sICDClientStorage, chipToolCheckInDelegate(), engine));

CommissionerIdentity nullIdentity{ kIdentityNull, chip::kUndefinedNodeId };
ReturnLogErrorOnFailure(InitializeCommissioner(nullIdentity, kIdentityNullFabricId));
Expand Down
22 changes: 19 additions & 3 deletions examples/chip-tool/commands/icd/ICDCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ CHIP_ERROR ICDWaitForDeviceCommand::RunCommand()
return CHIP_ERROR_NOT_FOUND;
}
mInterestedNode = ScopedNodeId(GetDestinationId(), CurrentCommissioner().GetFabricIndex());
RegisterOnCheckInCompleteCallback(this);
ChipLogError(chipTool, "Please trigger the device active mode.");
return CHIP_NO_ERROR;
}

void ICDWaitForDeviceCommand::OnCheckInComplete(const chip::app::ICDClientInfo & clientInfo)
{
DefaultCheckInDelegate::OnCheckInComplete(clientInfo);

if (clientInfo.peer_node != mInterestedNode)
{
ChipLogDetail(chipTool, "The node " ChipLogFormatScopedNodeId " is not the one we are interested in.",
Expand All @@ -88,7 +89,7 @@ void ICDWaitForDeviceCommand::OnCheckInComplete(const chip::app::ICDClientInfo &
}

ChipLogDetail(chipTool, "Received check-in message from the node, send stay active request to the device.");
UnregisterOnCheckInCompleteCallback(this);
mInterestedNode = ScopedNodeId();

CHIP_ERROR err = ClusterCommand::RunCommand();
if (err != CHIP_NO_ERROR)
Expand All @@ -107,14 +108,29 @@ CHIP_ERROR ICDWaitForDeviceCommand::SendCommand(chip::DeviceProxy * device,
Clusters::IcdManagement::Commands::StayActiveRequest::Id, request);
}

namespace {
DefaultCheckInDelegate * checkInDelegate;
}

void registerCommandsICD(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
{
const char * name = "ICD";

auto icdWaitForDeviceCommand = make_unique<ICDWaitForDeviceCommand>(credsIssuerConfig);

// This should be safe within CHIPTool, since the lifespan of Commands is longer than any commands and the CHIPStack.
// So this object will not be used after free within CHIPTool.
checkInDelegate = static_cast<ICDWaitForDeviceCommand *>(icdWaitForDeviceCommand.get());

commands_list list = {
make_unique<ICDListCommand>(credsIssuerConfig),
make_unique<ICDWaitForDeviceCommand>(credsIssuerConfig),
std::move(icdWaitForDeviceCommand),
};

commands.RegisterCommandSet(name, list, "Commands for client-side ICD management.");
}

DefaultCheckInDelegate * chipToolCheckInDelegate()
{
return checkInDelegate;
}
6 changes: 4 additions & 2 deletions examples/chip-tool/commands/icd/ICDCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "commands/common/Commands.h"

#include <app/CommandSender.h>
#include <app/icd/client/DefaultCheckInDelegate.h>
#include <app/tests/suites/commands/interaction_model/InteractionModel.h>
#include <commands/common/ChipToolCheckInDelegate.h>
#include <lib/support/Span.h>

class ICDCommand : public CHIPCommand
Expand All @@ -46,7 +46,7 @@ class ICDListCommand : public ICDCommand
CHIP_ERROR RunCommand() override;
};

class ICDWaitForDeviceCommand : public ClusterCommand, public CheckInCompleteCallback
class ICDWaitForDeviceCommand : public ClusterCommand, public chip::app::DefaultCheckInDelegate
{
public:
ICDWaitForDeviceCommand(CredentialIssuerCommands * credIssuerCmds) : ClusterCommand("wait-for-device", credIssuerCmds)
Expand All @@ -70,3 +70,5 @@ class ICDWaitForDeviceCommand : public ClusterCommand, public CheckInCompleteCal
};

void registerCommandsICD(Commands & commands, CredentialIssuerCommands * credsIssuerConfig);

chip::app::DefaultCheckInDelegate * chipToolCheckInDelegate();

0 comments on commit ca3501c

Please sign in to comment.