mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
dispatch error to request callback if callback set
This commit is contained in:
parent
0ca8b090be
commit
c792439cc8
2 changed files with 42 additions and 8 deletions
|
|
@ -111,26 +111,29 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
|
||||||
{
|
{
|
||||||
// call template with input arguments (not including callback which is last argument TODO currently with callback. won't hurt)
|
// call template with input arguments (not including callback which is last argument TODO currently with callback. won't hurt)
|
||||||
//reqPack = reqTemplate.call(args);
|
//reqPack = reqTemplate.call(args);
|
||||||
reqPack = reqTemplate.apply(this, req_proxy.arguments);
|
var reqPack = reqTemplate.apply(this, req_proxy.arguments);
|
||||||
var format = reqPack[0];
|
var format = reqPack[0];
|
||||||
var requestArguments = reqPack[1];
|
var requestArguments = reqPack[1];
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
this.replies[this.seq_num] = [reqName, callback];
|
this.replies[this.seq_num] = [reqName, callback];
|
||||||
|
|
||||||
//console.error([format, requestArguments]);
|
//console.log([format, requestArguments]);
|
||||||
client.pack_stream.pack(format, requestArguments);
|
client.pack_stream.pack(format, requestArguments);
|
||||||
client.pack_stream.flush();
|
client.pack_stream.flush();
|
||||||
} else if (templateType == 'Array'){
|
} else if (templateType == 'Array'){
|
||||||
var format = reqTemplate[0];
|
var format = reqTemplate[0];
|
||||||
var requestArguments = reqTemplate[1];
|
var requestArguments = [];
|
||||||
|
|
||||||
|
for (a = 0; a < reqTemplate[1].length; ++a)
|
||||||
|
requestArguments.push(reqTemplate[1][a]);
|
||||||
for (a in args)
|
for (a in args)
|
||||||
requestArguments.push(args[a]);
|
requestArguments.push(args[a]);
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
this.replies[this.seq_num] = [reqName, callback];
|
this.replies[this.seq_num] = [reqName, callback];
|
||||||
|
|
||||||
//console.error([format, requestArguments]);
|
//console.log([format, requestArguments]);
|
||||||
client.pack_stream.pack(format, requestArguments);
|
client.pack_stream.pack(format, requestArguments);
|
||||||
client.pack_stream.flush();
|
client.pack_stream.flush();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -210,8 +213,14 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
error.minorOpcode = res[1];
|
error.minorOpcode = res[1];
|
||||||
error.majorOpcode = res[2];
|
error.majorOpcode = res[2];
|
||||||
}
|
}
|
||||||
console.log(error);
|
//console.log(error);
|
||||||
//client.emit('error', error);
|
var handler = client.replies[seq_num];
|
||||||
|
if (handler) {
|
||||||
|
var callback = handler[1];
|
||||||
|
callback(error);
|
||||||
|
delete client.replies[seq_num];
|
||||||
|
} else
|
||||||
|
client.emit('error', error);
|
||||||
client.expectReplyHeader();
|
client.expectReplyHeader();
|
||||||
} );
|
} );
|
||||||
return;
|
return;
|
||||||
|
|
@ -244,8 +253,8 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
var result = unpack( data );
|
var result = unpack( data );
|
||||||
var callback = handler[1];
|
var callback = handler[1];
|
||||||
callback(result);
|
callback(result);
|
||||||
|
delete client.replies[seq_num];
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for new packet from server
|
// wait for new packet from server
|
||||||
client.expectReplyHeader();
|
client.expectReplyHeader();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
25
test/xlsatoms.js
Normal file
25
test/xlsatoms.js
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
var x11 = require('../lib/x11');
|
||||||
|
|
||||||
|
var xclient = x11.createClient();
|
||||||
|
var atomId = 10;
|
||||||
|
xclient.on('connect', function(display) {
|
||||||
|
var X = this;
|
||||||
|
function listAtoms()
|
||||||
|
{
|
||||||
|
function getAtom(a)
|
||||||
|
{
|
||||||
|
X.GetAtomName(a, function(str) {
|
||||||
|
if (typeof str != 'string') // 'Bad atom' error
|
||||||
|
{
|
||||||
|
X.terminate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(a + ' ' + str);
|
||||||
|
listAtoms();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
getAtom(atomId);
|
||||||
|
atomId++;
|
||||||
|
}
|
||||||
|
listAtoms();
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue