Commit | Line | Data |
---|---|---|
9f2e3130 | 1 | import type ChargingStation from '../ChargingStation'; |
d1888640 | 2 | import { JsonType } from '../../types/JsonType'; |
c0560973 JB |
3 | import { RequestCommand } from '../../types/ocpp/Requests'; |
4 | ||
5 | export default abstract class OCPPResponseService { | |
9f2e3130 JB |
6 | private static readonly instances: Map<string, OCPPResponseService> = new Map<string, OCPPResponseService>(); |
7 | protected readonly chargingStation: ChargingStation; | |
c0560973 | 8 | |
9f2e3130 | 9 | protected constructor(chargingStation: ChargingStation) { |
c0560973 JB |
10 | this.chargingStation = chargingStation; |
11 | } | |
12 | ||
9f2e3130 JB |
13 | public static getInstance<T extends OCPPResponseService>(this: new (chargingStation: ChargingStation) => T, chargingStation: ChargingStation): T { |
14 | if (!OCPPResponseService.instances.has(chargingStation.id)) { | |
15 | OCPPResponseService.instances.set(chargingStation.id, new this(chargingStation)); | |
16 | } | |
17 | return OCPPResponseService.instances.get(chargingStation.id) as T; | |
18 | } | |
19 | ||
d1888640 | 20 | public abstract handleResponse(commandName: RequestCommand, payload: JsonType | string, requestPayload: JsonType): Promise<void>; |
c0560973 | 21 | } |