From 43ebcd1a419d1cb4bc78076331a42ea81c6cb551 Mon Sep 17 00:00:00 2001 From: Wayne Parrott <5588978+wayneparrott@users.noreply.github.com> Date: Fri, 22 Jul 2022 08:42:31 -0500 Subject: [PATCH 1/2] Fix ActionServer cancelCallback declaration, doc & test Fix #866 --- lib/action/server.js | 2 +- test/test-action-server.js | 6 +++--- test/types/main.ts | 14 +++++++------- types/action_server.d.ts | 10 ++++++---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/action/server.js b/lib/action/server.js index d2607ff2..a7de1d51 100644 --- a/lib/action/server.js +++ b/lib/action/server.js @@ -190,7 +190,7 @@ class ActionServer extends Entity { * * The purpose of the cancel callback is to decide if a request to cancel an on-going * (or queued) goal should be accepted or rejected. - * The callback should take one parameter containing the cancel request and must return a + * The callback should take one parameter containing the cancel request (a goal handle) and must return a * {@link CancelResponse} value. * * There can only be one cancel callback per {@link ActionServer}, therefore calling this diff --git a/test/test-action-server.js b/test/test-action-server.js index a14a4cf2..7fc462a9 100644 --- a/test/test-action-server.js +++ b/test/test-action-server.js @@ -289,7 +289,7 @@ describe('rclnodejs action server', function () { return new Fibonacci.Result(); } - function cancelCallback() { + function cancelCallback(goalHandle) { return rclnodejs.CancelResponse.ACCEPT; } @@ -334,7 +334,7 @@ describe('rclnodejs action server', function () { return new Fibonacci.Result(); } - function cancelCallback() { + function cancelCallback(goalHandle) { return rclnodejs.CancelResponse.REJECT; } @@ -381,7 +381,7 @@ describe('rclnodejs action server', function () { serverGoalHandle = goalHandle; } - function cancelCallback() { + function cancelCallback(goalHandle) { return rclnodejs.CancelResponse.ACCEPT; } diff --git a/test/types/main.ts b/test/types/main.ts index c538ff37..038edf28 100644 --- a/test/types/main.ts +++ b/test/types/main.ts @@ -454,13 +454,13 @@ logger.fatal('test msg'); // f64arr.data; // $ExpectType FibonacciConstructor -const Fibonacci = rclnodejs.require('test_msgs/action/Fibonacci'); +const Fibonacci = rclnodejs.require('example_interfaces/action/Fibonacci'); // ---- ActionClient ----- -// $ExpectType ActionClient<"test_msgs/action/Fibonacci"> +// $ExpectType ActionClient<"example_interfaces/action/Fibonacci"> const actionClient = new rclnodejs.ActionClient( node, - 'test_msgs/action/Fibonacci', + 'example_interfaces/action/Fibonacci', 'fibonnaci' ); @@ -473,7 +473,7 @@ actionClient.waitForServer(); // $ExpectType void actionClient.destroy(); -// $ExpectType Promise> +// $ExpectType Promise> const goalHandlePromise = actionClient.sendGoal(new Fibonacci.Goal()); goalHandlePromise.then((goalHandle) => { @@ -515,10 +515,10 @@ goalHandlePromise.then((goalHandle) => { }); // ---- ActionServer ----- -// $ExpectType ActionServer<"test_msgs/action/Fibonacci"> +// $ExpectType ActionServer<"example_interfaces/action/Fibonacci"> const actionServer = new rclnodejs.ActionServer( node, - 'test_msgs/action/Fibonacci', + 'example_interfaces/action/Fibonacci', 'fibonnaci', executeCallback ); @@ -539,7 +539,7 @@ actionServer.registerExecuteCallback(() => new Fibonacci.Result()); actionServer.destroy(); function executeCallback( - goalHandle: rclnodejs.ServerGoalHandle<'test_msgs/action/Fibonacci'> + goalHandle: rclnodejs.ServerGoalHandle<'example_interfaces/action/Fibonacci'> ) { // $ExpectType UUID goalHandle.goalId; diff --git a/types/action_server.d.ts b/types/action_server.d.ts index 314bc2db..63198d04 100644 --- a/types/action_server.d.ts +++ b/types/action_server.d.ts @@ -84,7 +84,9 @@ declare module 'rclnodejs' { type HandleAcceptedCallback> = ( goalHandle: ServerGoalHandle ) => void; - type CancelCallback = () => Promise | CancelResponse; + type CancelCallback> = ( + goalHandle: ServerGoalHandle + ) => Promise | CancelResponse; interface ActionServerOptions extends Options { /** @@ -116,7 +118,7 @@ declare module 'rclnodejs' { executeCallback: ExecuteCallback, goalCallback?: GoalCallback, handleAcceptedCallback?: HandleAcceptedCallback, - cancelCallback?: CancelCallback, + cancelCallback?: CancelCallback, options?: ActionServerOptions ); @@ -153,14 +155,14 @@ declare module 'rclnodejs' { * * The purpose of the cancel callback is to decide if a request to cancel an on-going * (or queued) goal should be accepted or rejected. - * The callback should take one parameter containing the cancel request and must return a + * The callback should take one parameter containing the cancel request ( a GoalHandle) and must return a * {@link CancelResponse} value. * * There can only be one cancel callback per {@link ActionServer}, therefore calling this * function will replace any previously registered callback. * @param cancelCallback - Callback function, if not provided, then unregisters any previously registered callback. */ - registerCancelCallback(cancelCallback?: CancelCallback): void; + registerCancelCallback(cancelCallback?: CancelCallback): void; /** * Register a callback for executing action goals. From 9dfc22c460825c4e9de817fdd6bc54c690c73a99 Mon Sep 17 00:00:00 2001 From: Wayne Parrott <5588978+wayneparrott@users.noreply.github.com> Date: Sun, 24 Jul 2022 06:26:36 -0500 Subject: [PATCH 2/2] Converted CancelCallback fn's goal param to an optional param --- types/action_server.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/action_server.d.ts b/types/action_server.d.ts index 63198d04..194cb4a7 100644 --- a/types/action_server.d.ts +++ b/types/action_server.d.ts @@ -85,7 +85,7 @@ declare module 'rclnodejs' { goalHandle: ServerGoalHandle ) => void; type CancelCallback> = ( - goalHandle: ServerGoalHandle + goalHandle?: ServerGoalHandle ) => Promise | CancelResponse; interface ActionServerOptions extends Options {