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 { | |
e7aeea18 JB |
6 | private static readonly instances: Map<string, OCPPResponseService> = new Map< |
7 | string, | |
8 | OCPPResponseService | |
9 | >(); | |
9f2e3130 | 10 | protected readonly chargingStation: ChargingStation; |
c0560973 | 11 | |
9f2e3130 | 12 | protected constructor(chargingStation: ChargingStation) { |
c0560973 JB |
13 | this.chargingStation = chargingStation; |
14 | } | |
15 | ||
e7aeea18 JB |
16 | public static getInstance<T extends OCPPResponseService>( |
17 | this: new (chargingStation: ChargingStation) => T, | |
18 | chargingStation: ChargingStation | |
19 | ): T { | |
9f2e3130 JB |
20 | if (!OCPPResponseService.instances.has(chargingStation.id)) { |
21 | OCPPResponseService.instances.set(chargingStation.id, new this(chargingStation)); | |
22 | } | |
23 | return OCPPResponseService.instances.get(chargingStation.id) as T; | |
24 | } | |
25 | ||
e7aeea18 JB |
26 | public abstract handleResponse( |
27 | commandName: RequestCommand, | |
28 | payload: JsonType | string, | |
29 | requestPayload: JsonType | |
30 | ): Promise<void>; | |
c0560973 | 31 | } |