chik

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: GPL-3.0 Imports: 17 Imported by: 2

README

Chik

Chik is the sound my child makes when he runs touching everything around the house

Tag Build Status Documentation

Framework that allows to create a simple network of remotely connected IOT devices.

The framework allows to compose applications that are instantiating an event loop and a communication bus on top of which a series of handlers operates. Each handler is providing a different functionality to the application.

Available handlers are:

  • Actor: allows to execute some actions in reaction to a state change or to a series of conditions
  • Heartbeat: sends a periodic heartbeat to check for network connectivity and server availability
  • IO: allows to communicate with various kind of IO devices and protocols
  • Router: allows to route messages between two devices (handler used in server applications)
  • Status: stores a global status comphrensive of every handler state and allows to register remote devices as listener for status changes within the application
  • Time: allows to execute an action at a certain date and time or at sunrise/sunset
  • Version: stores the version of the application and allows OTA updates

Ready made applications:

Documentation

Index

Constants

View Source
const BufferSize = 10

BufferSize is the size of channel buffers

View Source
const MaxIdleTime = 5 * time.Minute

MaxIdleTime is the maximum time to wait before closing a connection for inactivity

View Source
const WriteTimeout = 1 * time.Minute

WriteTimeout defines the time after which a write operation is considered failed

Variables

View Source
var LoopbackID = uuid.Nil

LoopbackID is the id internal only messages are sent to

Functions

func Equal

func Equal(v1, v2 *Message) bool

Equal compares two messages

Types

type Controller

type Controller struct {
	ID uuid.UUID
	// contains filtered or unexported fields
}

func NewController

func NewController() *Controller

NewController creates a new controller

func (*Controller) Connect

func (c *Controller) Connect(connection net.Conn) <-chan bool

Connect tries to brign up the remoe connection it returns a channel that gets closed when the connection goes down

func (*Controller) Disconnect

func (c *Controller) Disconnect()

Disconnect disconnects the remote connection (if any)

func (*Controller) Pub

func (c *Controller) Pub(command *types.Command, receiverID uuid.UUID)

Pub publishes a Message composed by the given Command

func (*Controller) PubMessage

func (c *Controller) PubMessage(message *Message, topics ...string)

PubMessage publishes a Message

func (*Controller) Reply

func (c *Controller) Reply(request *Message, replyType types.CommandType, replyContent interface{})

Reply sends back a reply message

func (*Controller) Start

func (c *Controller) Start(ctx context.Context, handlers []Handler)

Start starts every registered handler

func (*Controller) Sub

func (c *Controller) Sub(topics ...string) chan interface{}

Sub Subscribes to one or more message types

func (*Controller) SubOnce

func (c *Controller) SubOnce(topics ...string) chan interface{}

SubOnce subscribes to the first event of one of the given topics, then it deletes the subscription

type Handler

type Handler interface {
	fmt.Stringer
	Dependencies() []string
	Topics() []types.CommandType
	Setup(controller *Controller) Timer
	HandleMessage(message *Message, controller *Controller) error
	HandleTimerEvent(tick time.Time, controller *Controller)
	Teardown()
}

Handler is the interface that handles network messages and optionally can return a reply

type Message

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

func NewMessage

func NewMessage(receiver uuid.UUID, command *types.Command) *Message

NewMessage creates a new message

func ParseMessage

func ParseMessage(reader io.Reader) (*Message, error)

ParseMessage handles incoming data and creates a Message object

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes returns the binary rapresentation of the message

func (*Message) Command

func (m *Message) Command() *types.Command

Command returns message content as a Command object

func (*Message) ReceiverUUID

func (m *Message) ReceiverUUID() (uuid.UUID, error)

ReceiverUUID returns the receiver identity

func (*Message) SenderUUID

func (m *Message) SenderUUID() uuid.UUID

SenderUUID returns the sender identity

func (Message) String

func (m Message) String() string

type Remote

type Remote struct {
	Closed chan bool
	// contains filtered or unexported fields
}

Remote represents a remote endpoint, data can be sent or received through InBuffer and OutBuffer

func (*Remote) Terminate

func (r *Remote) Terminate()

Terminate closes the connection and the send channel

type StatusHolder

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

StatusHolder is a struct that stores status of an handler that needs to trigger status changes when something happens

func NewStatusHolder

func NewStatusHolder(moduleName string) *StatusHolder

NewStatusHolder creates a StatusHolder

func (*StatusHolder) Edit

func (s *StatusHolder) Edit(controller *Controller, editFunction func(interface{}) interface{})

Edit the current status via editFunction

func (*StatusHolder) Set

func (s *StatusHolder) Set(status interface{}, controller *Controller)

Set stores the status and emits it if it is changed

type Timer added in v1.4.0

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

func NewEmptyTimer added in v1.4.0

func NewEmptyTimer() Timer

NewEmptyTimer creates a timer that does never fire

func NewTimer added in v1.4.0

func NewTimer(interval time.Duration, triggerAtStart bool) Timer

NewTimer creates a new timer given an interval and the option to fire when started

Jump to

Keyboard shortcuts

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