1 import type ChargingStation from
'../ChargingStation';
2 import { IncomingRequestCommand
} from
'../../types/ocpp/Requests';
3 import { JsonType
} from
'../../types/JsonType';
4 import logger from
'../../utils/Logger';
6 export default abstract class OCPPIncomingRequestService
{
7 private static readonly instances
: Map
<string, OCPPIncomingRequestService
> = new Map
<string, OCPPIncomingRequestService
>();
8 protected chargingStation
: ChargingStation
;
10 protected constructor(chargingStation
: ChargingStation
) {
11 this.chargingStation
= chargingStation
;
14 public static getInstance
<T
extends OCPPIncomingRequestService
>(this: new (chargingStation
: ChargingStation
) => T
, chargingStation
: ChargingStation
): T
{
15 if (!OCPPIncomingRequestService
.instances
.has(chargingStation
.id
)) {
16 OCPPIncomingRequestService
.instances
.set(chargingStation
.id
, new this(chargingStation
));
18 return OCPPIncomingRequestService
.instances
.get(chargingStation
.id
) as T
;
21 protected handleIncomingRequestError
<T
>(commandName
: IncomingRequestCommand
, error
: Error, errorOcppResponse
?: T
): T
{
22 logger
.error(this.chargingStation
.logPrefix() + ' Incoming request command %s error: %j', commandName
, error
);
23 if (errorOcppResponse
) {
24 return errorOcppResponse
;
29 public abstract handleRequest(messageId
: string, commandName
: IncomingRequestCommand
, commandPayload
: JsonType
): Promise
<void>;