public
Description: Mozilla bindings for dbus
Home | Edit | New

API

MozJS D-Bus

This page describes the MozJS D-BUS API. For usage information, see Home.

DBUS object

This is a global singleton instance, not a prototype (i.e., you do not need to
instantiate this object).

Properties

systemBus

Returns a DBusConnection for the system bus.

var bus = DBUS.systemBus;

sessionBus

Returns a DBusConnection for the sesssion (current login) bus.

var bus = DBUS.sessionBus;

h2(#DBusConnection). DBusConnection type

Instances of this type are returned by the DBUS.systemBus/DBUS.sessionBus
properties. New instances of this type should not be created by hand.

Methods

getObject(serviceName, objectPath, interface)

Return a local proxy for the given remote object.

var bus = DBUS.systemBus; var notify = bus.getObject(“org.freedesktop.Notifications”, “/org/freedesktop/Notifications”, “org.freedesktop.Notifications”);
Parameters

serviceName

Name of the service that owns the object.

objectPath

The object path of the desired object.

interface

The desired interface on the remote object.

Return Value

A DBusProxyObject representing the remote object.

addNameAddedHandler(serviceName, callback)

Register a function to be called when the specified name appears on the bus.

var bus = DBUS.sessionBus; bus.addNameAddedHandler(‘org.gnome.Banshee’, function () { alert(‘Banshee is now available!’); });
Parameters

serviceName

Name of the service to watch for.

callback

A javascript function to be called when the service appears.

removeNameAddedHandler(serviceName)

Not yet documented.

addNameRemovedHandler(serviceName, callback)

Register a function to be called when the specified name disappears from the bus.

var bus = DBUS.sessionBus; bus.addNameRemovedHandler(‘org.gnome.Banshee’, function () { alert(‘Banshee is no longer available!’); });
Parameters

serviceName

Name of the service to watch for.

callback

A javascript function to be called when the service is lost.

removeNameRemovedHandler(serviceName)

Not yet documented.

h4(#requestService). requestService(serviceName)

Request a new name (a new service) on the bus. For more information, see “Creating Services” on the Home page.

var bus = DBUS.sessionBus; var service = bus.requestService(‘net.extremeboredom.TestService’);
Parameters

serviceName

Name of the service to request.

Return Value

A new DBusService object representing the newly obtained service.

h4(#disconnectFromSignal). disconnectFromSignal(signalId)

Unregisters a signal callback that was previously registered using DBusProxyObject.connectToSignal.

Parameters

signalId

The id of the signal/callback, returned by DBusProxyObject.connectToSignal.

h2(#DBusProxyObject). DBusProxyObject type

Methods

h4(#connectToSignal). connectToSignal(signalName, handler)

Registers a Javascript function to be called when a DBus signal is emitted.

var bus = DBUS.systemBus; var notify = bus.getObject(“org.freedesktop.Notifications”, “/org/freedesktop/Notifications”, “org.freedesktop.Notifications”); notify.connectToSignal(‘NotificationClosed’, function (id, reason) { alert(‘Notification popup closed!’); });
Parameters

signalName

Name of the signal to connect to.

handler

A Javascript function to be called when the signal is emitted.

Return Value

id

Unique ID representing this callback/handler. Used by DBUS.disconnectFromSignal so callbacks can be unregistered.

callMethod(methodName,[args])

Calls a method by name on the remote object asynchronously (if a callback function is specified) or synchronously (if callback is null).

var bus = DBUS.sessionBus; var obj = bus.getObject(‘org.freedesktop.DBus’, ‘/org/freedesktop/DBus’, ‘org.freedesktop.DBus’); var names = obj.callMethod(‘ListNames’);

Parameters

methodName

Name of the method to call.

args

An array of arguments that the remote method should be called with.

callback (optional)
A javascript function to be called when the result of the method call has been
received. If this is null, callMethod will block until
a response is received, and return the result.

Return Value

If callback is specified, returns null. Otherwise,
returns the result of the remote method call.

h2(#DBusService). DBusService

Represents a custom service on the bus. Returned by DBusConnection.requestService, should not be created manually.

Methods

h4(#exportObject). exportObject(objectPath, object)

Adds a new object (represented by a DBusObject) to this service, and makes it available on the bus.

var testObj = new DBusObject(); // Define interfaces/methods/signals/etc. on testObj. var bus = DBUS.sessionBus(); var service = bus.requestService(‘net.extremeboredom.TestService’); service.exportObject(‘/Test’, testObj);
Parameters

objectPath

Desired object path (relative to service object path) of new object.

object

Object to export. Must be a DBusObject.

h2(#DBusObject). DBusObject type

Methods

defineInterface

Defines a new interface on the object.

var testObj = new DBusObject(); var iface = testObj.defineInterface(“net.extremeboredom.TestInterface”); // XXX: Define methods and signals on iface. var bus = DBUS.getSessionBus(); var service = bus.requestService(‘net.extremeboredom.TestService’); service.exportObject(‘/Test’, testObj);
Parameters

name

Name of the new interface.

Return Value

A new DBusInterface object.

h2(#DBusInterface). DBusInterface type

Methods

defineMethod(name, inSignature, outSignature, func)

Defines a new method on the interface.

var testObj = new DBusObject(); var iface = testObj.defineInterface(“net.extremeboredom.TestInterface”); iface.defineMethod(‘sum’, ‘ii’, ‘i’, function(first, second) { return first+second; }); var bus = DBUS.getSessionBus(); var service = bus.requestService(‘net.extremeboredom.TestService’); service.exportObject(‘/Test’, testObj);
Parameters

name

Name of the new method.

inSignature

DBus method signature string representing the method arguments. See here for details.

outSignature

DBus method signature string representing the method return value. See here for details.

func

The javascript function that should be called when this method is called.

defineSignal(name, signature)

Defines a new signal on the interface.

var testObj = new DBusObject(); var iface = testObj.defineInterface(“net.extremeboredom.TestInterface”); iface.defineSignal(‘somethingHappen’, ‘ssi’); var bus = DBUS.getSessionBus(); var service = bus.requestService(‘net.extremeboredom.TestService’); service.exportObject(‘/Test’, testObj);
Parameters

name

Name of the new signal.

signature

DBus method signature string representing the signal arguments. See here for details.

emitSignal(name, [arg1, arg2, …])

Emits a signal that was defined previously using defineSignal. Can only be called after the object containing this interface has been exported (DBusService.exportObject).

var testObj = new DBusObject(); var iface = testObj.defineInterface(“net.extremeboredom.TestInterface”); iface.defineSignal(‘somethingHappen’, ‘ssi’); var bus = DBUS.getSessionBus(); var service = bus.requestService(‘net.extremeboredom.TestService’); service.exportObject(‘/Test’, testObj); // Then, later… iface.emitSignal(‘somethingHappen’, ‘foo’, ‘bar’, 42);
Parameters

name

Name of the signal to emit.

arg1, arg2, ...

Arbitrary number of arguments to emit the signal with. Types must match signal signature in order.

Last edited by FireRabbit, Sun Sep 21 20:39:02 -0700 2008
Home | Edit | New
Versions: