UNPKG

@itwin/core-backend

Version:
111 lines 5.27 kB
/** @packageDocumentation * @module NativeApp */ import { EditingScopeNotifications, IpcAppNotifications, IpcListener, IpcSocketBackend, RemoveFunction, TxnNotifications } from "@itwin/core-common"; import { ProgressFunction, ProgressStatus } from "./CheckpointManager"; import { BriefcaseDb, StandaloneDb } from "./IModelDb"; import { IModelHostOptions } from "./IModelHost"; /** * Options for [[IpcHost.startup]] * @public */ export interface IpcHostOpts { iModelHost?: IModelHostOptions; ipcHost?: { /** The Ipc socket to use for communications with frontend. Allows undefined only for headless tests. */ socket?: IpcSocketBackend; /** don't send stack information on exceptions */ exceptions?: { noStack?: boolean; }; }; } /** * Used by applications that have a dedicated backend. IpcHosts may send messages to their corresponding IpcApp. * @note if either end terminates, the other must too. * @public */ export declare class IpcHost { static noStack: boolean; private static _ipc; /** Get the implementation of the [IpcSocketBackend]($common) interface. */ private static get ipc(); /** Determine whether Ipc is available for this backend. This will only be true if [[startup]] has been called on this class. */ static get isValid(): boolean; /** * Send a message to the frontend over an Ipc channel. * @param channel the name of the channel matching the name registered with [[IpcApp.addListener]]. * @param data The content of the message. */ static send(channel: string, ...data: any[]): void; /** * Establish a handler for an Ipc channel to receive [[Frontend.invoke]] calls * @param channel The name of the channel for this handler. * @param handler A function that supplies the implementation for `channel` * @note returns A function to call to remove the handler. */ static handle(channel: string, handler: (...args: any[]) => Promise<any>): RemoveFunction; /** * Establish a handler to receive messages sent via [[IpcApp.send]]. * @param channel The name of the channel for the messages. * @param listener A function called when messages are sent over `channel` * @note returns A function to call to remove the listener. */ static addListener(channel: string, listener: IpcListener): RemoveFunction; /** * Remove a previously registered listener * @param channel The name of the channel for the listener previously registered with [[addListener]] * @param listener The function passed to [[addListener]] */ static removeListener(channel: string, listener: IpcListener): void; private static notify; /** @internal */ static notifyIpcFrontend<T extends keyof IpcAppNotifications>(methodName: T, ...args: Parameters<IpcAppNotifications[T]>): void; /** @internal */ static notifyTxns<T extends keyof TxnNotifications>(briefcase: BriefcaseDb | StandaloneDb, methodName: T, ...args: Parameters<TxnNotifications[T]>): void; /** @internal */ static notifyEditingScope<T extends keyof EditingScopeNotifications>(briefcase: BriefcaseDb | StandaloneDb, methodName: T, ...args: Parameters<EditingScopeNotifications[T]>): void; /** * Start the backend of an Ipc app. * @param opt * @note this method calls [[IModelHost.startup]] internally. */ static startup(opt?: IpcHostOpts): Promise<void>; /** Shutdown IpcHost backend. Also calls [[IModelHost.shutdown]] */ static shutdown(): Promise<void>; } /** * Base class for all implementations of an Ipc interface. * * Create a subclass to implement your Ipc interface. Your class should be declared like this: * ```ts * class MyHandler extends IpcHandler implements MyInterface * ``` * to ensure all methods and signatures are correct. * * Then, call `MyClass.register` at startup to connect your class to your channel. * @public */ export declare abstract class IpcHandler { /** * All subclasses *must* implement this method to specify their channel name. * * Channel names are the key that connects Handlers and senders. The channel name of IpcHandlers must exactly match the name used by senders. * By convention, channel names should be prefixed by a *namespace* (e.g. `${appName}/`) * unique enough to disambiguate them from channels for other apps that may be running in the same processes. */ abstract get channelName(): string; /** * Register this class as the handler for methods on its channel. This static method creates a new instance * that becomes the handler and is `this` when its methods are called. * @returns A function that can be called to remove the handler. * @note this method should only be called once per channel. If it is called multiple times, subsequent calls replace the previous ones. */ static register(): RemoveFunction; } /** * Prevents progress callback being called more frequently when provided interval. * @internal */ export declare function throttleProgressCallback(func: ProgressFunction, checkAbort: () => ProgressStatus, progressInterval?: number): ProgressFunction; //# sourceMappingURL=IpcHost.d.ts.map