blob: cd18b533484279bfbdfd29c6a3cfe77150bd0c11 [file] [log] [blame] [view]
Andrei Litvin72450e42024-06-06 11:48:57 -04001# Upgrading notes
2
3## API changes and code migration
4
5### `CommandHandler`
6
7`CommandHandler` ability to directly invoke `Prepare/TLV-Write/Finish` cycles
8has been changed to only expose `AddResponse/AddStatus/AddClusterSpecific*`.
9
10Original versions of `CommandHandler` exposed the following low-level
11implementation-specific methods: `PrepareCommand`,
12`PrepareInvokeResponseCommand`, `GetCommandDataIBTLVWriter` and `FinishCommand`.
13These are not exposed anymore and instead one should use `AddResponse` or
14`AddResponseData`. When using an `EncodableToTLV` argument, the same
15functionality should be achievable.
16
17Example
18
19Before:
20
21```cpp
22
23const CommandHandler::InvokeResponseParameters prepareParams(requestPath);
24ReturnOnFailure(commandHandler->PrepareInvokeResponseCommand(path, prepareParams));
25
26TLV::TLVWriter *writer = commandHandler->GetCommandDataIBTLVWriter();
27ReturnOnFailure(writer->Put(chip::TLV::ContextTag(1), 123));
28ReturnOnFailure(writer->Put(chip::TLV::ContextTag(2), 234));
29return commandHandler->FinishCommand();
30```
31
32After:
33
34```cpp
35
36class ReplyEncoder : public DataModel::EncodableToTLV
37{
38public:
39 CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override
40 {
41 TLV::TLVType outerType;
42 ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outerType));
43
44 ReturnOnFailure(writer.Put(chip::TLV::ContextTag(1), 123));
45 ReturnOnFailure(writer.Put(chip::TLV::ContextTag(2), 234));
46
47 return writer.EndContainer(outerType);
48 }
49};
50
51// ...
52ReplyEncoder replyEncoder;
53commandHandler->AddResponse(path, kReplyCommandId, replyEncoder);
54
55// or if error handling is implemented:
56//
57// ReturnErrorOnFailure(commandHandler->AddResponseData(path, kReplyCommandId, replyEncoder));
58//
59// In many cases error recovery from not being able to send a reply is not easy or expected,
60// so code does AddResponse rather than AddResponseData.
61
62```