More setup and an example componente
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user