| 1 | import type { Server as HttpServer } from 'http'; |
| 2 | |
| 3 | import type WebSocket from 'ws'; |
| 4 | |
| 5 | import type { ChargingStationData } from '../../types/ChargingStationWorker'; |
| 6 | import type { |
| 7 | ProcedureName, |
| 8 | ProtocolRequest, |
| 9 | ProtocolResponse, |
| 10 | ProtocolVersion, |
| 11 | RequestPayload, |
| 12 | ResponsePayload, |
| 13 | } from '../../types/UIProtocol'; |
| 14 | import type AbstractUIService from './ui-services/AbstractUIService'; |
| 15 | |
| 16 | export abstract class AbstractUIServer { |
| 17 | public readonly chargingStations: Map<string, ChargingStationData>; |
| 18 | protected server: WebSocket.Server | HttpServer; |
| 19 | protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>; |
| 20 | |
| 21 | public constructor() { |
| 22 | this.chargingStations = new Map<string, ChargingStationData>(); |
| 23 | this.uiServices = new Map<ProtocolVersion, AbstractUIService>(); |
| 24 | } |
| 25 | |
| 26 | public buildProtocolRequest( |
| 27 | id: string, |
| 28 | procedureName: ProcedureName, |
| 29 | requestPayload: RequestPayload |
| 30 | ): ProtocolRequest { |
| 31 | return [id, procedureName, requestPayload]; |
| 32 | } |
| 33 | |
| 34 | public buildProtocolResponse(id: string, responsePayload: ResponsePayload): ProtocolResponse { |
| 35 | return [id, responsePayload]; |
| 36 | } |
| 37 | |
| 38 | public abstract start(): void; |
| 39 | public abstract stop(): void; |
| 40 | public abstract sendRequest(request: ProtocolRequest): void; |
| 41 | public abstract sendResponse(response: ProtocolResponse): void; |
| 42 | public abstract logPrefix( |
| 43 | moduleName?: string, |
| 44 | methodName?: string, |
| 45 | prefixSuffix?: string |
| 46 | ): string; |
| 47 | } |