From c49b6bc22fa4a14415a5b8bb1b62df08c2163803 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 4 Jul 2022 15:23:03 +0200 Subject: [PATCH] [chip-tool] Add read-all command to read all events and attributes from a given endpoint (could be wildcard) onto a single transaction --- .../commands/clusters/ReportCommand.h | 26 +++++++++++++++ examples/chip-tool/templates/commands.zapt | 1 + .../interaction_model/InteractionModel.cpp | 32 +++++++++++++++++++ .../interaction_model/InteractionModel.h | 3 ++ 4 files changed, 62 insertions(+) diff --git a/examples/chip-tool/commands/clusters/ReportCommand.h b/examples/chip-tool/commands/clusters/ReportCommand.h index 5a6bb4bf20c3b3..98f8f6de772051 100644 --- a/examples/chip-tool/commands/clusters/ReportCommand.h +++ b/examples/chip-tool/commands/clusters/ReportCommand.h @@ -411,3 +411,29 @@ class SubscribeEvent : public SubscribeCommand chip::Optional mKeepSubscriptions; chip::Optional> 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 endpointIds) override + { + return ReadCommand::ReadAll(device, endpointIds, mFabricFiltered); + } + +private: + chip::Optional mFabricFiltered; +}; diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt index 25c8a54859f471..2600ce10eeaa1f 100644 --- a/examples/chip-tool/templates/commands.zapt +++ b/examples/chip-tool/templates/commands.zapt @@ -137,6 +137,7 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // + make_unique(credsIssuerConfig), // }; commands.Register(clusterName, clusterCommands); diff --git a/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp b/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp index 526106c56d4a07..f1aac31ab93e83 100644 --- a/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp +++ b/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp @@ -448,3 +448,35 @@ 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 endpointIds, + const Optional & fabricFiltered) +{ + AttributePathParams attributePathParams[kMaxAllowedPaths]; + EventPathParams eventPathParams[kMaxAllowedPaths]; + + auto pathsCount = endpointIds.size(); + 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(InteractionModelEngine::GetInstance(), device->GetExchangeManager(), + mBufferedReadAdapter, ReadClient::InteractionType::Read); + ReturnErrorOnFailure(client->SendRequest(params)); + mReadClients.push_back(std::move(client)); + return CHIP_NO_ERROR; +} diff --git a/src/app/tests/suites/commands/interaction_model/InteractionModel.h b/src/app/tests/suites/commands/interaction_model/InteractionModel.h index a5853fdd3ac560..157195bf2a8352 100644 --- a/src/app/tests/suites/commands/interaction_model/InteractionModel.h +++ b/src/app/tests/suites/commands/interaction_model/InteractionModel.h @@ -107,6 +107,9 @@ class InteractionModelReports const chip::Optional & keepSubscriptions = chip::NullOptional, const chip::Optional> & isUrgents = chip::NullOptional); + CHIP_ERROR ReadAll(chip::DeviceProxy * device, std::vector endpointIds, + const chip::Optional & fabricFiltered = chip::Optional(true)); + void Shutdown() { mReadClients.clear(); } void CleanupReadClient(chip::app::ReadClient * aReadClient);