From 9a06cfccdedda4919f841c04ed9ded1e72591191 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 3 Jun 2024 12:19:42 -0400 Subject: [PATCH] Use EncodableToTLV in im_responder (#33693) * Use EncodableToTLV in im_responder. This makes the API cleaner and safer (have snapshot & rollback capabilities, less use of prepare/finish). * Update src/app/tests/integration/chip_im_responder.cpp Co-authored-by: Boris Zbarsky --------- Co-authored-by: Andrei Litvin Co-authored-by: Boris Zbarsky --- .../tests/integration/chip_im_responder.cpp | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index 72f056ca6ab8b7..86d654b99ff94c 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -50,6 +50,25 @@ namespace chip { namespace app { +namespace { + +class TestTLVDataEncoder : public DataModel::EncodableToTLV +{ +public: + CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override + { + TLV::TLVType outerType; + ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outerType)); + + ReturnErrorOnFailure(writer.Put(chip::TLV::ContextTag(kTestFieldId1), kTestFieldValue1)); + ReturnErrorOnFailure(writer.Put(chip::TLV::ContextTag(kTestFieldId2), kTestFieldValue2)); + + return writer.EndContainer(outerType); + } +}; + +} // namespace + Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aCommandPath) { // The Mock cluster catalog -- only have one command on one cluster on one endpoint. @@ -104,17 +123,8 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPat { printf("responder constructing command data in command"); - chip::TLV::TLVWriter * writer; - - const CommandHandler::InvokeResponseParameters prepareParams(aRequestCommandPath); - ReturnOnFailure(apCommandObj->PrepareInvokeResponseCommand(path, prepareParams)); - - writer = apCommandObj->GetCommandDataIBTLVWriter(); - ReturnOnFailure(writer->Put(chip::TLV::ContextTag(kTestFieldId1), kTestFieldValue1)); - - ReturnOnFailure(writer->Put(chip::TLV::ContextTag(kTestFieldId2), kTestFieldValue2)); - - ReturnOnFailure(apCommandObj->FinishCommand()); + TestTLVDataEncoder testData; + apCommandObj->AddResponse(path, kTestCommandId, testData); } statusCodeFlipper = !statusCodeFlipper; }