Skip to content

Commit

Permalink
Use EncodableToTLV in im_responder (project-chip#33693)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Jun 3, 2024
1 parent 960329a commit 9a06cfc
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9a06cfc

Please sign in to comment.