import { IAdapterOptions } from '../types'; import { Logger } from '../utils/logger'; /** * Context passed to each writeChunk() call */ export interface ChunkWriteContext { /** Device identifier */ deviceId: string; /** Service UUID */ serviceId: string; /** Characteristic UUID */ characteristicId: string; } /** * Configuration for the adaptive write strategy */ export interface AdaptiveWriteConfig { /** Default chunk size in bytes */ defaultChunkSize: number; /** Default inter-chunk delay in ms */ defaultDelay: number; /** Default retry count */ defaultRetries: number; /** Minimum chunk size */ minChunkSize: number; /** Maximum chunk size (can be overridden per-call by adapter) */ maxChunkSize: number; /** Maximum delay between retries in ms */ maxDelay: number; /** Number of successful chunks before increasing chunk size */ successThreshold: number; /** Number of consecutive failures before reducing chunk size */ failureThreshold: number; /** Interval (in chunks) for connection re-check */ connectionCheckInterval: number; } /** * Default adaptive write configuration */ export declare const DEFAULT_ADAPTIVE_CONFIG: AdaptiveWriteConfig; /** * Result of a single chunk write attempt */ export interface ChunkWriteResult { /** Whether the write was successful */ success: boolean; /** The error if write failed */ error?: Error; } /** * Adaptive Chunk Write Strategy (Template Method) * * Provides the full adaptive chunk-based write pipeline. Subclasses * (or composing classes) implement writeSingleChunk() for platform- * specific BLE write operations. */ export declare abstract class ChunkWriteStrategy { protected readonly logger: ReturnType; protected readonly config: AdaptiveWriteConfig; constructor(loggerScope: string, config?: Partial); /** * Write a single chunk to the device. * * Platform-specific implementation — subclasses must implement this * to call the appropriate BLE API (Taro, React Native, etc.). * * @param chunk - Data chunk to write * @param context - Device/service/characteristic identifiers * @param options - Platform-specific options * @returns Result indicating success or failure */ protected abstract writeSingleChunk(chunk: Uint8Array, context: ChunkWriteContext, options?: TOptions): Promise; /** * Check if the device is still connected (optional hook). * Default: no-op. Override for platforms that support connection state polling. */ protected checkConnection(_deviceId: string): Promise; /** Step size for increasing chunk size on success (bytes) */ private static readonly CHUNK_SIZE_STEP; /** Delay backoff multiplier on failure */ private static readonly DELAY_BACKOFF_FACTOR; /** Delay recovery divisor on success */ private static readonly DELAY_RECOVERY_FACTOR; /** Timeout base (ms) for computeTimeoutMs */ private static readonly TIMEOUT_BASE_MS; /** Timeout per-byte factor (ms) for computeTimeoutMs */ private static readonly TIMEOUT_PER_BYTE_MS; /** Maximum timeout (ms) for computeTimeoutMs */ private static readonly TIMEOUT_MAX_MS; /** * Compute chunk write timeout based on chunk size. * Override to customize timeout formula per platform. */ protected computeTimeoutMs(chunkLength: number): number; /** * Compute the maximum chunk size for a given device. * Override to respect MTU or other platform-specific limits. */ protected getMaxChunkSize(_deviceId: string): number; /** * Execute the adaptive chunk-based write pipeline. * * @param buffer - Full data buffer to write * @param context - Device/service/characteristic identifiers * @param adapterOptions - IAdapterOptions (chunkSize, delay, retries) * @param platformOptions - Platform-specific options forwarded to writeSingleChunk * * @throws {BluetoothPrintError} When all retries are exhausted for a chunk */ execute(buffer: ArrayBuffer, context: ChunkWriteContext, adapterOptions?: IAdapterOptions, platformOptions?: TOptions): Promise; /** * Initialize transmission parameters from adapter options */ private initializeTransmissionParams; /** * Check connection periodically based on interval */ private maybeCheckConnection; /** * Write a single chunk with retry logic * @returns true if successful, false if all retries exhausted (error thrown) */ private writeChunkWithRetries; /** * Adjust chunk size and delay based on success/failure */ private adjustTransmissionParams; /** * Apply inter-chunk delay to prevent BLE congestion */ private maybeDelay; }