Skip to content
Open
40 changes: 32 additions & 8 deletions src/core/Param.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class Param {
* Fetch the value of the param.
*
* @param {getCallback} callback - The callback function.
* @param {getFailedCallback} [failedCallback] - The callback function when the service call failed.
* @param {getFailedCallback} [failedCallback] - The callback function when the service call failed or the parameter retrieval was unsuccessful.
*/
get(callback, failedCallback) {
var paramClient = new Service({
Expand All @@ -40,13 +40,17 @@ export default class Param {
serviceType: 'rosapi/GetParam'
});

var request = {name: this.name};
var request = { name: this.name };

paramClient.callService(
request,
function (result) {
var value = JSON.parse(result.value);
callback(value);
if (result.successful === false && failedCallback) {
failedCallback(result.reason);
} else {
var value = JSON.parse(result.value);
callback(value);
}
},
failedCallback
);
Expand All @@ -64,7 +68,7 @@ export default class Param {
*
* @param {Object} value - The value to set param to.
* @param {setParamCallback} [callback] - The callback function.
* @param {setParamFailedCallback} [failedCallback] - The callback function when the service call failed.
* @param {setParamFailedCallback} [failedCallback] - The callback function when the service call failed or the parameter setting was unsuccessful.
*/
set(value, callback, failedCallback) {
var paramClient = new Service({
Expand All @@ -78,13 +82,23 @@ export default class Param {
value: JSON.stringify(value)
};

paramClient.callService(request, callback, failedCallback);
paramClient.callService(
request,
function (result) {
if (result.successful === false && failedCallback) {
failedCallback(result.reason);
} else if (callback) {
callback(result);
}
},
failedCallback
);
}
/**
* Delete this parameter on the ROS server.
*
* @param {setParamCallback} callback - The callback function.
* @param {setParamFailedCallback} [failedCallback] - The callback function when the service call failed.
* @param {setParamFailedCallback} [failedCallback] - The callback function when the service call failed or the parameter deletion was unsuccessful.
*/
delete(callback, failedCallback) {
var paramClient = new Service({
Expand All @@ -97,6 +111,16 @@ export default class Param {
name: this.name
};

paramClient.callService(request, callback, failedCallback);
paramClient.callService(
request,
function (result) {
if (result.successful === false && failedCallback) {
failedCallback(result.reason);
} else if (callback) {
callback(result);
}
},
failedCallback
);
}
}