Documentation
¶
Index ¶
- type Client
- func (c *Client) AddDeviceAndConnect(ctx context.Context, busID uint32, deviceType string, o *device.CreateOptions) (*DeviceStream, *apitypes.Device, error)
- func (c *Client) BusCreate(busID uint32) (*apitypes.BusCreateResponse, error)
- func (c *Client) BusCreateCtx(ctx context.Context, busID uint32) (*apitypes.BusCreateResponse, error)
- func (c *Client) BusList() (*apitypes.BusListResponse, error)
- func (c *Client) BusListCtx(ctx context.Context) (*apitypes.BusListResponse, error)
- func (c *Client) BusRemove(busID uint32) (*apitypes.BusRemoveResponse, error)
- func (c *Client) BusRemoveCtx(ctx context.Context, busID uint32) (*apitypes.BusRemoveResponse, error)
- func (c *Client) DeviceAdd(busID uint32, devType string, o *device.CreateOptions) (*apitypes.Device, error)
- func (c *Client) DeviceAddCtx(ctx context.Context, busID uint32, devType string, o *device.CreateOptions) (*apitypes.Device, error)
- func (c *Client) DeviceRemove(busID uint32, busid string) (*apitypes.DeviceRemoveResponse, error)
- func (c *Client) DeviceRemoveCtx(ctx context.Context, busID uint32, busid string) (*apitypes.DeviceRemoveResponse, error)
- func (c *Client) DevicesList(busID uint32) (*apitypes.DevicesListResponse, error)
- func (c *Client) DevicesListCtx(ctx context.Context, busID uint32) (*apitypes.DevicesListResponse, error)
- func (c *Client) OpenStream(ctx context.Context, busID uint32, devID string) (*DeviceStream, error)
- func (c *Client) Ping() (*apitypes.PingResponse, error)
- func (c *Client) PingCtx(ctx context.Context) (*apitypes.PingResponse, error)
- type Config
- type DeviceStream
- func (s *DeviceStream) Close() error
- func (s *DeviceStream) Read(buf []byte) (int, error)
- func (s *DeviceStream) SetReadDeadline(t time.Time) error
- func (s *DeviceStream) SetWriteDeadline(t time.Time) error
- func (s *DeviceStream) StartReading(ctx context.Context, chSize int, ...) (<-chan encoding.BinaryUnmarshaler, <-chan error)
- func (s *DeviceStream) Write(data []byte) (int, error)
- func (s *DeviceStream) WriteBinary(v encoding.BinaryMarshaler) error
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a high-level interface to the VIIPER API, handling request formatting, response parsing, and error handling.
func New ¶
New constructs a high-level API client using the internal low-level Transport. The addr parameter specifies the TCP address (host:port) of the VIIPER API server.
func NewWithConfig ¶
NewWithConfig constructs a client with custom transport timeouts.
func WithTransport ¶
WithTransport constructs a Client using a custom Transport implementation. This is primarily useful for testing or when advanced transport configuration is needed.
func (*Client) AddDeviceAndConnect ¶
func (c *Client) AddDeviceAndConnect(ctx context.Context, busID uint32, deviceType string, o *device.CreateOptions) (*DeviceStream, *apitypes.Device, error)
AddDeviceAndConnect creates a device on the specified bus and immediately connects to its stream. This is a convenience wrapper that combines DeviceAdd + OpenStream in one call.
func (*Client) BusCreate ¶
func (c *Client) BusCreate(busID uint32) (*apitypes.BusCreateResponse, error)
BusCreate creates a new virtual USB bus with the specified bus number. Returns the created bus ID or an error if the bus number is already allocated.
func (*Client) BusCreateCtx ¶
func (*Client) BusList ¶
func (c *Client) BusList() (*apitypes.BusListResponse, error)
BusList retrieves a list of all active virtual USB bus numbers.
func (*Client) BusListCtx ¶
func (*Client) BusRemove ¶
func (c *Client) BusRemove(busID uint32) (*apitypes.BusRemoveResponse, error)
BusRemove removes an existing virtual USB bus and all devices attached to it. Returns the removed bus ID or an error if the bus does not exist.
func (*Client) BusRemoveCtx ¶
func (*Client) DeviceAdd ¶
func (c *Client) DeviceAdd(busID uint32, devType string, o *device.CreateOptions) (*apitypes.Device, error)
DeviceAdd adds a new device of the specified type to the given bus. The devType parameter specifies the device type (e.g., "xbox360"). Returns the assigned bus ID (e.g., "1-1") or an error if the bus does not exist or the device type is unknown.
func (*Client) DeviceAddCtx ¶
func (*Client) DeviceRemove ¶
DeviceRemove removes a device from the specified bus by its device ID. The busid parameter is the device number (e.g., "1") on the given bus. Active USB-IP connections to the device will be closed. Returns the removed device's bus and device ID or an error if not found.
func (*Client) DeviceRemoveCtx ¶
func (*Client) DevicesList ¶
func (c *Client) DevicesList(busID uint32) (*apitypes.DevicesListResponse, error)
DevicesList retrieves a list of all devices attached to the specified bus. Each device entry includes bus ID, device ID, VID, PID, and device type.
func (*Client) DevicesListCtx ¶
func (*Client) OpenStream ¶
OpenStream connects to an existing device's stream channel. The device must already exist on the bus (use DeviceAdd first).
type Config ¶
type Config struct {
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
}
Config controls low-level transport behavior such as timeouts.
type DeviceStream ¶
DeviceStream represents a bidirectional connection to a device stream.
func (*DeviceStream) Close ¶
func (s *DeviceStream) Close() error
Close closes the stream connection and stops any background reading.
func (*DeviceStream) Read ¶
func (s *DeviceStream) Read(buf []byte) (int, error)
Read receives raw bytes from the device stream (device → client feedback). For event-driven reading, use StartReading() instead to avoid blocking/polling.
func (*DeviceStream) SetReadDeadline ¶
func (s *DeviceStream) SetReadDeadline(t time.Time) error
SetReadDeadline sets the read deadline for the underlying connection.
func (*DeviceStream) SetWriteDeadline ¶
func (s *DeviceStream) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the write deadline for the underlying connection.
func (*DeviceStream) StartReading ¶
func (s *DeviceStream) StartReading(ctx context.Context, chSize int, decode func(r *bufio.Reader) (encoding.BinaryUnmarshaler, error)) (<-chan encoding.BinaryUnmarshaler, <-chan error)
StartReading begins asynchronously reading from the device stream in a background goroutine. You provide a decode function that reads exactly one message from the given *bufio.Reader and returns any value that implements encoding.BinaryUnmarshaler (the interface is only used for typing; StartReading does not call UnmarshalBinary itself).
Example (xbox360 rumble, fixed 2 bytes):
rumbleCh, errCh := stream.StartReading(ctx, 10, func(r *bufio.Reader) (encoding.BinaryUnmarshaler, error) {
var b [2]byte
if _, err := io.ReadFull(r, b[:]); err != nil { return nil, err }
msg := new(xbox360.XRumbleState)
if err := msg.UnmarshalBinary(b[:]); err != nil { return nil, err }
return msg, nil
})
func (*DeviceStream) Write ¶
func (s *DeviceStream) Write(data []byte) (int, error)
Write sends raw bytes to the device stream (client → device input).
func (*DeviceStream) WriteBinary ¶
func (s *DeviceStream) WriteBinary(v encoding.BinaryMarshaler) error
WriteBinary marshals and sends a BinaryMarshaler to the device stream. This is the preferred way to send device input (e.g., xbox360.InputState, keyboard.InputState).
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the low-level VIIPER management protocol implementation used by higher-level API clients. Request framing: `<path>[ SP <payload>] \x00` (null terminator). The payload may contain any data including newlines (e.g. pretty JSON, binary) because only \x00 ends the request. Response framing: server writes a single JSON (or empty success) line terminated by `\n` and then closes the connection. We therefore read until EOF (connection close) and trim a single trailing newline if present. Embedded newlines in the response (future multi-line responses) are preserved.
func NewMockTransport ¶
func NewMockTransport(responder func(path string, payload any, pathParams map[string]string) (string, error)) *Transport
NewMockTransport creates a transport that returns canned responses without real networking. The responder function receives the path, payload and path params and returns the raw line.
func NewTransport ¶
NewTransport creates a new low-level transport.
func NewTransportWithConfig ¶
NewTransportWithConfig creates a new low-level transport with optional timeouts configuration.