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,78 +233,114 @@ function VNBClient(socket, authentication) {
}); });
self.sendCommand = function (name, buffer) { /**
* @function sendCommand
}; * Send a command message
* @param {string} name Name of the command
self.callFunction = function (name, buffer) { * @param {number} buffer Name of the buffer
* @param {...string} arguments Parameters of the command
*/
function sendCommand(name, buffer) {
let seqno = currentSeqno; let seqno = currentSeqno;
currentSeqno += 1; 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); socket.pipe(messageTransform);
} }
function NetbeansColor (value) { function color (value) {
"use strict"; "use strict";
this.convert = function() { return value ? value : "none";
return value ? value : "none";
};
} }
function NetbeansBool (value) { function bool (value) {
"use strict"; "use strict";
this.convert = function () { return value ? "T" : "F";
return value ? "T" : "F";
};
} }
function NetbeansPosition (line, col) { function position (line, col) {
"use strict"; "use strict";
this.convert = function () { return line+"/"+col;
return line+"/"+col;
};
} }
function NetbeansString (value) { function string (value) {
"use strict"; "use strict";
this.convert = function () { var buffer = "\"";
var buffer = "\"";
for (var i = 0 ; i < value.length ; ++i){ for (var i = 0 ; i < value.length ; ++i){
switch (value[i]) { switch (value[i]) {
case "\n" : case "\n" :
buffer += "\\n"; buffer += "\\n";
break; break;
case "\t" : case "\t" :
buffer += "\\t"; buffer += "\\t";
break; break;
case "\r" : case "\r" :
buffer += "\\r"; buffer += "\\r";
break; break;
case "\\" : case "\\" :
buffer += "\\\\"; buffer += "\\\\";
break; break;
case "\"" : case "\"" :
buffer += "\\\""; buffer += "\\\"";
break; break;
default : default :
buffer += value[i]; buffer += value[i];
break; break;
}
} }
buffer += "\"";
return buffer;
} }
buffer += "\"";
return buffer;
} }