42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package torrent
|
|
|
|
import (
|
|
"github.com/looplab/fsm"
|
|
)
|
|
|
|
func NewTorrentState(initial string) *fsm.FSM {
|
|
// ok
|
|
// broken
|
|
// under_repair
|
|
// deleted
|
|
// unplayable
|
|
return fsm.NewFSM(
|
|
initial,
|
|
fsm.Events{
|
|
{Name: "break", Src: []string{"ok", "unplayable"}, Dst: "broken"},
|
|
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
|
|
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
|
|
{Name: "delete", Src: []string{"ok", "broken", "under_repair", "unplayable"}, Dst: "deleted"},
|
|
{Name: "mark_as_unplayable", Src: []string{"ok", "under_repair"}, Dst: "unplayable"},
|
|
},
|
|
fsm.Callbacks{},
|
|
)
|
|
}
|
|
|
|
func NewFileState(initial string) *fsm.FSM {
|
|
// ok
|
|
// broken
|
|
// under_repair
|
|
// deleted
|
|
return fsm.NewFSM(
|
|
initial,
|
|
fsm.Events{
|
|
{Name: "break", Src: []string{"ok"}, Dst: "broken"},
|
|
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
|
|
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
|
|
{Name: "delete", Src: []string{"ok", "broken", "under_repair"}, Dst: "deleted"},
|
|
},
|
|
fsm.Callbacks{},
|
|
)
|
|
}
|