36 lines
923 B
Go
36 lines
923 B
Go
package torrent
|
|
|
|
import (
|
|
"github.com/looplab/fsm"
|
|
)
|
|
|
|
func NewTorrentState(initial string) *fsm.FSM {
|
|
// ok_torrent 1
|
|
// broken_torrent 1
|
|
// unplayable_torrent 1
|
|
return fsm.NewFSM(
|
|
initial,
|
|
fsm.Events{
|
|
{Name: "break_torrent", Src: []string{"ok_torrent", "unplayable_torrent"}, Dst: "broken_torrent"},
|
|
{Name: "repair_torrent", Src: []string{"broken_torrent"}, Dst: "ok_torrent"},
|
|
{Name: "mark_as_unplayable_torrent", Src: []string{"ok_torrent"}, Dst: "unplayable_torrent"},
|
|
},
|
|
fsm.Callbacks{},
|
|
)
|
|
}
|
|
|
|
func NewFileState(initial string) *fsm.FSM {
|
|
// ok_file 13
|
|
// broken_file 5
|
|
// deleted_file 3
|
|
return fsm.NewFSM(
|
|
initial,
|
|
fsm.Events{
|
|
{Name: "break_file", Src: []string{"ok_file"}, Dst: "broken_file"},
|
|
{Name: "repair_file", Src: []string{"broken_file"}, Dst: "ok_file"},
|
|
{Name: "delete_file", Src: []string{"ok_file", "broken_file"}, Dst: "deleted_file"},
|
|
},
|
|
fsm.Callbacks{},
|
|
)
|
|
}
|