Skip to content

Commit 9a06cfc

Browse files
andy31415andreilitvinbzbarsky-apple
authored
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 <bzbarsky@apple.com> --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 960329a commit 9a06cfc

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/app/tests/integration/chip_im_responder.cpp

+21-11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@
5050
namespace chip {
5151
namespace app {
5252

53+
namespace {
54+
55+
class TestTLVDataEncoder : public DataModel::EncodableToTLV
56+
{
57+
public:
58+
CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override
59+
{
60+
TLV::TLVType outerType;
61+
ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outerType));
62+
63+
ReturnErrorOnFailure(writer.Put(chip::TLV::ContextTag(kTestFieldId1), kTestFieldValue1));
64+
ReturnErrorOnFailure(writer.Put(chip::TLV::ContextTag(kTestFieldId2), kTestFieldValue2));
65+
66+
return writer.EndContainer(outerType);
67+
}
68+
};
69+
70+
} // namespace
71+
5372
Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aCommandPath)
5473
{
5574
// The Mock cluster catalog -- only have one command on one cluster on one endpoint.
@@ -104,17 +123,8 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPat
104123
{
105124
printf("responder constructing command data in command");
106125

107-
chip::TLV::TLVWriter * writer;
108-
109-
const CommandHandler::InvokeResponseParameters prepareParams(aRequestCommandPath);
110-
ReturnOnFailure(apCommandObj->PrepareInvokeResponseCommand(path, prepareParams));
111-
112-
writer = apCommandObj->GetCommandDataIBTLVWriter();
113-
ReturnOnFailure(writer->Put(chip::TLV::ContextTag(kTestFieldId1), kTestFieldValue1));
114-
115-
ReturnOnFailure(writer->Put(chip::TLV::ContextTag(kTestFieldId2), kTestFieldValue2));
116-
117-
ReturnOnFailure(apCommandObj->FinishCommand());
126+
TestTLVDataEncoder testData;
127+
apCommandObj->AddResponse(path, kTestCommandId, testData);
118128
}
119129
statusCodeFlipper = !statusCodeFlipper;
120130
}

0 commit comments

Comments
 (0)