rclnodejs 0.33.0 → 1.0.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.
- package/README.md +3 -3
- package/binding.gyp +17 -2
- package/lib/client.js +2 -3
- package/lib/context.js +8 -0
- package/lib/logging.js +26 -9
- package/lib/node.js +53 -0
- package/lib/publisher.js +8 -0
- package/lib/service.js +9 -2
- package/lib/subscription.js +8 -0
- package/lib/timer.js +32 -0
- package/package.json +4 -4
- package/scripts/config.js +1 -0
- package/scripts/npmjs-readme.md +3 -3
- package/src/addon.cpp +54 -53
- package/src/executor.cpp +19 -10
- package/src/{executor.hpp → executor.h} +7 -5
- package/src/handle_manager.cpp +30 -56
- package/src/{handle_manager.hpp → handle_manager.h} +8 -7
- package/src/{macros.hpp → macros.h} +7 -5
- package/src/rcl_action_client_bindings.cpp +231 -0
- package/src/{rcl_action_bindings.hpp → rcl_action_client_bindings.h} +6 -11
- package/src/rcl_action_goal_bindings.cpp +117 -0
- package/src/rcl_action_goal_bindings.h +26 -0
- package/src/rcl_action_server_bindings.cpp +470 -0
- package/src/rcl_action_server_bindings.h +26 -0
- package/src/rcl_bindings.cpp +42 -2010
- package/src/{rcl_bindings.hpp → rcl_bindings.h} +5 -25
- package/src/rcl_client_bindings.cpp +183 -0
- package/src/rcl_client_bindings.h +26 -0
- package/src/rcl_context_bindings.cpp +156 -0
- package/src/rcl_context_bindings.h +26 -0
- package/src/rcl_graph_bindings.cpp +280 -0
- package/src/rcl_graph_bindings.h +26 -0
- package/src/rcl_guard_condition_bindings.cpp +75 -0
- package/src/rcl_guard_condition_bindings.h +26 -0
- package/src/rcl_handle.cpp +41 -57
- package/src/{rcl_handle.hpp → rcl_handle.h} +18 -17
- package/src/rcl_lifecycle_bindings.cpp +135 -114
- package/src/{rcl_lifecycle_bindings.hpp → rcl_lifecycle_bindings.h} +5 -7
- package/src/rcl_logging_bindings.cpp +96 -0
- package/src/rcl_logging_bindings.h +26 -0
- package/src/rcl_names_bindings.cpp +255 -0
- package/src/rcl_names_bindings.h +26 -0
- package/src/rcl_node_bindings.cpp +447 -0
- package/src/rcl_node_bindings.h +26 -0
- package/src/rcl_publisher_bindings.cpp +141 -0
- package/src/rcl_publisher_bindings.h +26 -0
- package/src/rcl_service_bindings.cpp +185 -0
- package/src/rcl_service_bindings.h +26 -0
- package/src/rcl_subscription_bindings.cpp +335 -0
- package/src/rcl_subscription_bindings.h +26 -0
- package/src/rcl_time_point_bindings.cpp +194 -0
- package/src/rcl_time_point_bindings.h +26 -0
- package/src/rcl_timer_bindings.cpp +237 -0
- package/src/rcl_timer_bindings.h +26 -0
- package/src/rcl_utilities.cpp +166 -1
- package/src/{rcl_utilities.hpp → rcl_utilities.h} +21 -3
- package/src/shadow_node.cpp +56 -75
- package/src/{shadow_node.hpp → shadow_node.h} +18 -17
- package/types/context.d.ts +6 -0
- package/types/node.d.ts +37 -0
- package/types/publisher.d.ts +6 -0
- package/types/service.d.ts +6 -0
- package/types/subscription.d.ts +6 -0
- package/types/timer.d.ts +18 -0
- package/src/rcl_action_bindings.cpp +0 -826
|
@@ -0,0 +1,470 @@
|
|
|
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_server_bindings.h"
|
|
16
|
+
|
|
17
|
+
#include <rcl/error_handling.h>
|
|
18
|
+
#include <rcl/rcl.h>
|
|
19
|
+
#include <rcl_action/rcl_action.h>
|
|
20
|
+
|
|
21
|
+
#include <string>
|
|
22
|
+
|
|
23
|
+
#include "handle_manager.h"
|
|
24
|
+
#include "macros.h"
|
|
25
|
+
#include "rcl_handle.h"
|
|
26
|
+
#include "rcl_utilities.h"
|
|
27
|
+
|
|
28
|
+
namespace rclnodejs {
|
|
29
|
+
|
|
30
|
+
Napi::Value ActionCreateServer(const Napi::CallbackInfo& info) {
|
|
31
|
+
Napi::Env env = info.Env();
|
|
32
|
+
|
|
33
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
34
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
35
|
+
RclHandle* clock_handle = RclHandle::Unwrap(info[1].As<Napi::Object>());
|
|
36
|
+
rcl_clock_t* clock = reinterpret_cast<rcl_clock_t*>(clock_handle->ptr());
|
|
37
|
+
std::string action_name = info[2].As<Napi::String>().Utf8Value();
|
|
38
|
+
std::string interface_name = info[3].As<Napi::String>().Utf8Value();
|
|
39
|
+
std::string package_name = info[4].As<Napi::String>().Utf8Value();
|
|
40
|
+
int64_t result_timeout = info[10].As<Napi::Number>().Int64Value();
|
|
41
|
+
|
|
42
|
+
const rosidl_action_type_support_t* ts =
|
|
43
|
+
GetActionTypeSupport(package_name, interface_name);
|
|
44
|
+
|
|
45
|
+
if (ts) {
|
|
46
|
+
rcl_action_server_options_t action_server_ops =
|
|
47
|
+
rcl_action_server_get_default_options();
|
|
48
|
+
|
|
49
|
+
auto goal_service_qos = GetQoSProfile(info[5]);
|
|
50
|
+
auto result_service_qos = GetQoSProfile(info[6]);
|
|
51
|
+
auto cancel_service_qos = GetQoSProfile(info[7]);
|
|
52
|
+
auto feedback_topic_qos = GetQoSProfile(info[8]);
|
|
53
|
+
auto status_topic_qos = GetQoSProfile(info[9]);
|
|
54
|
+
|
|
55
|
+
if (goal_service_qos) {
|
|
56
|
+
action_server_ops.goal_service_qos = *goal_service_qos;
|
|
57
|
+
}
|
|
58
|
+
if (result_service_qos) {
|
|
59
|
+
action_server_ops.result_service_qos = *result_service_qos;
|
|
60
|
+
}
|
|
61
|
+
if (cancel_service_qos) {
|
|
62
|
+
action_server_ops.cancel_service_qos = *cancel_service_qos;
|
|
63
|
+
}
|
|
64
|
+
if (feedback_topic_qos) {
|
|
65
|
+
action_server_ops.feedback_topic_qos = *feedback_topic_qos;
|
|
66
|
+
}
|
|
67
|
+
if (status_topic_qos) {
|
|
68
|
+
action_server_ops.status_topic_qos = *status_topic_qos;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
action_server_ops.result_timeout.nanoseconds =
|
|
72
|
+
static_cast<rcl_duration_value_t>(RCL_S_TO_NS(result_timeout));
|
|
73
|
+
|
|
74
|
+
rcl_action_server_t* action_server = reinterpret_cast<rcl_action_server_t*>(
|
|
75
|
+
malloc(sizeof(rcl_action_server_t)));
|
|
76
|
+
*action_server = rcl_action_get_zero_initialized_server();
|
|
77
|
+
|
|
78
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
79
|
+
rcl_action_server_init(action_server, node, clock, ts,
|
|
80
|
+
action_name.c_str(), &action_server_ops),
|
|
81
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
82
|
+
auto js_obj = RclHandle::NewInstance(
|
|
83
|
+
env, action_server, node_handle, [node](void* ptr) {
|
|
84
|
+
rcl_action_server_t* action_server =
|
|
85
|
+
reinterpret_cast<rcl_action_server_t*>(ptr);
|
|
86
|
+
rcl_ret_t ret = rcl_action_server_fini(action_server, node);
|
|
87
|
+
free(ptr);
|
|
88
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return js_obj;
|
|
92
|
+
} else {
|
|
93
|
+
Napi::Error::New(env, GetErrorMessageAndClear())
|
|
94
|
+
.ThrowAsJavaScriptException();
|
|
95
|
+
return env.Undefined();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Napi::Value ActionSendCancelRequest(const Napi::CallbackInfo& info) {
|
|
100
|
+
Napi::Env env = info.Env();
|
|
101
|
+
|
|
102
|
+
RclHandle* action_client_handle =
|
|
103
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
104
|
+
rcl_action_client_t* action_client =
|
|
105
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
106
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
107
|
+
|
|
108
|
+
int64_t sequence_number;
|
|
109
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
110
|
+
rcl_action_send_cancel_request(action_client, buffer, &sequence_number),
|
|
111
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
112
|
+
|
|
113
|
+
return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Napi::Value ActionTakeResultRequest(const Napi::CallbackInfo& info) {
|
|
117
|
+
Napi::Env env = info.Env();
|
|
118
|
+
|
|
119
|
+
RclHandle* action_server_handle =
|
|
120
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
121
|
+
rcl_action_server_t* action_server =
|
|
122
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
123
|
+
|
|
124
|
+
rmw_request_id_t* header =
|
|
125
|
+
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
|
|
126
|
+
|
|
127
|
+
void* taken_request = info[1].As<Napi::Buffer<char>>().Data();
|
|
128
|
+
rcl_ret_t ret =
|
|
129
|
+
rcl_action_take_result_request(action_server, header, taken_request);
|
|
130
|
+
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) {
|
|
131
|
+
auto js_obj = RclHandle::NewInstance(env, header, nullptr,
|
|
132
|
+
[](void* ptr) { free(ptr); });
|
|
133
|
+
return js_obj;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return env.Undefined();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
Napi::Value ActionTakeGoalRequest(const Napi::CallbackInfo& info) {
|
|
140
|
+
Napi::Env env = info.Env();
|
|
141
|
+
|
|
142
|
+
RclHandle* action_server_handle =
|
|
143
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
144
|
+
rcl_action_server_t* action_server =
|
|
145
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
146
|
+
rmw_request_id_t* header =
|
|
147
|
+
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
|
|
148
|
+
|
|
149
|
+
void* taken_request = info[1].As<Napi::Buffer<char>>().Data();
|
|
150
|
+
rcl_ret_t ret =
|
|
151
|
+
rcl_action_take_goal_request(action_server, header, taken_request);
|
|
152
|
+
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) {
|
|
153
|
+
auto js_obj = RclHandle::NewInstance(env, header, nullptr,
|
|
154
|
+
[](void* ptr) { free(ptr); });
|
|
155
|
+
return js_obj;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return env.Undefined();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
Napi::Value ActionSendGoalResponse(const Napi::CallbackInfo& info) {
|
|
162
|
+
Napi::Env env = info.Env();
|
|
163
|
+
|
|
164
|
+
RclHandle* action_server_handle =
|
|
165
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
166
|
+
rcl_action_server_t* action_server =
|
|
167
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
168
|
+
rmw_request_id_t* header = reinterpret_cast<rmw_request_id_t*>(
|
|
169
|
+
RclHandle::Unwrap(info[1].As<Napi::Object>())->ptr());
|
|
170
|
+
void* buffer = info[2].As<Napi::Buffer<char>>().Data();
|
|
171
|
+
|
|
172
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
173
|
+
rcl_action_send_goal_response(action_server, header, buffer), RCL_RET_OK,
|
|
174
|
+
rcl_get_error_string().str);
|
|
175
|
+
|
|
176
|
+
return env.Undefined();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Napi::Value ActionSendCancelResponse(const Napi::CallbackInfo& info) {
|
|
180
|
+
Napi::Env env = info.Env();
|
|
181
|
+
|
|
182
|
+
RclHandle* action_server_handle =
|
|
183
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
184
|
+
rcl_action_server_t* action_server =
|
|
185
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
186
|
+
rmw_request_id_t* header = reinterpret_cast<rmw_request_id_t*>(
|
|
187
|
+
RclHandle::Unwrap(info[1].As<Napi::Object>())->ptr());
|
|
188
|
+
void* buffer = info[2].As<Napi::Buffer<char>>().Data();
|
|
189
|
+
|
|
190
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
191
|
+
rcl_action_send_cancel_response(action_server, header, buffer),
|
|
192
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
193
|
+
|
|
194
|
+
return env.Undefined();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
Napi::Value ActionSendResultResponse(const Napi::CallbackInfo& info) {
|
|
198
|
+
Napi::Env env = info.Env();
|
|
199
|
+
|
|
200
|
+
RclHandle* action_server_handle =
|
|
201
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
202
|
+
rcl_action_server_t* action_server =
|
|
203
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
204
|
+
rmw_request_id_t* header = reinterpret_cast<rmw_request_id_t*>(
|
|
205
|
+
RclHandle::Unwrap(info[1].As<Napi::Object>())->ptr());
|
|
206
|
+
void* buffer = info[2].As<Napi::Buffer<char>>().Data();
|
|
207
|
+
|
|
208
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
209
|
+
rcl_action_send_result_response(action_server, header, buffer),
|
|
210
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
211
|
+
|
|
212
|
+
return env.Undefined();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
Napi::Value ActionTakeGoalResponse(const Napi::CallbackInfo& info) {
|
|
216
|
+
Napi::Env env = info.Env();
|
|
217
|
+
|
|
218
|
+
RclHandle* action_client_handle =
|
|
219
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
220
|
+
rcl_action_client_t* action_client =
|
|
221
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
222
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
223
|
+
rmw_request_id_t* header =
|
|
224
|
+
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
|
|
225
|
+
|
|
226
|
+
rcl_ret_t ret = rcl_action_take_goal_response(action_client, header, buffer);
|
|
227
|
+
int64_t sequence_number = header->sequence_number;
|
|
228
|
+
free(header);
|
|
229
|
+
|
|
230
|
+
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
231
|
+
rcl_reset_error();
|
|
232
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
233
|
+
.ThrowAsJavaScriptException();
|
|
234
|
+
return env.Undefined();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
238
|
+
return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
|
|
239
|
+
}
|
|
240
|
+
return env.Undefined();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
Napi::Value ActionTakeCancelResponse(const Napi::CallbackInfo& info) {
|
|
244
|
+
Napi::Env env = info.Env();
|
|
245
|
+
|
|
246
|
+
RclHandle* action_client_handle =
|
|
247
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
248
|
+
rcl_action_client_t* action_client =
|
|
249
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
250
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
251
|
+
rmw_request_id_t* header =
|
|
252
|
+
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
|
|
253
|
+
|
|
254
|
+
rcl_ret_t ret =
|
|
255
|
+
rcl_action_take_cancel_response(action_client, header, buffer);
|
|
256
|
+
int64_t sequence_number = header->sequence_number;
|
|
257
|
+
free(header);
|
|
258
|
+
|
|
259
|
+
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
260
|
+
rcl_reset_error();
|
|
261
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
262
|
+
.ThrowAsJavaScriptException();
|
|
263
|
+
return env.Undefined();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
267
|
+
return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
|
|
268
|
+
}
|
|
269
|
+
return env.Undefined();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
Napi::Value ActionTakeResultResponse(const Napi::CallbackInfo& info) {
|
|
273
|
+
Napi::Env env = info.Env();
|
|
274
|
+
|
|
275
|
+
RclHandle* action_client_handle =
|
|
276
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
277
|
+
rcl_action_client_t* action_client =
|
|
278
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
279
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
280
|
+
rmw_request_id_t* header =
|
|
281
|
+
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
|
|
282
|
+
|
|
283
|
+
rcl_ret_t ret =
|
|
284
|
+
rcl_action_take_result_response(action_client, header, buffer);
|
|
285
|
+
int64_t sequence_number = header->sequence_number;
|
|
286
|
+
free(header);
|
|
287
|
+
|
|
288
|
+
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
289
|
+
rcl_reset_error();
|
|
290
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
291
|
+
.ThrowAsJavaScriptException();
|
|
292
|
+
return env.Undefined();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
296
|
+
return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
|
|
297
|
+
}
|
|
298
|
+
return env.Undefined();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
Napi::Value ActionExpireGoals(const Napi::CallbackInfo& info) {
|
|
302
|
+
Napi::Env env = info.Env();
|
|
303
|
+
|
|
304
|
+
RclHandle* action_server_handle =
|
|
305
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
306
|
+
rcl_action_server_t* action_server =
|
|
307
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
308
|
+
int64_t max_num_goals = info[1].As<Napi::Number>().Int64Value();
|
|
309
|
+
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
|
|
310
|
+
info[2].As<Napi::Buffer<char>>().Data());
|
|
311
|
+
|
|
312
|
+
size_t num_expired;
|
|
313
|
+
THROW_ERROR_IF_NOT_EQUAL(rcl_action_expire_goals(action_server, buffer,
|
|
314
|
+
max_num_goals, &num_expired),
|
|
315
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
316
|
+
|
|
317
|
+
return Napi::Number::New(env, static_cast<int32_t>(num_expired));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
Napi::Value ActionPublishStatus(const Napi::CallbackInfo& info) {
|
|
321
|
+
Napi::Env env = info.Env();
|
|
322
|
+
|
|
323
|
+
RclHandle* action_server_handle =
|
|
324
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
325
|
+
rcl_action_server_t* action_server =
|
|
326
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
327
|
+
|
|
328
|
+
rcl_action_goal_status_array_t status_message =
|
|
329
|
+
rcl_action_get_zero_initialized_goal_status_array();
|
|
330
|
+
|
|
331
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
332
|
+
rcl_action_get_goal_status_array(action_server, &status_message),
|
|
333
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
334
|
+
|
|
335
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
336
|
+
rcl_action_publish_status(action_server, &status_message), RCL_RET_OK,
|
|
337
|
+
rcl_get_error_string().str);
|
|
338
|
+
|
|
339
|
+
return env.Undefined();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
Napi::Value ActionNotifyGoalDone(const Napi::CallbackInfo& info) {
|
|
343
|
+
Napi::Env env = info.Env();
|
|
344
|
+
|
|
345
|
+
RclHandle* action_server_handle =
|
|
346
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
347
|
+
rcl_action_server_t* action_server =
|
|
348
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
349
|
+
|
|
350
|
+
THROW_ERROR_IF_NOT_EQUAL(rcl_action_notify_goal_done(action_server),
|
|
351
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
352
|
+
|
|
353
|
+
return env.Undefined();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
Napi::Value ActionPublishFeedback(const Napi::CallbackInfo& info) {
|
|
357
|
+
Napi::Env env = info.Env();
|
|
358
|
+
|
|
359
|
+
rcl_action_server_t* action_server = reinterpret_cast<rcl_action_server_t*>(
|
|
360
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>())->ptr());
|
|
361
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
362
|
+
|
|
363
|
+
THROW_ERROR_IF_NOT_EQUAL(rcl_action_publish_feedback(action_server, buffer),
|
|
364
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
365
|
+
|
|
366
|
+
return env.Undefined();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
Napi::Value ActionProcessCancelRequest(const Napi::CallbackInfo& info) {
|
|
370
|
+
Napi::Env env = info.Env();
|
|
371
|
+
|
|
372
|
+
RclHandle* action_server_handle =
|
|
373
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
374
|
+
rcl_action_server_t* action_server =
|
|
375
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
376
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
377
|
+
rcl_action_cancel_request_t* cancel_request =
|
|
378
|
+
reinterpret_cast<rcl_action_cancel_request_t*>(buffer);
|
|
379
|
+
void* response_buffer = info[2].As<Napi::Buffer<char>>().Data();
|
|
380
|
+
action_msgs__srv__CancelGoal_Response* response =
|
|
381
|
+
reinterpret_cast<action_msgs__srv__CancelGoal_Response*>(response_buffer);
|
|
382
|
+
|
|
383
|
+
rcl_action_cancel_response_t* cancel_response_ptr =
|
|
384
|
+
reinterpret_cast<rcl_action_cancel_response_t*>(
|
|
385
|
+
malloc(sizeof(rcl_action_cancel_response_t)));
|
|
386
|
+
|
|
387
|
+
*cancel_response_ptr = rcl_action_get_zero_initialized_cancel_response();
|
|
388
|
+
|
|
389
|
+
rcl_ret_t ret = rcl_action_process_cancel_request(
|
|
390
|
+
action_server, cancel_request, cancel_response_ptr);
|
|
391
|
+
if (ret != RCL_RET_OK) {
|
|
392
|
+
// fetch the error triggered by rcl_action_process_cancel_request
|
|
393
|
+
rcutils_error_string_t cancel_error = rcl_get_error_string();
|
|
394
|
+
rcl_reset_error();
|
|
395
|
+
rcl_ret_t ret_fini = rcl_action_cancel_response_fini(cancel_response_ptr);
|
|
396
|
+
if (ret_fini != RCL_RET_OK) {
|
|
397
|
+
RCUTILS_LOG_WARN_NAMED(
|
|
398
|
+
PACKAGE_NAME,
|
|
399
|
+
"There was an error finalizing the action cancel response: %s",
|
|
400
|
+
rcl_get_error_string().str);
|
|
401
|
+
rcl_reset_error();
|
|
402
|
+
}
|
|
403
|
+
free(cancel_response_ptr);
|
|
404
|
+
Napi::Error::New(env, cancel_error.str).ThrowAsJavaScriptException();
|
|
405
|
+
return env.Undefined();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
*response = cancel_response_ptr->msg;
|
|
409
|
+
auto js_obj =
|
|
410
|
+
RclHandle::NewInstance(env, cancel_response_ptr, nullptr, [](void* ptr) {
|
|
411
|
+
rcl_action_cancel_response_t* cancel_response_ptr =
|
|
412
|
+
reinterpret_cast<rcl_action_cancel_response_t*>(ptr);
|
|
413
|
+
rcl_ret_t ret = rcl_action_cancel_response_fini(cancel_response_ptr);
|
|
414
|
+
free(ptr);
|
|
415
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
|
|
416
|
+
});
|
|
417
|
+
return js_obj;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
Napi::Value ActionServerGoalExists(const Napi::CallbackInfo& info) {
|
|
421
|
+
Napi::Env env = info.Env();
|
|
422
|
+
|
|
423
|
+
RclHandle* action_server_handle =
|
|
424
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
425
|
+
rcl_action_server_t* action_server =
|
|
426
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
427
|
+
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
|
|
428
|
+
info[1].As<Napi::Buffer<char>>().Data());
|
|
429
|
+
|
|
430
|
+
bool exists = rcl_action_server_goal_exists(action_server, buffer);
|
|
431
|
+
|
|
432
|
+
return Napi::Boolean::New(env, exists);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
Napi::Object InitActionServerBindings(Napi::Env env, Napi::Object exports) {
|
|
436
|
+
exports.Set("actionCreateServer",
|
|
437
|
+
Napi::Function::New(env, ActionCreateServer));
|
|
438
|
+
exports.Set("actionSendCancelRequest",
|
|
439
|
+
Napi::Function::New(env, ActionSendCancelRequest));
|
|
440
|
+
exports.Set("actionTakeResultRequest",
|
|
441
|
+
Napi::Function::New(env, ActionTakeResultRequest));
|
|
442
|
+
exports.Set("actionTakeGoalRequest",
|
|
443
|
+
Napi::Function::New(env, ActionTakeGoalRequest));
|
|
444
|
+
exports.Set("actionSendGoalResponse",
|
|
445
|
+
Napi::Function::New(env, ActionSendGoalResponse));
|
|
446
|
+
exports.Set("actionSendCancelResponse",
|
|
447
|
+
Napi::Function::New(env, ActionSendCancelResponse));
|
|
448
|
+
exports.Set("actionSendResultResponse",
|
|
449
|
+
Napi::Function::New(env, ActionSendResultResponse));
|
|
450
|
+
exports.Set("actionTakeGoalResponse",
|
|
451
|
+
Napi::Function::New(env, ActionTakeGoalResponse));
|
|
452
|
+
exports.Set("actionTakeCancelResponse",
|
|
453
|
+
Napi::Function::New(env, ActionTakeCancelResponse));
|
|
454
|
+
exports.Set("actionTakeResultResponse",
|
|
455
|
+
Napi::Function::New(env, ActionTakeResultResponse));
|
|
456
|
+
exports.Set("actionExpireGoals", Napi::Function::New(env, ActionExpireGoals));
|
|
457
|
+
exports.Set("actionPublishStatus",
|
|
458
|
+
Napi::Function::New(env, ActionPublishStatus));
|
|
459
|
+
exports.Set("actionNotifyGoalDone",
|
|
460
|
+
Napi::Function::New(env, ActionNotifyGoalDone));
|
|
461
|
+
exports.Set("actionPublishFeedback",
|
|
462
|
+
Napi::Function::New(env, ActionPublishFeedback));
|
|
463
|
+
exports.Set("actionProcessCancelRequest",
|
|
464
|
+
Napi::Function::New(env, ActionProcessCancelRequest));
|
|
465
|
+
exports.Set("actionServerGoalExists",
|
|
466
|
+
Napi::Function::New(env, ActionServerGoalExists));
|
|
467
|
+
return exports;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
} // 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_SERVER_BINDINGS_H_
|
|
16
|
+
#define SRC_RCL_ACTION_SERVER_BINDINGS_H_
|
|
17
|
+
|
|
18
|
+
#include <napi.h>
|
|
19
|
+
|
|
20
|
+
namespace rclnodejs {
|
|
21
|
+
|
|
22
|
+
Napi::Object InitActionServerBindings(Napi::Env env, Napi::Object exports);
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#endif // SRC_RCL_ACTION_SERVER_BINDINGS_H_
|