ShadowNode

Use Node.js in your end devices(QQ: 796448809)

View the Project on GitHub yodaos-project/ShadowNode

DBus

DBus is the module for IPC.

Example

var dbus = require('dbus').getBus('session');

dbus.getInterface(
  'org.an.service-name', 
  '/path/to/object', 
  'ifaceName', 
  function(err, iface) {
    iface.someMethod();
  }
);

getInterface(serviceName, objectPath, interfaceName, cb)

Gets the interface with specified service, object and name.

registerService(channel, name)

register the servie with specified name, it returns an Service object.

Class: Service

The class Service is used to create the ServiceInterface instance.

createObject(objectPath)

Creates the object under this service.

createInterface(name)

Creates the interface, it returns an ServiceInterface instance.

Class: ServiceInterface

addMethod(name, opts, handler)

Adds an method to the interface, to start a D-Bus service and add a method:

var dbus = require('dbus');
var service = dbus.registerService('session', 'org.myservice');
var object = service.createObject('/rokid/myservice');
var iface = object.createInterface('rokid.myservice.iface0');

iface.addMethod('ping', { in: [], out: ['s'] }, function(cb) {
  cb(null, 'pong');
});

And then we are able to ping this service in another script:

var assert = require('assert');
var dbus = require('dbus').getBus('session');
dbus.getInterface(
  'org.myservice', 
  '/rokid/myservice', 
  'rokid.myservice.iface0', 
  function onResponse(err, iface) {
    iface.ping(function(err, data) {
      assert.equal(data, 'pong');
    });
  }
);

addSignal(name, opts)

Add the named signal.

emit(name, data)

Emits the added signal.