Working commit
This commit is contained in:
@@ -1,51 +1,11 @@
|
||||
import {PDU} from "../CommonObjects";
|
||||
import Logger from "../Logger";
|
||||
import {SmppSession} from "../SmppSession";
|
||||
|
||||
export abstract class PduProcessor {
|
||||
static processors: PduProcessor[] = [];
|
||||
private static logger: Logger = new Logger("PduProcessor");
|
||||
abstract readonly serverSessionType: string;
|
||||
readonly name: string = this.constructor.name;
|
||||
readonly logger: Logger = new Logger(`PduProcessor: ${this.name}`);
|
||||
|
||||
static getProcessor(name: string): PduProcessor {
|
||||
this.logger.log1(`Looking for processor with name ${name}...`);
|
||||
let pduProcessor = this.processors.find((processor: PduProcessor) => processor.name === name);
|
||||
if (pduProcessor) {
|
||||
this.logger.log1(`Found processor with name ${name}`);
|
||||
return pduProcessor;
|
||||
} else {
|
||||
this.logger.log1(`Processor with name ${name} not found`);
|
||||
return this.processors[0];
|
||||
}
|
||||
}
|
||||
|
||||
static attachProcessor(session: SmppSession, processor: PduProcessor): void {
|
||||
this.logger.log1(`Trying to attach processor ${processor.name} to session ${session.constructor.name}-${session.id}`);
|
||||
if (PduProcessor.areCompatible(session, processor)) {
|
||||
session.addPduProcessor(processor);
|
||||
}
|
||||
}
|
||||
|
||||
static detachProcessor(session: SmppSession, processor: PduProcessor): void {
|
||||
this.logger.log1(`Trying to detach processor ${processor.name} from session ${session.constructor.name}-${session.id}`);
|
||||
session.removePduProcessor(processor);
|
||||
}
|
||||
|
||||
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
||||
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.id} and processor ${processor.name}`);
|
||||
return session.constructor.name === processor.serverSessionType;
|
||||
}
|
||||
|
||||
static addProcessor(processor: new () => PduProcessor): void {
|
||||
PduProcessor.processors.push(new processor());
|
||||
}
|
||||
|
||||
static getProcessorsForType(type: string): PduProcessor[] {
|
||||
return this.processors.filter((processor: PduProcessor) => processor.serverSessionType === type);
|
||||
}
|
||||
|
||||
abstract processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any>;
|
||||
|
||||
serialize(): object {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Center} from "../Center/Center";
|
||||
import {PDU} from "../CommonObjects";
|
||||
import {PduProcessor} from "./PduProcessor";
|
||||
import {Center} from "../../../Center/Center";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export class DebugPduProcessor extends PduProcessor {
|
||||
export class DebugPduProcessor extends Postprocessor {
|
||||
serverSessionType: string = Center.name;
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
@@ -1,10 +1,10 @@
|
||||
import {Center} from "../Center/Center";
|
||||
import {PDU} from "../CommonObjects";
|
||||
import {PduProcessor} from "./PduProcessor";
|
||||
import {Center} from "../../../Center/Center";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
const smpp = require("smpp");
|
||||
|
||||
export class EchoPduProcessor extends PduProcessor {
|
||||
export class EchoPduProcessor extends Postprocessor {
|
||||
serverSessionType: string = Center.name;
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Client} from "../../Client/Client";
|
||||
import {PDU} from "../../CommonObjects";
|
||||
import {PduProcessor} from "../PduProcessor";
|
||||
import {Client} from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export class DeliverSmReplyProcessor extends PduProcessor {
|
||||
export class DeliverSmReplyProcessor extends Postprocessor {
|
||||
serverSessionType: string = Client.name;
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
5
src/PDUProcessor/Postprocessor/Postprocessor.ts
Normal file
5
src/PDUProcessor/Postprocessor/Postprocessor.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import {PduProcessor} from "../PduProcessor";
|
||||
|
||||
export default abstract class Postprocessor extends PduProcessor {
|
||||
readonly type: string = this.name;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Client} from "../../Client/Client";
|
||||
import {PDU} from "../../CommonObjects";
|
||||
import {PduProcessor} from "../PduProcessor";
|
||||
import {Client} from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export class DestinationEnumeratorProcessor extends PduProcessor {
|
||||
export class DestinationEnumeratorProcessor extends Preprocessor {
|
||||
serverSessionType: string = Client.name;
|
||||
private iterator = 0;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Client} from "../../Client/Client";
|
||||
import {PDU} from "../../CommonObjects";
|
||||
import {PduProcessor} from "../PduProcessor";
|
||||
import {Client} from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export class SourceEnumeratorProcessor extends PduProcessor {
|
||||
export class SourceEnumeratorProcessor extends Preprocessor {
|
||||
serverSessionType: string = Client.name;
|
||||
private iterator = 0;
|
||||
|
||||
5
src/PDUProcessor/Preprocessor/Preprocessor.ts
Normal file
5
src/PDUProcessor/Preprocessor/Preprocessor.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import {PduProcessor} from "../PduProcessor";
|
||||
|
||||
export default abstract class Preprocessor extends PduProcessor {
|
||||
readonly type: string = this.name;
|
||||
}
|
||||
61
src/PDUProcessor/ProcessorManager.ts
Normal file
61
src/PDUProcessor/ProcessorManager.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import Logger from "../Logger";
|
||||
import {SmppSession} from "../SmppSession";
|
||||
import {PduProcessor} from "./PduProcessor";
|
||||
import {DebugPduProcessor} from "./Postprocessor/Center/DebugPduProcessor";
|
||||
import {EchoPduProcessor} from "./Postprocessor/Center/EchoPduProcessor";
|
||||
import {DeliverSmReplyProcessor} from "./Postprocessor/Client/DeliverSmReplyProcessor";
|
||||
import {DestinationEnumeratorProcessor} from "./Preprocessor/Client/DestinationEnumeratorProcessor";
|
||||
import {SourceEnumeratorProcessor} from "./Preprocessor/Client/SourceEnumeratorProcessor";
|
||||
|
||||
export default class ProcessorManager {
|
||||
static readonly preprocessors: PduProcessor[] = [
|
||||
new DestinationEnumeratorProcessor(),
|
||||
new SourceEnumeratorProcessor()
|
||||
];
|
||||
static readonly postprocessors: PduProcessor[] = [
|
||||
new DebugPduProcessor(),
|
||||
new EchoPduProcessor(),
|
||||
new DeliverSmReplyProcessor(),
|
||||
];
|
||||
private static readonly logger: Logger = new Logger(this.name);
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
static get processors(): PduProcessor[] {
|
||||
return this.preprocessors.concat(this.postprocessors);
|
||||
}
|
||||
|
||||
static getProcessor(name: string): PduProcessor {
|
||||
this.logger.log1(`Looking for processor with name ${name}...`);
|
||||
let pduProcessor: PduProcessor | undefined = this.processors.find((processor: PduProcessor) => processor.name === name);
|
||||
if (pduProcessor) {
|
||||
this.logger.log1(`Found processor with name ${name}`);
|
||||
return pduProcessor;
|
||||
} else {
|
||||
this.logger.log1(`Processor with name ${name} not found`);
|
||||
return this.processors[0];
|
||||
}
|
||||
}
|
||||
|
||||
static attachProcessor(session: SmppSession, processor: PduProcessor): void {
|
||||
this.logger.log1(`Trying to attach processor ${processor.name} to session ${session.constructor.name}-${session.id}`);
|
||||
if (this.areCompatible(session, processor)) {
|
||||
session.addPduProcessor(processor);
|
||||
}
|
||||
}
|
||||
|
||||
static detachProcessor(session: SmppSession, processor: PduProcessor): void {
|
||||
this.logger.log1(`Trying to detach processor ${processor.name} from session ${session.constructor.name}-${session.id}`);
|
||||
session.removePduProcessor(processor);
|
||||
}
|
||||
|
||||
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
||||
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.id} and processor ${processor.name}`);
|
||||
return session.constructor.name === processor.serverSessionType;
|
||||
}
|
||||
|
||||
static getProcessorsForType(type: string): PduProcessor[] {
|
||||
return this.processors.filter((processor: PduProcessor) => processor.serverSessionType === type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user