- Added dbus typings (#35481)

This commit is contained in:
Luca Adrian L
2019-05-15 09:00:07 -07:00
committed by Nathan Shively-Sanders
parent 3492c0644a
commit dbe44d6d01
4 changed files with 95 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import * as DBus from "dbus";
const dbus = DBus.getBus("system");
dbus.getInterface("org.bluez", "/org/bluez/hci0", "org.bluez.Media1", (err, iface) => {});
dbus.getInterface("org.bluez", "/org/bluez/hci0", "org.bluez.Adapter1", (err, iface) => {
if (!err) {
iface.setProperty("Powered", true, err => {});
}
});
dbus.disconnect();
const agentPath = "/test/my/agent";
const agentService = DBus.registerService("system", agentPath.split("/").slice(1).join("."));
const agentObj = agentService.createObject(agentPath);
const agentIface = agentObj.createInterface("org.bluez.Agent1");
agentIface.addMethod("Release", {in: "", out: ""}, () => {});
+52
View File
@@ -0,0 +1,52 @@
// Type definitions for dbus 1.0
// Project: https://github.com/Shouqun/node-dbus#readme
// Definitions by: Luca Lindhorst <https://github.com/lal12>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export type busType = "session"|"system";
export function getBus(type: busType): DBusConnection;
export function registerService(busName: busType, serviceName: string): DBusService;
export interface DBusConnection {
getInterface(serviceName: string, objectPath: string, interfaceName: string, callback: (err: DBusError, iface: DBusInterface) => void): void;
disconnect(): void;
}
export interface DBusInterface {
getProperty(name: string, callback: (err: DBusError, name: string) => void): void;
setProperty(name: string, value: any, callback: (err: DBusError) => void): void;
getProperties(callback: (err: DBusError, properties: Array<{[name: string]: any}>) => void): void;
/**
* ...args
* options: {timeout: number}
* callback: (err: DBusError|undefined, res: any)=>void
*/
[methodName: string]: (...args: any[]) => void;
}
export interface DBusService {
createObject(path: string): DBusServiceObject;
removeObject(service: DBusServiceObject): void;
disconnect(): void;
}
export interface DBusServiceObject {
createInterface(name: string): DBusServiceInterface;
}
export type PropsCB = (err: DBusError|undefined, value: any) => void;
export interface DBusServiceInterface {
addMethod(method: string, opts: {in: string, out: string}, handler: (name: string, quality: any, callback: (res: any) => void) => void): void;
addProperty(name: string, opts: {
type: string,
getter: (cb: (val: string) => void) => void,
setter?: (value: any, done: () => void) => void
}): void;
addSignal(name: string, opts: {types: string[]}): void;
emitSignal(name: string, ...values: any[]): void;
update(): void;
}
export class DBusError extends Error {
readonly dbusName: string;
constructor(name: string, message: string);
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"dbus-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }