rclnodejs 0.33.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +3 -3
  2. package/binding.gyp +25 -2
  3. package/lib/action/client.js +40 -0
  4. package/lib/action/server.js +21 -0
  5. package/lib/client.js +3 -4
  6. package/lib/context.js +8 -0
  7. package/lib/distro.js +2 -0
  8. package/lib/lifecycle.js +9 -0
  9. package/lib/logging.js +26 -9
  10. package/lib/node.js +81 -1
  11. package/lib/node_options.js +21 -1
  12. package/lib/publisher.js +27 -0
  13. package/lib/service.js +10 -3
  14. package/lib/subscription.js +8 -0
  15. package/lib/timer.js +32 -0
  16. package/lib/type_description_service.js +82 -0
  17. package/package.json +4 -4
  18. package/scripts/config.js +1 -0
  19. package/scripts/npmjs-readme.md +3 -3
  20. package/src/addon.cpp +60 -53
  21. package/src/executor.cpp +19 -10
  22. package/src/{executor.hpp → executor.h} +7 -5
  23. package/src/handle_manager.cpp +30 -56
  24. package/src/{handle_manager.hpp → handle_manager.h} +8 -7
  25. package/src/{macros.hpp → macros.h} +7 -5
  26. package/src/rcl_action_client_bindings.cpp +306 -0
  27. package/src/{rcl_action_bindings.hpp → rcl_action_client_bindings.h} +6 -11
  28. package/src/rcl_action_goal_bindings.cpp +117 -0
  29. package/src/rcl_action_goal_bindings.h +26 -0
  30. package/src/rcl_action_server_bindings.cpp +520 -0
  31. package/src/rcl_action_server_bindings.h +26 -0
  32. package/src/rcl_bindings.cpp +42 -2010
  33. package/src/{rcl_bindings.hpp → rcl_bindings.h} +5 -25
  34. package/src/rcl_client_bindings.cpp +183 -0
  35. package/src/rcl_client_bindings.h +26 -0
  36. package/src/rcl_context_bindings.cpp +156 -0
  37. package/src/rcl_context_bindings.h +26 -0
  38. package/src/rcl_graph_bindings.cpp +280 -0
  39. package/src/rcl_graph_bindings.h +26 -0
  40. package/src/rcl_guard_condition_bindings.cpp +75 -0
  41. package/src/rcl_guard_condition_bindings.h +26 -0
  42. package/src/rcl_handle.cpp +41 -57
  43. package/src/{rcl_handle.hpp → rcl_handle.h} +18 -17
  44. package/src/rcl_lifecycle_bindings.cpp +148 -114
  45. package/src/{rcl_lifecycle_bindings.hpp → rcl_lifecycle_bindings.h} +5 -7
  46. package/src/rcl_logging_bindings.cpp +96 -0
  47. package/src/rcl_logging_bindings.h +26 -0
  48. package/src/rcl_names_bindings.cpp +255 -0
  49. package/src/rcl_names_bindings.h +26 -0
  50. package/src/rcl_node_bindings.cpp +476 -0
  51. package/src/rcl_node_bindings.h +26 -0
  52. package/src/rcl_publisher_bindings.cpp +160 -0
  53. package/src/rcl_publisher_bindings.h +26 -0
  54. package/src/rcl_service_bindings.cpp +185 -0
  55. package/src/rcl_service_bindings.h +26 -0
  56. package/src/rcl_subscription_bindings.cpp +335 -0
  57. package/src/rcl_subscription_bindings.h +26 -0
  58. package/src/rcl_time_point_bindings.cpp +194 -0
  59. package/src/rcl_time_point_bindings.h +26 -0
  60. package/src/rcl_timer_bindings.cpp +237 -0
  61. package/src/rcl_timer_bindings.h +26 -0
  62. package/src/rcl_type_description_service_bindings.cpp +79 -0
  63. package/src/rcl_type_description_service_bindings.h +27 -0
  64. package/src/rcl_utilities.cpp +166 -1
  65. package/src/{rcl_utilities.hpp → rcl_utilities.h} +21 -3
  66. package/src/shadow_node.cpp +56 -75
  67. package/src/{shadow_node.hpp → shadow_node.h} +18 -17
  68. package/types/action_client.d.ts +18 -0
  69. package/types/action_server.d.ts +12 -0
  70. package/types/context.d.ts +6 -0
  71. package/types/lifecycle.d.ts +7 -0
  72. package/types/node.d.ts +69 -0
  73. package/types/publisher.d.ts +23 -0
  74. package/types/service.d.ts +6 -0
  75. package/types/subscription.d.ts +6 -0
  76. package/types/timer.d.ts +18 -0
  77. package/src/rcl_action_bindings.cpp +0 -826
