rclnodejs 1.8.0 → 1.8.1
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/lib/native_loader.js +11 -1
- package/lib/time.js +2 -2
- package/lib/time_source.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +3 -3
- package/prebuilds/linux-arm64/humble-jammy-arm64-rclnodejs.node +0 -0
- package/prebuilds/linux-arm64/jazzy-noble-arm64-rclnodejs.node +0 -0
- package/prebuilds/linux-arm64/kilted-noble-arm64-rclnodejs.node +0 -0
- package/prebuilds/linux-x64/humble-jammy-x64-rclnodejs.node +0 -0
- package/prebuilds/linux-x64/jazzy-noble-x64-rclnodejs.node +0 -0
- package/prebuilds/linux-x64/kilted-noble-x64-rclnodejs.node +0 -0
- package/rosidl_gen/packages.js +1 -1
- package/src/rcl_subscription_bindings.cpp +99 -36
package/lib/native_loader.js
CHANGED
|
@@ -175,4 +175,14 @@ function loadNativeAddon() {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
const addon = loadNativeAddon();
|
|
179
|
+
|
|
180
|
+
// Export internal functions for testing purposes
|
|
181
|
+
if (process.env.NODE_ENV === 'test') {
|
|
182
|
+
addon.TestHelpers = {
|
|
183
|
+
customFallbackLoader,
|
|
184
|
+
loadNativeAddon,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = addon;
|
package/lib/time.js
CHANGED
|
@@ -352,8 +352,8 @@ class Time {
|
|
|
352
352
|
toMsg() {
|
|
353
353
|
const secondsAndNanoseconds = this.secondsAndNanoseconds;
|
|
354
354
|
return {
|
|
355
|
-
sec: secondsAndNanoseconds.seconds,
|
|
356
|
-
nanosec: secondsAndNanoseconds.nanoseconds,
|
|
355
|
+
sec: Number(secondsAndNanoseconds.seconds),
|
|
356
|
+
nanosec: Number(secondsAndNanoseconds.nanoseconds),
|
|
357
357
|
};
|
|
358
358
|
}
|
|
359
359
|
|
package/lib/time_source.js
CHANGED
|
@@ -102,7 +102,7 @@ class TimeSource {
|
|
|
102
102
|
* @return {undefined}
|
|
103
103
|
*/
|
|
104
104
|
attachNode(node) {
|
|
105
|
-
if ((
|
|
105
|
+
if (!(node instanceof rclnodejs.ShadowNode)) {
|
|
106
106
|
throw new TypeValidationError('node', node, 'Node', {
|
|
107
107
|
entityType: 'time source',
|
|
108
108
|
});
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rclnodejs",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "ROS2.0 JavaScript client with Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"install": "node scripts/install.js",
|
|
26
26
|
"postinstall": "npm run generate-messages",
|
|
27
27
|
"docs": "cd docs && make",
|
|
28
|
-
"test": "nyc node --expose-gc ./scripts/run_test.js && tsd",
|
|
28
|
+
"test": "nyc node --expose-gc ./scripts/run_test.js && tsd && npm install --no-save electron && node test/electron/run_test.js",
|
|
29
29
|
"test-idl": "nyc node --expose-gc ./scripts/run_test.js --idl",
|
|
30
30
|
"lint": "eslint && node ./scripts/cpplint.js",
|
|
31
31
|
"format": "clang-format -i -style=file ./src/*.cpp ./src/*.h && npx --yes prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark,rostsd_gen}/**/*.{js,md,ts}\" ./*.{js,md,ts}",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"eslint": "^9.16.0",
|
|
60
60
|
"eslint-config-prettier": "^10.0.2",
|
|
61
61
|
"eslint-plugin-prettier": "^5.2.1",
|
|
62
|
-
"globals": "^
|
|
62
|
+
"globals": "^17.0.0",
|
|
63
63
|
"husky": "^9.1.7",
|
|
64
64
|
"jsdoc": "^4.0.4",
|
|
65
65
|
"lint-staged": "^16.2.0",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/rosidl_gen/packages.js
CHANGED
|
@@ -223,7 +223,7 @@ async function findPackagesInDirectory(dir, useIDL) {
|
|
|
223
223
|
|
|
224
224
|
// If there is a folder named 'share' under the root path, we consider that
|
|
225
225
|
// the ament build tool has been executed and |amentExecuted| will be true.
|
|
226
|
-
fs.
|
|
226
|
+
fs.stat(path.join(dir, 'share'), (err) => {
|
|
227
227
|
if (err) {
|
|
228
228
|
amentExecuted = false;
|
|
229
229
|
}
|
|
@@ -38,9 +38,9 @@ Napi::Value RclTake(const Napi::CallbackInfo& info) {
|
|
|
38
38
|
rcl_ret_t ret = rcl_take(subscription, msg_taken, nullptr, nullptr);
|
|
39
39
|
|
|
40
40
|
if (ret != RCL_RET_OK && ret != RCL_RET_SUBSCRIPTION_TAKE_FAILED) {
|
|
41
|
+
std::string error_string = rcl_get_error_string().str;
|
|
41
42
|
rcl_reset_error();
|
|
42
|
-
Napi::Error::New(env,
|
|
43
|
-
.ThrowAsJavaScriptException();
|
|
43
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
44
44
|
return Napi::Boolean::New(env, false);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -99,7 +99,7 @@ Napi::Value CreateSubscription(const Napi::CallbackInfo& info) {
|
|
|
99
99
|
for (int i = 0; i < argc; i++) {
|
|
100
100
|
std::string arg = jsArgv.Get(i).As<Napi::String>().Utf8Value();
|
|
101
101
|
int len = arg.length() + 1;
|
|
102
|
-
argv[i] = reinterpret_cast<char*>(malloc(len * sizeof(char
|
|
102
|
+
argv[i] = reinterpret_cast<char*>(malloc(len * sizeof(char)));
|
|
103
103
|
snprintf(argv[i], len, "%s", arg.c_str());
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -109,9 +109,9 @@ Napi::Value CreateSubscription(const Napi::CallbackInfo& info) {
|
|
|
109
109
|
expression.c_str(), argc, (const char**)argv, &subscription_ops);
|
|
110
110
|
|
|
111
111
|
if (ret != RCL_RET_OK) {
|
|
112
|
+
std::string error_string = rcl_get_error_string().str;
|
|
112
113
|
rcl_reset_error();
|
|
113
|
-
Napi::Error::New(env,
|
|
114
|
-
.ThrowAsJavaScriptException();
|
|
114
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (argc) {
|
|
@@ -120,6 +120,11 @@ Napi::Value CreateSubscription(const Napi::CallbackInfo& info) {
|
|
|
120
120
|
}
|
|
121
121
|
free(argv);
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
if (ret != RCL_RET_OK) {
|
|
125
|
+
free(subscription);
|
|
126
|
+
return env.Undefined();
|
|
127
|
+
}
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -127,11 +132,15 @@ Napi::Value CreateSubscription(const Napi::CallbackInfo& info) {
|
|
|
127
132
|
GetMessageTypeSupport(package_name, message_sub_folder, message_name);
|
|
128
133
|
|
|
129
134
|
if (ts) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
rcl_ret_t ret = rcl_subscription_init(subscription, node, ts, topic.c_str(),
|
|
136
|
+
&subscription_ops);
|
|
137
|
+
if (ret != RCL_RET_OK) {
|
|
138
|
+
std::string error_msg = rcl_get_error_string().str;
|
|
139
|
+
rcl_reset_error();
|
|
140
|
+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
|
|
141
|
+
free(subscription);
|
|
142
|
+
return env.Undefined();
|
|
143
|
+
}
|
|
135
144
|
|
|
136
145
|
auto js_obj = RclHandle::NewInstance(
|
|
137
146
|
env, subscription, node_handle, [node, env](void* ptr) {
|
|
@@ -139,14 +148,18 @@ Napi::Value CreateSubscription(const Napi::CallbackInfo& info) {
|
|
|
139
148
|
reinterpret_cast<rcl_subscription_t*>(ptr);
|
|
140
149
|
rcl_ret_t ret = rcl_subscription_fini(subscription, node);
|
|
141
150
|
free(ptr);
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
if (ret != RCL_RET_OK) {
|
|
152
|
+
std::string error_msg = rcl_get_error_string().str;
|
|
153
|
+
rcl_reset_error();
|
|
154
|
+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
|
|
155
|
+
}
|
|
144
156
|
});
|
|
145
157
|
|
|
146
158
|
return js_obj;
|
|
147
159
|
} else {
|
|
148
160
|
Napi::Error::New(env, GetErrorMessageAndClear())
|
|
149
161
|
.ThrowAsJavaScriptException();
|
|
162
|
+
free(subscription);
|
|
150
163
|
return env.Undefined();
|
|
151
164
|
}
|
|
152
165
|
}
|
|
@@ -235,7 +248,7 @@ Napi::Value SetContentFilter(const Napi::CallbackInfo& info) {
|
|
|
235
248
|
for (int i = 0; i < argc; i++) {
|
|
236
249
|
std::string arg = jsArgv.Get(i).As<Napi::String>().Utf8Value();
|
|
237
250
|
int len = arg.length() + 1;
|
|
238
|
-
argv[i] = reinterpret_cast<char*>(malloc(len * sizeof(char
|
|
251
|
+
argv[i] = reinterpret_cast<char*>(malloc(len * sizeof(char)));
|
|
239
252
|
snprintf(argv[i], len, "%s", arg.c_str());
|
|
240
253
|
}
|
|
241
254
|
}
|
|
@@ -245,15 +258,23 @@ Napi::Value SetContentFilter(const Napi::CallbackInfo& info) {
|
|
|
245
258
|
rcl_subscription_content_filter_options_t options =
|
|
246
259
|
rcl_get_zero_initialized_subscription_content_filter_options();
|
|
247
260
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
261
|
+
rcl_ret_t ret = rcl_subscription_content_filter_options_set(
|
|
262
|
+
subscription, expression.c_str(), argc, (const char**)argv, &options);
|
|
263
|
+
|
|
264
|
+
if (ret != RCL_RET_OK) {
|
|
265
|
+
if (argc) {
|
|
266
|
+
for (int i = 0; i < argc; i++) {
|
|
267
|
+
free(argv[i]);
|
|
268
|
+
}
|
|
269
|
+
free(argv);
|
|
270
|
+
}
|
|
271
|
+
std::string error_string = rcl_get_error_string().str;
|
|
272
|
+
rcl_reset_error();
|
|
273
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
274
|
+
return env.Undefined();
|
|
275
|
+
}
|
|
253
276
|
|
|
254
|
-
|
|
255
|
-
RCL_RET_OK, rcl_subscription_set_content_filter(subscription, &options),
|
|
256
|
-
rcl_get_error_string().str);
|
|
277
|
+
ret = rcl_subscription_set_content_filter(subscription, &options);
|
|
257
278
|
|
|
258
279
|
if (argc) {
|
|
259
280
|
for (int i = 0; i < argc; i++) {
|
|
@@ -262,6 +283,27 @@ Napi::Value SetContentFilter(const Napi::CallbackInfo& info) {
|
|
|
262
283
|
free(argv);
|
|
263
284
|
}
|
|
264
285
|
|
|
286
|
+
std::string error_string = "";
|
|
287
|
+
if (ret != RCL_RET_OK) {
|
|
288
|
+
error_string = rcl_get_error_string().str;
|
|
289
|
+
rcl_reset_error();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
rcl_ret_t fini_ret =
|
|
293
|
+
rcl_subscription_content_filter_options_fini(subscription, &options);
|
|
294
|
+
|
|
295
|
+
if (ret != RCL_RET_OK) {
|
|
296
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
297
|
+
return env.Undefined();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (fini_ret != RCL_RET_OK) {
|
|
301
|
+
error_string = rcl_get_error_string().str;
|
|
302
|
+
rcl_reset_error();
|
|
303
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
304
|
+
return env.Undefined();
|
|
305
|
+
}
|
|
306
|
+
|
|
265
307
|
return Napi::Boolean::New(env, true);
|
|
266
308
|
}
|
|
267
309
|
|
|
@@ -277,15 +319,33 @@ Napi::Value ClearContentFilter(const Napi::CallbackInfo& info) {
|
|
|
277
319
|
rcl_subscription_content_filter_options_t options =
|
|
278
320
|
rcl_get_zero_initialized_subscription_content_filter_options();
|
|
279
321
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
322
|
+
rcl_ret_t ret = rcl_subscription_content_filter_options_init(
|
|
323
|
+
subscription, "", 0, (const char**)nullptr, &options);
|
|
324
|
+
|
|
325
|
+
if (ret != RCL_RET_OK) {
|
|
326
|
+
std::string error_string = rcl_get_error_string().str;
|
|
327
|
+
rcl_reset_error();
|
|
328
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
329
|
+
return env.Undefined();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
ret = rcl_subscription_set_content_filter(subscription, &options);
|
|
333
|
+
rcl_ret_t fini_ret =
|
|
334
|
+
rcl_subscription_content_filter_options_fini(subscription, &options);
|
|
335
|
+
|
|
336
|
+
if (ret != RCL_RET_OK) {
|
|
337
|
+
std::string error_string = rcl_get_error_string().str;
|
|
338
|
+
rcl_reset_error();
|
|
339
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
340
|
+
return env.Undefined();
|
|
341
|
+
}
|
|
285
342
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
343
|
+
if (fini_ret != RCL_RET_OK) {
|
|
344
|
+
std::string error_string = rcl_get_error_string().str;
|
|
345
|
+
rcl_reset_error();
|
|
346
|
+
Napi::Error::New(env, error_string).ThrowAsJavaScriptException();
|
|
347
|
+
return env.Undefined();
|
|
348
|
+
}
|
|
289
349
|
|
|
290
350
|
return Napi::Boolean::New(env, true);
|
|
291
351
|
}
|
|
@@ -303,9 +363,9 @@ Napi::Value GetContentFilter(const Napi::CallbackInfo& info) {
|
|
|
303
363
|
|
|
304
364
|
rcl_ret_t ret = rcl_subscription_get_content_filter(subscription, &options);
|
|
305
365
|
if (ret != RCL_RET_OK) {
|
|
306
|
-
|
|
307
|
-
.ThrowAsJavaScriptException();
|
|
366
|
+
std::string error_msg = rcl_get_error_string().str;
|
|
308
367
|
rcl_reset_error();
|
|
368
|
+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
|
|
309
369
|
return env.Undefined();
|
|
310
370
|
}
|
|
311
371
|
|
|
@@ -331,9 +391,9 @@ Napi::Value GetContentFilter(const Napi::CallbackInfo& info) {
|
|
|
331
391
|
rcl_ret_t fini_ret =
|
|
332
392
|
rcl_subscription_content_filter_options_fini(subscription, &options);
|
|
333
393
|
if (fini_ret != RCL_RET_OK) {
|
|
334
|
-
|
|
335
|
-
.ThrowAsJavaScriptException();
|
|
394
|
+
std::string error_msg = rcl_get_error_string().str;
|
|
336
395
|
rcl_reset_error();
|
|
396
|
+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
|
|
337
397
|
return env.Undefined();
|
|
338
398
|
}
|
|
339
399
|
|
|
@@ -347,9 +407,12 @@ Napi::Value GetPublisherCount(const Napi::CallbackInfo& info) {
|
|
|
347
407
|
RclHandle::Unwrap(info[0].As<Napi::Object>())->ptr());
|
|
348
408
|
|
|
349
409
|
size_t count = 0;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
410
|
+
rcl_ret_t ret = rcl_subscription_get_publisher_count(subscription, &count);
|
|
411
|
+
if (ret != RCL_RET_OK) {
|
|
412
|
+
std::string error_msg = rcl_get_error_string().str;
|
|
413
|
+
rcl_reset_error();
|
|
414
|
+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
|
|
415
|
+
}
|
|
353
416
|
|
|
354
417
|
return Napi::Number::New(env, count);
|
|
355
418
|
}
|