Andrei Litvin | 72450e4 | 2024-06-06 11:48:57 -0400 | [diff] [blame] | 1 | # Upgrading notes |
| 2 | |
| 3 | ## API changes and code migration |
| 4 | |
| 5 | ### `CommandHandler` |
| 6 | |
| 7 | `CommandHandler` ability to directly invoke `Prepare/TLV-Write/Finish` cycles |
| 8 | has been changed to only expose `AddResponse/AddStatus/AddClusterSpecific*`. |
| 9 | |
| 10 | Original versions of `CommandHandler` exposed the following low-level |
| 11 | implementation-specific methods: `PrepareCommand`, |
| 12 | `PrepareInvokeResponseCommand`, `GetCommandDataIBTLVWriter` and `FinishCommand`. |
| 13 | These are not exposed anymore and instead one should use `AddResponse` or |
| 14 | `AddResponseData`. When using an `EncodableToTLV` argument, the same |
| 15 | functionality should be achievable. |
| 16 | |
| 17 | Example |
| 18 | |
| 19 | Before: |
| 20 | |
| 21 | ```cpp |
| 22 | |
| 23 | const CommandHandler::InvokeResponseParameters prepareParams(requestPath); |
| 24 | ReturnOnFailure(commandHandler->PrepareInvokeResponseCommand(path, prepareParams)); |
| 25 | |
| 26 | TLV::TLVWriter *writer = commandHandler->GetCommandDataIBTLVWriter(); |
| 27 | ReturnOnFailure(writer->Put(chip::TLV::ContextTag(1), 123)); |
| 28 | ReturnOnFailure(writer->Put(chip::TLV::ContextTag(2), 234)); |
| 29 | return commandHandler->FinishCommand(); |
| 30 | ``` |
| 31 | |
| 32 | After: |
| 33 | |
| 34 | ```cpp |
| 35 | |
| 36 | class ReplyEncoder : public DataModel::EncodableToTLV |
| 37 | { |
| 38 | public: |
| 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 | // ... |
| 52 | ReplyEncoder replyEncoder; |
| 53 | commandHandler->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 | ``` |