@@ -0,0 +1,306 @@
1
+ // Copyright (c) 2020 Matt Richard. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "rcl_action_client_bindings.h"
16
+
17
+ #include <rcl/error_handling.h>
18
+ #include <rcl/rcl.h>
19
+ #include <rcl_action/action_client.h>
20
+ #include <rcl_action/rcl_action.h>
21
+
22
+ #include <string>
23
+
24
+ #include "handle_manager.h"
25
+ #include "macros.h"
26
+ #include "rcl_handle.h"
27
+ #include "rcl_utilities.h"
28
+
29
+ namespace rclnodejs {
30
+
31
+ Napi::Value ActionCreateClient(const Napi::CallbackInfo& info) {
32
+ Napi::Env env = info.Env();
33
+
34
+ RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
35
+ rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
36
+ std::string action_name = info[1].As<Napi::String>().Utf8Value();
37
+ std::string interface_name = info[2].As<Napi::String>().Utf8Value();
38
+ std::string package_name = info[3].As<Napi::String>().Utf8Value();
39
+
40
+ const rosidl_action_type_support_t* ts =
41
+ GetActionTypeSupport(package_name, interface_name);
42
+
43
+ if (ts) {
44
+ rcl_action_client_options_t action_client_ops =
45
+ rcl_action_client_get_default_options();
46
+
47
+ auto goal_service_qos = GetQoSProfile(info[4]);
48
+ auto result_service_qos = GetQoSProfile(info[5]);
49
+ auto cancel_service_qos = GetQoSProfile(info[6]);
50
+ auto feedback_topic_qos = GetQoSProfile(info[7]);
51
+ auto status_topic_qos = GetQoSProfile(info[8]);
52
+
53
+ if (goal_service_qos) {
54
+ action_client_ops.goal_service_qos = *goal_service_qos;
55
+ }
56
+ if (result_service_qos) {
57
+ action_client_ops.result_service_qos = *result_service_qos;
58
+ }
59
+ if (cancel_service_qos) {
60
+ action_client_ops.cancel_service_qos = *cancel_service_qos;
61
+ }
62
+ if (feedback_topic_qos) {
63
+ action_client_ops.feedback_topic_qos = *feedback_topic_qos;
64
+ }
65
+ if (status_topic_qos) {
66
+ action_client_ops.status_topic_qos = *status_topic_qos;
67
+ }
68
+
69
+ rcl_action_client_t* action_client = reinterpret_cast<rcl_action_client_t*>(
70
+ malloc(sizeof(rcl_action_client_t)));
71
+ *action_client = rcl_action_get_zero_initialized_client();
72
+
73
+ THROW_ERROR_IF_NOT_EQUAL(
74
+ rcl_action_client_init(action_client, node, ts, action_name.c_str(),
75
+ &action_client_ops),
76
+ RCL_RET_OK, rcl_get_error_string().str);
77
+ auto js_obj = RclHandle::NewInstance(
78
+ env, action_client, node_handle, [node](void* ptr) {
79
+ rcl_action_client_t* action_client =
80
+ reinterpret_cast<rcl_action_client_t*>(ptr);
81
+ rcl_ret_t ret = rcl_action_client_fini(action_client, node);
82
+ free(ptr);
83
+ THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
84
+ });
85
+
86
+ return js_obj;
87
+ } else {
88
+ Napi::Error::New(env, GetErrorMessageAndClear())
89
+ .ThrowAsJavaScriptException();
90
+ return env.Undefined();
91
+ }
92
+ }
93
+
94
+ Napi::Value ActionServerIsAvailable(const Napi::CallbackInfo& info) {
95
+ Napi::Env env = info.Env();
96
+
97
+ RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
98
+ rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
99
+ RclHandle* action_client_handle =
100
+ RclHandle::Unwrap(info[1].As<Napi::Object>());
101
+ rcl_action_client_t* action_client =
102
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
103
+
104
+ bool is_available;
105
+ THROW_ERROR_IF_NOT_EQUAL(
106
+ RCL_RET_OK,
107
+ rcl_action_server_is_available(node, action_client, &is_available),
108
+ rcl_get_error_string().str);
109
+
110
+ return Napi::Boolean::New(env, is_available);
111
+ }
112
+
113
+ Napi::Value ActionSendGoalRequest(const Napi::CallbackInfo& info) {
114
+ Napi::Env env = info.Env();
115
+
116
+ RclHandle* action_client_handle =
117
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
118
+ rcl_action_client_t* action_client =
119
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
120
+ void* buffer = info[1].As<Napi::Buffer<char>>().Data();
121
+
122
+ int64_t sequence_number;
123
+ THROW_ERROR_IF_NOT_EQUAL(
124
+ rcl_action_send_goal_request(action_client, buffer, &sequence_number),
125
+ RCL_RET_OK, rcl_get_error_string().str);
126
+
127
+ return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
128
+ }
129
+
130
+ Napi::Value ActionSendResultRequest(const Napi::CallbackInfo& info) {
131
+ Napi::Env env = info.Env();
132
+
133
+ RclHandle* action_client_handle =
134
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
135
+ rcl_action_client_t* action_client =
136
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
137
+ void* buffer = info[1].As<Napi::Buffer<char>>().Data();
138
+
139
+ int64_t sequence_number;
140
+ THROW_ERROR_IF_NOT_EQUAL(
141
+ rcl_action_send_result_request(action_client, buffer, &sequence_number),
142
+ RCL_RET_OK, rcl_get_error_string().str);
143
+
144
+ return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
145
+ }
146
+
147
+ Napi::Value ActionTakeFeedback(const Napi::CallbackInfo& info) {
148
+ Napi::Env env = info.Env();
149
+
150
+ RclHandle* action_client_handle =
151
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
152
+ rcl_action_client_t* action_client =
153
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
154
+ void* buffer = info[1].As<Napi::Buffer<char>>().Data();
155
+
156
+ rcl_ret_t ret = rcl_action_take_feedback(action_client, buffer);
157
+ if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
158
+ Napi::Error::New(env, rcl_get_error_string().str)
159
+ .ThrowAsJavaScriptException();
160
+ rcl_reset_error();
161
+ return Napi::Boolean::New(env, false);
162
+ }
163
+
164
+ if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
165
+ return Napi::Boolean::New(env, true);
166
+ }
167
+ return env.Undefined();
168
+ }
169
+
170
+ Napi::Value ActionTakeStatus(const Napi::CallbackInfo& info) {
171
+ Napi::Env env = info.Env();
172
+
173
+ RclHandle* action_client_handle =
174
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
175
+ rcl_action_client_t* action_client =
176
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
177
+ void* buffer = info[1].As<Napi::Buffer<char>>().Data();
178
+
179
+ rcl_ret_t ret = rcl_action_take_status(action_client, buffer);
180
+ if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
181
+ rcl_reset_error();
182
+ Napi::Error::New(env, rcl_get_error_string().str)
183
+ .ThrowAsJavaScriptException();
184
+ return Napi::Boolean::New(env, false);
185
+ }
186
+
187
+ if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
188
+ return Napi::Boolean::New(env, true);
189
+ }
190
+ return env.Undefined();
191
+ }
192
+
193
+ Napi::Value GetNumEntities(const Napi::CallbackInfo& info) {
194
+ Napi::Env env = info.Env();
195
+ RclHandle* action_client_handle =
196
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
197
+ rcl_action_client_t* action_client =
198
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
199
+
200
+ size_t num_subscriptions = 0u;
201
+ size_t num_guard_conditions = 0u;
202
+ size_t num_timers = 0u;
203
+ size_t num_clients = 0u;
204
+ size_t num_services = 0u;
205
+
206
+ rcl_ret_t ret;
207
+ ret = rcl_action_client_wait_set_get_num_entities(
208
+ action_client, &num_subscriptions, &num_guard_conditions, &num_timers,
209
+ &num_clients, &num_services);
210
+ if (RCL_RET_OK != ret) {
211
+ rcl_reset_error();
212
+ std::string error_text{
213
+ "Failed to get number of entities for 'rcl_action_client_t'"};
214
+ Napi::Error::New(env, error_text).ThrowAsJavaScriptException();
215
+ return env.Undefined();
216
+ }
217
+ Napi::Object entities = Napi::Object::New(env);
218
+ entities.Set("subscriptionsNumber",
219
+ Napi::Number::New(env, num_subscriptions));
220
+ entities.Set("guardConditionsNumber",
221
+ Napi::Number::New(env, num_guard_conditions));
222
+ entities.Set("timersNumber", Napi::Number::New(env, num_timers));
223
+ entities.Set("clientsNumber", Napi::Number::New(env, num_clients));
224
+ entities.Set("servicesNumber", Napi::Number::New(env, num_services));
225
+ return entities;
226
+ }
227
+
228
+ Napi::Value ActionSendCancelRequest(const Napi::CallbackInfo& info) {
229
+ Napi::Env env = info.Env();
230
+
231
+ RclHandle* action_client_handle =
232
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
233
+ rcl_action_client_t* action_client =
234
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
235
+ void* buffer = info[1].As<Napi::Buffer<char>>().Data();
236
+
237
+ int64_t sequence_number;
238
+ THROW_ERROR_IF_NOT_EQUAL(
239
+ rcl_action_send_cancel_request(action_client, buffer, &sequence_number),
240
+ RCL_RET_OK, rcl_get_error_string().str);
241
+
242
+ return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
243
+ }
244
+
245
+ #if ROS_VERSION >= 2505 // ROS2 >= Kilted
246
+ Napi::Value ConfigureActionClientIntrospection(const Napi::CallbackInfo& info) {
247
+ Napi::Env env = info.Env();
248
+ RclHandle* action_client_handle =
249
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
250
+ rcl_action_client_t* action_client =
251
+ reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
252
+ RclHandle* node_handle = RclHandle::Unwrap(info[1].As<Napi::Object>());
253
+ rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
254
+ rcl_clock_t* clock = reinterpret_cast<rcl_clock_t*>(
255
+ RclHandle::Unwrap(info[2].As<Napi::Object>())->ptr());
256
+
257
+ std::string action_name = info[3].As<Napi::String>().Utf8Value();
258
+ std::string package_name = info[4].As<Napi::String>().Utf8Value();
259
+ const rosidl_action_type_support_t* ts =
260
+ GetActionTypeSupport(package_name, action_name);
261
+ rcl_ret_t ret = RCL_RET_ERROR;
262
+ if (ts) {
263
+ rcl_publisher_options_t publisher_ops = rcl_publisher_get_default_options();
264
+ auto qos_profile = GetQoSProfile(info[5]);
265
+ if (qos_profile) {
266
+ publisher_ops.qos = *qos_profile;
267
+ }
268
+ rcl_service_introspection_state_t state =
269
+ static_cast<rcl_service_introspection_state_t>(
270
+ info[6].As<Napi::Number>().Uint32Value());
271
+ ret = rcl_action_client_configure_action_introspection(
272
+ action_client, node, clock, ts, publisher_ops, state);
273
+ if (ret == RCL_RET_OK) {
274
+ return env.Undefined();
275
+ }
276
+ }
277
+
278
+ Napi::Error::New(env, "failed to configure action client introspection")
279
+ .ThrowAsJavaScriptException();
280
+ return env.Undefined();
281
+ }
282
+ #endif // ROS_VERSION >= 2505
283
+
284
+ Napi::Object InitActionClientBindings(Napi::Env env, Napi::Object exports) {
285
+ exports.Set("actionCreateClient",
286
+ Napi::Function::New(env, ActionCreateClient));
287
+ exports.Set("actionServerIsAvailable",
288
+ Napi::Function::New(env, ActionServerIsAvailable));
289
+ exports.Set("actionSendGoalRequest",
290
+ Napi::Function::New(env, ActionSendGoalRequest));
291
+ exports.Set("actionSendResultRequest",
292
+ Napi::Function::New(env, ActionSendResultRequest));
293
+ exports.Set("actionTakeFeedback",
294
+ Napi::Function::New(env, ActionTakeFeedback));
295
+ exports.Set("actionTakeStatus", Napi::Function::New(env, ActionTakeStatus));
296
+ exports.Set("getNumEntities", Napi::Function::New(env, GetNumEntities));
297
+ exports.Set("actionSendCancelRequest",
298
+ Napi::Function::New(env, ActionSendCancelRequest));
299
+ #if ROS_VERSION >= 2505 // ROS2 >= Kilted
300
+ exports.Set("configureActionClientIntrospection",
301
+ Napi::Function::New(env, ConfigureActionClientIntrospection));
302
+ #endif // ROS_VERSION >= 2505
303
+ return exports;
304
+ }
305
+
306
+ } // namespace rclnodejs
@@ -12,20 +12,15 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- #ifndef SRC_RCL_ACTION_BINDINGS_HPP_
16
- #define SRC_RCL_ACTION_BINDINGS_HPP_
15
+ #ifndef SRC_RCL_ACTION_CLIENT_BINDINGS_H_
16
+ #define SRC_RCL_ACTION_CLIENT_BINDINGS_H_
17
17
 
