More setup and an example componente

This commit is contained in:
Daniel Kluge
2023-10-16 18:29:16 +02:00
parent 2bf455b44a
commit 99fd86ff95
11 changed files with 1692 additions and 74 deletions
+63
View File
@@ -0,0 +1,63 @@
import { types } from "@aas-core-works/aas-core3.0rc02-typescript";
import type AASInterfaceServer from "server";
import type { PossibleRequests } from "server";
import type InterfaceConnectionObject from "interfaceConnectionObject";
import AASStore from "aasStore";
class MultiMessageBroker {
private store = AASStore.getInstance();
private serverInterfaces: Array<typeof AASInterfaceServer> = [];
private serverInterfaceConfigs: Array<any> = [];
private serverInstances: Array<AASInterfaceServer<any>|null> = [];
private connectorInterfaces: Array<typeof InterfaceConnectionObject> = [];
private connectorConfigs: Array<any> = [];
private connectorInstances: Array<InterfaceConnectionObject<any>|null> = [];
public constructor() {}
public registerServerInterface(serverInterface: typeof AASInterfaceServer, config: any): void {
this.serverInterfaces.push(serverInterface);
this.serverInterfaceConfigs.push(config);
}
public registerConnectorInterface(connectorInterface: typeof InterfaceConnectionObject, config: any): void {
this.connectorInterfaces.push(connectorInterface);
this.connectorConfigs.push(config);
}
private createServerInstances(aas: types.Environment): void {
this.serverInstances = this.serverInterfaces.map((serverInterface, index) => {
try {
// @ts-ignore
return new serverInterface(this.serverInterfaceConfigs[index], aas, this.onInterfaceRequest);
} catch (e) {
console.error(`Error while creating server instance for ${serverInterface.name}: ${e}`);
return null;
}
});
}
private createConnectorInstances(): void {
this.connectorInstances = this.connectorInterfaces.map((connectorInterface, index) => {
try {
// @ts-ignore
return new connectorInterface(this.connectorConfigs[index], this.onConnectorEvent);
} catch (e) {
console.error(`Error while creating connector instance for ${connectorInterface.name}: ${e}`);
return null;
}
});
}
private onInterfaceRequest(request: PossibleRequests) {
// TODO
}
private onConnectorEvent(response: any) {
this.serverInstances.forEach(server => {
if (server) server.notify(response);
});
}
}