42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { types } from "@aas-core-works/aas-core3.0-typescript";
|
|
import type { Request, OnRequestCallback } from "types/requests";
|
|
|
|
export default abstract class AASInterfaceServer<ConfigInterface> {
|
|
protected abstract readonly name: string;
|
|
protected config: ConfigInterface;
|
|
protected abstract readonly supportsSubscriptions: boolean;
|
|
protected readonly aas: types.Environment;
|
|
private onRequestCallback: OnRequestCallback
|
|
|
|
constructor(config: ConfigInterface, aas: types.Environment, onRequestCallback: OnRequestCallback) {
|
|
this.config = config;
|
|
this.aas = aas;
|
|
this.onRequestCallback = onRequestCallback;
|
|
}
|
|
|
|
public abstract prepare(): void;
|
|
public abstract run(): void;
|
|
public abstract stop(): void;
|
|
public abstract notify(event: any): void;
|
|
|
|
protected abstract findElementByRequest(request: Request): any | null;
|
|
|
|
protected findElementBySemanticId(id: string): types.Class | null {
|
|
for (const element of this.aas.descend()) {
|
|
if ((element as any).semanticId === id) {
|
|
return element;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
protected findElementByShortId(id: string): types.Class | null {
|
|
for (const element of this.aas.descend()) {
|
|
if ((element as any).idShort === id) {
|
|
return element;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
} |