sim

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert added in v0.45.0

func Convert(input any, output any) error

func CreateService added in v0.48.0

func CreateService(engine *Engine, objectId string, properties map[string]any) *goja.Object

CreateService creates a new service with proxy wrapper

func CreateServiceProxy added in v0.48.0

func CreateServiceProxy(vm *goja.Runtime, service *ObjectService) *goja.Object

Types

type Channel added in v0.45.0

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

func NewChannel added in v0.45.0

func NewChannel(engine *Engine, url string) (*Channel, error)

func (*Channel) Connect added in v0.45.0

func (c *Channel) Connect() error

func (*Channel) CreateClient added in v0.45.0

func (c *Channel) CreateClient(object string) *ObjectClient

func (*Channel) DestroyClient added in v0.45.0

func (c *Channel) DestroyClient(object string)

func (*Channel) Disconnect added in v0.45.0

func (c *Channel) Disconnect() error

func (*Channel) GetClient added in v0.45.0

func (c *Channel) GetClient(object string) *ObjectClient

func (*Channel) String added in v0.45.0

func (c *Channel) String() string

func (*Channel) Url added in v0.45.0

func (c *Channel) Url() string

type Emitter added in v0.45.0

type Emitter[T any] struct {
	// contains filtered or unexported fields
}

func NewEmitter added in v0.45.0

func NewEmitter[T any]() *Emitter[T]

func (*Emitter[T]) Add added in v0.45.0

func (e *Emitter[T]) Add(event string, handler func(value T)) func()

Add adds a handler for the given event. It returns a function that can be called to remove the handler.

func (*Emitter[T]) Any added in v0.45.0

func (e *Emitter[T]) Any(handler func(key string, value T))

func (*Emitter[T]) Clear added in v0.45.0

func (e *Emitter[T]) Clear(event string) int

Clear clears all handlers for the given event. It returns the number of handlers removed.

func (*Emitter[T]) ClearAll added in v0.45.0

func (e *Emitter[T]) ClearAll() int

ClearAll clears all handlers for all events. It returns the number of handlers removed.

func (*Emitter[T]) Count added in v0.45.0

func (e *Emitter[T]) Count(event string) int

Count returns the number of handlers for the given event. It returns 0 if there are no handlers.

func (*Emitter[T]) CountAll added in v0.45.0

func (e *Emitter[T]) CountAll() int

CountAll returns the total number of handlers for all events. It returns 0 if there are no handlers.

func (*Emitter[T]) Emit added in v0.45.0

func (e *Emitter[T]) Emit(event string, value T)

Emit triggers the handlers for the given event. It returns an error if any of the handlers return an error.

func (*Emitter[T]) Has added in v0.45.0

func (e *Emitter[T]) Has(event string) bool

Has checks if there are any handlers for the given event. It returns true if there are handlers, false otherwise.

func (*Emitter[T]) Remove added in v0.45.0

func (e *Emitter[T]) Remove(event string, id string)

Remove removes the handler for the given event. If the event has no handlers, it does nothing.

type Engine added in v0.45.0

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

func NewEngine added in v0.45.0

func NewEngine(opts EngineOptions) *Engine

func (*Engine) Close added in v0.45.0

func (e *Engine) Close()

func (*Engine) CompileScript added in v0.46.2

func (e *Engine) CompileScript(name string, src string) error

func (*Engine) RunFunction added in v0.45.0

func (e *Engine) RunFunction(name string, args ...any)

func (*Engine) RunOnLoop added in v0.48.0

func (e *Engine) RunOnLoop(fn func(rt *goja.Runtime))

func (*Engine) RunScript added in v0.45.0

func (e *Engine) RunScript(name string, content string)

func (*Engine) Runtime added in v0.48.0

func (e *Engine) Runtime() *goja.Runtime

func (*Engine) SetOlinkServer added in v0.45.0

func (e *Engine) SetOlinkServer(server IOlinkServer)

type EngineOptions added in v0.45.0

