UNPKG

dbus-sdk

Version:

A Node.js SDK for interacting with DBus, enabling seamless service calling and exposure with TypeScript support

153 lines 7.77 kB
import { LocalInterface } from './LocalInterface'; import { DBus } from './DBus'; import { LocalService } from './LocalService'; import { IntrospectNode } from './types/IntrospectNode'; import { IntrospectableInterface } from './lib/common/IntrospectableInterface'; import { PropertiesInterface } from './lib/common/PropertiesInterface'; import { PeerInterface } from './lib/common/PeerInterface'; import { DBusSignedValue } from './lib/DBusSignedValue'; /** * A class representing a local DBus object. * This class manages a collection of interfaces associated with a specific object path * within a local DBus service. It provides methods to add, remove, and query interfaces, * as well as to access standard DBus interfaces like Properties and Introspectable. * It serves as a container for interfaces under a unique object path. */ export declare class LocalObject { #private; /** * The LocalService instance associated with this object, if any. * Links the object to a specific service within a DBus connection for context. */ service: LocalService | undefined; /** * Getter for the DBus instance associated with this object's service. * Provides access to the DBus connection for operations like signal emission. * * @returns The DBus instance if the service is defined, otherwise undefined. */ get dbus(): DBus | undefined; /** * Getter for the name (object path) of this local object. * Returns the validated object path set during construction. * * @returns The object path as a string (e.g., '/org/example/Object'). */ get name(): string; /** * Getter for the Properties interface associated with this object. * Provides access to the standard 'org.freedesktop.DBus.Properties' interface * for handling property-related operations across all interfaces on this object. * * @returns The PropertiesInterface instance for handling property-related operations. */ get propertiesInterface(): PropertiesInterface; /** * Getter for the Introspectable interface associated with this object. * Provides access to the standard 'org.freedesktop.DBus.Introspectable' interface * for handling introspection operations to describe the object's structure. * * @returns The IntrospectableInterface instance for handling introspection operations. */ get introspectableInterface(): IntrospectableInterface; /** * Getter for the Peer interface associated with this object. * Provides access to the standard 'org.freedesktop.DBus.Peer' interface * for handling peer-related operations like ping and machine ID retrieval. * * @returns The PeerInterface instance for handling peer-related operations. */ get peerInterface(): PeerInterface; /** * Constructor for LocalObject. * Initializes the object with a validated object path and adds standard DBus interfaces * (Properties, Introspectable, and Peer) for compliance with DBus conventions. * * @param objectPath - The DBus object path to be validated and set (e.g., '/org/example/Object'). * @throws {LocalObjectInvalidNameError} If the provided object path does not meet DBus naming criteria. */ constructor(objectPath: string); /** * Validates a DBus object path based on DBus naming rules. * Ensures the path is a non-empty string, within length limits, starts with a slash, * does not end with a slash (except for root path '/'), avoids consecutive slashes, * and uses only allowed characters (letters, digits, underscores) in each element. * * @param objectPath - The path to validate. * @returns The validated object path if it passes all checks. * @throws {LocalObjectInvalidNameError} If the path does not meet DBus naming criteria. */ protected validateDBusObjectPath(objectPath: string | any): string; /** * Sets the LocalService associated with this object. * Links the object to a specific service within a DBus connection for context during operations. * * @param service - The LocalService to associate with this object, or undefined to clear the association. * @returns The instance of this LocalObject for method chaining. */ setService(service: LocalService | undefined): this; /** * Getter for the introspection data of this object. * Provides metadata about all interfaces associated with this object for DBus introspection. * * @returns An IntrospectNode object containing the introspection data for all interfaces associated with this object. */ get introspectNode(): IntrospectNode; /** * Adds a LocalInterface to this object. * Associates the interface with this object, linking it to the object's context, * and notifies the service's object manager of the addition if applicable. * * @param localInterface - The LocalInterface instance to add to this object. * @returns A boolean indicating whether the interface was successfully added (true if added, false if already present). * @throws {LocalInterfaceExistsError} If an interface with the same name already exists and is not the same instance. */ addInterface(localInterface: LocalInterface): boolean; /** * Removes a LocalInterface from this object by name. * Unlinks the interface from the object and notifies the service's object manager of the removal. * * @param interfaceName - The name of the interface to remove. * @returns A boolean indicating whether the interface was successfully removed (true if removed, false if not found). */ removeInterface(interfaceName: string): boolean; /** * Removes a LocalInterface from this object by instance. * Unlinks the interface from the object and notifies the service's object manager of the removal. * * @param localInterface - The LocalInterface instance to remove. * @returns A boolean indicating whether the interface was successfully removed (true if removed, false if not found). */ removeInterface(localInterface: LocalInterface): boolean; /** * Lists all interfaces associated with this object. * Provides a convenient way to inspect all interfaces currently linked to the object. * * @returns A record mapping interface names to their LocalInterface instances. */ listInterfaces(): Record<string, LocalInterface>; /** * Lists the names of all interfaces associated with this object. * Provides a quick way to retrieve just the names of the interfaces for enumeration. * * @returns An array of interface names as strings. */ interfaceNames(): string[]; /** * Finds a LocalInterface by its name. * Allows retrieval of a specific interface with type casting for specialized interface types. * * @param name - The name of the interface to find (e.g., 'org.example.MyInterface'). * @returns The LocalInterface instance of the specified type if found, otherwise undefined. * @template T - The type of LocalInterface to cast the result to (defaults to LocalInterface). */ findInterfaceByName<T extends LocalInterface = LocalInterface>(name: string): T | undefined; /** * Gets all managed interfaces and their properties as a record. * Retrieves the current properties of all interfaces on this object as DBusSignedValue instances. * * @returns A record mapping interface names to their property records (property name to DBusSignedValue). */ getManagedInterfaces(): Record<string, Record<string, DBusSignedValue>>; } //# sourceMappingURL=LocalObject.d.ts.map