| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package fsm |
| |
| type internalEvent string |
| |
| const ( |
| // Next is the event attempted if a state exits with no pending transition |
| Next internalEvent = "next" |
| // exit is the event generated by a controller quitting with an error |
| controllerError internalEvent = "exit" |
| ) |
| |
| // Event is the type for events that get delivered to the state machine, causing transitions. |
| type Event interface{} |
| |
| // Transition describes a set of possible transitions in an fsm. |
| // When being compiled, this will generate one CompiledTransition per state this Transition matches. |
| type Transition struct { |
| // From matches all the states this transition is allowed to start in. |
| // See Match for details on how this is used. |
| From interface{} |
| // Event is the event that triggers this transition. |
| Event Event |
| // To is the state this should transition to. |
| To StateID |
| } |
| |
| // CompiledTransition is a compiled Transition. |
| type CompiledTransition struct { |
| // From is the state this transition comes from. |
| From *CompiledState |
| // Event is the event that triggers this transition. |
| Event Event |
| // To is the state this should transition to. |
| To *CompiledState |
| // Hooks are the hooks to invoke when this transition occurs. |
| Hooks []HookBuilder |
| } |
| |
| // runningTransition is a transition entry in a runningState |
| type runningTransition struct { |
| to *runningState |
| hooks []HookFunc |
| } |