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