Use Node.js in your end devices(QQ: 796448809)
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();
}
);
serviceName
{String} the service name.objectPath
{String} the object path.interfaceName
{String} the interface name.cb
{Function} the callback when the interface is loaded.Gets the interface with specified service, object and name.
channel
{String} the channel to register, “session” or “system”.name
{String} the service name.register the servie with specified name, it returns an Service
object.
The class Service
is used to create the ServiceInterface
instance.
objectPath
{String} the object path.Creates the object under this
service.
name
{String} the interface name.Creates the interface, it returns an ServiceInterface
instance.
name
{String} the method name.opts
{Object} the method options.
opts.in
{Array} the arguments of this method.opts.out
{Array} the returns of this method.handler
{Function} the handler for this method.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');
});
}
);
name
{String} the signal name.opts
{Object} the signal options.
opts.types
{Array} the arguments of this signal.Add the named signal.
Emits the added signal.