X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-server%2FAbstractUIServer.ts;h=902b6bd5d70bcd4152f6bcabb7eae33fc11787b4;hb=92403944ed5cdbdd07faaa2da783682e1ea9a9dd;hp=432c91e7140916089fc393430ae1922e5e2baf31;hpb=8114d10e3893e96bb725ce2fca9744429ee4b75b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index 432c91e7..902b6bd5 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -1,22 +1,43 @@ -import { Server as HttpServer } from 'http'; +import type { Server as HttpServer } from 'http'; -import WebSocket from 'ws'; +import type WebSocket from 'ws'; -import { ProtocolVersion } from '../../types/UIProtocol'; -import AbstractUIService from './ui-services/AbstractUIService'; +import type { ChargingStationData } from '../../types/ChargingStationWorker'; +import type { + ProcedureName, + ProtocolRequest, + ProtocolResponse, + ProtocolVersion, + RequestPayload, + ResponsePayload, +} from '../../types/UIProtocol'; +import type AbstractUIService from './ui-services/AbstractUIService'; export abstract class AbstractUIServer { - public readonly chargingStations: Set; + public readonly chargingStations: Map; protected readonly uiServices: Map; protected server: WebSocket.Server | HttpServer; public constructor() { - this.chargingStations = new Set(); + this.chargingStations = new Map(); this.uiServices = new Map(); } + public buildProtocolRequest( + id: string, + procedureName: ProcedureName, + requestPayload: RequestPayload + ): string { + return JSON.stringify([id, procedureName, requestPayload] as ProtocolRequest); + } + + public buildProtocolResponse(id: string, responsePayload: ResponsePayload): string { + return JSON.stringify([id, responsePayload] as ProtocolResponse); + } + public abstract start(): void; public abstract stop(): void; - public abstract sendResponse(message: string): void; - public abstract logPrefix(): string; + public abstract sendRequest(request: string): void; + public abstract sendResponse(response: string): void; + public abstract logPrefix(modName?: string, methodName?: string): string; }