scbus

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Defines interfaces for creating communciation channels between server and clients

Index

Constants

View Source
const ChSize = 100

The default channel size

View Source
const ModelUpdateStr = "model"
View Source
const PtyDataUpdateStr = "pty"

Variables

This section is empty.

Functions

func GetUpdateItems

func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I

Returns the items in the update that are of type I

Types

type Bus

type Bus[I packet.PacketType] struct {
	Lock     *sync.Mutex
	Channels map[string]Channel[I]
}

A concurrent bus for registering and managing channels

func (*Bus[I]) RegisterChannel

func (bus *Bus[I]) RegisterChannel(key string, channelEntry Channel[I]) chan I

Opens new channel and registers it with the bus. If a channel exists, it is closed and replaced.

func (*Bus[I]) UnregisterChannel

func (bus *Bus[I]) UnregisterChannel(key string)

Closes the channel matching the provided key and removes it from the bus

type Channel

type Channel[I packet.PacketType] interface {
	GetChannel() chan I
	SetChannel(chan I)
	Match(string) bool
}

type CleanableUpdateItem

type CleanableUpdateItem interface {
	Clean()
}

An interface for model updates that can be cleaned

type ModelUpdate

type ModelUpdate []ModelUpdateItem

An inner data type for the ModelUpdatePacketType. Stores a collection of model updates to be sent to the client.

func (*ModelUpdate) IsEmpty

func (mu *ModelUpdate) IsEmpty() bool

func (*ModelUpdate) MarshalJSON

func (mu *ModelUpdate) MarshalJSON() ([]byte, error)

type ModelUpdateChannel

type ModelUpdateChannel[J any] struct {
	ScreenId string
	ClientId string
	// contains filtered or unexported fields
}

A channel for sending model updates to the client

func (*ModelUpdateChannel[J]) GetChannel

func (uch *ModelUpdateChannel[J]) GetChannel() chan J

func (*ModelUpdateChannel[J]) Match

func (sch *ModelUpdateChannel[J]) Match(screenId string) bool

Match the screenId to the channel

func (*ModelUpdateChannel[J]) SetChannel

func (uch *ModelUpdateChannel[J]) SetChannel(ch chan J)

type ModelUpdateItem

type ModelUpdateItem interface {
	// The key to use when marshalling to JSON and interpreting in the client
	GetType() string
}

An interface for all model updates

type ModelUpdatePacketType

type ModelUpdatePacketType struct {
	Type string       `json:"type"`
	Data *ModelUpdate `json:"data"`
}

An UpdatePacket for sending model updates to the client

func MakeUpdatePacket

func MakeUpdatePacket() *ModelUpdatePacketType

Create a new model update packet

func (*ModelUpdatePacketType) AddUpdate

func (upk *ModelUpdatePacketType) AddUpdate(items ...ModelUpdateItem)

Add a collection of model updates to the update

func (*ModelUpdatePacketType) Clean

func (upk *ModelUpdatePacketType) Clean()

Clean the ClientData in an update, if present

func (*ModelUpdatePacketType) GetType

func (*ModelUpdatePacketType) GetType() string

func (*ModelUpdatePacketType) IsEmpty

func (upk *ModelUpdatePacketType) IsEmpty() bool

func (*ModelUpdatePacketType) Merge

func (upk *ModelUpdatePacketType) Merge(p2Arg UpdatePacket) error

adds the items from p2 to the update (p2 must be ModelUpdatePacketType)

type PtyDataUpdate

type PtyDataUpdate struct {
	ScreenId   string `json:"screenid,omitempty"`
	LineId     string `json:"lineid,omitempty"`
	RemoteId   string `json:"remoteid,omitempty"`
	PtyPos     int64  `json:"ptypos"`
	PtyData64  string `json:"ptydata64"`
	PtyDataLen int64  `json:"ptydatalen"`
}

The inner data type for the PtyDataUpdatePacketType. Stores the pty data to be sent to the client.

