import type { TDeviceStateHandler, TPortStateHandler, EConnectionErrorType } from '../../../types/public.js'; /** * Interface for the State Manager. */ export interface IStateManager { setDeviceHandler(handler: TDeviceStateHandler): void; setDeviceHandlerForTransport(transportId: string, handler: TDeviceStateHandler): Promise; notifyDeviceConnected(transportId: string, slaveId: number): Promise; notifyDeviceDisconnected(transportId: string, slaveId: number, errorType: EConnectionErrorType, message: string): Promise; setPortHandler(handler: TPortStateHandler): void; setPortHandlerForTransport(transportId: string, handler: TPortStateHandler): Promise; notifyPortConnected(transportId: string, slaveIds: number[]): Promise; notifyPortDisconnected(transportId: string, slaveIds: number[], errorType: EConnectionErrorType, message: string): Promise; createTrackersForTransport(transportId: string): void; clearTransport(transportId: string): Promise; removeDeviceState(slaveId: number, transportId?: string): void; } /** * Manages connection states and event propagation for devices (Slave IDs) and ports (Transports). * It aggregates local transport trackers into global state handlers. */ export declare class StateManager implements IStateManager { private readonly _mutex; private _globalDeviceHandler; private _globalPortHandler; private readonly _deviceTrackers; private readonly _portTrackers; private readonly _deviceHandlers; private readonly _portHandlers; /** * Initializes internal trackers for a newly created transport. * @param {string} transportId - The transport identifier. */ createTrackersForTransport(transportId: string): void; /** * Sets a global handler that will be called whenever ANY device state changes. * @param {TDeviceStateHandler} handler - Callback for device state events. */ setDeviceHandler(handler: TDeviceStateHandler): void; /** * Sets a specific handler for a single transport's device events. * @param {string} transportId - Target transport ID. * @param {TDeviceStateHandler} handler - Callback for events from this transport. */ setDeviceHandlerForTransport(transportId: string, handler: TDeviceStateHandler): Promise; /** * Triggers a 'connected' state event for a specific Slave ID on a transport. * @param {string} transportId - The transport where the device was found. * @param {number} slaveId - The Slave ID. */ notifyDeviceConnected(transportId: string, slaveId: number): Promise; /** * Triggers a 'disconnected' state event for a specific Slave ID. * @param {string} transportId - Originating transport. * @param {number} slaveId - The Slave ID. * @param {EConnectionErrorType} errorType - Reason for disconnection. * @param {string} message - Descriptive error message. */ notifyDeviceDisconnected(transportId: string, slaveId: number, errorType: EConnectionErrorType, message: string): Promise; /** * Sets a global handler for port/transport connection status changes. * @param {TPortStateHandler} handler - Callback for port state events. */ setPortHandler(handler: TPortStateHandler): void; /** * Sets a port handler for a specific transport. */ setPortHandlerForTransport(transportId: string, handler: TPortStateHandler): Promise; /** * Notifies that a port (transport) is successfully connected. */ notifyPortConnected(transportId: string, slaveIds: number[]): Promise; /** * Notifies that a port (transport) has been disconnected or failed. */ notifyPortDisconnected(transportId: string, slaveIds: number[], errorType: EConnectionErrorType, message: string): Promise; /** * Cleans up stored state for a specific slave. * @param {number} slaveId - The slave ID to remove. * @param {string} [transportId] - Optional transport ID to limit the scope. */ removeDeviceState(slaveId: number, transportId?: string): void; /** * Completely removes a transport and all its associated trackers and handlers. * This is a thread-safe operation. * @param {string} transportId - The transport ID to clear. */ clearTransport(transportId: string): Promise; /** * Internal helper to propagate events to the global device handler. * @private */ private _emitDeviceState; /** * Internal helper to propagate events to the global port handler. * @private */ private _emitPortState; }