sys

package
v0.0.0-...-d368998 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package sys manages the state of a running dex system.

Index

Constants

This section is empty.

Variables

View Source
var ErrAllowedMissingDevice = errors.New("allowed missing device")

ErrAllowedMissingDevice is returned by Manager.DeviceFor when a device is not available for a service, but the device has been configured with config.Device.Required set to false.

View Source
var ErrNotFound = jsonrpc2.NewError(rpc.ErrCodeNotFound, "item not found")

ErrNotFound is returned by Store.Get if the item is not found.

Functions

func Funcs

func Funcs[K Kernel, D Device[B], B Button](redact bool) func(manager *Manager[K, D, B], log *slog.Logger) rpc.Funcs

Funcs returns an rpc.Funcs with a function table for accessing the manager.

The RPC methods in the table are:

If redact is true, fields marked with private will be redacted using private.Redact.

Types

type Button

type Button interface {
	Draw(ctx context.Context, img image.Image)
}

Button wraps the button drawing method.

type Device

type Device[B Button] interface {
	Serial() string

	SetPages(ctx context.Context, deflt *string, pages []string) error
	SendTo(service rpc.UID, listen []config.Button) error

	Layout() (rows, cols int)
	Key(row, col int) int

	CurrentName() string
	Page(name string) (p Page[B], ok bool)
	PageNames() []string
	PageDetails() map[string][]config.Button

	Bounds() (image.Rectangle, error)
	RawImage(img image.Image) (*ardilla.RawImage, error)

	SetDisplayTo(ctx context.Context, name string) error
	SetBrightness(percent int) error

	SleepState() string
	Last() time.Time
	Wake(ctx context.Context)
	Blank() error
	Clear() error

	Close() error
}

Device is the dex device interface.

type Kernel

type Kernel interface {
	Builtin(ctx context.Context, uid string, dialer net.Dialer, binder jsonrpc2.Binder) error
	Funcs(funcs rpc.Funcs)
	jsonrpc2.Handler

	Conn(ctx context.Context, uid string) (rpc.Connection, time.Time, bool)

	Spawn(ctx context.Context, stdout, stderr io.Writer, done func(), uid, name string, args ...string) error
	SetDrop(uid string, drop func() error) error
	Kill(uid string)

	Close() error
}

Kernel is the RPC kernel interface.

type Manager

type Manager[K Kernel, D Device[B], B Button] struct {
	// contains filtered or unexported fields
}

Manager is a dex system manager.

func NewManager

func NewManager[K Kernel, D Device[B], B Button](kernel NewKernel[K], device NewDevice[K, D, B], store Store, datadir string, log *slog.Logger, level *slog.LevelVar, addSource *atomic.Bool) (*Manager[K, D, B], error)

NewManager returns a new system manager.

func (*Manager[K, D, B]) Close

func (m *Manager[K, D, B]) Close() error

Close terminates the kernel and all devices.

func (*Manager[K, D, B]) Configure

func (m *Manager[K, D, B]) Configure(ctx context.Context, cfg *config.System) error

Configure changes a managed system's state to match the provided configuration. If the system is not yet running, it will be started.

func (*Manager[K, D, B]) Datadir

func (m *Manager[K, D, B]) Datadir() string

Datadir returns the manager's data directory.

func (*Manager[K, D, B]) DeviceFor

func (m *Manager[K, D, B]) DeviceFor(svc rpc.UID) (D, error)

DeviceFor returns the device the service is registered to.

func (*Manager[K, D, B]) Kernel

func (m *Manager[K, D, B]) Kernel() (kernel K, ok bool)

Kernel returned the RPC kernel held by the manager and whether the kernel is running.

func (*Manager[K, D, B]) SetBuiltins

func (m *Manager[K, D, B]) SetBuiltins(ctx context.Context, builtins map[string]jsonrpc2.Binder) error

SetBuiltins inserts the provided builtins into the RPC kernel's handler. If builtins is nil the entire kernel mapping table is reset.

func (*Manager[K, D, B]) SetFuncs

func (m *Manager[K, D, B]) SetFuncs(funcs rpc.Funcs)

SetFuncs inserts the provided functions into the RPC kernel's handler. If funcs is nil the entire kernel mapping table is reset.

func (*Manager[K, D, B]) Store

func (m *Manager[K, D, B]) Store() Store

Store returns the manager's persistent data store which may be nil.

type NewDevice

type NewDevice[K Kernel, D Device[B], B Button] func(ctx context.Context, pid ardilla.PID, serial string, kernel K, log *slog.Logger) (D, error)

NewDevice is a new dex device constructor.

type NewKernel

type NewKernel[K Kernel] func(ctx context.Context, network string, options jsonrpc2.NetListenOptions, log *slog.Logger) (K, error)

NewKernel is a new RPC kernel constructor.

type Page

type Page[B Button] interface {
	Button(row, col int) B
}

Page is a dex device page of buttons.

type Store

type Store interface {
	Set(owner rpc.UID, item string, val []byte) error
	Get(owner rpc.UID, item string) (val []byte, err error)
	Put(owner rpc.UID, item string, new []byte) (old []byte, written bool, err error)
	Delete(owner rpc.UID, item string) error
	Drop(owner rpc.UID) error
	DropModule(module string) error
}

Store is a common persistent data store held by the manager.

Jump to

Keyboard shortcuts

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