-
Notifications
You must be signed in to change notification settings - Fork 23
/
component.go
73 lines (61 loc) · 2.55 KB
/
component.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package runtime
import (
"github.com/fluxninja/aperture/v2/pkg/config"
"github.com/fluxninja/aperture/v2/pkg/notifiers"
)
// Component is the interface that all components must implement.
type Component interface {
Execute(inPortReadings PortToReading, circuitAPI CircuitAPI) (outPortReadings PortToReading, err error)
DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller)
// Generic name of the component, eg. "Gradient"
Name() string
Type() ComponentType
// ShortDescription is used when generating mermaid or dot diagrams.
ShortDescription() string
// IsActuator returns true if the component is an actuator.
IsActuator() bool
}
// ComponentType describes the type of a component based on its connectivity in the circuit.
type ComponentType string
const (
// ComponentTypeStandAlone is a component that does not accept or emit any
// signals.
ComponentTypeStandAlone ComponentType = "StandAlone"
// ComponentTypeSource is a component that emits output signal(s) but does
// not accept an input signal.
ComponentTypeSource ComponentType = "Source"
// ComponentTypeSink is a component that accepts input signal(s) but does
// not emit an output signal.
ComponentTypeSink ComponentType = "Sink"
// ComponentTypeSignalProcessor is a component that accepts input signal(s)
// and emits output signal(s).
ComponentTypeSignalProcessor ComponentType = "SignalProcessor"
)
// NewDummyComponent creates a component with provided name and type.
func NewDummyComponent(name, shortDescription string, componentType ComponentType) Component {
return dummyComponent{
name: name,
shortDescription: shortDescription,
componentType: componentType,
}
}
type dummyComponent struct {
name string
componentType ComponentType
shortDescription string
}
// Execute implements runtime.Component.
func (c dummyComponent) Execute(inPortReadings PortToReading, circuitAPI CircuitAPI) (outPortReadings PortToReading, err error) {
return nil, nil
}
// DynamicConfigUpdate implements runtime.Component.
func (c dummyComponent) DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller) {
}
// Name implements runtime.Component.
func (c dummyComponent) Name() string { return c.name }
// Type implements runtime.Component.
func (c dummyComponent) Type() ComponentType { return c.componentType }
// ShortDescription implements runtime.Component.
func (c dummyComponent) ShortDescription() string { return c.shortDescription }
// IsActuator implements runtime.Component.
func (c dummyComponent) IsActuator() bool { return false }