type EngineOptions struct {
	WorkDir   string
	Server    IOlinkServer
	Connector IOlinkConnector
}

type Hook added in v0.45.0

type Hook[T any] struct {
	// contains filtered or unexported fields
}

Hook is a generic type for managing hooks

func NewHook added in v0.45.0

func NewHook[T any]() *Hook[T]

func (*Hook[T]) Add added in v0.45.0

func (h *Hook[T]) Add(hook func(v T)) func()

Add a new hook and return a function to unregister it

func (*Hook[T]) Clear added in v0.45.0

func (h *Hook[T]) Clear()

Clear all hooks

func (*Hook[T]) Count added in v0.45.0

func (h *Hook[T]) Count() int

Count returns the number of registered hooks

func (*Hook[T]) Emit added in v0.45.0

func (h *Hook[T]) Emit(v T)

Emit the hook with the value

func (*Hook[T]) Remove added in v0.45.0

func (h *Hook[T]) Remove(id string)

Remove the hook from the list

type IOlinkConnector added in v0.45.0

type IOlinkConnector interface {
	Connect(url string) error
	Disconnect(url string) error
	RegisterSink(url string, sink client.IObjectSink)
	UnregisterSink(url string, sink client.IObjectSink)
	Node(objectId string) *client.Node
}

type IOlinkServer added in v0.45.0

type IOlinkServer interface {
	RegisterSource(source remote.IObjectSource)
	UnregisterSource(source remote.IObjectSource)
}

type LogPrinter added in v0.45.0

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

func NewLogPrinter added in v0.45.0

func NewLogPrinter(logger *zerolog.Logger) *LogPrinter

func (*LogPrinter) Error added in v0.45.0

func (lp *LogPrinter) Error(s string)

func (*LogPrinter) Log added in v0.45.0

func (lp *LogPrinter) Log(s string)

func (*LogPrinter) Warn added in v0.45.0

func (lp *LogPrinter) Warn(s string)

type Manager added in v0.45.0

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

func NewManager added in v0.45.0

func NewManager(opts ManagerOptions) *Manager

func (*Manager) FunctionRun added in v0.45.0

func (m *Manager) FunctionRun(fn string, args []any)

func (*Manager) ScriptRun added in v0.45.0

func (m *Manager) ScriptRun(script Script) string

func (*Manager) ScriptStop added in v0.45.0

func (m *Manager) ScriptStop(worldId string) error

func (*Manager) Start added in v0.45.0

func (m *Manager) Start(netman *net.NetworkManager)

func (*Manager) Stop added in v0.45.0

func (m *Manager) Stop()

type ManagerOptions added in v0.45.0

type ManagerOptions struct {
	Server IOlinkServer
}

type NullConnector added in v0.45.0

type NullConnector struct {
}

func NewNullConnector added in v0.45.0

func NewNullConnector() *NullConnector

func (*NullConnector) Connect added in v0.45.0

func (c *NullConnector) Connect(url string) error

func (*NullConnector) Disconnect added in v0.45.0

func (c *NullConnector) Disconnect(url string) error

func (*NullConnector) Node added in v0.45.0

func (c *NullConnector) Node(url string) *client.Node

func (*NullConnector) RegisterSink added in v0.45.0

func (c *NullConnector) RegisterSink(url string, sink client.IObjectSink)

func (*NullConnector) UnregisterSink added in v0.45.0

func (c *NullConnector) UnregisterSink(url string, sink client.IObjectSink)

type NullServer added in v0.45.0

type NullServer struct {
}

func NewNullServer added in v0.45.0

func NewNullServer() *NullServer

func (*NullServer) RegisterSource added in v0.45.0

func (c *NullServer) RegisterSource(sink remote.IObjectSource)

func (*NullServer) UnregisterSource added in v0.45.0

func (c *NullServer) UnregisterSource(sink remote.IObjectSource)

type OLinkSource added in v0.45.0

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

func NewOLinkSource added in v0.45.0

func NewOLinkSource(service *ObjectService) *OLinkSource

