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