18
- #include <nan.h>
19
- #include <rcl/rcl.h>
20
-
21
- #include <vector>
22
-
23
- #include "rcl_bindings.hpp"
18
+ #include <napi.h>
24
19
 
25
20
  namespace rclnodejs {
26
21
 
27
- extern std::vector<BindingMethod> action_binding_methods;
22
+ Napi::Object InitActionClientBindings(Napi::Env env, Napi::Object exports);
28
23
 
29
- } // namespace rclnodejs
24
+ }
30
25
 
31
- #endif // SRC_RCL_ACTION_BINDINGS_HPP_
26
+ #endif // SRC_RCL_ACTION_CLIENT_BINDINGS_H_
@@ -0,0 +1,117 @@
1
+ // Copyright (c) 2020 Matt Richard. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "rcl_action_goal_bindings.h"
16
+
17
+ #include <rcl/error_handling.h>
18
+ #include <rcl/rcl.h>
19
+ #include <rcl_action/rcl_action.h>
20
+
21
+ #include "handle_manager.h"
22
+ #include "macros.h"
23
+ #include "rcl_handle.h"
24
+ #include "rcl_utilities.h"
25
+
26
+ namespace rclnodejs {
27
+
28
+ Napi::Value ActionAcceptNewGoal(const Napi::CallbackInfo& info) {
29
+ Napi::Env env = info.Env();
30
+
31
+ RclHandle* action_server_handle =
32
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
33
+ rcl_action_server_t* action_server =
34
+ reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
35
+ rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
36
+ info[1].As<Napi::Buffer<char>>().Data());
37
+
38
+ rcl_action_goal_handle_t* new_goal =
39
+ rcl_action_accept_new_goal(action_server, buffer);
40
+ if (!new_goal) {
41
+ Napi::Error::New(env, rcl_get_error_string().str)
42
+ .ThrowAsJavaScriptException();
43
+ rcl_reset_error();
44
+ return env.Undefined();
45
+ }
46
+
47
+ rcl_action_goal_handle_t* goal_handle =
48
+ reinterpret_cast<rcl_action_goal_handle_t*>(
49
+ malloc(sizeof(rcl_action_goal_handle_t)));
50
+ *goal_handle = *new_goal;
51
+ auto js_obj =
52
+ RclHandle::NewInstance(env, goal_handle, nullptr, [](void* ptr) {
53
+ rcl_action_goal_handle_t* goal_handle =
54
+ reinterpret_cast<rcl_action_goal_handle_t*>(ptr);
55
+ rcl_ret_t ret = rcl_action_goal_handle_fini(goal_handle);
56
+ free(ptr);
57
+ THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
58
+ });
59
+
60
+ return js_obj;
61
+ }
62
+
63
+ Napi::Value ActionUpdateGoalState(const Napi::CallbackInfo& info) {
64
+ Napi::Env env = info.Env();
65
+
66
+ RclHandle* goal_handle_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
67
+ rcl_action_goal_handle_t* goal_handle =
68
+ reinterpret_cast<rcl_action_goal_handle_t*>(goal_handle_handle->ptr());
69
+ rcl_action_goal_event_t event = static_cast<rcl_action_goal_event_t>(
70
+ info[1].As<Napi::Number>().Int32Value());
71
+
72
+ THROW_ERROR_IF_NOT_EQUAL(rcl_action_update_goal_state(goal_handle, event),
73
+ RCL_RET_OK, rcl_get_error_string().str);
74
+
75
+ return env.Undefined();
76
+ }
77
+
78
+ Napi::Value ActionGoalHandleIsActive(const Napi::CallbackInfo& info) {
79
+ Napi::Env env = info.Env();
80
+
81
+ RclHandle* goal_handle_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
82
+ rcl_action_goal_handle_t* goal_handle =
83
+ reinterpret_cast<rcl_action_goal_handle_t*>(goal_handle_handle->ptr());
84
+
85
+ bool is_active = rcl_action_goal_handle_is_active(goal_handle);
86
+
87
+ return Napi::Boolean::New(env, is_active);
88
+ }
89
+
90
+ Napi::Value ActionGoalHandleGetStatus(const Napi::CallbackInfo& info) {
91
+ Napi::Env env = info.Env();
92
+
93
+ RclHandle* goal_handle_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
94
+ rcl_action_goal_handle_t* goal_handle =
95
+ reinterpret_cast<rcl_action_goal_handle_t*>(goal_handle_handle->ptr());
96
+
97
+ rcl_action_goal_state_t status;
98
+ THROW_ERROR_IF_NOT_EQUAL(
99
+ rcl_action_goal_handle_get_status(goal_handle, &status), RCL_RET_OK,
100
+ rcl_get_error_string().str);
101
+
102
+ return Napi::Number::New(env, static_cast<int32_t>(status));
103
+ }
104
+
105
+ Napi::Object InitActionGoalBindings(Napi::Env env, Napi::Object exports) {
106
+ exports.Set("actionAcceptNewGoal",
107
+ Napi::Function::New(env, ActionAcceptNewGoal));
108
+ exports.Set("actionUpdateGoalState",
109
+ Napi::Function::New(env, ActionUpdateGoalState));
110
+ exports.Set("actionGoalHandleIsActive",
111
+ Napi::Function::New(env, ActionGoalHandleIsActive));
112
+ exports.Set("actionGoalHandleGetStatus",
113
+ Napi::Function::New(env, ActionGoalHandleGetStatus));
114
+ return exports;
115
+ }
116
+
117
+ } // namespace rclnodejs
@@ -0,0 +1,26 @@
1
+ // Copyright (c) 2020 Matt Richard. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef SRC_RCL_ACTION_GOAL_BINDINGS_H_
16
+ #define SRC_RCL_ACTION_GOAL_BINDINGS_H_
17
+
18
+ #include <napi.h>
19
+
20
+ namespace rclnodejs {
21
+
22
+ Napi::Object InitActionGoalBindings(Napi::Env env, Napi::Object exports);
23
+
24
+ }
25
+
26
+ #endif // SRC_RCL_ACTION_GOAL_BINDINGS_H_