dbus-sdk
Version:
A Node.js SDK for interacting with DBus, enabling seamless service calling and exposure with TypeScript support
175 lines • 7.95 kB
TypeScript
import EventEmitter from 'node:events';
import { CreateSignalEmitterOpts } from '../types/CreateSignalEmitterOpts';
/**
* A class that extends Node.js EventEmitter to handle DBus signal emissions.
* Manages signal listeners and emitters for a specific DBus service, object path, and interface.
* Supports wildcard '*' for unique name, object path, and interface to handle multiple sources.
*/
export declare class DBusSignalEmitter extends EventEmitter {
#private;
/**
* A handler function to be called when a signal is registered or emitted.
* Used to notify external systems about signal subscriptions or emissions.
*/
protected readonly onSignalHandler: (service: string | '*', objectPath: string | '*', interfaceName: string | '*', signalName: string | '*') => void;
/**
* The service name associated with this emitter.
* This is a public readonly property, though it is not initialized in the provided code.
* Likely set elsewhere or intended for future use.
*/
readonly service: string;
/**
* Getter for the unique name of the DBus connection or wildcard '*'.
*
* @returns The unique name or '*' if wildcard is used.
*/
get uniqueName(): string | '*';
/**
* Getter for the object path or wildcard '*'.
*
* @returns The object path or '*' if wildcard is used.
*/
get objectPath(): string | '*';
/**
* Getter for the interface name or wildcard '*'.
*
* @returns The interface name or '*' if wildcard is used.
*/
get interface(): string | '*';
/**
* Constructor for DBusSignalEmitter.
* Initializes the emitter with options and a handler for signal events.
*
* @param opts - Options for creating the signal emitter, including uniqueName, objectPath, and interface.
* @param signalEmitters - A set of all DBusSignalEmitter instances to manage active emitters.
* @param onSignalHandler - A callback function invoked when signals are registered or updated.
*/
constructor(opts: CreateSignalEmitterOpts, signalEmitters: Set<DBusSignalEmitter>, onSignalHandler: (service: string | '*', objectPath: string | '*', interfaceName: string | '*', signalName: string | '*') => void);
/**
* Updates the unique name of the emitter if it is not set to wildcard '*'.
* Notifies the signal handler for each registered event with the updated unique name.
*
* @param newUniqueName - The new unique name to set for this emitter.
*/
protected updateUniqueName(newUniqueName: string): void;
/**
* Updates the set of signal emitters based on whether this emitter has active events.
* Removes this emitter from the set if no events are registered, or adds it if events exist.
*/
protected updateSignalEmitters(): void;
/**
* Adds a listener for the specified event (signal name) and notifies the signal handler.
* Overrides EventEmitter's addListener to include DBus-specific logic.
*
* @param eventName - The name of the event (signal) to listen for.
* @param listener - The callback function to execute when the event is emitted.
* @returns This instance for method chaining.
*/
addListener(eventName: string, listener: (...args: any[]) => void): this;
/**
* Emits an event (signal) with the provided arguments and updates the signal emitters set.
* Overrides EventEmitter's emit to include DBus-specific logic.
*
* @param eventName - The name of the event (signal) to emit.
* @param args - Arguments to pass to the event listeners.
* @returns True if the event had listeners, false otherwise.
*/
emit(eventName: string, ...args: any[]): boolean;
/**
* Returns an array of event names (signal names) for which this emitter has listeners.
*
* @returns An array of event names as strings.
*/
eventNames(): string[];
/**
* Returns the maximum number of listeners allowed for any event.
*
* @returns The maximum number of listeners.
*/
getMaxListeners(): number;
/**
* Returns the number of listeners for a specific event.
*
* @param eventName - The name of the event to check.
* @param listener - Optional specific listener function to count.
* @returns The number of listeners for the event.
*/
listenerCount(eventName: string, listener?: (...args: any[]) => void): number;
/**
* Returns an array of listener functions for a specific event.
*
* @param eventName - The name of the event to retrieve listeners for.
* @returns An array of listener functions.
*/
listeners(eventName: string): Function[];
/**
* Removes a specific listener for an event and updates the signal emitters set.
*
* @param eventName - The name of the event.
* @param listener - The listener function to remove.
* @returns This instance for method chaining.
*/
off(eventName: string, listener: (...args: any[]) => void): this;
/**
* Adds a listener for an event and notifies the signal handler.
*
* @param eventName - The name of the event (signal) to listen for.
* @param listener - The callback function to execute when the event is emitted.
* @returns This instance for method chaining.
*/
on(eventName: string, listener: (...args: any[]) => void): this;
/**
* Adds a one-time listener for an event and notifies the signal handler.
*
* @param eventName - The name of the event (signal) to listen for.
* @param listener - The callback function to execute once when the event is emitted.
* @returns This instance for method chaining.
*/
once(eventName: string, listener: (...args: any[]) => void): this;
/**
* Adds a listener to the beginning of the listeners array for an event and notifies the signal handler.
*
* @param eventName - The name of the event (signal) to listen for.
* @param listener - The callback function to execute when the event is emitted.
* @returns This instance for method chaining.
*/
prependListener(eventName: string, listener: (...args: any[]) => void): this;
/**
* Adds a one-time listener to the beginning of the listeners array for an event and notifies the signal handler.
*
* @param eventName - The name of the event (signal) to listen for.
* @param listener - The callback function to execute once when the event is emitted.
* @returns This instance for method chaining.
*/
prependOnceListener(eventName: string, listener: (...args: any[]) => void): this;
/**
* Returns an array of raw listener functions for a specific event (including wrappers like 'once').
*
* @param eventName - The name of the event to retrieve listeners for.
* @returns An array of raw listener functions.
*/
rawListeners(eventName: string): Function[];
/**
* Removes all listeners for an event (or all events if no event name is provided) and updates the signal emitters set.
*
* @param eventName - Optional name of the event to remove listeners for.
* @returns This instance for method chaining.
*/
removeAllListeners(eventName?: string): this;
/**
* Removes a specific listener for an event and updates the signal emitters set.
*
* @param eventName - The name of the event.
* @param listener - The listener function to remove.
* @returns This instance for method chaining.
*/
removeListener(eventName: string, listener: (...args: any[]) => void): this;
/**
* Sets the maximum number of listeners allowed for any event.
*
* @param n - The maximum number of listeners to set.
* @returns This instance for method chaining.
*/
setMaxListeners(n: number): this;
}
//# sourceMappingURL=DBusSignalEmitter.d.ts.map