gofsm

package module
v0.0.0-...-f47f6a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 7 Imported by: 2

README

gofsm

Build Status GoDoc

Go library for building finite-state machines (automata).

Why yet another FSM library for go?

gofsm is aimed squarely at home automation - human visible, configured and friendly. The configuration format is yaml, and easy to read/write by hand.

gofsm is used in the gohome automation project: http://github.com/barnybug/gohome

Changelog

0.1.0

  • First release

Documentation

Overview

Package gofsm is a library for building finite-state machines (automata).

Why yet another FSM library for go?

gofsm is aimed squarely at home automation - human visible, configured and friendly. The configuration format is yaml, and easy to read/write by hand.

gofsm is used in the gohome automation project: http://github.com/barnybug/gohome

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name    string
	Trigger interface{}
	Change  Change
}

func (Action) String

func (self Action) String() string

type Actions

type Actions []string

type Automata

type Automata struct {
	Automaton map[string]*Automaton
	Actions   chan Action
	Changes   chan Change
}

func Load

func Load(str []byte) (*Automata, error)

func LoadFile

func LoadFile(filename string) (*Automata, error)

func (*Automata) Persist

func (self *Automata) Persist() AutomataState

func (*Automata) Process

func (self *Automata) Process(event Event)

func (*Automata) Restore

func (self *Automata) Restore(s AutomataState)

func (*Automata) String

func (self *Automata) String() string

type AutomataState

type AutomataState map[string]AutomatonState

type Automaton

type Automaton struct {
	Start  string
	States map[string]struct {
		Entering Actions
		Leaving  Actions
	}
	Transitions map[string][]Transition
	Name        string
	State       *State
	Since       time.Time
	// contains filtered or unexported fields
}

func (*Automaton) ChangeState

func (self *Automaton) ChangeState(next string, event Event)

func (*Automaton) Process

func (self *Automaton) Process(event Event)

type AutomatonState

type AutomatonState struct {
	State string
	Since time.Time
}

type Change

type Change struct {
	Automaton string
	Old       string
	New       string
	Since     time.Time
	Duration  time.Duration
	Trigger   interface{}
}

type Event

type Event interface {
	Match(s string) bool
}

type State

type State struct {
	Name     string
	Steps    []Step
	Entering Actions
	Leaving  Actions
}

type Step

type Step struct {
	When    string
	Actions Actions
	Next    string
}

type Transition

type Transition struct {
	When    string
	Actions Actions
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL