UNPKG

webserial-core

Version:

A strongly-typed, event-driven, abstract TypeScript library for the Web Serial API with custom parsers, command queue, handshake validation, and auto-reconnect.

54 lines (53 loc) 1.88 kB
import { AbstractSerialDevice } from './AbstractSerialDevice.js'; /** * Global registry for serial device instances and port locks. * * Maintains: * - A `Set` of all registered {@link AbstractSerialDevice} instances. * - A `WeakMap` from `SerialPort` to the device instance that currently owns it. * * All methods are static; this class acts as a module-level singleton. */ export declare class SerialRegistry { private static instances; private static portInstanceMap; /** * Returns all currently registered device instances. * * @returns An array snapshot of all registered devices. */ static getInstances(): AbstractSerialDevice<unknown>[]; /** * Registers a device instance so it appears in `getInstances()`. * * @param instance - The device to register. */ static register(instance: AbstractSerialDevice<unknown>): void; /** * Removes a device instance from the registry. * * @param instance - The device to unregister. */ static unregister(instance: AbstractSerialDevice<unknown>): void; /** * Returns `true` if the port is held by a **different** device instance. * * @param port - The serial port to check. * @param instance - The device requesting access. * @returns `true` if the port is locked by another device. */ static isPortInUse(port: SerialPort, instance: AbstractSerialDevice<unknown>): boolean; /** * Assigns exclusive ownership of a port to an instance. * * @param port - The port to lock. * @param instance - The device claiming the port. */ static lockPort(port: SerialPort, instance: AbstractSerialDevice<unknown>): void; /** * Releases the exclusive lock on a port. * * @param port - The port to unlock. */ static unlockPort(port: SerialPort): void; }