func (*OLinkSource) Close added in v0.45.0

func (s *OLinkSource) Close()

func (*OLinkSource) CollectProperties added in v0.45.0

func (s *OLinkSource) CollectProperties() (core.KWArgs, error)

func (*OLinkSource) Invoke added in v0.45.0

func (s *OLinkSource) Invoke(methodId string, args core.Args) (core.Any, error)

func (*OLinkSource) Linked added in v0.45.0

func (s *OLinkSource) Linked(objectId string, node *remote.Node) error

func (*OLinkSource) NotifyPropertyChanged added in v0.45.0

func (s *OLinkSource) NotifyPropertyChanged(name string, value core.Any)

func (*OLinkSource) NotifySignal added in v0.45.0

func (s *OLinkSource) NotifySignal(name string, args core.Args)

func (*OLinkSource) ObjectId added in v0.45.0

func (s *OLinkSource) ObjectId() string

func (*OLinkSource) SetProperty added in v0.45.0

func (s *OLinkSource) SetProperty(propertyId string, value core.Any) error

type ObjectClient added in v0.45.0

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

func NewObjectClient added in v0.45.0

func NewObjectClient(channel *Channel, objectId string) *ObjectClient

func (*ObjectClient) CallMethod added in v0.45.0

func (o *ObjectClient) CallMethod(method string, args ...any) any

func (*ObjectClient) Close added in v0.45.0

func (c *ObjectClient) Close()

func (*ObjectClient) GetProperty added in v0.45.0

func (o *ObjectClient) GetProperty(name string) any

func (*ObjectClient) ObjectId added in v0.45.0

func (o *ObjectClient) ObjectId() string

func (*ObjectClient) OnProperty added in v0.45.0

func (o *ObjectClient) OnProperty(name string, fn func(value any))

func (*ObjectClient) OnSignal added in v0.45.0

func (o *ObjectClient) OnSignal(signal string, fn func(args ...any))

func (*ObjectClient) SetProperty added in v0.45.0

func (o *ObjectClient) SetProperty(name string, value any)

SetProperty

type ObjectClientSink added in v0.45.0

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

func NewObjectClientSink added in v0.45.0

func NewObjectClientSink(client *ObjectClient) *ObjectClientSink

func (*ObjectClientSink) HandleInit added in v0.45.0

func (s *ObjectClientSink) HandleInit(objectId string, props core.KWArgs, node *client.Node)

func (*ObjectClientSink) HandlePropertyChange added in v0.45.0

func (s *ObjectClientSink) HandlePropertyChange(propertyId string, value core.Any)

func (*ObjectClientSink) HandleRelease added in v0.45.0

func (s *ObjectClientSink) HandleRelease()

func (*ObjectClientSink) HandleSignal added in v0.45.0

func (s *ObjectClientSink) HandleSignal(signalId string, args core.Args)

func (*ObjectClientSink) ObjectId added in v0.45.0

func (s *ObjectClientSink) ObjectId() string

type ObjectService added in v0.45.0

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

func NewObjectService added in v0.45.0

func NewObjectService(engine *Engine, objectId string, properties map[string]any) *ObjectService

func (*ObjectService) CallMethod added in v0.45.0

func (o *ObjectService) CallMethod(method string, args ...any) (goja.Value, error)

func (*ObjectService) Close added in v0.45.0

func (s *ObjectService) Close()

func (*ObjectService) EmitSignal added in v0.45.0

func (o *ObjectService) EmitSignal(signal string, args ...any)

func (*ObjectService) GetMethod added in v0.45.0

func (o *ObjectService) GetMethod(method string) goja.Callable

GetMethod return method

func (*ObjectService) GetProperties added in v0.45.0

func (o *ObjectService) GetProperties() map[string]any

func (*ObjectService) GetProperty added in v0.45.0

func (o *ObjectService) GetProperty(name string) any

func (*ObjectService) GetProxy added in v0.48.0

func (s *ObjectService) GetProxy() *goja.Object

