Skip to content

Commit

Permalink
sendSignal helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sidorares committed Jan 18, 2013
1 parent 52cf001 commit 33decd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
37 changes: 26 additions & 11 deletions lib/bus.js
Expand Up @@ -53,6 +53,21 @@ module.exports = function bus(conn) {
return JSON.stringify(obj);
};

this.sendSignal = function(path, iface, name, signature, args) {
var signalMsg = {
type: constants.messageType.signal,
serial: self.serial,
'interface': iface,
path: path,
member: name
};
if (signature) {
signalMsg.signature = signature;
signalMsg.body = args;
}
self.connection.message(signalMsg);
}

this.sendError = function(msg, errorName, errorText) {
var reply = {
type: constants.messageType.error,
Expand Down Expand Up @@ -102,15 +117,13 @@ module.exports = function bus(conn) {
self.signals.emit(self.mangle(msg), msg.body, msg.signature);
} else { // methodCall

//console.log(msg);
//console.log(JSON.stringify(self.exportedObjects, null, 4));
// exported interfaces handlers

if (stdDbusIfaces(msg, self))
return;

var obj, iface, impl;
if (obj = self.exportedObjects[msg.path]) {

if (stdDbusIfaces(msg, self))
return;

if (iface = obj[msg['interface']]) {
// now we are ready to serve msg.member
impl = iface[1];
Expand Down Expand Up @@ -143,8 +156,7 @@ module.exports = function bus(conn) {
console.error('Interface ' + msg['interface'] + ' is not supported');
// TODO: respond with standard dbus error
}
}

}
// setMethodCall handlers
handler = self.methodCallHandlers[self.mangle(msg)];
if (handler) {
Expand All @@ -153,8 +165,8 @@ module.exports = function bus(conn) {
result = handler[0].apply(null, msg.body);
} catch (e) {
console.error("Caught exception while trying to execute handler: ", e);
throw e;
// TODO: send error reply to bus
self.sendError(e.message, e.description);
return;
}
var reply = {
type: constants.messageType.methodReturn,
Expand All @@ -164,10 +176,13 @@ module.exports = function bus(conn) {
};
if (result) {
reply.signature = handler[1];
reply.body = [result];
reply.body = result;
}
self.connection.message(reply);
} else {
self.sendError(msg, 'org.freedesktop.DBus.Error.UnknownService', 'Uh oh oh');
}

}
});

Expand Down
2 changes: 0 additions & 2 deletions lib/unmarshall.js
Expand Up @@ -169,8 +169,6 @@ function readSimpleType(bs, t, callback)
});
*/
return bs.buffer('buff', 4).tap(function(vars) {
console.log(vars);
console.log(vars.buff.length);
var param = vars.buff.readInt32LE(0);
callback(null, param);
});
Expand Down

0 comments on commit 33decd8

Please sign in to comment.