forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
CommandHandler
a pure interface class, have actual implementat…
…ion in `CommandHandlerImpl` (project-chip#33736) * First pass: renames only and moved things around. It should not yet compile * Move CommandHandler::Callback to CommandHandlerImpl::Callback * Prepare some compile fixes. Uses of preparation of responses is not ok yet * More replace fixes * More compile updates * Try to implement the addResponse properly * Many more updates for compilation * More compile tests - getting closer * Things compile * Restyle * Split out CommandHandler (the interface) from CommandHandlerImpl (actual IM implementation) * Restyle * make GetExchangeContext also be virtual * Fix some includes that were previously part of CommandHandler.h * Restyle * No need for casts and private APIs: Exchange context is actually available * Code review feedback * Restyle * Upgrading docs * Slight example fix --------- Co-authored-by: Andrei Litvin <[email protected]>
- Loading branch information
1 parent
88ebdf7
commit 72450e4
Showing
14 changed files
with
1,764 additions
and
1,603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ BUG_REPORT | |
code_generation | ||
zap_clusters | ||
spec_clusters | ||
upgrading | ||
ERROR_CODES | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Upgrading notes | ||
|
||
## API changes and code migration | ||
|
||
### `CommandHandler` | ||
|
||
`CommandHandler` ability to directly invoke `Prepare/TLV-Write/Finish` cycles | ||
has been changed to only expose `AddResponse/AddStatus/AddClusterSpecific*`. | ||
|
||
Original versions of `CommandHandler` exposed the following low-level | ||
implementation-specific methods: `PrepareCommand`, | ||
`PrepareInvokeResponseCommand`, `GetCommandDataIBTLVWriter` and `FinishCommand`. | ||
These are not exposed anymore and instead one should use `AddResponse` or | ||
`AddResponseData`. When using an `EncodableToTLV` argument, the same | ||
functionality should be achievable. | ||
|
||
Example | ||
|
||
Before: | ||
|
||
```cpp | ||
|
||
const CommandHandler::InvokeResponseParameters prepareParams(requestPath); | ||
ReturnOnFailure(commandHandler->PrepareInvokeResponseCommand(path, prepareParams)); | ||
|
||
TLV::TLVWriter *writer = commandHandler->GetCommandDataIBTLVWriter(); | ||
ReturnOnFailure(writer->Put(chip::TLV::ContextTag(1), 123)); | ||
ReturnOnFailure(writer->Put(chip::TLV::ContextTag(2), 234)); | ||
return commandHandler->FinishCommand(); | ||
``` | ||
After: | ||
```cpp | ||
class ReplyEncoder : 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)); | ||
ReturnOnFailure(writer.Put(chip::TLV::ContextTag(1), 123)); | ||
ReturnOnFailure(writer.Put(chip::TLV::ContextTag(2), 234)); | ||
return writer.EndContainer(outerType); | ||
} | ||
}; | ||
// ... | ||
ReplyEncoder replyEncoder; | ||
commandHandler->AddResponse(path, kReplyCommandId, replyEncoder); | ||
// or if error handling is implemented: | ||
// | ||
// ReturnErrorOnFailure(commandHandler->AddResponseData(path, kReplyCommandId, replyEncoder)); | ||
// | ||
// In many cases error recovery from not being able to send a reply is not easy or expected, | ||
// so code does AddResponse rather than AddResponseData. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.