GetProxy returns the proxy object for this service

func (*ObjectService) HasMethod added in v0.45.0

func (o *ObjectService) HasMethod(method string) bool

HasMethod

func (*ObjectService) HasProperty added in v0.45.0

func (o *ObjectService) HasProperty(name string) bool

HasProperty

func (*ObjectService) ObjectId added in v0.45.0

func (s *ObjectService) ObjectId() string

func (*ObjectService) OnMethod added in v0.45.0

func (o *ObjectService) OnMethod(method string, v goja.Value)

func (*ObjectService) OnProperty added in v0.45.0

func (o *ObjectService) OnProperty(name string, fn func(value any))

func (*ObjectService) OnSignal added in v0.45.0

func (o *ObjectService) OnSignal(signal string, fn func(args ...any))

func (*ObjectService) RemoveMethod added in v0.48.0

func (o *ObjectService) RemoveMethod(method string)

RemoveMethod removes a method from the service

func (*ObjectService) RemoveProperty added in v0.48.0

func (o *ObjectService) RemoveProperty(name string)

RemoveProperty removes a property from the service

func (*ObjectService) SetProperties added in v0.45.0

func (o *ObjectService) SetProperties(properties map[string]any)

func (*ObjectService) SetProperty added in v0.45.0

func (o *ObjectService) SetProperty(name string, value any)

type OlinkConnector added in v0.45.0

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

func NewOlinkConnector added in v0.45.0

func NewOlinkConnector() *OlinkConnector

func (*OlinkConnector) Close added in v0.45.0

func (c *OlinkConnector) Close()

func (*OlinkConnector) Connect added in v0.45.0

func (c *OlinkConnector) Connect(url string) error

Connect connects to a given url and returns a connection id. The connection id can be used to disconnect from the server using Disconnect.

func (*OlinkConnector) Disconnect added in v0.45.0

func (c *OlinkConnector) Disconnect(url string) error

Disconnect closes a connection to the server. The connection id is the string returned when connecting to the server using Connect. If the connection id is not found, this function does nothing and returns nil.

func (*OlinkConnector) Node added in v0.45.0

func (c *OlinkConnector) Node(url string) *client.Node

func (*OlinkConnector) RegisterSink added in v0.45.0

func (c *OlinkConnector) RegisterSink(url string, sink client.IObjectSink)

func (*OlinkConnector) UnregisterSink added in v0.45.0

func (c *OlinkConnector) UnregisterSink(url string, sink client.IObjectSink)

type OlinkServer added in v0.45.0

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

func NewOlinkServer added in v0.45.0

func NewOlinkServer() *OlinkServer

func (*OlinkServer) Close added in v0.45.0

func (s *OlinkServer) Close()

func (*OlinkServer) RegisterSource added in v0.45.0

func (s *OlinkServer) RegisterSource(source remote.IObjectSource)

func (*OlinkServer) ServeHTTP added in v0.45.0

func (s *OlinkServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*OlinkServer) UnregisterSource added in v0.45.0

func (s *OlinkServer) UnregisterSource(source remote.IObjectSource)

type Script

type Script struct {
	Content string `json:"content"`
	Path    string `json:"path"`
	Dir     string `json:"dir"`
	Name    string `json:"name"`
}

func NewScript added in v0.45.0

func NewScript(path string, content string) Script

func (Script) String added in v0.45.0

func (s Script) String() string

type World added in v0.45.0

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

func NewWorld added in v0.45.0

func NewWorld(engine *Engine) *World

func (*World) CreateChannel added in v0.45.0

func (w *World) CreateChannel(url string) (*Channel, error)

func (*World) CreateService added in v0.45.0

func (w *World) CreateService(object string, properties map[string]any) (any, error)

func (*World) GetChannel added in v0.45.0

func (w *World) GetChannel(url string) *Channel

func (*World) GetService added in v0.45.0

func (w *World) GetService(object string) *ObjectService

Jump to

Keyboard shortcuts

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