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.
- package/README.md +3 -3
- package/binding.gyp +25 -2
- package/lib/action/client.js +40 -0
- package/lib/action/server.js +21 -0
- package/lib/client.js +3 -4
- package/lib/context.js +8 -0
- package/lib/distro.js +2 -0
- package/lib/lifecycle.js +9 -0
- package/lib/logging.js +26 -9
- package/lib/node.js +81 -1
- package/lib/node_options.js +21 -1
- package/lib/publisher.js +27 -0
- package/lib/service.js +10 -3
- package/lib/subscription.js +8 -0
- package/lib/timer.js +32 -0
- package/lib/type_description_service.js +82 -0
- package/package.json +4 -4
- package/scripts/config.js +1 -0
- package/scripts/npmjs-readme.md +3 -3
- package/src/addon.cpp +60 -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 +306 -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 +520 -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 +148 -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 +476 -0
- package/src/rcl_node_bindings.h +26 -0
- package/src/rcl_publisher_bindings.cpp +160 -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_type_description_service_bindings.cpp +79 -0
- package/src/rcl_type_description_service_bindings.h +27 -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/action_client.d.ts +18 -0
- package/types/action_server.d.ts +12 -0
- package/types/context.d.ts +6 -0
- package/types/lifecycle.d.ts +7 -0
- package/types/node.d.ts +69 -0
- package/types/publisher.d.ts +23 -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,280 @@
|
|
|
1
|
+
// Copyright (c) 2025, The Robot Web Tools Contributors
|
|
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_graph_bindings.h"
|
|
16
|
+
|
|
17
|
+
#include <rcl/error_handling.h>
|
|
18
|
+
#include <rcl/graph.h>
|
|
19
|
+
#include <rcl/rcl.h>
|
|
20
|
+
|
|
21
|
+
#include <rcpputils/scope_exit.hpp>
|
|
22
|
+
// NOLINTNEXTLINE
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
#include "macros.h"
|
|
26
|
+
#include "rcl_handle.h"
|
|
27
|
+
#include "rcl_utilities.h"
|
|
28
|
+
|
|
29
|
+
namespace rclnodejs {
|
|
30
|
+
|
|
31
|
+
typedef rcl_ret_t (*rcl_get_info_by_topic_func_t)(
|
|
32
|
+
const rcl_node_t* node, rcutils_allocator_t* allocator,
|
|
33
|
+
const char* topic_name, bool no_mangle,
|
|
34
|
+
rcl_topic_endpoint_info_array_t* info_array);
|
|
35
|
+
|
|
36
|
+
Napi::Value GetPublisherNamesAndTypesByNode(const Napi::CallbackInfo& info) {
|
|
37
|
+
Napi::Env env = info.Env();
|
|
38
|
+
|
|
39
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
40
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
41
|
+
std::string node_name = info[1].As<Napi::String>().Utf8Value();
|
|
42
|
+
std::string node_namespace = info[2].As<Napi::String>().Utf8Value();
|
|
43
|
+
bool no_demangle = info[3].As<Napi::Boolean>();
|
|
44
|
+
|
|
45
|
+
rcl_names_and_types_t topic_names_and_types =
|
|
46
|
+
rcl_get_zero_initialized_names_and_types();
|
|
47
|
+
rcl_allocator_t allocator = rcl_get_default_allocator();
|
|
48
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
49
|
+
rcl_get_publisher_names_and_types_by_node(
|
|
50
|
+
node, &allocator, no_demangle, node_name.c_str(),
|
|
51
|
+
node_namespace.c_str(), &topic_names_and_types),
|
|
52
|
+
"Failed to get_publisher_names_and_types.");
|
|
53
|
+
|
|
54
|
+
Napi::Array result_list =
|
|
55
|
+
Napi::Array::New(env, topic_names_and_types.names.size);
|
|
56
|
+
ExtractNamesAndTypes(topic_names_and_types, &result_list);
|
|
57
|
+
|
|
58
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
59
|
+
rcl_names_and_types_fini(&topic_names_and_types),
|
|
60
|
+
"Failed to destroy topic_names_and_types");
|
|
61
|
+
|
|
62
|
+
return result_list;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Napi::Value GetSubscriptionNamesAndTypesByNode(const Napi::CallbackInfo& info) {
|
|
66
|
+
Napi::Env env = info.Env();
|
|
67
|
+
|
|
68
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
69
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
70
|
+
std::string node_name = info[1].As<Napi::String>().Utf8Value();
|
|
71
|
+
std::string node_namespace = info[2].As<Napi::String>().Utf8Value();
|
|
72
|
+
bool no_demangle = info[3].As<Napi::Boolean>();
|
|
73
|
+
|
|
74
|
+
rcl_names_and_types_t topic_names_and_types =
|
|
75
|
+
rcl_get_zero_initialized_names_and_types();
|
|
76
|
+
rcl_allocator_t allocator = rcl_get_default_allocator();
|
|
77
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
78
|
+
rcl_get_subscriber_names_and_types_by_node(
|
|
79
|
+
node, &allocator, no_demangle, node_name.c_str(),
|
|
80
|
+
node_namespace.c_str(), &topic_names_and_types),
|
|
81
|
+
"Failed to get_publisher_names_and_types.");
|
|
82
|
+
|
|
83
|
+
Napi::Array result_list =
|
|
84
|
+
Napi::Array::New(env, topic_names_and_types.names.size);
|
|
85
|
+
ExtractNamesAndTypes(topic_names_and_types, &result_list);
|
|
86
|
+
|
|
87
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
88
|
+
rcl_names_and_types_fini(&topic_names_and_types),
|
|
89
|
+
"Failed to destroy topic_names_and_types");
|
|
90
|
+
|
|
91
|
+
return result_list;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Napi::Value GetServiceNamesAndTypesByNode(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
|
+
std::string node_name = info[1].As<Napi::String>().Utf8Value();
|
|
100
|
+
std::string node_namespace = info[2].As<Napi::String>().Utf8Value();
|
|
101
|
+
|
|
102
|
+
rcl_names_and_types_t service_names_and_types =
|
|
103
|
+
rcl_get_zero_initialized_names_and_types();
|
|
104
|
+
rcl_allocator_t allocator = rcl_get_default_allocator();
|
|
105
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
106
|
+
RCL_RET_OK,
|
|
107
|
+
rcl_get_service_names_and_types_by_node(
|
|
108
|
+
node, &allocator, node_name.c_str(), node_namespace.c_str(),
|
|
109
|
+
&service_names_and_types),
|
|
110
|
+
"Failed to get_service_names_and_types.");
|
|
111
|
+
|
|
112
|
+
Napi::Array result_list =
|
|
113
|
+
Napi::Array::New(env, service_names_and_types.names.size);
|
|
114
|
+
ExtractNamesAndTypes(service_names_and_types, &result_list);
|
|
115
|
+
|
|
116
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
117
|
+
RCL_RET_OK, rcl_names_and_types_fini(&service_names_and_types),
|
|
118
|
+
"Failed to destroy rcl_get_zero_initialized_names_and_types");
|
|
119
|
+
|
|
120
|
+
return result_list;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Napi::Value GetClientNamesAndTypesByNode(const Napi::CallbackInfo& info) {
|
|
124
|
+
Napi::Env env = info.Env();
|
|
125
|
+
|
|
126
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
127
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
128
|
+
std::string node_name = info[1].As<Napi::String>().Utf8Value();
|
|
129
|
+
std::string node_namespace = info[2].As<Napi::String>().Utf8Value();
|
|
130
|
+
|
|
131
|
+
rcl_names_and_types_t client_names_and_types =
|
|
132
|
+
rcl_get_zero_initialized_names_and_types();
|
|
133
|
+
rcl_allocator_t allocator = rcl_get_default_allocator();
|
|
134
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
135
|
+
rcl_get_client_names_and_types_by_node(
|
|
136
|
+
node, &allocator, node_name.c_str(),
|
|
137
|
+
node_namespace.c_str(), &client_names_and_types),
|
|
138
|
+
"Failed to get_client_names_and_types.");
|
|
139
|
+
|
|
140
|
+
Napi::Array result_list =
|
|
141
|
+
Napi::Array::New(env, client_names_and_types.names.size);
|
|
142
|
+
ExtractNamesAndTypes(client_names_and_types, &result_list);
|
|
143
|
+
|
|
144
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
145
|
+
RCL_RET_OK, rcl_names_and_types_fini(&client_names_and_types),
|
|
146
|
+
"Failed to destroy rcl_get_zero_initialized_names_and_types");
|
|
147
|
+
|
|
148
|
+
return result_list;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
Napi::Value GetTopicNamesAndTypes(const Napi::CallbackInfo& info) {
|
|
152
|
+
Napi::Env env = info.Env();
|
|
153
|
+
|
|
154
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
155
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
156
|
+
bool no_demangle = info[1].As<Napi::Boolean>();
|
|
157
|
+
rcl_names_and_types_t topic_names_and_types =
|
|
158
|
+
rcl_get_zero_initialized_names_and_types();
|
|
159
|
+
rcl_allocator_t allocator = rcl_get_default_allocator();
|
|
160
|
+
|
|
161
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
162
|
+
RCL_RET_OK,
|
|
163
|
+
rcl_get_topic_names_and_types(node, &allocator, no_demangle,
|
|
164
|
+
&topic_names_and_types),
|
|
165
|
+
"Failed to get_publisher_names_and_types.");
|
|
166
|
+
|
|
167
|
+
Napi::Array result_list =
|
|
168
|
+
Napi::Array::New(env, topic_names_and_types.names.size);
|
|
169
|
+
ExtractNamesAndTypes(topic_names_and_types, &result_list);
|
|
170
|
+
|
|
171
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
172
|
+
rcl_names_and_types_fini(&topic_names_and_types),
|
|
173
|
+
"Failed to destroy topic_names_and_types");
|
|
174
|
+
|
|
175
|
+
return result_list;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
Napi::Value GetServiceNamesAndTypes(const Napi::CallbackInfo& info) {
|
|
179
|
+
Napi::Env env = info.Env();
|
|
180
|
+
|
|
181
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
182
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
183
|
+
rcl_names_and_types_t service_names_and_types =
|
|
184
|
+
rcl_get_zero_initialized_names_and_types();
|
|
185
|
+
rcl_allocator_t allocator = rcl_get_default_allocator();
|
|
186
|
+
|
|
187
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
188
|
+
rcl_get_service_names_and_types(
|
|
189
|
+
node, &allocator, &service_names_and_types),
|
|
190
|
+
"Failed to get_publisher_names_and_types.");
|
|
191
|
+
|
|
192
|
+
Napi::Array result_list =
|
|
193
|
+
Napi::Array::New(env, service_names_and_types.names.size);
|
|
194
|
+
ExtractNamesAndTypes(service_names_and_types, &result_list);
|
|
195
|
+
|
|
196
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
197
|
+
rcl_names_and_types_fini(&service_names_and_types),
|
|
198
|
+
"Failed to destroy topic_names_and_types");
|
|
199
|
+
|
|
200
|
+
return result_list;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
Napi::Value GetInfoByTopic(Napi::Env env, rcl_node_t* node,
|
|
204
|
+
const char* topic_name, bool no_mangle,
|
|
205
|
+
const char* type,
|
|
206
|
+
rcl_get_info_by_topic_func_t rcl_get_info_by_topic) {
|
|
207
|
+
rcutils_allocator_t allocator = rcutils_get_default_allocator();
|
|
208
|
+
rcl_topic_endpoint_info_array_t info_array =
|
|
209
|
+
rcl_get_zero_initialized_topic_endpoint_info_array();
|
|
210
|
+
|
|
211
|
+
RCPPUTILS_SCOPE_EXIT({
|
|
212
|
+
rcl_ret_t fini_ret =
|
|
213
|
+
rcl_topic_endpoint_info_array_fini(&info_array, &allocator);
|
|
214
|
+
if (RCL_RET_OK != fini_ret) {
|
|
215
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
216
|
+
.ThrowAsJavaScriptException();
|
|
217
|
+
rcl_reset_error();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
rcl_ret_t ret = rcl_get_info_by_topic(node, &allocator, topic_name, no_mangle,
|
|
222
|
+
&info_array);
|
|
223
|
+
if (RCL_RET_OK != ret) {
|
|
224
|
+
if (RCL_RET_UNSUPPORTED == ret) {
|
|
225
|
+
Napi::Error::New(
|
|
226
|
+
env, std::string("Failed to get information by topic for ") + type +
|
|
227
|
+
": function not supported by RMW_IMPLEMENTATION")
|
|
228
|
+
.ThrowAsJavaScriptException();
|
|
229
|
+
return env.Undefined();
|
|
230
|
+
}
|
|
231
|
+
Napi::Error::New(
|
|
232
|
+
env, std::string("Failed to get information by topic for ") + type)
|
|
233
|
+
.ThrowAsJavaScriptException();
|
|
234
|
+
return env.Undefined();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return ConvertToJSTopicEndpointInfoList(env, &info_array);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
Napi::Value GetPublishersInfoByTopic(const Napi::CallbackInfo& info) {
|
|
241
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
242
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
243
|
+
std::string topic_name = info[1].As<Napi::String>().Utf8Value();
|
|
244
|
+
bool no_mangle = info[2].As<Napi::Boolean>();
|
|
245
|
+
|
|
246
|
+
return GetInfoByTopic(info.Env(), node, topic_name.c_str(), no_mangle,
|
|
247
|
+
"publishers", rcl_get_publishers_info_by_topic);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
Napi::Value GetSubscriptionsInfoByTopic(const Napi::CallbackInfo& info) {
|
|
251
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
252
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
253
|
+
std::string topic_name = info[1].As<Napi::String>().Utf8Value();
|
|
254
|
+
bool no_mangle = info[2].As<Napi::Boolean>();
|
|
255
|
+
|
|
256
|
+
return GetInfoByTopic(info.Env(), node, topic_name.c_str(), no_mangle,
|
|
257
|
+
"subscriptions", rcl_get_subscriptions_info_by_topic);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Napi::Object InitGraphBindings(Napi::Env env, Napi::Object exports) {
|
|
261
|
+
exports.Set("getPublisherNamesAndTypesByNode",
|
|
262
|
+
Napi::Function::New(env, GetPublisherNamesAndTypesByNode));
|
|
263
|
+
exports.Set("getSubscriptionNamesAndTypesByNode",
|
|
264
|
+
Napi::Function::New(env, GetSubscriptionNamesAndTypesByNode));
|
|
265
|
+
exports.Set("getServiceNamesAndTypesByNode",
|
|
266
|
+
Napi::Function::New(env, GetServiceNamesAndTypesByNode));
|
|
267
|
+
exports.Set("getClientNamesAndTypesByNode",
|
|
268
|
+
Napi::Function::New(env, GetClientNamesAndTypesByNode));
|
|
269
|
+
exports.Set("getTopicNamesAndTypes",
|
|
270
|
+
Napi::Function::New(env, GetTopicNamesAndTypes));
|
|
271
|
+
exports.Set("getServiceNamesAndTypes",
|
|
272
|
+
Napi::Function::New(env, GetServiceNamesAndTypes));
|
|
273
|
+
exports.Set("getPublishersInfoByTopic",
|
|
274
|
+
Napi::Function::New(env, GetPublishersInfoByTopic));
|
|
275
|
+
exports.Set("getSubscriptionsInfoByTopic",
|
|
276
|
+
Napi::Function::New(env, GetSubscriptionsInfoByTopic));
|
|
277
|
+
return exports;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
} // namespace rclnodejs
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2025, The Robot Web Tools Contributors
|
|
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_GRAPH_BINDINGS_H_
|
|
16
|
+
#define SRC_RCL_GRAPH_BINDINGS_H_
|
|
17
|
+
|
|
18
|
+
#include <napi.h>
|
|
19
|
+
|
|
20
|
+
namespace rclnodejs {
|
|
21
|
+
|
|
22
|
+
Napi::Object InitGraphBindings(Napi::Env env, Napi::Object exports);
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#endif // SRC_RCL_GRAPH_BINDINGS_H_
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) 2025, The Robot Web Tools Contributors
|
|
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_guard_condition_bindings.h"
|
|
16
|
+
|
|
17
|
+
#include <rcl/error_handling.h>
|
|
18
|
+
#include <rcl/rcl.h>
|
|
19
|
+
|
|
20
|
+
#include "macros.h"
|
|
21
|
+
#include "rcl_handle.h"
|
|
22
|
+
#include "rcl_utilities.h"
|
|
23
|
+
|
|
24
|
+
namespace rclnodejs {
|
|
25
|
+
|
|
26
|
+
Napi::Value CreateGuardCondition(const Napi::CallbackInfo& info) {
|
|
27
|
+
Napi::Env env = info.Env();
|
|
28
|
+
|
|
29
|
+
RclHandle* context_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
30
|
+
rcl_context_t* context =
|
|
31
|
+
reinterpret_cast<rcl_context_t*>(context_handle->ptr());
|
|
32
|
+
|
|
33
|
+
rcl_guard_condition_t* gc = reinterpret_cast<rcl_guard_condition_t*>(
|
|
34
|
+
malloc(sizeof(rcl_guard_condition_t)));
|
|
35
|
+
|
|
36
|
+
*gc = rcl_get_zero_initialized_guard_condition();
|
|
37
|
+
rcl_guard_condition_options_t gc_options =
|
|
38
|
+
rcl_guard_condition_get_default_options();
|
|
39
|
+
|
|
40
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
|
|
41
|
+
rcl_guard_condition_init(gc, context, gc_options),
|
|
42
|
+
rcl_get_error_string().str);
|
|
43
|
+
|
|
44
|
+
auto handle = RclHandle::NewInstance(env, gc, nullptr, [](void* ptr) {
|
|
45
|
+
rcl_guard_condition_t* gc = reinterpret_cast<rcl_guard_condition_t*>(ptr);
|
|
46
|
+
rcl_ret_t ret = rcl_guard_condition_fini(gc);
|
|
47
|
+
free(ptr);
|
|
48
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return handle;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Napi::Value TriggerGuardCondition(const Napi::CallbackInfo& info) {
|
|
55
|
+
Napi::Env env = info.Env();
|
|
56
|
+
|
|
57
|
+
RclHandle* gc_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
58
|
+
rcl_guard_condition_t* gc =
|
|
59
|
+
reinterpret_cast<rcl_guard_condition_t*>(gc_handle->ptr());
|
|
60
|
+
|
|
61
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, rcl_trigger_guard_condition(gc),
|
|
62
|
+
rcl_get_error_string().str);
|
|
63
|
+
|
|
64
|
+
return env.Undefined();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Napi::Object InitGuardConditionBindings(Napi::Env env, Napi::Object exports) {
|
|
68
|
+
exports.Set("createGuardCondition",
|
|
69
|
+
Napi::Function::New(env, CreateGuardCondition));
|
|
70
|
+
exports.Set("triggerGuardCondition",
|
|
71
|
+
Napi::Function::New(env, TriggerGuardCondition));
|
|
72
|
+
return exports;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // namespace rclnodejs
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2025, The Robot Web Tools Contributors
|
|
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_GUARD_CONDITION_BINDINGS_H_
|
|
16
|
+
#define SRC_RCL_GUARD_CONDITION_BINDINGS_H_
|
|
17
|
+
|
|
18
|
+
#include <napi.h>
|
|
19
|
+
|
|
20
|
+
namespace rclnodejs {
|
|
21
|
+
|
|
22
|
+
Napi::Object InitGuardConditionBindings(Napi::Env env, Napi::Object exports);
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#endif // SRC_RCL_GUARD_CONDITION_BINDINGS_H_
|
package/src/rcl_handle.cpp
CHANGED
|
@@ -12,91 +12,75 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#include "rcl_handle.
|
|
15
|
+
#include "rcl_handle.h"
|
|
16
16
|
|
|
17
17
|
#include <rcl/error_handling.h>
|
|
18
18
|
#include <rcl/rcl.h>
|
|
19
19
|
|
|
20
|
+
#include "rcl_utilities.h"
|
|
21
|
+
|
|
20
22
|
namespace rclnodejs {
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
Napi::FunctionReference RclHandle::constructor;
|
|
23
25
|
|
|
24
|
-
RclHandle::RclHandle(
|
|
26
|
+
RclHandle::RclHandle(const Napi::CallbackInfo& info)
|
|
27
|
+
: Napi::ObjectWrap<RclHandle>(info), pointer_(nullptr), parent_(nullptr) {}
|
|
25
28
|
|
|
26
29
|
RclHandle::~RclHandle() {
|
|
27
30
|
if (pointer_) Reset();
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
tpl->SetClassName(Nan::New("RclHandle").ToLocalChecked());
|
|
33
|
-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
33
|
+
Napi::Object RclHandle::Init(Napi::Env env, Napi::Object exports) {
|
|
34
|
+
Napi::HandleScope scope(env);
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
Napi::Function func = DefineClass(
|
|
37
|
+
env, "RclHandle",
|
|
38
|
+
{InstanceMethod("release", &RclHandle::Release),
|
|
39
|
+
InstanceMethod("dismiss", &RclHandle::Dismiss),
|
|
40
|
+
InstanceAccessor("properties", &RclHandle::PropertiesGetter, nullptr)});
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
constructor = Napi::Persistent(func);
|
|
43
|
+
constructor.SuppressDestruct();
|
|
44
|
+
exports.Set("RclHandle", func);
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
Nan::Set(exports, Nan::New("RclHandle").ToLocalChecked(),
|
|
44
|
-
tpl->GetFunction(context).ToLocalChecked());
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
void RclHandle::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
|
48
|
-
if (info.IsConstructCall()) {
|
|
49
|
-
RclHandle* obj = new RclHandle();
|
|
50
|
-
obj->Wrap(info.This());
|
|
51
|
-
info.GetReturnValue().Set(info.This());
|
|
52
|
-
}
|
|
46
|
+
return exports;
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
void RclHandle::SyncProperties() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
Napi::Env env = rclnodejs::GetEnv();
|
|
51
|
+
Napi::HandleScope scope(env);
|
|
52
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
53
|
+
for (auto& pair : properties_) {
|
|
54
|
+
obj.Set(pair.first, Napi::Boolean::New(env, pair.second));
|
|
60
55
|
}
|
|
61
|
-
|
|
62
|
-
properties_obj_ = obj;
|
|
56
|
+
properties_obj_ = Napi::Persistent(obj);
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!me->properties_obj_.IsEmpty())
|
|
69
|
-
info.GetReturnValue().Set(me->properties_obj_);
|
|
70
|
-
else
|
|
71
|
-
info.GetReturnValue().Set(Nan::Undefined());
|
|
59
|
+
Napi::Value RclHandle::PropertiesGetter(const Napi::CallbackInfo& info) {
|
|
60
|
+
return !properties_obj_.IsEmpty() ? properties_obj_.Value()
|
|
61
|
+
: info.Env().Undefined();
|
|
72
62
|
}
|
|
73
63
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
info.GetReturnValue().Set(Nan::Undefined());
|
|
64
|
+
Napi::Value RclHandle::Release(const Napi::CallbackInfo& info) {
|
|
65
|
+
Napi::Env env = info.Env();
|
|
66
|
+
if (ptr()) Reset();
|
|
67
|
+
return env.Undefined();
|
|
79
68
|
}
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
info.GetReturnValue().Set(Nan::Undefined());
|
|
70
|
+
Napi::Value RclHandle::Dismiss(const Napi::CallbackInfo& info) {
|
|
71
|
+
Napi::Env env = info.Env();
|
|
72
|
+
set_ptr(nullptr);
|
|
73
|
+
return env.Undefined();
|
|
86
74
|
}
|
|
87
75
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
|
|
93
|
-
v8::Local<v8::Context> context =
|
|
94
|
-
v8::Isolate::GetCurrent()->GetCurrentContext();
|
|
76
|
+
Napi::Object RclHandle::NewInstance(Napi::Env env, void* handle,
|
|
77
|
+
RclHandle* parent,
|
|
78
|
+
std::function<void(void*)> deleter) {
|
|
79
|
+
Napi::EscapableHandleScope scope(env);
|
|
95
80
|
|
|
96
|
-
|
|
97
|
-
cons->NewInstance(context, 0, nullptr).ToLocalChecked();
|
|
81
|
+
Napi::Object instance = constructor.New({});
|
|
98
82
|
|
|
99
|
-
|
|
83
|
+
RclHandle* rcl_handle = Napi::ObjectWrap<RclHandle>::Unwrap(instance);
|
|
100
84
|
rcl_handle->set_ptr(handle);
|
|
101
85
|
rcl_handle->set_deleter(deleter);
|
|
102
86
|
if (parent) {
|
|
@@ -104,7 +88,7 @@ v8::Local<v8::Object> RclHandle::NewInstance(
|
|
|
104
88
|
parent->AddChild(rcl_handle);
|
|
105
89
|
}
|
|
106
90
|
|
|
107
|
-
return scope.Escape(instance);
|
|
91
|
+
return scope.Escape(instance).As<Napi::Object>();
|
|
108
92
|
}
|
|
109
93
|
|
|
110
94
|
void RclHandle::Reset() {
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#ifndef
|
|
16
|
-
#define
|
|
15
|
+
#ifndef SRC_RCL_HANDLE_H_
|
|
16
|
+
#define SRC_RCL_HANDLE_H_
|
|
17
17
|
|
|
18
|
-
#include <
|
|
18
|
+
#include <napi.h>
|
|
19
19
|
|
|
20
20
|
#include <functional>
|
|
21
21
|
#include <map>
|
|
@@ -24,11 +24,15 @@
|
|
|
24
24
|
|
|
25
25
|
namespace rclnodejs {
|
|
26
26
|
|
|
27
|
-
class RclHandle : public
|
|
27
|
+
class RclHandle : public Napi::ObjectWrap<RclHandle> {
|
|
28
28
|
public:
|
|
29
|
-
static
|
|
30
|
-
static
|
|
31
|
-
|
|
29
|
+
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
30
|
+
static Napi::Object NewInstance(Napi::Env env, void* handle,
|
|
31
|
+
RclHandle* parent,
|
|
32
|
+
std::function<void(void*)> deleter);
|
|
33
|
+
|
|
34
|
+
explicit RclHandle(const Napi::CallbackInfo& info);
|
|
35
|
+
~RclHandle();
|
|
32
36
|
|
|
33
37
|
void set_deleter(std::function<void(void*)> deleter) { deleter_ = deleter; }
|
|
34
38
|
|
|
@@ -47,25 +51,22 @@ class RclHandle : public Nan::ObjectWrap {
|
|
|
47
51
|
void SyncProperties();
|
|
48
52
|
|
|
49
53
|
private:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
static Nan::Persistent<v8::Function> constructor;
|
|
54
|
-
static void New(const Nan::FunctionCallbackInfo<v8::Value>& info);
|
|
55
|
-
static NAN_METHOD(Release);
|
|
56
|
-
static NAN_METHOD(Dismiss);
|
|
57
|
-
static NAN_GETTER(PropertiesGetter);
|
|
54
|
+
Napi::Value Release(const Napi::CallbackInfo& info);
|
|
55
|
+
Napi::Value Dismiss(const Napi::CallbackInfo& info);
|
|
56
|
+
Napi::Value PropertiesGetter(const Napi::CallbackInfo& info);
|
|
58
57
|
|
|
59
58
|
private:
|
|
60
59
|
void* pointer_;
|
|
61
60
|
RclHandle* parent_;
|
|
62
61
|
std::map<std::string, bool> properties_;
|
|
63
|
-
|
|
62
|
+
Napi::ObjectReference properties_obj_;
|
|
64
63
|
|
|
65
64
|
std::function<void(void*)> deleter_;
|
|
66
65
|
std::set<RclHandle*> children_;
|
|
66
|
+
|
|
67
|
+
static Napi::FunctionReference constructor;
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
} // namespace rclnodejs
|
|
70
71
|
|
|
71
|
-
#endif //
|
|
72
|
+
#endif // SRC_RCL_HANDLE_H_
|