Refine TS and linter configuration
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / AbstractUIServer.ts
CommitLineData
6c1761d4 1import type { Server as HttpServer } from 'http';
8114d10e 2
6c1761d4 3import type WebSocket from 'ws';
fe94fce0 4
6c1761d4
JB
5import type { ChargingStationData } from '../../types/ChargingStationWorker';
6import type {
852a4c5f
JB
7 ProcedureName,
8 ProtocolRequest,
9 ProtocolResponse,
10 ProtocolVersion,
11 RequestPayload,
12 ResponsePayload,
13} from '../../types/UIProtocol';
db2336d9 14import type AbstractUIService from './ui-services/AbstractUIService';
8114d10e 15
fe94fce0 16export abstract class AbstractUIServer {
32de5a57 17 public readonly chargingStations: Map<string, ChargingStationData>;
fe94fce0 18 protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>;
0d8140bd 19 protected server: WebSocket.Server | HttpServer;
fe94fce0
JB
20
21 public constructor() {
32de5a57 22 this.chargingStations = new Map<string, ChargingStationData>();
fe94fce0
JB
23 this.uiServices = new Map<ProtocolVersion, AbstractUIService>();
24 }
25
852a4c5f
JB
26 public buildProtocolRequest(
27 id: string,
28 procedureName: ProcedureName,
29 requestPayload: RequestPayload
30 ): string {
31 return JSON.stringify([id, procedureName, requestPayload] as ProtocolRequest);
32 }
33
34 public buildProtocolResponse(id: string, responsePayload: ResponsePayload): string {
35 return JSON.stringify([id, responsePayload] as ProtocolResponse);
36 }
37
fe94fce0
JB
38 public abstract start(): void;
39 public abstract stop(): void;
02a6943a
JB
40 public abstract sendRequest(request: string): void;
41 public abstract sendResponse(response: string): void;
32de5a57 42 public abstract logPrefix(modName?: string, methodName?: string): string;
fe94fce0 43}