Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
vivien-apple marked this conversation as resolved.
Show resolved Hide resolved
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.