Base for sending function and command messages
This commit is contained in:
@@ -233,78 +233,114 @@ 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";
|
||||
};
|
||||
return value ? value : "none";
|
||||
}
|
||||
|
||||
function NetbeansBool (value) {
|
||||
function bool (value) {
|
||||
"use strict";
|
||||
|
||||
this.convert = function () {
|
||||
return value ? "T" : "F";
|
||||
};
|
||||
return value ? "T" : "F";
|
||||
}
|
||||
|
||||
function NetbeansPosition (line, col) {
|
||||
function position (line, col) {
|
||||
"use strict";
|
||||
|
||||
this.convert = function () {
|
||||
return line+"/"+col;
|
||||
};
|
||||
return line+"/"+col;
|
||||
}
|
||||
|
||||
function NetbeansString (value) {
|
||||
function string (value) {
|
||||
"use strict";
|
||||
|
||||
this.convert = function () {
|
||||
var buffer = "\"";
|
||||
var buffer = "\"";
|
||||
|
||||
for (var i = 0 ; i < value.length ; ++i){
|
||||
switch (value[i]) {
|
||||
case "\n" :
|
||||
buffer += "\\n";
|
||||
break;
|
||||
case "\t" :
|
||||
buffer += "\\t";
|
||||
break;
|
||||
case "\r" :
|
||||
buffer += "\\r";
|
||||
break;
|
||||
case "\\" :
|
||||
buffer += "\\\\";
|
||||
break;
|
||||
case "\"" :
|
||||
buffer += "\\\"";
|
||||
break;
|
||||
default :
|
||||
buffer += value[i];
|
||||
break;
|
||||
for (var i = 0 ; i < value.length ; ++i){
|
||||
switch (value[i]) {
|
||||
case "\n" :
|
||||
buffer += "\\n";
|
||||
break;
|
||||
case "\t" :
|
||||
buffer += "\\t";
|
||||
break;
|
||||
case "\r" :
|
||||
buffer += "\\r";
|
||||
break;
|
||||
case "\\" :
|
||||
buffer += "\\\\";
|
||||
break;
|
||||
case "\"" :
|
||||
buffer += "\\\"";
|
||||
break;
|
||||
default :
|
||||
buffer += value[i];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
buffer += "\"";
|
||||
return buffer;
|
||||
}
|
||||
|
||||
buffer += "\"";
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user