@lakutata/dbus 2.3.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +253 -25
- package/dist/cjs/adapters/DBusEntrypoint.d.ts +89 -0
- package/dist/cjs/adapters/DBusEntrypoint.js +280 -0
- package/dist/cjs/channel/DBusChannel.d.ts +36 -0
- package/dist/cjs/channel/DBusChannel.js +70 -0
- package/dist/cjs/components/DBusClientComponent.d.ts +494 -0
- package/dist/cjs/components/DBusClientComponent.js +272 -0
- package/dist/cjs/components/DBusObjectManager.d.ts +164 -0
- package/dist/cjs/components/DBusObjectManager.js +200 -0
- package/dist/cjs/context/DBusContext.d.ts +52 -0
- package/dist/cjs/context/DBusContext.js +68 -0
- package/dist/cjs/decorators/DBusInterface.d.ts +74 -0
- package/dist/cjs/decorators/DBusInterface.js +63 -0
- package/dist/cjs/decorators/DBusMethod.d.ts +115 -0
- package/dist/cjs/decorators/DBusMethod.js +20 -0
- package/dist/cjs/exports/DBus.d.ts +11 -0
- package/dist/cjs/exports/DBus.js +42 -0
- package/dist/cjs/lib/DBusClientOptions.d.ts +30 -0
- package/dist/cjs/lib/Declarations.d.ts +187 -0
- package/dist/cjs/lib/Declarations.js +113 -0
- package/dist/cjs/lib/Names.d.ts +35 -0
- package/dist/cjs/lib/Names.js +80 -0
- package/dist/cjs/lib/Signature.d.ts +14 -0
- package/dist/cjs/lib/Signature.js +53 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/DBusContextParams.d.ts +22 -0
- package/dist/cjs/types/DBusContextParams.js +2 -0
- package/dist/esm/adapters/DBusEntrypoint.js +274 -0
- package/dist/esm/channel/DBusChannel.js +67 -0
- package/dist/esm/components/DBusClientComponent.js +267 -0
- package/dist/esm/components/DBusObjectManager.js +197 -0
- package/dist/esm/context/DBusContext.js +64 -0
- package/dist/esm/decorators/DBusInterface.js +60 -0
- package/dist/esm/decorators/DBusMethod.js +17 -0
- package/dist/esm/exports/DBus.js +12 -0
- package/dist/esm/lib/DBusClientOptions.js +1 -0
- package/dist/esm/lib/Declarations.js +107 -0
- package/dist/esm/lib/Names.js +73 -0
- package/dist/esm/lib/Signature.js +49 -0
- package/dist/esm/types/DBusContextParams.js +1 -0
- package/dist/types/adapters/DBusEntrypoint.d.ts +89 -0
- package/dist/types/channel/DBusChannel.d.ts +36 -0
- package/dist/types/components/DBusClientComponent.d.ts +494 -0
- package/dist/types/components/DBusObjectManager.d.ts +164 -0
- package/dist/types/context/DBusContext.d.ts +52 -0
- package/dist/types/decorators/DBusInterface.d.ts +74 -0
- package/dist/types/decorators/DBusMethod.d.ts +115 -0
- package/dist/types/exports/DBus.d.ts +11 -0
- package/dist/types/lib/DBusClientOptions.d.ts +30 -0
- package/dist/types/lib/Declarations.d.ts +187 -0
- package/dist/types/lib/Names.d.ts +35 -0
- package/dist/types/lib/Signature.d.ts +14 -0
- package/dist/types/types/DBusContextParams.d.ts +22 -0
- package/package.json +38 -39
- package/CHANGELOG.md +0 -145
- package/dist/CommonExports.d.ts +0 -2
- package/dist/CommonExports.d.ts.map +0 -1
- package/dist/CommonExports.js +0 -44
- package/dist/ComponentExports.d.ts +0 -2
- package/dist/ComponentExports.d.ts.map +0 -1
- package/dist/ComponentExports.js +0 -5
- package/dist/ProviderExports.d.ts +0 -2
- package/dist/ProviderExports.d.ts.map +0 -1
- package/dist/ProviderExports.js +0 -5
- package/dist/components/DBusClientComponent.d.ts +0 -75
- package/dist/components/DBusClientComponent.d.ts.map +0 -1
- package/dist/components/DBusClientComponent.js +0 -125
- package/dist/interfaces/DBusClientOptions.d.ts +0 -7
- package/dist/interfaces/DBusClientOptions.d.ts.map +0 -1
- package/dist/providers/DBusClientProvider.d.ts +0 -75
- package/dist/providers/DBusClientProvider.d.ts.map +0 -1
- package/dist/providers/DBusClientProvider.js +0 -125
- package/dist/tests/DBusTest.spec.d.ts +0 -2
- package/dist/tests/DBusTest.spec.d.ts.map +0 -1
- package/dist/tests/DBusTest.spec.js +0 -26
- package/dist/tests/Test.d.ts +0 -9
- package/dist/tests/Test.d.ts.map +0 -1
- package/dist/tests/Test.js +0 -80
- package/tsconfig.json +0 -7
- /package/dist/{interfaces → cjs/lib}/DBusClientOptions.js +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { EntrypointAdapter, MiddlewareDefinition } from '@lakutata/entrypoint';
|
|
2
|
+
import { DBusContext } from '../context/DBusContext.js';
|
|
3
|
+
/**
|
|
4
|
+
* The options of {@link dbusEntrypoint}: the bus to connect to, and the service name to own on it.
|
|
5
|
+
*/
|
|
6
|
+
export type DBusEntrypointOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The adapter's name, which tells it apart from the entrypoint's other adapters.
|
|
9
|
+
* @default undefined
|
|
10
|
+
*/
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The bus to connect to: `'session'` (the address in `DBUS_SESSION_BUS_ADDRESS`), `'system'` (the address in
|
|
14
|
+
* `DBUS_SYSTEM_BUS_ADDRESS`, else `unix:path=/var/run/dbus/system_bus_socket`), the address of a bus
|
|
15
|
+
* (`'unix:path=/run/my-bus.sock'`, `'tcp:host=127.0.0.1,port=5555'`), or the path of the socket of a private bus.
|
|
16
|
+
* The adapter fails to start when the bus cannot be reached (for `'session'`, also when `DBUS_SESSION_BUS_ADDRESS`
|
|
17
|
+
* is not set).
|
|
18
|
+
* @default 'session'
|
|
19
|
+
*/
|
|
20
|
+
bus?: 'session' | 'system' | string;
|
|
21
|
+
/**
|
|
22
|
+
* The well-known name the service owns on the bus (`'com.example.DeviceService'`): two or more elements separated by
|
|
23
|
+
* dots. The clients address the service by it, and it prefixes the names of the D-Bus errors. On the system bus,
|
|
24
|
+
* the bus policy (`/etc/dbus-1/system.d/`) must allow the process to own it.
|
|
25
|
+
*/
|
|
26
|
+
service: string;
|
|
27
|
+
/**
|
|
28
|
+
* Take the name from its current owner when that owner allowed it to be replaced (`allowReplacement`). Without it,
|
|
29
|
+
* the adapter fails to start when another connection owns the name; the request is never queued.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
replaceExisting?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Let another connection take the name with `replaceExisting`. The adapter is not stopped when the name is taken:
|
|
35
|
+
* the clients reach the new owner.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
allowReplacement?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The middlewares of this adapter's method calls, run after the entrypoint's global middlewares.
|
|
41
|
+
* @default []
|
|
42
|
+
*/
|
|
43
|
+
middlewares?: MiddlewareDefinition[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Build the D-Bus adapter of the entrypoint (its `dbus` option): the application owns a service name on a bus and
|
|
47
|
+
* serves the controllers declared with `@DBusInterface` as the interfaces of its objects, their `@DBusMethod` actions
|
|
48
|
+
* as the methods. The objects of the paths without variables are exported when the adapter starts, until it stops
|
|
49
|
+
* ({@link DBusObjectManager.removeObject} does not remove them); the objects of the path templates are exported when
|
|
50
|
+
* they are added with {@link DBusObjectManager.addObject}, before or after the start.
|
|
51
|
+
*
|
|
52
|
+
* Starting connects to the bus and requests the name. The adapter stops gracefully with the entrypoint: it releases the
|
|
53
|
+
* name (no new call reaches it), the calls in progress end, then the connection closes. It needs a D-Bus daemon, as on
|
|
54
|
+
* Linux: the system bus, a session bus, or a private `dbus-daemon`.
|
|
55
|
+
* @param options The bus, the service name and how it is owned, the adapter's middlewares.
|
|
56
|
+
* @returns The adapter, to give to the `dbus` option of `buildEntrypoints()`.
|
|
57
|
+
* @throws {TypeError} At once, when the service name is invalid; when the adapter starts, when an action declared with
|
|
58
|
+
* `@DBusMethod` belongs to a controller without `@DBusInterface`.
|
|
59
|
+
* @throws {Error} When the adapter starts, if the bus cannot be reached, or if another connection owns the name
|
|
60
|
+
* (`The DBus name … is owned by another service`): the entrypoint fails to start.
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import {Application} from 'lakutata'
|
|
64
|
+
* import {buildEntrypoints, Controller} from 'lakutata/com/entrypoint'
|
|
65
|
+
* import {dbusEntrypoint, DBusInterface, DBusMethod} from '@lakutata/dbus'
|
|
66
|
+
*
|
|
67
|
+
* @DBusInterface('com.example.Manager', {path: '/com/example/Manager'})
|
|
68
|
+
* class ManagerController extends Controller {
|
|
69
|
+
* @DBusMethod('Ping', {returns: 's'})
|
|
70
|
+
* public async ping(): Promise<string> {
|
|
71
|
+
* return 'pong'
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* //busctl --system call com.example.DeviceService /com/example/Manager com.example.Manager Ping
|
|
76
|
+
* Application.run(() => ({
|
|
77
|
+
* id: 'devices.app',
|
|
78
|
+
* name: 'Devices',
|
|
79
|
+
* components: {
|
|
80
|
+
* entrypoint: buildEntrypoints({
|
|
81
|
+
* controllers: [ManagerController],
|
|
82
|
+
* dbus: dbusEntrypoint({bus: 'system', service: 'com.example.DeviceService'})
|
|
83
|
+
* })
|
|
84
|
+
* },
|
|
85
|
+
* bootstrap: ['entrypoint']
|
|
86
|
+
* }))
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function dbusEntrypoint(options: DBusEntrypointOptions): EntrypointAdapter<DBusContext>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type EntrypointAdapter } from '@lakutata/entrypoint';
|
|
2
|
+
import { type ChannelDefinition } from '@lakutata/entrypoint/channel';
|
|
3
|
+
import { DBusContext } from '../context/DBusContext.js';
|
|
4
|
+
declare module '@lakutata/entrypoint' {
|
|
5
|
+
interface EntrypointOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The D-Bus adapters, built by `dbusEntrypoint()`: one, or several for several buses or service names.
|
|
8
|
+
* @default undefined (no D-Bus adapter)
|
|
9
|
+
*/
|
|
10
|
+
dbus?: EntrypointAdapter<DBusContext> | EntrypointAdapter<DBusContext>[];
|
|
11
|
+
}
|
|
12
|
+
interface PrefixOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The object path (or path template) and the interface of a controller's D-Bus methods. `@DBusInterface` sets
|
|
15
|
+
* it; an application does not set it itself.
|
|
16
|
+
*/
|
|
17
|
+
dbus?: {
|
|
18
|
+
/**
|
|
19
|
+
* The object path, or path template, of the methods.
|
|
20
|
+
*/
|
|
21
|
+
path?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The name of the methods' interface.
|
|
24
|
+
*/
|
|
25
|
+
interface?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The definition of the D-Bus channel of the entrypoint, named `dbus`: its actions are the methods of D-Bus interfaces,
|
|
31
|
+
* addressed by `{member, interface, path}` (the method name from `@DBusMethod`, the interface and the path template from
|
|
32
|
+
* `@DBusInterface`). A call matches an action by its interface, its method and its object path; a call matching none
|
|
33
|
+
* fails with `ControllerActionNotFoundException`. `@DBusMethod` and {@link dbusEntrypoint} use it: an application only
|
|
34
|
+
* needs it to write an adapter of its own.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DBusChannel: ChannelDefinition;
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { BusNameBasicInfo, DBus, DBusInterface, DBusMessage, DBusObject, DBusService, DBusSignalEmitter, type DecodeOpts, InvokeOpts } from 'dbus-sdk';
|
|
2
|
+
import { Component, type ComponentOptionsBuilder } from '@lakutata/core';
|
|
3
|
+
import type { DBusClientOptions } from '../lib/DBusClientOptions.js';
|
|
4
|
+
/**
|
|
5
|
+
* Build the declaration of a {@link DBusClientComponent} for the `components` of an application or a module, from its
|
|
6
|
+
* typed options.
|
|
7
|
+
* @param options The bus address and the connection options.
|
|
8
|
+
* @returns The declaration: the options with `class: DBusClientComponent`.
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {Application} from 'lakutata'
|
|
12
|
+
* import {buildDBusClientOptions, DBusClientComponent} from '@lakutata/dbus'
|
|
13
|
+
*
|
|
14
|
+
* Application
|
|
15
|
+
* .run(() => ({
|
|
16
|
+
* id: 'client.app',
|
|
17
|
+
* name: 'Client',
|
|
18
|
+
* components: {
|
|
19
|
+
* dbus: buildDBusClientOptions({busAddress: 'unix:path=/var/run/dbus/system_bus_socket', timeout: 5000})
|
|
20
|
+
* }
|
|
21
|
+
* }))
|
|
22
|
+
* .onLaunched(async (app: Application): Promise<void> => {
|
|
23
|
+
* const dbus: DBusClientComponent = await app.getObject('dbus')
|
|
24
|
+
* console.log(await dbus.listNames())
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const buildDBusClientOptions: ComponentOptionsBuilder<DBusClientOptions>;
|
|
29
|
+
/**
|
|
30
|
+
* A D-Bus client: a connection to a bus, to call the services on it, read their objects, properties and introspection,
|
|
31
|
+
* and listen to their signals. Declare it in the `components` of an application with {@link buildDBusClientOptions}
|
|
32
|
+
* (or `{class: DBusClientComponent, busAddress: …}`) and get it with `getObject()` or `@Inject`; it is a singleton
|
|
33
|
+
* component. It connects when it is created, so a bus that cannot be reached fails its creation; it disconnects when it
|
|
34
|
+
* is destroyed (the application stopping). It is a thin layer over the `DBus` connection of `dbus-sdk`, whose classes
|
|
35
|
+
* (`DBusService`, `DBusObject`, `DBusRemoteInterface`…) its methods return.
|
|
36
|
+
*
|
|
37
|
+
* Its `on`, `once`, `off` and `removeListener` listen to the connection's events (`'nameOwnerChanged'`,
|
|
38
|
+
* `'connectionClose'`…), not to events of the component.
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import {Application} from 'lakutata'
|
|
42
|
+
* import {DBusClientComponent, type DBusRemoteInterface} from '@lakutata/dbus'
|
|
43
|
+
*
|
|
44
|
+
* Application
|
|
45
|
+
* .run(() => ({
|
|
46
|
+
* id: 'client.app',
|
|
47
|
+
* name: 'Client',
|
|
48
|
+
* components: {
|
|
49
|
+
* dbus: {class: DBusClientComponent, busAddress: 'unix:path=/var/run/dbus/system_bus_socket'}
|
|
50
|
+
* }
|
|
51
|
+
* }))
|
|
52
|
+
* .onLaunched(async (app: Application): Promise<void> => {
|
|
53
|
+
* const dbus: DBusClientComponent = await app.getObject('dbus')
|
|
54
|
+
* //A method call: the output arguments, as an array
|
|
55
|
+
* const [owner] = await dbus.invoke({
|
|
56
|
+
* service: 'org.freedesktop.DBus',
|
|
57
|
+
* objectPath: '/org/freedesktop/DBus',
|
|
58
|
+
* interface: 'org.freedesktop.DBus',
|
|
59
|
+
* method: 'GetNameOwner',
|
|
60
|
+
* signature: 's',
|
|
61
|
+
* args: ['org.freedesktop.DBus']
|
|
62
|
+
* })
|
|
63
|
+
* console.log(owner)
|
|
64
|
+
* //An interface, from the introspection of its object: its methods, properties and signals
|
|
65
|
+
* const device: DBusRemoteInterface = await dbus.interface('com.example.DeviceService', '/com/example/Devices/A1', 'com.example.Device')
|
|
66
|
+
* console.log(await device.method.Status({sn: 'A1'}))
|
|
67
|
+
* console.log(await device.property.State.get())
|
|
68
|
+
* device.signal.on('Changed', (data: unknown): void => console.log(data))
|
|
69
|
+
* dbus.on('nameOwnerChanged', (name: string, oldOwner: string, newOwner: string): void => console.log(name, oldOwner, newOwner))
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare class DBusClientComponent extends Component {
|
|
74
|
+
/**
|
|
75
|
+
* The address of the bus: `'unix:path=/var/run/dbus/system_bus_socket'` (the system bus),
|
|
76
|
+
* `'unix:path=/run/user/1000/bus'`, `'tcp:host=127.0.0.1,port=5555'`; the value of `DBUS_SESSION_BUS_ADDRESS` for
|
|
77
|
+
* the session bus. Required.
|
|
78
|
+
*/
|
|
79
|
+
protected readonly busAddress: string;
|
|
80
|
+
/**
|
|
81
|
+
* How long the connection to the bus may take, in milliseconds (a positive integer); the creation of the component
|
|
82
|
+
* fails after it.
|
|
83
|
+
* @default 20000 (dbus-sdk's default)
|
|
84
|
+
*/
|
|
85
|
+
protected readonly timeout: number;
|
|
86
|
+
/**
|
|
87
|
+
* How long a call may wait for its reply, in milliseconds (a positive integer); a call's own `timeout` overrides it.
|
|
88
|
+
* @default dbus-sdk's default
|
|
89
|
+
*/
|
|
90
|
+
protected readonly callTimeout: number;
|
|
91
|
+
/**
|
|
92
|
+
* How the replies and the signals are decoded (`DecodeOpts` of `dbus-sdk`): `types` (`'none'`, `'variants'`,
|
|
93
|
+
* `'all'`: where the values keep their D-Bus types as typed values), `dictionaries` (`'object'` or `'map'`),
|
|
94
|
+
* `int64` (`'number'` or `'bigint'`). A call's own `decode` overrides it.
|
|
95
|
+
* @default {int64: 'number'} (the 64-bit integers as numbers when they are safe integers, else bigints)
|
|
96
|
+
*/
|
|
97
|
+
protected readonly decode: DecodeOpts;
|
|
98
|
+
/**
|
|
99
|
+
* The `dbus-sdk` connection to the bus, open from the component's creation to its destruction; the subclasses use
|
|
100
|
+
* it for what the component's methods do not cover.
|
|
101
|
+
*/
|
|
102
|
+
protected dbus: DBus;
|
|
103
|
+
/**
|
|
104
|
+
* The unique name the bus gave this connection (`':1.42'`).
|
|
105
|
+
*/
|
|
106
|
+
get uniqueName(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Connect to the bus, when the component is created.
|
|
109
|
+
* @throws {Error} When the bus cannot be reached, or the authentication fails.
|
|
110
|
+
*/
|
|
111
|
+
protected init(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Disconnect from the bus, when the component is destroyed.
|
|
114
|
+
*/
|
|
115
|
+
protected destroy(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Call a method without waiting for its reply (the call is flagged as expecting none): its errors are not reported.
|
|
118
|
+
* @param opts The service, the object path, the interface and the method to call, with the signature and the
|
|
119
|
+
* arguments of the call, and `noReply: true`.
|
|
120
|
+
* @throws {Error} An `InvalidValueError` or a `SignatureError` of `dbus-sdk` when the arguments do not fit the
|
|
121
|
+
* signature.
|
|
122
|
+
*/
|
|
123
|
+
invoke(opts: InvokeOpts & {
|
|
124
|
+
noReply: true;
|
|
125
|
+
}): void;
|
|
126
|
+
/**
|
|
127
|
+
* Call a method and wait for its reply.
|
|
128
|
+
* @param opts The service, the object path, the interface and the method to call, with the signature (`'sa{sv}'`)
|
|
129
|
+
* and the arguments of the call; its `timeout` and `decode` override the component's.
|
|
130
|
+
* @returns The output arguments of the method, in order (an empty array for a method returning nothing).
|
|
131
|
+
* @throws {Error} When the method replies with a D-Bus error (its name and message), the call times out, the
|
|
132
|
+
* arguments do not fit the signature, or the connection closes.
|
|
133
|
+
*/
|
|
134
|
+
invoke(opts: InvokeOpts & {
|
|
135
|
+
noReply?: false;
|
|
136
|
+
}): Promise<any[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Listen to the connection's `'serviceOnline'` event, emitted when a bus name gets an owner (a service comes online):
|
|
139
|
+
* the listener is called every time it is emitted.
|
|
140
|
+
* @param eventName The event, `'serviceOnline'`.
|
|
141
|
+
* @param listener The listener; its arguments: the bus name.
|
|
142
|
+
* @returns The component, for chaining.
|
|
143
|
+
*/
|
|
144
|
+
on(eventName: 'serviceOnline', listener: (name: string) => void): this;
|
|
145
|
+
/**
|
|
146
|
+
* Listen to the connection's `'serviceOffline'` event, emitted when a service name loses its owner (the service goes
|
|
147
|
+
* offline): the listener is called every time it is emitted.
|
|
148
|
+
* @param eventName The event, `'serviceOffline'`.
|
|
149
|
+
* @param listener The listener; its arguments: the bus name.
|
|
150
|
+
* @returns The component, for chaining.
|
|
151
|
+
*/
|
|
152
|
+
on(eventName: 'serviceOffline', listener: (name: string) => void): this;
|
|
153
|
+
/**
|
|
154
|
+
* Listen to the connection's `'serviceReplaced'` event, emitted when the owner of a service name changes from one
|
|
155
|
+
* connection to another: the listener is called every time it is emitted.
|
|
156
|
+
* @param eventName The event, `'serviceReplaced'`.
|
|
157
|
+
* @param listener The listener; its arguments: the bus name.
|
|
158
|
+
* @returns The component, for chaining.
|
|
159
|
+
*/
|
|
160
|
+
on(eventName: 'serviceReplaced', listener: (name: string) => void): this;
|
|
161
|
+
/**
|
|
162
|
+
* Listen to the connection's `'methodCall'` event, emitted when a method call addressed to this connection is
|
|
163
|
+
* received: the listener is called every time it is emitted.
|
|
164
|
+
* @param eventName The event, `'methodCall'`.
|
|
165
|
+
* @param listener The listener; its arguments: the message of the call.
|
|
166
|
+
* @returns The component, for chaining.
|
|
167
|
+
*/
|
|
168
|
+
on(eventName: 'methodCall', listener: (message: DBusMessage) => void): this;
|
|
169
|
+
/**
|
|
170
|
+
* Listen to the connection's `'nameOwnerChanged'` event, emitted when the bus announces that the owner of a name
|
|
171
|
+
* changed (an empty owner means none): the listener is called every time it is emitted.
|
|
172
|
+
* @param eventName The event, `'nameOwnerChanged'`.
|
|
173
|
+
* @param listener The listener; its arguments: the name, its previous owner and its new owner (unique names).
|
|
174
|
+
* @returns The component, for chaining.
|
|
175
|
+
*/
|
|
176
|
+
on(eventName: 'nameOwnerChanged', listener: (name: string, oldOwner: string, newOwner: string) => void): this;
|
|
177
|
+
/**
|
|
178
|
+
* Listen to the connection's `'nameLost'` event, emitted when this connection loses a name it owned: the listener is
|
|
179
|
+
* called every time it is emitted.
|
|
180
|
+
* @param eventName The event, `'nameLost'`.
|
|
181
|
+
* @param listener The listener; its arguments: the name lost.
|
|
182
|
+
* @returns The component, for chaining.
|
|
183
|
+
*/
|
|
184
|
+
on(eventName: 'nameLost', listener: (name: string) => void): this;
|
|
185
|
+
/**
|
|
186
|
+
* Listen to the connection's `'nameAcquired'` event, emitted when this connection acquires a name (its unique name
|
|
187
|
+
* at least, when it connects): the listener is called every time it is emitted.
|
|
188
|
+
* @param eventName The event, `'nameAcquired'`.
|
|
189
|
+
* @param listener The listener; its arguments: the name acquired.
|
|
190
|
+
* @returns The component, for chaining.
|
|
191
|
+
*/
|
|
192
|
+
on(eventName: 'nameAcquired', listener: (name: string) => void): this;
|
|
193
|
+
/**
|
|
194
|
+
* Listen to the connection's `'connectionClose'` event, emitted when the connection to the bus closes: the listener
|
|
195
|
+
* is called every time it is emitted.
|
|
196
|
+
* @param eventName The event, `'connectionClose'`.
|
|
197
|
+
* @param listener The listener, called with no argument.
|
|
198
|
+
* @returns The component, for chaining.
|
|
199
|
+
*/
|
|
200
|
+
on(eventName: 'connectionClose', listener: () => void): this;
|
|
201
|
+
/**
|
|
202
|
+
* Listen to the connection's `'connectionError'` event, emitted when an error occurs on the connection to the bus:
|
|
203
|
+
* the listener is called every time it is emitted.
|
|
204
|
+
* @param eventName The event, `'connectionError'`.
|
|
205
|
+
* @param listener The listener; its arguments: the error.
|
|
206
|
+
* @returns The component, for chaining.
|
|
207
|
+
*/
|
|
208
|
+
on(eventName: 'connectionError', listener: (error: Error) => void): this;
|
|
209
|
+
/**
|
|
210
|
+
* Listen once to the connection's `'serviceOnline'` event, emitted when a service name gets an owner (the service comes
|
|
211
|
+
* online): the listener is called the next time it is emitted.
|
|
212
|
+
* @param eventName The event, `'serviceOnline'`.
|
|
213
|
+
* @param listener The listener; its arguments: the bus name.
|
|
214
|
+
* @returns The component, for chaining.
|
|
215
|
+
*/
|
|
216
|
+
once(eventName: 'serviceOnline', listener: (name: string) => void): this;
|
|
217
|
+
/**
|
|
218
|
+
* Listen once to the connection's `'serviceOffline'` event, emitted when a service name loses its owner (the service goes
|
|
219
|
+
* offline): the listener is called the next time it is emitted.
|
|
220
|
+
* @param eventName The event, `'serviceOffline'`.
|
|
221
|
+
* @param listener The listener; its arguments: the bus name.
|
|
222
|
+
* @returns The component, for chaining.
|
|
223
|
+
*/
|
|
224
|
+
once(eventName: 'serviceOffline', listener: (name: string) => void): this;
|
|
225
|
+
/**
|
|
226
|
+
* Listen once to the connection's `'serviceReplaced'` event, emitted when the owner of a service name changes from one
|
|
227
|
+
* connection to another: the listener is called the next time it is emitted.
|
|
228
|
+
* @param eventName The event, `'serviceReplaced'`.
|
|
229
|
+
* @param listener The listener; its arguments: the bus name.
|
|
230
|
+
* @returns The component, for chaining.
|
|
231
|
+
*/
|
|
232
|
+
once(eventName: 'serviceReplaced', listener: (name: string) => void): this;
|
|
233
|
+
/**
|
|
234
|
+
* Listen once to the connection's `'methodCall'` event, emitted when a method call addressed to this connection is
|
|
235
|
+
* received: the listener is called the next time it is emitted.
|
|
236
|
+
* @param eventName The event, `'methodCall'`.
|
|
237
|
+
* @param listener The listener; its arguments: the message of the call.
|
|
238
|
+
* @returns The component, for chaining.
|
|
239
|
+
*/
|
|
240
|
+
once(eventName: 'methodCall', listener: (message: DBusMessage) => void): this;
|
|
241
|
+
/**
|
|
242
|
+
* Listen once to the connection's `'nameOwnerChanged'` event, emitted when the bus announces that the owner of a
|
|
243
|
+
* name changed (an empty owner means none): the listener is called the next time it is emitted.
|
|
244
|
+
* @param eventName The event, `'nameOwnerChanged'`.
|
|
245
|
+
* @param listener The listener; its arguments: the name, its previous owner and its new owner (unique names).
|
|
246
|
+
* @returns The component, for chaining.
|
|
247
|
+
*/
|
|
248
|
+
once(eventName: 'nameOwnerChanged', listener: (name: string, oldOwner: string, newOwner: string) => void): this;
|
|
249
|
+
/**
|
|
250
|
+
* Listen once to the connection's `'nameLost'` event, emitted when this connection loses a name it owned: the
|
|
251
|
+
* listener is called the next time it is emitted.
|
|
252
|
+
* @param eventName The event, `'nameLost'`.
|
|
253
|
+
* @param listener The listener; its arguments: the name lost.
|
|
254
|
+
* @returns The component, for chaining.
|
|
255
|
+
*/
|
|
256
|
+
once(eventName: 'nameLost', listener: (name: string) => void): this;
|
|
257
|
+
/**
|
|
258
|
+
* Listen once to the connection's `'nameAcquired'` event, emitted when this connection acquires a name (its unique
|
|
259
|
+
* name at least, when it connects): the listener is called the next time it is emitted.
|
|
260
|
+
* @param eventName The event, `'nameAcquired'`.
|
|
261
|
+
* @param listener The listener; its arguments: the name acquired.
|
|
262
|
+
* @returns The component, for chaining.
|
|
263
|
+
*/
|
|
264
|
+
once(eventName: 'nameAcquired', listener: (name: string) => void): this;
|
|
265
|
+
/**
|
|
266
|
+
* Listen once to the connection's `'connectionClose'` event, emitted when the connection to the bus closes: the
|
|
267
|
+
* listener is called the next time it is emitted.
|
|
268
|
+
* @param eventName The event, `'connectionClose'`.
|
|
269
|
+
* @param listener The listener, called with no argument.
|
|
270
|
+
* @returns The component, for chaining.
|
|
271
|
+
*/
|
|
272
|
+
once(eventName: 'connectionClose', listener: () => void): this;
|
|
273
|
+
/**
|
|
274
|
+
* Listen once to the connection's `'connectionError'` event, emitted when an error occurs on the connection to the
|
|
275
|
+
* bus: the listener is called the next time it is emitted.
|
|
276
|
+
* @param eventName The event, `'connectionError'`.
|
|
277
|
+
* @param listener The listener; its arguments: the error.
|
|
278
|
+
* @returns The component, for chaining.
|
|
279
|
+
*/
|
|
280
|
+
once(eventName: 'connectionError', listener: (error: Error) => void): this;
|
|
281
|
+
/**
|
|
282
|
+
* Stop listening to the connection's `'serviceOnline'` event: remove a listener added with `on` or `once`.
|
|
283
|
+
* @param eventName The event, `'serviceOnline'`.
|
|
284
|
+
* @param listener The listener to remove, as it was added.
|
|
285
|
+
* @returns The component, for chaining.
|
|
286
|
+
*/
|
|
287
|
+
off(eventName: 'serviceOnline', listener: (name: string) => void): this;
|
|
288
|
+
/**
|
|
289
|
+
* Stop listening to the connection's `'serviceOffline'` event: remove a listener added with `on` or `once`.
|
|
290
|
+
* @param eventName The event, `'serviceOffline'`.
|
|
291
|
+
* @param listener The listener to remove, as it was added.
|
|
292
|
+
* @returns The component, for chaining.
|
|
293
|
+
*/
|
|
294
|
+
off(eventName: 'serviceOffline', listener: (name: string) => void): this;
|
|
295
|
+
/**
|
|
296
|
+
* Stop listening to the connection's `'serviceReplaced'` event: remove a listener added with `on` or `once`.
|
|
297
|
+
* @param eventName The event, `'serviceReplaced'`.
|
|
298
|
+
* @param listener The listener to remove, as it was added.
|
|
299
|
+
* @returns The component, for chaining.
|
|
300
|
+
*/
|
|
301
|
+
off(eventName: 'serviceReplaced', listener: (name: string) => void): this;
|
|
302
|
+
/**
|
|
303
|
+
* Stop listening to the connection's `'methodCall'` event: remove a listener added with `on` or `once`.
|
|
304
|
+
* @param eventName The event, `'methodCall'`.
|
|
305
|
+
* @param listener The listener to remove, as it was added.
|
|
306
|
+
* @returns The component, for chaining.
|
|
307
|
+
*/
|
|
308
|
+
off(eventName: 'methodCall', listener: (message: DBusMessage) => void): this;
|
|
309
|
+
/**
|
|
310
|
+
* Stop listening to the connection's `'nameOwnerChanged'` event: remove a listener added with `on` or `once`.
|
|
311
|
+
* @param eventName The event, `'nameOwnerChanged'`.
|
|
312
|
+
* @param listener The listener to remove, as it was added.
|
|
313
|
+
* @returns The component, for chaining.
|
|
314
|
+
*/
|
|
315
|
+
off(eventName: 'nameOwnerChanged', listener: (name: string, oldOwner: string, newOwner: string) => void): this;
|
|
316
|
+
/**
|
|
317
|
+
* Stop listening to the connection's `'nameLost'` event: remove a listener added with `on` or `once`.
|
|
318
|
+
* @param eventName The event, `'nameLost'`.
|
|
319
|
+
* @param listener The listener to remove, as it was added.
|
|
320
|
+
* @returns The component, for chaining.
|
|
321
|
+
*/
|
|
322
|
+
off(eventName: 'nameLost', listener: (name: string) => void): this;
|
|
323
|
+
/**
|
|
324
|
+
* Stop listening to the connection's `'nameAcquired'` event: remove a listener added with `on` or `once`.
|
|
325
|
+
* @param eventName The event, `'nameAcquired'`.
|
|
326
|
+
* @param listener The listener to remove, as it was added.
|
|
327
|
+
* @returns The component, for chaining.
|
|
328
|
+
*/
|
|
329
|
+
off(eventName: 'nameAcquired', listener: (name: string) => void): this;
|
|
330
|
+
/**
|
|
331
|
+
* Stop listening to the connection's `'connectionClose'` event: remove a listener added with `on` or `once`.
|
|
332
|
+
* @param eventName The event, `'connectionClose'`.
|
|
333
|
+
* @param listener The listener to remove, as it was added.
|
|
334
|
+
* @returns The component, for chaining.
|
|
335
|
+
*/
|
|
336
|
+
off(eventName: 'connectionClose', listener: () => void): this;
|
|
337
|
+
/**
|
|
338
|
+
* Stop listening to the connection's `'connectionError'` event: remove a listener added with `on` or `once`.
|
|
339
|
+
* @param eventName The event, `'connectionError'`.
|
|
340
|
+
* @param listener The listener to remove, as it was added.
|
|
341
|
+
* @returns The component, for chaining.
|
|
342
|
+
*/
|
|
343
|
+
off(eventName: 'connectionError', listener: (error: Error) => void): this;
|
|
344
|
+
/**
|
|
345
|
+
* Stop listening to the connection's `'serviceOnline'` event: remove a listener added with `on` or `once`.
|
|
346
|
+
* @param eventName The event, `'serviceOnline'`.
|
|
347
|
+
* @param listener The listener to remove, as it was added.
|
|
348
|
+
* @returns The component, for chaining (same as `off`).
|
|
349
|
+
*/
|
|
350
|
+
removeListener(eventName: 'serviceOnline', listener: (name: string) => void): this;
|
|
351
|
+
/**
|
|
352
|
+
* Stop listening to the connection's `'serviceOffline'` event: remove a listener added with `on` or `once`.
|
|
353
|
+
* @param eventName The event, `'serviceOffline'`.
|
|
354
|
+
* @param listener The listener to remove, as it was added.
|
|
355
|
+
* @returns The component, for chaining (same as `off`).
|
|
356
|
+
*/
|
|
357
|
+
removeListener(eventName: 'serviceOffline', listener: (name: string) => void): this;
|
|
358
|
+
/**
|
|
359
|
+
* Stop listening to the connection's `'serviceReplaced'` event: remove a listener added with `on` or `once`.
|
|
360
|
+
* @param eventName The event, `'serviceReplaced'`.
|
|
361
|
+
* @param listener The listener to remove, as it was added.
|
|
362
|
+
* @returns The component, for chaining (same as `off`).
|
|
363
|
+
*/
|
|
364
|
+
removeListener(eventName: 'serviceReplaced', listener: (name: string) => void): this;
|
|
365
|
+
/**
|
|
366
|
+
* Stop listening to the connection's `'methodCall'` event: remove a listener added with `on` or `once`.
|
|
367
|
+
* @param eventName The event, `'methodCall'`.
|
|
368
|
+
* @param listener The listener to remove, as it was added.
|
|
369
|
+
* @returns The component, for chaining (same as `off`).
|
|
370
|
+
*/
|
|
371
|
+
removeListener(eventName: 'methodCall', listener: (message: DBusMessage) => void): this;
|
|
372
|
+
/**
|
|
373
|
+
* Stop listening to the connection's `'nameOwnerChanged'` event: remove a listener added with `on` or `once`.
|
|
374
|
+
* @param eventName The event, `'nameOwnerChanged'`.
|
|
375
|
+
* @param listener The listener to remove, as it was added.
|
|
376
|
+
* @returns The component, for chaining (same as `off`).
|
|
377
|
+
*/
|
|
378
|
+
removeListener(eventName: 'nameOwnerChanged', listener: (name: string, oldOwner: string, newOwner: string) => void): this;
|
|
379
|
+
/**
|
|
380
|
+
* Stop listening to the connection's `'nameLost'` event: remove a listener added with `on` or `once`.
|
|
381
|
+
* @param eventName The event, `'nameLost'`.
|
|
382
|
+
* @param listener The listener to remove, as it was added.
|
|
383
|
+
* @returns The component, for chaining (same as `off`).
|
|
384
|
+
*/
|
|
385
|
+
removeListener(eventName: 'nameLost', listener: (name: string) => void): this;
|
|
386
|
+
/**
|
|
387
|
+
* Stop listening to the connection's `'nameAcquired'` event: remove a listener added with `on` or `once`.
|
|
388
|
+
* @param eventName The event, `'nameAcquired'`.
|
|
389
|
+
* @param listener The listener to remove, as it was added.
|
|
390
|
+
* @returns The component, for chaining (same as `off`).
|
|
391
|
+
*/
|
|
392
|
+
removeListener(eventName: 'nameAcquired', listener: (name: string) => void): this;
|
|
393
|
+
/**
|
|
394
|
+
* Stop listening to the connection's `'connectionClose'` event: remove a listener added with `on` or `once`.
|
|
395
|
+
* @param eventName The event, `'connectionClose'`.
|
|
396
|
+
* @param listener The listener to remove, as it was added.
|
|
397
|
+
* @returns The component, for chaining (same as `off`).
|
|
398
|
+
*/
|
|
399
|
+
removeListener(eventName: 'connectionClose', listener: () => void): this;
|
|
400
|
+
/**
|
|
401
|
+
* Stop listening to the connection's `'connectionError'` event: remove a listener added with `on` or `once`.
|
|
402
|
+
* @param eventName The event, `'connectionError'`.
|
|
403
|
+
* @param listener The listener to remove, as it was added.
|
|
404
|
+
* @returns The component, for chaining (same as `off`).
|
|
405
|
+
*/
|
|
406
|
+
removeListener(eventName: 'connectionError', listener: (error: Error) => void): this;
|
|
407
|
+
/**
|
|
408
|
+
* Ask the bus to route the messages matching a rule to this connection, without waiting for the bus's answer (the
|
|
409
|
+
* signal emitters of {@link interface} and {@link interfaceSignal} add their own rules).
|
|
410
|
+
* @param rule The match rule (`"type='signal',interface='com.example.Device'"`).
|
|
411
|
+
*/
|
|
412
|
+
addMatch(rule: string): void;
|
|
413
|
+
/**
|
|
414
|
+
* Remove a match rule added with {@link addMatch}, without waiting for the bus's answer.
|
|
415
|
+
* @param rule The match rule, as it was added.
|
|
416
|
+
*/
|
|
417
|
+
removeMatch(rule: string): void;
|
|
418
|
+
/**
|
|
419
|
+
* Get the connection owning a name.
|
|
420
|
+
* @param name The bus name (`'com.example.DeviceService'`).
|
|
421
|
+
* @returns The unique name of its owner (`':1.42'`), or `undefined` when nobody owns it or the query fails.
|
|
422
|
+
*/
|
|
423
|
+
getNameOwner(name: string): Promise<string | undefined>;
|
|
424
|
+
/**
|
|
425
|
+
* List the names the bus can start a service for (D-Bus activation), running or not.
|
|
426
|
+
* @returns The names.
|
|
427
|
+
*/
|
|
428
|
+
listActivatableNames(): Promise<string[]>;
|
|
429
|
+
/**
|
|
430
|
+
* List the names owned on the bus now: the well-known names and the unique names of the connections.
|
|
431
|
+
* @returns The names.
|
|
432
|
+
*/
|
|
433
|
+
listNames(): Promise<string[]>;
|
|
434
|
+
/**
|
|
435
|
+
* Tell whether a name is owned on the bus now.
|
|
436
|
+
* @param name The bus name.
|
|
437
|
+
* @returns `true` when a connection owns it.
|
|
438
|
+
*/
|
|
439
|
+
nameHasOwner(name: string): Promise<boolean>;
|
|
440
|
+
/**
|
|
441
|
+
* List the names of the bus, owned or activatable, with their owner, whether they are active or activatable, and the
|
|
442
|
+
* process id of their owner.
|
|
443
|
+
* @returns The names and their details.
|
|
444
|
+
*/
|
|
445
|
+
listBusNames(): Promise<BusNameBasicInfo[]>;
|
|
446
|
+
/**
|
|
447
|
+
* List the services of the bus: its well-known names (the unique names `:1.42` left out), with their details.
|
|
448
|
+
* @returns The services and their details.
|
|
449
|
+
*/
|
|
450
|
+
listServices(): Promise<BusNameBasicInfo[]>;
|
|
451
|
+
/**
|
|
452
|
+
* Get the services of the bus which are running, to browse their objects (the activatable services which are not
|
|
453
|
+
* running are left out, not started: get one with {@link service} to start it).
|
|
454
|
+
* @returns The services.
|
|
455
|
+
*/
|
|
456
|
+
services(): Promise<DBusService[]>;
|
|
457
|
+
/**
|
|
458
|
+
* Get a service, starting it when it is activatable and not running.
|
|
459
|
+
* @param service The service's well-known name (`'org.freedesktop.NetworkManager'`).
|
|
460
|
+
* @returns The service.
|
|
461
|
+
* @throws {Error} A `ServiceNotFoundError` of `dbus-sdk` when the name is neither owned nor activatable.
|
|
462
|
+
*/
|
|
463
|
+
service(service: string): Promise<DBusService>;
|
|
464
|
+
/**
|
|
465
|
+
* Get an object of a service, to read its introspection and its interfaces.
|
|
466
|
+
* @param service The service's well-known name.
|
|
467
|
+
* @param objectPath The object path (`'/org/freedesktop/NetworkManager'`).
|
|
468
|
+
* @returns The object.
|
|
469
|
+
* @throws {Error} A `ServiceNotFoundError` of `dbus-sdk` when the service is neither running nor activatable.
|
|
470
|
+
*/
|
|
471
|
+
object(service: string, objectPath: string): Promise<DBusObject>;
|
|
472
|
+
/**
|
|
473
|
+
* Get an interface of an object, built from the object's introspection: its methods (`method.Name(...args)`, or
|
|
474
|
+
* `noReplyMethod`), its properties (`property.Name.get()`, `.set(value)`) and its signals (`signal.on('Name', …)`).
|
|
475
|
+
* @param service The service's well-known name.
|
|
476
|
+
* @param objectPath The object path.
|
|
477
|
+
* @param iface The interface name (`'org.freedesktop.NetworkManager'`).
|
|
478
|
+
* @returns The interface.
|
|
479
|
+
* @throws {Error} When the service is not found, or the object does not implement the interface
|
|
480
|
+
* (`InterfaceNotFoundError` of `dbus-sdk`).
|
|
481
|
+
*/
|
|
482
|
+
interface(service: string, objectPath: string, iface: string): Promise<DBusInterface>;
|
|
483
|
+
/**
|
|
484
|
+
* Get the signals of an interface of an object: an event emitter emitting each signal under its name, with its
|
|
485
|
+
* arguments.
|
|
486
|
+
* @param service The service's well-known name.
|
|
487
|
+
* @param objectPath The object path.
|
|
488
|
+
* @param iface The interface name.
|
|
489
|
+
* @returns The emitter of the interface's signals.
|
|
490
|
+
* @throws {Error} When the service is not found, or the object does not implement the interface
|
|
491
|
+
* (`InterfaceNotFoundError` of `dbus-sdk`).
|
|
492
|
+
*/
|
|
493
|
+
interfaceSignal(service: string, objectPath: string, iface: string): Promise<DBusSignalEmitter>;
|
|
494
|
+
}
|