sim

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventSimulationStart ProgramEventType = "simulation.start"
	EventSimulationStop  ProgramEventType = "simulation.stop"
	EventCall            APIEventType     = "call"
	EventResponse        APIEventType     = "response"
	EventSignal          APIEventType     = "signal"
	EventPropertySet     APIEventType     = "property.set"
	EventPropertyChanged APIEventType     = "property.changed"
)

Variables

View Source
var ApiEventEmitter = make(chan APIEvent)
View Source
var ErrorEventEmitter = make(chan ErrorEvent)
View Source
var ProgramEventEmitter = make(chan ProgramEvent)

Functions

func NewServer

func NewServer() *server

Types

type APIEvent

type APIEvent struct {
	Type   APIEventType   `json:"type"`
	Symbol string         `json:"symbol"`
	Params []any          `json:"params"`
	Props  map[string]any `json:"props"`
	Error  error          `json:"error"`
}

type APIEventType

type APIEventType string

type ErrorEvent

type ErrorEvent struct {
	Error   error  `json:"error"`
	Message string `json:"message"`
}

type InterfaceEntry

type InterfaceEntry struct {
	Name        string                 `json:"name" yaml:"name"`
	Description string                 `json:"description" yaml:"description"`
	Properties  []PropertyEntry        `json:"properties" yaml:"properties"`
	Methods     map[string]MethodEntry `json:"methods" yaml:"methods"`
}

InterfaceEntry is a single interface entry in a scenario.

type MethodEntry

type MethodEntry struct {
	Name    string   `json:"name" yaml:"name"`
	Actions []string `json:"actions" yaml:"actions"`
}

type ProgramEvent

type ProgramEvent struct {
	Type    APIEventType `json:"type"`
	Message string       `json:"message"`
}

type ProgramEventType

type ProgramEventType string

type PropertyEntry

type PropertyEntry struct {
	Name        string `json:"name" yaml:"name"`
	Description string `json:"description" yaml:"description"`
	Value       any    `json:"value" yaml:"value"`
}

PropertyEntry is a named value of an interface method or return entry. { "name": "count", "value": 0 }

type ScenarioDoc

type ScenarioDoc struct {
	Name        string                    `json:"name" yaml:"name"`
	Version     string                    `json:"version" yaml:"version"`
	Description string                    `json:"description" yaml:"description"`
	Interfaces  map[string]InterfaceEntry `json:"interfaces" yaml:"interfaces"`
}

Scenario is a scenario of a simulation.

func ReadJsonScenario

func ReadJsonScenario(file string) (*ScenarioDoc, error)

func ReadScenario

func ReadScenario(file string) (*ScenarioDoc, error)

func ReadYamlScenario

func ReadYamlScenario(file string) (*ScenarioDoc, error)

type Script

type Script struct {
	Name    string
	Source  string
	Context map[string]any
}

type ScriptEngine

type ScriptEngine struct {
	// contains filtered or unexported fields
}

ScriptEngine is a runs the different scripts in the context of a simulation. The engine produces events which are sent via a channel. Typically the simulation listens to all script engines passes them on to the network communication.

func NewScriptEngine

func NewScriptEngine() *ScriptEngine

func (*ScriptEngine) Run

func (s *ScriptEngine) Run(script Script) error

func (*ScriptEngine) Set

func (s *ScriptEngine) Set(key string, value any)

type Simulation

type Simulation struct {
	Scenarios []*ScenarioDoc
}

Simulate runs one or more simulation scenarios. To unload a scenario call the Stop method with the scenario name. To stop all scenarios call the StopAll method. A scenario can simulation properties, methods and signals using static values or scripted behavior. The scripted behavior can be either triggered by a call or by a script entry All results are send out via the event channel.

func NewSimulation

func NewSimulation() *Simulation

func (*Simulation) AddScenario

func (s *Simulation) AddScenario(scenario *ScenarioDoc)

func (Simulation) CallMethod

func (s Simulation) CallMethod(service string, method string, params map[string]any) error

func (Simulation) LookupInterface

func (s Simulation) LookupInterface(ifaceName string) *InterfaceEntry

func (Simulation) LookupMethod

func (s Simulation) LookupMethod(ifaceName string, methodName string) *MethodEntry

func (*Simulation) RemoveAll

func (s *Simulation) RemoveAll()

func (*Simulation) RemoveScenario

func (s *Simulation) RemoveScenario(name string)

type Symbol

type Symbol string

Symbol is a symbol in the form of <interface>/<resource>.

func MakeSymbol

func MakeSymbol(path, resource string) Symbol

MakeSymbol creates a symbol from a path and resource.

func (Symbol) Path

func (s Symbol) Path() string

Path returns the path part of a symbol.

func (Symbol) Resource

func (s Symbol) Resource() string

Resource returns the resource part of a symbol.

func (Symbol) Split

func (s Symbol) Split() (string, string)

Split splits a symbol into its path and resource parts. A symbol is in the form of <interface>/<resource>. A an interface can be prefixed with a module name using the dot (".") separator.

func (Symbol) String

func (s Symbol) String() string

String returns the string representation of a symbol.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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