nanotoolbox

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package nanotoolbox provides a minimal set of tools for communicating with the vmx.

Index

Constants

This section is empty.

Variables

View Source
var (
	// RpciOK is the return code for a successful RPCI request.
	RpciOK = []byte{'1', ' '}
	// RpciERR is the return code for a failed RPCI request.
	RpciERR = []byte{'0', ' '}
)
View Source
var ErrNotVirtualWorld = errors.New("not in a virtual world")

ErrNotVirtualWorld is returned when the current process is not running in a virtual world.

Functions

func NewHypervisorChannelPair

func NewHypervisorChannelPair() (Channel, Channel)

NewHypervisorChannelPair returns a pair of channels for communicating with the vmx.

Types

type Channel

type Channel interface {
	Start() error
	Stop() error
	Send([]byte) error
	Receive() ([]byte, error)
}

Channel abstracts the guest<->vmx RPC transport.

type ChannelOut

type ChannelOut struct {
	Channel
}

ChannelOut extends Channel to provide RPCI protocol helpers.

func (*ChannelOut) Request

func (c *ChannelOut) Request(request []byte) ([]byte, error)

Request sends an RPC command to the vmx and checks the return code for success or error.

type CommandHandler

type CommandHandler func([]byte) ([]byte, error)

CommandHandler is given the raw argument portion of an RPC request and returns a response.

type OptionHandler

type OptionHandler func(key, value string)

OptionHandler is given the raw key and value of Set_Option requests.

type Service

type Service struct {
	Log logrus.FieldLogger
	Out *ChannelOut
	// contains filtered or unexported fields
}

Service receives and dispatches incoming RPC requests from the vmx.

func NewService

func NewService(log logrus.FieldLogger, rpcIn Channel, rpcOut Channel) *Service

NewService initializes a Service instance.

func (*Service) AddCapability

func (s *Service) AddCapability(name string)

AddCapability adds a capability to the Service.

func (*Service) Dispatch

func (s *Service) Dispatch(request []byte) []byte

Dispatch an incoming RPC request to a CommandHandler.

func (*Service) HandleCapabilitiesRegister

func (s *Service) HandleCapabilitiesRegister([]byte) ([]byte, error)

HandleCapabilitiesRegister sends the Service's capabilities to the vmx.

func (*Service) HandlePing

func (s *Service) HandlePing([]byte) ([]byte, error)

HandlePing responds to a ping request.

func (*Service) HandleReset

func (s *Service) HandleReset([]byte) ([]byte, error)

HandleReset resets the Service.

func (*Service) HandleSetOption

func (s *Service) HandleSetOption(args []byte) ([]byte, error)

HandleSetOption handles Set_Option requests.

func (*Service) RegisterCommandHandler

func (s *Service) RegisterCommandHandler(name string, handler CommandHandler)

RegisterCommandHandler adds a CommandHandler to the Service.

func (*Service) RegisterOptionHandler

func (s *Service) RegisterOptionHandler(key string, handler OptionHandler)

RegisterOptionHandler adds an OptionHandler to the Service.

func (*Service) RegisterResetHandler

func (s *Service) RegisterResetHandler(f func())

RegisterResetHandler adds a function to be called when the Service is reset.

func (*Service) Start

func (s *Service) Start() error

Start initializes the RPC channels and starts a goroutine to listen for incoming RPC requests.

func (*Service) Stop

func (s *Service) Stop()

Stop cancels the RPC listener routine created via Start.

func (*Service) Wait

func (s *Service) Wait()

Wait blocks until Start returns, allowing any current RPC in progress to complete.

Jump to

Keyboard shortcuts

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