Skip to content

Commit

Permalink
[chip-tool] Add read-all command to read all events and attributes fr…
Browse files Browse the repository at this point in the history
…om a given endpoint (could be wildcard) onto a single transaction (#20270)

* [chip-tool] Add read-all command to read all events and attributes from a given endpoint (could be wildcard) onto a single transaction

* Update generated code
  • Loading branch information
vivien-apple authored Jul 5, 2022
1 parent 777ee25 commit a498673
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,29 @@ class SubscribeEvent : public SubscribeCommand
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<std::vector<bool>> mIsUrgents;
};

class ReadAll : public ReadCommand
{
public:
ReadAll(CredentialIssuerCommands * credsIssuerConfig) : ReadCommand("read-all", credsIssuerConfig)
{
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
ReadCommand::AddArguments();
}

~ReadAll() {}

void OnDone(chip::app::ReadClient * aReadClient) override
{
InteractionModelReports::CleanupReadClient(aReadClient);
SetCommandExitStatus(mError);
}

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReadCommand::ReadAll(device, endpointIds, mFabricFiltered);
}

private:
chip::Optional<bool> mFabricFiltered;
};
1 change: 1 addition & 0 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss
make_unique<SubscribeAttribute>(credsIssuerConfig), //
make_unique<ReadEvent>(credsIssuerConfig), //
make_unique<SubscribeEvent>(credsIssuerConfig), //
make_unique<ReadAll>(credsIssuerConfig), //
};

commands.Register(clusterName, clusterCommands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,37 @@ void InteractionModelReports::CleanupReadClient(ReadClient * aReadClient)
std::remove_if(mReadClients.begin(), mReadClients.end(), [aReadClient](auto & item) { return item.get() == aReadClient; }),
mReadClients.end());
}

CHIP_ERROR InteractionModelReports::ReadAll(DeviceProxy * device, std::vector<EndpointId> endpointIds,
const Optional<bool> & fabricFiltered)
{
AttributePathParams attributePathParams[kMaxAllowedPaths];
EventPathParams eventPathParams[kMaxAllowedPaths];

auto pathsCount = endpointIds.size();
VerifyOrReturnError(pathsCount > 0 && pathsCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT);

for (size_t i = 0; i < pathsCount; i++)
{
auto endpointId = endpointIds.at(i);
attributePathParams[i].mEndpointId = endpointId;
eventPathParams[i].mEndpointId = endpointId;
}

ReadPrepareParams params(device->GetSecureSession().Value());
params.mpEventPathParamsList = eventPathParams;
params.mEventPathParamsListSize = pathsCount;
params.mpAttributePathParamsList = attributePathParams;
params.mAttributePathParamsListSize = pathsCount;

if (fabricFiltered.HasValue())
{
params.mIsFabricFiltered = fabricFiltered.Value();
}

auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
mBufferedReadAdapter, ReadClient::InteractionType::Read);
ReturnErrorOnFailure(client->SendRequest(params));
mReadClients.push_back(std::move(client));
return CHIP_NO_ERROR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class InteractionModelReports
const chip::Optional<bool> & keepSubscriptions = chip::NullOptional,
const chip::Optional<std::vector<bool>> & isUrgents = chip::NullOptional);

CHIP_ERROR ReadAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
const chip::Optional<bool> & fabricFiltered = chip::Optional<bool>(true));

void Shutdown() { mReadClients.clear(); }

void CleanupReadClient(chip::app::ReadClient * aReadClient);
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/chip-tool/zap-generated/cluster/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a498673

Please sign in to comment.