-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add variant-type-driven state machine to libs #12223
Merged
Merged
Conversation
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 commit introduces a functional approach for State Machine implementation that leverages the sdk's Variant and Optional types. By providing a clean separation between states, events, and transitions, state machines can be implemented in such a way that states and events may be provided in the core sdk, but with transitions defined in consuming applications to support individual use cases. And because states and events are associated to the state machine by inclusion in variants and not by inheritance, applications may also extend state machines with arbitrary, application-specific events and states. Co-Authored-by: Bill Schiller <bill.schiller@smartthings.com>
PR #12223: Size comparison from 8bfdc13 to 0b0f9e0 Full report (21 builds for efr32, k32w, linux, p6, qpg, telink)
|
PR #12223: Size comparison from 8bfdc13 to 1006308 Full report (38 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
|
PR #12223: Size comparison from 65f4475 to deec40c Full report (38 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
|
The following are made explicitly illegal and will abort: * Dispatch from Exit() or LogTransition() state methods * Dispatch from transitions table w/ returned transition
PR #12223: Size comparison from 77258f7 to 5baa5a2 Decreases (2 builds for linux)
Full report (37 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg)
|
Fast tracking, given this has been up for a while, and has had no further feedback. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The SDK has many state machines, but no consistent approach to cleanly define core SDK state machine functionality in a way that still allows extensibility in consuming applications.
Change overview
This introduces a functional approach for the state machine design pattern with a new StateMachine class, emulating patterns available in C++17, but leveraging the SDK's Optional and Variant types for C++14 compatibility. The new StateMachine class allows for a clean separation and decoupling of states, events and transitions such that states and events may be implemented in the core SDK, but transitions may be defined in consuming applications to support application-specific needs.
Testing
A new unit test has been added for the new StateMachine class.