X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPResponseService.ts;h=ffcb888fe422bf35bb24549205ff4dfbc3ba09f5;hb=ada189a839743451d477d5b3bddc698f2634d799;hp=0a1cd0c610a117ad9c7b0af8211c6ef2efe037c5;hpb=1af50fac1ab71fed19f11864d1644261046698a3;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 0a1cd0c6..ffcb888f 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -1,12 +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: Record | string, requestPayload: Record): 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; }