| 1 | import type ChargingStation from '../ChargingStation'; |
| 2 | import { JsonType } from '../../types/JsonType'; |
| 3 | import { RequestCommand } from '../../types/ocpp/Requests'; |
| 4 | |
| 5 | export default abstract class OCPPResponseService { |
| 6 | private static readonly instances: Map<string, OCPPResponseService> = new Map< |
| 7 | string, |
| 8 | OCPPResponseService |
| 9 | >(); |
| 10 | |
| 11 | protected readonly chargingStation: ChargingStation; |
| 12 | |
| 13 | protected constructor(chargingStation: ChargingStation) { |
| 14 | this.chargingStation = chargingStation; |
| 15 | } |
| 16 | |
| 17 | public static getInstance<T extends OCPPResponseService>( |
| 18 | this: new (chargingStation: ChargingStation) => T, |
| 19 | chargingStation: ChargingStation |
| 20 | ): T { |
| 21 | if (!OCPPResponseService.instances.has(chargingStation.hashId)) { |
| 22 | OCPPResponseService.instances.set(chargingStation.hashId, new this(chargingStation)); |
| 23 | } |
| 24 | return OCPPResponseService.instances.get(chargingStation.hashId) as T; |
| 25 | } |
| 26 | |
| 27 | public abstract responseHandler( |
| 28 | commandName: RequestCommand, |
| 29 | payload: JsonType, |
| 30 | requestPayload: JsonType |
| 31 | ): Promise<void>; |
| 32 | } |