Skip to content

Commit a5ede31

Browse files
committed
Cleanup
1 parent cdf06f2 commit a5ede31

14 files changed

+79
-229
lines changed

lib/action/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ActionServer extends Entity {
130130
this.qos.statusSubQosProfile,
131131
this.options.resultTimeout
132132
);
133+
133134
node._addActionServer(this);
134135
}
135136

lib/logging.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ class Caller {
4747

4848
const stackLines = new Error().stack.split('\n');
4949

50-
// Adjust the index (usually 3 or 4) to correctly point to the caller frame
50+
// Adjust the index (usually 3 or 4) to correctly point to the caller frame.
5151
const callerFrame = stackLines[4] || stackLines[3];
52-
// Match both named and anonymous function stack frames
52+
// Match both named and anonymous function stack frames.
5353
const frameRegex = /^\s*at\s+(?:(.+)\s+\()?(.+):(\d+):(\d+)\)?$/;
5454
const match = callerFrame.match(frameRegex);
5555
if (match && match.length === 5) {
5656
this._info.functionName = match[1] || '(anonymous)';
5757
this._info.fileName = path.basename(match[2]);
5858
this._info.lineNumber = match[3];
5959
} else {
60-
// Handle anonymous functions or different stack formats
60+
// Handle anonymous functions or different stack formats.
6161
const altMatch = callerFrame.match(/at\s+(.*):(\d+):(\d+)/i);
6262
if (altMatch && altMatch.length >= 4) {
6363
this._info.functionName = '(anonymous)';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"json-bigint": "^1.0.0",
8282
"terser": "^5.39.0",
8383
"walk": "^2.3.15",
84-
"node-addon-api": "^5.0.0"
84+
"node-addon-api": "^8.3.1"
8585
},
8686
"husky": {
8787
"hooks": {

src/addon.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <napi.h>
1615
#include <node_api.h>
1716

1817
#include "macros.hpp"
@@ -31,10 +30,6 @@ bool IsRunningInElectronRenderer(const Napi::Env& env) {
3130
return processType.StrictEquals(Napi::String::New(env, "renderer"));
3231
}
3332

34-
void Cleanup(Napi::Env env, void* data) {
35-
rclnodejs::RclHandle::CleanupThreadSafeFunction();
36-
}
37-
3833
Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
3934
// workaround process name mangling by chromium
4035
//
@@ -52,36 +47,18 @@ Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
5247
}
5348
#endif
5449
rclnodejs::StoreEnv(env);
55-
// for (uint32_t i = 0; i < rclnodejs::binding_methods.size(); i++) {
56-
// exports.Set(rclnodejs::binding_methods[i].name,
57-
// Napi::Function::New(env,
58-
// rclnodejs::binding_methods[i].function));
59-
// }
6050
rclnodejs::InitBindings(env, exports);
61-
// for (uint32_t i = 0; i < rclnodejs::action_binding_methods.size(); i++) {
62-
// exports.Set(rclnodejs::action_binding_methods[i].name,
63-
// Napi::Function::New(env,
64-
// rclnodejs::action_binding_methods[i].function));
65-
// }
6651
rclnodejs::InitAction(env, exports);
67-
68-
for (uint32_t i = 0; i < rclnodejs::lifecycle_binding_methods.size(); i++) {
69-
exports.Set(rclnodejs::lifecycle_binding_methods[i].name,
70-
Napi::Function::New(
71-
env, rclnodejs::lifecycle_binding_methods[i].function));
72-
}
73-
52+
rclnodejs::InitLifecycle(env, exports);
7453
rclnodejs::ShadowNode::Init(env, exports);
7554
rclnodejs::RclHandle::Init(env, exports);
76-
// Initialize thread-safe function
77-
// rclnodejs::RclHandle::InitThreadSafeFunction(env);
55+
7856
#ifdef DEBUG_ON
7957
int result = rcutils_logging_set_logger_level(PACKAGE_NAME,
8058
RCUTILS_LOG_SEVERITY_DEBUG);
8159
RCUTILS_UNUSED(result);
8260
#endif
83-
// Register cleanup handler
84-
// env.SetInstanceData<void>(nullptr, Cleanup);
61+
8562
return exports;
8663
}
8764

src/handle_manager.cpp

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -300,24 +300,15 @@ rcl_ret_t HandleManager::CollectReadyActionHandles(
300300
if (ret != RCL_RET_OK) {
301301
return ret;
302302
}
303-
if (is_feedback_ready) {
304-
action_client->SetBoolProperty("isFeedbackReady", is_feedback_ready);
305-
}
306-
if (is_status_ready) {
307-
action_client->SetBoolProperty("isStatusReady", is_status_ready);
308-
}
309-
if (is_goal_response_ready) {
310-
action_client->SetBoolProperty("isGoalResponseReady",
311-
is_goal_response_ready);
312-
}
313-
if (is_cancel_response_ready) {
314-
action_client->SetBoolProperty("isCancelResponseReady",
315-
is_cancel_response_ready);
316-
}
317-
if (is_result_response_ready) {
318-
action_client->SetBoolProperty("isResultResponseReady",
319-
is_result_response_ready);
320-
}
303+
304+
action_client->SetBoolProperty("isFeedbackReady", is_feedback_ready);
305+
action_client->SetBoolProperty("isStatusReady", is_status_ready);
306+
action_client->SetBoolProperty("isGoalResponseReady",
307+
is_goal_response_ready);
308+
action_client->SetBoolProperty("isCancelResponseReady",
309+
is_cancel_response_ready);
310+
action_client->SetBoolProperty("isResultResponseReady",
311+
is_result_response_ready);
321312

322313
if (is_feedback_ready || is_status_ready || is_goal_response_ready ||
323314
is_cancel_response_ready || is_result_response_ready) {
@@ -339,21 +330,13 @@ rcl_ret_t HandleManager::CollectReadyActionHandles(
339330
if (ret != RCL_RET_OK) {
340331
return ret;
341332
}
342-
if (is_goal_request_ready) {
343-
action_server->SetBoolProperty("isGoalRequestReady",
344-
is_goal_request_ready);
345-
}
346-
if (is_cancel_request_ready) {
347-
action_server->SetBoolProperty("isCancelRequestReady",
348-
is_cancel_request_ready);
349-
}
350-
if (is_result_request_ready) {
351-
action_server->SetBoolProperty("isResultRequestReady",
352-
is_result_request_ready);
353-
}
354-
if (is_goal_expired) {
355-
action_server->SetBoolProperty("isGoalExpired", is_goal_expired);
356-
}
333+
334+
action_server->SetBoolProperty("isGoalRequestReady", is_goal_request_ready);
335+
action_server->SetBoolProperty("isCancelRequestReady",
336+
is_cancel_request_ready);
337+
action_server->SetBoolProperty("isResultRequestReady",
338+
is_result_request_ready);
339+
action_server->SetBoolProperty("isGoalExpired", is_goal_expired);
357340

358341
if (is_goal_request_ready || is_cancel_request_ready ||
359342
is_result_request_ready || is_goal_expired) {

src/rcl_action_bindings.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Napi::Value ActionSendGoalRequest(const Napi::CallbackInfo& info) {
190190
RclHandle::Unwrap(info[0].As<Napi::Object>());
191191
rcl_action_client_t* action_client =
192192
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
193-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
193+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
194194

195195
int64_t sequence_number;
196196
THROW_ERROR_IF_NOT_EQUAL(
@@ -210,7 +210,7 @@ Napi::Value ActionTakeGoalRequest(const Napi::CallbackInfo& info) {
210210
rmw_request_id_t* header =
211211
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
212212

213-
void* taken_request = info[1].As<Napi::Buffer<void>>().Data();
213+
void* taken_request = info[1].As<Napi::Buffer<char>>().Data();
214214
rcl_ret_t ret =
215215
rcl_action_take_goal_request(action_server, header, taken_request);
216216
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) {
@@ -231,7 +231,7 @@ Napi::Value ActionSendGoalResponse(const Napi::CallbackInfo& info) {
231231
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
232232
rmw_request_id_t* header = reinterpret_cast<rmw_request_id_t*>(
233233
RclHandle::Unwrap(info[1].As<Napi::Object>())->ptr());
234-
void* buffer = info[2].As<Napi::Buffer<void>>().Data();
234+
void* buffer = info[2].As<Napi::Buffer<char>>().Data();
235235

236236
THROW_ERROR_IF_NOT_EQUAL(
237237
rcl_action_send_goal_response(action_server, header, buffer), RCL_RET_OK,
@@ -247,7 +247,7 @@ Napi::Value ActionTakeGoalResponse(const Napi::CallbackInfo& info) {
247247
RclHandle::Unwrap(info[0].As<Napi::Object>());
248248
rcl_action_client_t* action_client =
249249
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
250-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
250+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
251251
rmw_request_id_t* header =
252252
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
253253

@@ -275,7 +275,7 @@ Napi::Value ActionSendCancelRequest(const Napi::CallbackInfo& info) {
275275
RclHandle::Unwrap(info[0].As<Napi::Object>());
276276
rcl_action_client_t* action_client =
277277
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
278-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
278+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
279279

280280
int64_t sequence_number;
281281
THROW_ERROR_IF_NOT_EQUAL(
@@ -295,7 +295,7 @@ Napi::Value ActionTakeCancelRequest(const Napi::CallbackInfo& info) {
295295
rmw_request_id_t* header =
296296
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
297297

298-
void* taken_request = info[1].As<Napi::Buffer<void>>().Data();
298+
void* taken_request = info[1].As<Napi::Buffer<char>>().Data();
299299
rcl_ret_t ret =
300300
rcl_action_take_cancel_request(action_server, header, taken_request);
301301
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) {
@@ -316,7 +316,7 @@ Napi::Value ActionSendCancelResponse(const Napi::CallbackInfo& info) {
316316
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
317317
rmw_request_id_t* header = reinterpret_cast<rmw_request_id_t*>(
318318
RclHandle::Unwrap(info[1].As<Napi::Object>())->ptr());
319-
void* buffer = info[2].As<Napi::Buffer<void>>().Data();
319+
void* buffer = info[2].As<Napi::Buffer<char>>().Data();
320320

321321
THROW_ERROR_IF_NOT_EQUAL(
322322
rcl_action_send_cancel_response(action_server, header, buffer),
@@ -332,7 +332,7 @@ Napi::Value ActionTakeCancelResponse(const Napi::CallbackInfo& info) {
332332
RclHandle::Unwrap(info[0].As<Napi::Object>());
333333
rcl_action_client_t* action_client =
334334
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
335-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
335+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
336336
rmw_request_id_t* header =
337337
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
338338

@@ -361,7 +361,7 @@ Napi::Value ActionSendResultRequest(const Napi::CallbackInfo& info) {
361361
RclHandle::Unwrap(info[0].As<Napi::Object>());
362362
rcl_action_client_t* action_client =
363363
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
364-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
364+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
365365

366366
int64_t sequence_number;
367367
THROW_ERROR_IF_NOT_EQUAL(
@@ -382,7 +382,7 @@ Napi::Value ActionTakeResultRequest(const Napi::CallbackInfo& info) {
382382
rmw_request_id_t* header =
383383
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
384384

385-
void* taken_request = info[1].As<Napi::Buffer<void>>().Data();
385+
void* taken_request = info[1].As<Napi::Buffer<char>>().Data();
386386
rcl_ret_t ret =
387387
rcl_action_take_result_request(action_server, header, taken_request);
388388
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) {
@@ -403,7 +403,7 @@ Napi::Value ActionSendResultResponse(const Napi::CallbackInfo& info) {
403403
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
404404
rmw_request_id_t* header = reinterpret_cast<rmw_request_id_t*>(
405405
RclHandle::Unwrap(info[1].As<Napi::Object>())->ptr());
406-
void* buffer = info[2].As<Napi::Buffer<void>>().Data();
406+
void* buffer = info[2].As<Napi::Buffer<char>>().Data();
407407

408408
THROW_ERROR_IF_NOT_EQUAL(
409409
rcl_action_send_result_response(action_server, header, buffer),
@@ -419,7 +419,7 @@ Napi::Value ActionTakeResultResponse(const Napi::CallbackInfo& info) {
419419
RclHandle::Unwrap(info[0].As<Napi::Object>());
420420
rcl_action_client_t* action_client =
421421
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
422-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
422+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
423423
rmw_request_id_t* header =
424424
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
425425

@@ -449,7 +449,7 @@ Napi::Value ActionAcceptNewGoal(const Napi::CallbackInfo& info) {
449449
rcl_action_server_t* action_server =
450450
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
451451
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
452-
info[1].As<Napi::Buffer<void>>().Data());
452+
info[1].As<Napi::Buffer<char>>().Data());
453453

454454
rcl_action_goal_handle_t* goal_handle =
455455
reinterpret_cast<rcl_action_goal_handle_t*>(
@@ -519,7 +519,7 @@ Napi::Value ActionTakeStatus(const Napi::CallbackInfo& info) {
519519
RclHandle::Unwrap(info[0].As<Napi::Object>());
520520
rcl_action_client_t* action_client =
521521
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
522-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
522+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
523523

524524
rcl_ret_t ret = rcl_action_take_status(action_client, buffer);
525525
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
@@ -581,7 +581,7 @@ Napi::Value ActionPublishFeedback(const Napi::CallbackInfo& info) {
581581

582582
rcl_action_server_t* action_server = reinterpret_cast<rcl_action_server_t*>(
583583
RclHandle::Unwrap(info[0].As<Napi::Object>())->ptr());
584-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
584+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
585585

586586
THROW_ERROR_IF_NOT_EQUAL(rcl_action_publish_feedback(action_server, buffer),
587587
RCL_RET_OK, rcl_get_error_string().str);
@@ -596,7 +596,7 @@ Napi::Value ActionTakeFeedback(const Napi::CallbackInfo& info) {
596596
RclHandle::Unwrap(info[0].As<Napi::Object>());
597597
rcl_action_client_t* action_client =
598598
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
599-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
599+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
600600

601601
rcl_ret_t ret = rcl_action_take_feedback(action_client, buffer);
602602
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
@@ -619,10 +619,10 @@ Napi::Value ActionProcessCancelRequest(const Napi::CallbackInfo& info) {
619619
RclHandle::Unwrap(info[0].As<Napi::Object>());
620620
rcl_action_server_t* action_server =
621621
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
622-
void* buffer = info[1].As<Napi::Buffer<void>>().Data();
622+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
623623
rcl_action_cancel_request_t* cancel_request =
624624
reinterpret_cast<rcl_action_cancel_request_t*>(buffer);
625-
void* response_buffer = info[2].As<Napi::Buffer<void>>().Data();
625+
void* response_buffer = info[2].As<Napi::Buffer<char>>().Data();
626626
action_msgs__srv__CancelGoal_Response* response =
627627
reinterpret_cast<action_msgs__srv__CancelGoal_Response*>(response_buffer);
628628

@@ -671,7 +671,7 @@ Napi::Value ActionServerGoalExists(const Napi::CallbackInfo& info) {
671671
rcl_action_server_t* action_server =
672672
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
673673
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
674-
info[1].As<Napi::Buffer<void>>().Data());
674+
info[1].As<Napi::Buffer<char>>().Data());
675675

676676
bool exists = rcl_action_server_goal_exists(action_server, buffer);
677677

@@ -687,7 +687,7 @@ Napi::Value ActionExpireGoals(const Napi::CallbackInfo& info) {
687687
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
688688
int64_t max_num_goals = info[1].As<Napi::Number>().Int64Value();
689689
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
690-
info[2].As<Napi::Buffer<void>>().Data());
690+
info[2].As<Napi::Buffer<char>>().Data());
691691

692692
size_t num_expired;
693693
THROW_ERROR_IF_NOT_EQUAL(rcl_action_expire_goals(action_server, buffer,

src/rcl_action_bindings.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <napi.h>
1919
#include <rcl/rcl.h>
2020

21-
#include <utility>
2221
#include <vector>
2322

2423
#include "rcl_bindings.hpp"

0 commit comments

Comments
 (0)