UNPKG

@mdf.js/openc2-core

Version:

MMS - API Core - OpenC2

178 lines 7.08 kB
/** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ import { Health } from '@mdf.js/core'; import { Crash } from '@mdf.js/crash'; import { Control, ProducerAdapter, ProducerOptions } from '../../types'; import { Component } from '../Component'; import { ConsumerMap } from './ConsumerMap'; import { AdapterWrapper } from './core'; export declare interface Producer { /** * Add a listener for the `error` event, emitted when the component detects an error. * @param event - `error` event * @param listener - Error event listener * @event */ on(event: 'error', listener: (error: Crash | Error) => void): this; /** * Add a listener for the `error` event, emitted when the component detects an error. * @param event - `error` event * @param listener - Error event listener * @event */ addListener(event: 'error', listener: (error: Crash | Error) => void): this; /** * Add a listener for the `error` event, emitted when the component detects an error. This is a * one-time event, the listener will be removed after the first emission. * @param event - `error` event * @param listener - Error event listener * @event */ once(event: 'error', listener: (error: Crash | Error) => void): this; /** * Removes the specified listener from the listener array for the `error` event. * @param event - `error` event * @param listener - Error event listener * @event */ off(event: 'error', listener: (error: Crash | Error) => void): this; /** * Removes the specified listener from the listener array for the `error` event. * @param event - `error` event * @param listener - Error event listener * @event */ removeListener(event: 'error', listener: (error: Crash | Error) => void): this; /** * Removes all listeners, or those of the specified event. * @param event - `error` event */ removeAllListeners(event?: 'error'): this; /** * Add a listener for the `status` event, emitted when the component changes its status. * @param event - `status` event * @param listener - Status event listener * @event */ on(event: 'status', listener: (status: Health.Status) => void): this; /** * Add a listener for the `status` event, emitted when the component changes its status. * @param event - `status` event * @param listener - Status event listener * @event */ addListener(event: 'status', listener: (status: Health.Status) => void): this; /** * Add a listener for the `status` event, emitted when the component changes its status. This is a * one-time event, the listener will be removed after the first emission. * @param event - `status` event * @param listener - Status event listener * @event */ once(event: 'status', listener: (status: Health.Status) => void): this; /** * Removes the specified listener from the listener array for the `status` event. * @param event - `status` event * @param listener - Status event listener * @event */ off(event: 'status', listener: (status: Health.Status) => void): this; /** * Removes the specified listener from the listener array for the `status` event. * @param event - `status` event * @param listener - Status event listener * @event */ removeListener(event: 'status', listener: (status: Health.Status) => void): this; } export declare class Producer extends Component<AdapterWrapper, ProducerOptions> { /** Lookup timer */ private lookupTimer?; /** Consumer Map*/ readonly consumerMap: ConsumerMap; /** * Regular OpenC2 producer implementation. * @param adapter - transport adapter * @param options - configuration options */ constructor(adapter: ProducerAdapter, options: ProducerOptions); /** Initialize the OpenC2 component */ protected startup(): Promise<void>; /** Shutdown the OpenC2 component */ protected shutdown(): Promise<void>; /** * Issue a new command to the requested consumers. If '*' is indicated as a consumer, the command * will be broadcasted. If an `actuator` is indicated in the command the command will not be * broadcasted even if it include the '*' symbol. * @param command - Command to be issued * @returns */ command(command: Control.CommandMessage): Promise<Control.ResponseMessage[]>; /** * Issue a new command to the requested consumers. If '*' is indicated as a consumer, the command * will be broadcasted. If an `actuator` is indicated in the command the command will not be * broadcasted even if it include the '*' symbol. * @param to - Consumer objetive of this command * @param content - Command to be issued * @returns */ command(to: string[], content: Control.Command): Promise<Control.ResponseMessage[]>; /** * Issue a new command to the requested consumers. If '*' is indicated as a consumer, the command * will be broadcasted. * @param to - Consumer objetive of this command * @param action - command action * @param target - command target * @returns */ command(to: string[], action: Control.Action, target: Control.Target): Promise<Control.ResponseMessage[]>; /** * Process incoming command message from the router * @param incomingMessage - incoming message * @param done - callback to return the response */ private readonly onCommandHandler; /** Perform the lookup of OpenC2 consumers */ private readonly lookup; /** * Get and validate the command message to be published * @param destinationsOrCommand - destination of command defined in content or command itself * @param contentOrAction - Command to be issued * @param id - producer identification * @returns */ private getCommand; /** * Wait for the response to an issued command * @param command - issued command */ private waitForResponse; /** * Wait for the response of several consumers during the defined duration in the command * @param command - issued command * @returns */ private waitForBroadCastResponses; /** * Wait for the response of several consumers during the defined duration in the command * @param command - issued command * @param responses - responses array */ private getBroadcastResponseHandler; /** * Wait for the response to an issued command from one consumer * @param command - issued command */ private waitForConsumerResponse; private handlerMessage; /** * Handle errors processing incoming messages * @param rawError - raw error */ private readonly onProcessingMessageError; } //# sourceMappingURL=Producer.d.ts.map