Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
| 19 | import "github.com/looplab/fsm" |
| 20 | |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 21 | var newFSM = fsm.NewFSM |
| 22 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 23 | func getOperStateFSM(cb fsm.Callback) *fsm.FSM { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 24 | return newFSM( |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 25 | "down", |
| 26 | fsm.Events{ |
| 27 | {Name: "enable", Src: []string{"down"}, Dst: "up"}, |
| 28 | {Name: "disable", Src: []string{"up"}, Dst: "down"}, |
| 29 | }, |
| 30 | fsm.Callbacks{ |
| 31 | "enter_state": func(e *fsm.Event) { |
| 32 | cb(e) |
| 33 | }, |
| 34 | }, |
| 35 | ) |
| 36 | } |