usbprinter

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package usbprinter provides an interface to configure and attach a virtual USB printer onto the system to be used for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DevInfo

type DevInfo struct {
	// VID contains the device's vendor ID.
	VID string
	// PID contains the devices's product ID.
	PID string
}

DevInfo contains information used to identify a USB device.

type Option

type Option func(*config) error

Option provides the type for functional options used to build a Printer via Start().

func ExpectUdevEventOnStop

func ExpectUdevEventOnStop() Option

ExpectUdevEventOnStop causes Printer.Stop() to propagate errors if a udev event is not seen.

func WaitUntilConfigured

func WaitUntilConfigured() Option

WaitUntilConfigured controls whether or not Start() blocks on printer autoconfiguration.

func WithAttributes

func WithAttributes(path string) Option

WithAttributes sets attributes.

func WithDescriptors

func WithDescriptors(path string) Option

WithDescriptors sets the required descriptors.

func WithESCLCapabilities

func WithESCLCapabilities(path string) Option

WithESCLCapabilities sets eSCL capabilities.

func WithGenericIPPAttributes

func WithGenericIPPAttributes() Option

WithGenericIPPAttributes passes the most commonly used IPP attributes.

func WithIPPUSBDescriptors

func WithIPPUSBDescriptors() Option

WithIPPUSBDescriptors passes the most commonly used USB descriptors.

func WithOutputLogDirectory

func WithOutputLogDirectory(directory string) Option

WithOutputLogDirectory sets the output log directory.

func WithRecordPath

func WithRecordPath(record string) Option

WithRecordPath sets the document output path.

type Printer

type Printer struct {
	// The printer name as detected by autoconfiguration.
	// Empty if Start() was called with info.WaitUntilConfigured
	// set false.
	ConfiguredName string

	// The printer's device information parsed from its USB
	// descriptors config.
	DevInfo DevInfo
	// contains filtered or unexported fields
}

Printer provides an interface to interact with the running virtual-usb-printer instance.

func Start

func Start(ctx context.Context, opts ...Option) (pr *Printer, err error)

Start creates a new Printer and starts the underlying virtual-usb-printer process.

func (*Printer) Stop

func (p *Printer) Stop(ctx context.Context) error

Stop terminates and waits for the virtual-usb-printer. Users must call this when finished with the virtual-usb-printer.

Returns an error if we fail to terminate or wait for the virtual-usb-printer, or if we don't see an expected udev event upon stoppage.

This method is idempotent.

Jump to

Keyboard shortcuts

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