Base for sending function and command messages

This commit is contained in:
2014-11-01 00:03:37 +01:00
parent ec03419e7d
commit 5a37474988

View File

@@ -233,49 +233,86 @@ function VNBClient(socket, authentication) {
});
self.sendCommand = function (name, buffer) {
};
self.callFunction = function (name, buffer) {
/**
* @function sendCommand
* Send a command message
* @param {string} name Name of the command
* @param {number} buffer Name of the buffer
* @param {...string} arguments Parameters of the command
*/
function sendCommand(name, buffer) {
let seqno = currentSeqno;
currentSeqno += 1;
socket.write()
var data = buffer + ":" + name + ":" + seqno;
};
for (var i = 2 ; i < arguments.length ; ++i) {
data += " " + arguments[i];
}
data += "\n";
socket.write(data);
}
/**
* @function callFunction
* Send a function message
* @param {string} name Name of the function
* @param {number} buffer ID of the buffer
* @param {...string} arguments Parameters of the function. Use the string, bool, color and position function
* of the method to convert javascript types to string
* @param {function} callback Callback function called with reply value
* */
function callFunction (name, buffer) {
let seqno = currentSeqno;
currentSeqno += 1;
var lastArg = arguments.length - 1;
//If the function is called with a callback (wich should always be the case)
//add the calback to the map so it's fired when the reply is received
if (typeof(arguments[lastArg]) === "function") {
callbacks[currentSeqno] = arguments[lastArg];
lastArg -= 1;
}
var data = buffer + ":" + name + "/" + seqno;
for (var i = 2 ; i < lastArg ; ++i) {
data += " " + arguments[i];
}
data += "\n";
socket.write(data);
}
socket.pipe(messageTransform);
}
function NetbeansColor (value) {
function color (value) {
"use strict";
this.convert = function() {
return value ? value : "none";
};
}
function NetbeansBool (value) {
function bool (value) {
"use strict";
this.convert = function () {
return value ? "T" : "F";
};
}
function NetbeansPosition (line, col) {
function position (line, col) {
"use strict";
this.convert = function () {
return line+"/"+col;
};
}
function NetbeansString (value) {
function string (value) {
"use strict";
this.convert = function () {
var buffer = "\"";
for (var i = 0 ; i < value.length ; ++i){
@@ -304,7 +341,6 @@ function NetbeansString (value) {
buffer += "\"";
return buffer;
}
}