core

package
v0.0.0-...-309e10c Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const APIAddr = ":8081"
View Source
const EventsExchange = "events"

Variables

This section is empty.

Functions

func NewNodeRouter

func NewNodeRouter(logger *log.Entry) *gin.Engine

Types

type Action

type Action struct {
	Name        string
	Do          EventHandler
	DoCondition ActionCondition
	DoDelay     int
	Then        *Action
}

type ActionCondition

type ActionCondition func(event *Event) bool

type ConnexionDetails

type ConnexionDetails struct {
	Username string
	Password string
	Host     string
	Port     string
}

type Event

type Event struct {
	Name     string
	Emitter  string
	Receiver string
	Payload  string
}

type EventHandler

type EventHandler func(event *Event)

type EventNetwork

type EventNetwork interface {
	BroadcastEvent(event *Event)
	SendEventTo(receiver string, event *Event)
	SetReceivedEventCallback(handler EventHandler)
	StartListeningForEvents()
	SetLogger(entry *log.Entry)
}

type Node

type Node struct {
	Info   NodeInfo
	Config NodeConfig
	State  internalState
	Logger *log.Entry

	RegistrationServer *RegistrationServer
	EventNetwork       EventNetwork
	Router             *gin.Engine
	Hardware           hardware.Hal
	MediaController    media.MediaController
	// contains filtered or unexported fields
}

Node is the main component of the demokit. It aims to be a base for your own node and to provide an easy access to events happening in the network.

func NewDefaultNode

func NewDefaultNode() *Node

NewDefaultNode returns a Node with a default configuration. The only components available are the Logger (logrus.Entry), the EventNetwork and the router (gin.Engine).

func NewNode

func NewNode(info NodeInfo,
	config NodeConfig,
	logger *log.Entry,
	rs *RegistrationServer,
	network EventNetwork,
	mediaController media.MediaController,
	hal hardware.Hal) *Node

func (*Node) BroadcastEvent

func (n *Node) BroadcastEvent(eventName, payload string)

func (*Node) ExecuteAction

func (n *Node) ExecuteAction(action *Action, event *Event)

func (*Node) OnEventDo

func (n *Node) OnEventDo(eventName string, action *Action)

OnEventDo is used to register an action to execute when a given event is received.

func (*Node) Register

func (n *Node) Register()

func (*Node) RegisterUI

func (n *Node) RegisterUI(endpoint string)

func (*Node) RetrieveLocalIp

func (n *Node) RetrieveLocalIp() net.IP

func (*Node) SendEventTo

func (n *Node) SendEventTo(receiver string, eventName, payload string)

func (*Node) ServeState

func (n *Node) ServeState(state interface{}, allowEdit bool)

func (*Node) ServeStatus

func (n *Node) ServeStatus()

func (*Node) SetEntryPoint

func (n *Node) SetEntryPoint(action *Action)

func (*Node) Start

func (n *Node) Start()

func (*Node) StartAPIServer

func (n *Node) StartAPIServer()

func (*Node) WaitForExit

func (n *Node) WaitForExit()

type NodeCapabilities

type NodeCapabilities struct {
	MediaAvailable    bool `json:"media_available"`
	HardwareAvailable bool `json:"hardware_available"`
}

type NodeConfig

type NodeConfig struct {
	ExposeActions bool
}

func DefaultNodeConfig

func DefaultNodeConfig() NodeConfig

type NodeError

type NodeError string

func (*NodeError) Error

func (ne *NodeError) Error() string

type NodeInfo

type NodeInfo struct {
	Name    string
	LocalIp string
}

type NodeStatus

type NodeStatus struct {
	IsReady           bool                `json:"is_ready"`
	Capabilities      NodeCapabilities    `json:"capabilities"`
	RegisteredActions map[string][]string `json:"registered_actions"`
	RegisteredUIs     []string            `json:"registered_ui"`
}

type RabbitMQEventNetwork

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

func NewRabbitMQEventNetwork

func NewRabbitMQEventNetwork(connDetails ConnexionDetails) *RabbitMQEventNetwork

func (*RabbitMQEventNetwork) BroadcastEvent

func (r *RabbitMQEventNetwork) BroadcastEvent(event *Event)

func (*RabbitMQEventNetwork) SendEventTo

func (r *RabbitMQEventNetwork) SendEventTo(receiver string, event *Event)

func (*RabbitMQEventNetwork) SetLogger

func (r *RabbitMQEventNetwork) SetLogger(logger *log.Entry)

func (*RabbitMQEventNetwork) SetReceivedEventCallback

func (r *RabbitMQEventNetwork) SetReceivedEventCallback(handler EventHandler)

func (*RabbitMQEventNetwork) StartListeningForEvents

func (r *RabbitMQEventNetwork) StartListeningForEvents()

type RegistrationServer

type RegistrationServer struct {
	Addr string
}

func NewDefaultRegistrationServer

func NewDefaultRegistrationServer(addr string) *RegistrationServer

func (*RegistrationServer) RegisterNode

func (rs *RegistrationServer) RegisterNode(node *Node) error

Jump to

Keyboard shortcuts

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