| 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 | protected readonly chargingStation: ChargingStation; |
| 11 | |
| 12 | protected constructor(chargingStation: ChargingStation) { |
| 13 | this.chargingStation = chargingStation; |
| 14 | } |
| 15 | |
| 16 | public static getInstance<T extends OCPPResponseService>( |
| 17 | this: new (chargingStation: ChargingStation) => T, |
| 18 | chargingStation: ChargingStation |
| 19 | ): T { |
| 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 | |
| 26 | public abstract handleResponse( |
| 27 | commandName: RequestCommand, |
| 28 | payload: JsonType | string, |
| 29 | requestPayload: JsonType |
| 30 | ): Promise<void>; |
| 31 | } |