diff --git a/types/dbus/dbus-tests.ts b/types/dbus/dbus-tests.ts new file mode 100644 index 0000000000..c596d70181 --- /dev/null +++ b/types/dbus/dbus-tests.ts @@ -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: ""}, () => {}); diff --git a/types/dbus/index.d.ts b/types/dbus/index.d.ts new file mode 100644 index 0000000000..9ab46ec092 --- /dev/null +++ b/types/dbus/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for dbus 1.0 +// Project: https://github.com/Shouqun/node-dbus#readme +// Definitions by: Luca Lindhorst +// 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); +} diff --git a/types/dbus/tsconfig.json b/types/dbus/tsconfig.json new file mode 100644 index 0000000000..a665d1081d --- /dev/null +++ b/types/dbus/tsconfig.json @@ -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" + ] +} diff --git a/types/dbus/tslint.json b/types/dbus/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dbus/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }