X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPResponseService.ts;h=ffcb888fe422bf35bb24549205ff4dfbc3ba09f5;hb=ada189a839743451d477d5b3bddc698f2634d799;hp=17bf80650c1e04e615e7b7ddc017f31d43822dc8;hpb=d18886407cdb8b8148c87492f2c953075e708401;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 17bf8065..ffcb888f 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -1,13 +1,25 @@ -import ChargingStation from '../ChargingStation'; import { JsonType } from '../../types/JsonType'; import { RequestCommand } from '../../types/ocpp/Requests'; +import type ChargingStation from '../ChargingStation'; export default abstract class OCPPResponseService { - protected chargingStation: ChargingStation; + private static instance: OCPPResponseService | null = null; - constructor(chargingStation: ChargingStation) { - this.chargingStation = chargingStation; + protected constructor() { + // This is intentional } - public abstract handleResponse(commandName: RequestCommand, payload: JsonType | string, requestPayload: JsonType): Promise; + public static getInstance(this: new () => T): T { + if (!OCPPResponseService.instance) { + OCPPResponseService.instance = new this(); + } + return OCPPResponseService.instance as T; + } + + public abstract responseHandler( + chargingStation: ChargingStation, + commandName: RequestCommand, + payload: JsonType, + requestPayload: JsonType + ): Promise; }