Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fail callback and missing docstrings to params #357

Merged
22 changes: 14 additions & 8 deletions src/core/Param.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ function Param(options) {
*
* @param {function} callback - Function with the following params:
* @param {Object} callback.value - The value of the param from ROS.
* @param {function} [failedCallback] - Function when the service call failed with the following params:
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Param.prototype.get = function(callback) {
Param.prototype.get = function(callback, failedCallback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/get_param',
Expand All @@ -40,16 +42,18 @@ Param.prototype.get = function(callback) {
paramClient.callService(request, function(result) {
var value = JSON.parse(result.value);
callback(value);
});
}, failedCallback);
};

/**
* Set the value of the param in ROS.
*
* @param {Object} value - The value to set param to.
* @param {function} callback - The callback function.
* @param {function} [callback] - The callback function.
* @param {function} [failedCallback] - The callback function when the service call failed.
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Param.prototype.set = function(value, callback) {
Param.prototype.set = function(value, callback, failedCallback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/set_param',
Expand All @@ -61,15 +65,17 @@ Param.prototype.set = function(value, callback) {
value : JSON.stringify(value)
});

paramClient.callService(request, callback);
paramClient.callService(request, callback, failedCallback);
};

/**
* Delete this parameter on the ROS server.
*
* @param {function} callback - The callback function.
* @param {function} [callback] - The callback function when the service call succeeded.
* @param {function} [failedCallback] - The callback function when the service call failed.
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Param.prototype.delete = function(callback) {
Param.prototype.delete = function(callback, failedCallback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/delete_param',
Expand All @@ -80,7 +86,7 @@ Param.prototype.delete = function(callback) {
name : this.name
});

paramClient.callService(request, callback);
paramClient.callService(request, callback, failedCallback);
};

module.exports = Param;