type PtyDataUpdatePacketType

type PtyDataUpdatePacketType struct {
	Type string         `json:"type"`
	Data *PtyDataUpdate `json:"data"`
}

An UpdatePacket for sending pty data to the client

func MakePtyDataUpdate

func MakePtyDataUpdate(update *PtyDataUpdate) *PtyDataUpdatePacketType

Create a new PtyDataUpdatePacketType

func (*PtyDataUpdatePacketType) Clean

func (pdu *PtyDataUpdatePacketType) Clean()

func (*PtyDataUpdatePacketType) GetType

func (*PtyDataUpdatePacketType) GetType() string

func (*PtyDataUpdatePacketType) IsEmpty

func (pdu *PtyDataUpdatePacketType) IsEmpty() bool

type RpcBus

type RpcBus struct {
	Bus[RpcResponse]
}

A collection of channels that can receive rpc responses

var MainRpcBus *RpcBus = MakeRpcBus()

func MakeRpcBus

func MakeRpcBus() *RpcBus

Create a new RpcBus

func (*RpcBus) DoRpc

func (bus *RpcBus) DoRpc(ctx context.Context, pk RpcPacket) (RpcResponse, error)

Send a user input request to the frontend and wait for a response

func (*RpcBus) GetRpcChannel

func (bus *RpcBus) GetRpcChannel(id string) (chan RpcResponse, bool)

Get the user input channel for the given request id

type RpcChannel

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

Implements the Channel interface to allow receiving rpc responses

func (*RpcChannel) GetChannel

func (ch *RpcChannel) GetChannel() chan RpcResponse

func (*RpcChannel) Match

func (ch *RpcChannel) Match(string) bool

This is a no-op, only used to satisfy the Channel interface

func (*RpcChannel) SetChannel

func (ch *RpcChannel) SetChannel(newCh chan RpcResponse)

type RpcPacket

type RpcPacket interface {
	SetReqId(string)
	SetTimeoutMs(int)
	GetType() string
}

An interface for rpc requests This is separate from the RpcPacketType defined in the waveshell/pkg/packet package, as that one is intended for use communicating between wavesrv and waveshell. It is has a different set of required methods.

type RpcResponse

type RpcResponse interface {
	SetError(string)
	GetError() string
	GetType() string
}

An interface for rpc responses This is separate from the RpcResponsePacketType defined in the waveshell/pkg/packet package, as that one is intended for use communicating between wavesrv and waveshell. It is has a different set of required methods.

type UpdateBus

type UpdateBus struct {
	Bus[UpdatePacket]
}

A collection of channels that can transmit updates

var MainUpdateBus *UpdateBus = MakeUpdateBus()

func MakeUpdateBus

func MakeUpdateBus() *UpdateBus

Create a new UpdateBus

func (*UpdateBus) DoScreenUpdate

func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket)

Send a model update to only clients that are subscribed to the given screenId

func (*UpdateBus) DoUpdate

func (bus *UpdateBus) DoUpdate(update UpdatePacket)

Send an update to all channels in the collection

func (*UpdateBus) GetLock

func (bus *UpdateBus) GetLock() *sync.Mutex

type UpdateChannel

type UpdateChannel struct {
	ScreenId string
	// contains filtered or unexported fields
}

A channel for sending model updates to the client

func (*UpdateChannel) GetChannel

func (uch *UpdateChannel) GetChannel() chan UpdatePacket

func (*UpdateChannel) Match

func (sch *UpdateChannel) Match(screenId string) bool

Match the screenId to the channel

func (*UpdateChannel) SetChannel

func (uch *UpdateChannel) SetChannel(ch chan UpdatePacket)

type UpdatePacket

type UpdatePacket interface {
	// The key to use when marshalling to JSON and interpreting in the client
	GetType() string
	Clean()
	IsEmpty() bool
}

An interface for updates to be sent over an UpdateChannel

Jump to

Keyboard shortcuts

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