Skip to content

Commit 5524df0

Browse files
committed
Cleanup
1 parent 185d74f commit 5524df0

13 files changed

+53
-203
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.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"

src/rcl_bindings.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#include "rcl_bindings.hpp"
1616

17+
#include <napi.h>
1718
#include <node.h>
18-
#include <node_buffer.h>
1919
#include <rcl/arguments.h>
2020
#include <rcl/error_handling.h>
2121
#include <rcl/expand_topic_name.h>
@@ -33,7 +33,6 @@
3333
#include <rmw/validate_namespace.h>
3434
#include <rmw/validate_node_name.h>
3535

36-
#include "v8.h"
3736
#if ROS_VERSION >= 2006
3837
#include <rosidl_runtime_c/string_functions.h>
3938
#else
@@ -53,8 +52,6 @@
5352
#include <utility>
5453
#endif
5554

56-
#include <napi.h>
57-
5855
#include "handle_manager.hpp"
5956
#include "macros.hpp"
6057
#include "rcl_handle.hpp"

src/rcl_bindings.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ void ExtractNamesAndTypes(rcl_names_and_types_t names_and_types,
3939

4040
std::unique_ptr<rmw_qos_profile_t> GetQoSProfile(Napi::Value qos);
4141

42-
extern std::vector<BindingMethod> binding_methods;
43-
4442
Napi::Object InitBindings(Napi::Env env, Napi::Object exports);
4543

46-
// Initialize the environment
47-
void InitEnvironment(Napi::Env env);
48-
49-
// Get the current environment
50-
Napi::Env GetEnvironment();
51-
5244
} // namespace rclnodejs
5345

5446
#endif // SRC_RCL_BINDINGS_HPP_

src/rcl_handle.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ namespace rclnodejs {
2525

2626
Napi::FunctionReference RclHandle::constructor;
2727

28-
// Define the static ThreadSafeFunction
29-
Napi::ThreadSafeFunction RclHandle::tsfn_;
30-
3128
RclHandle::RclHandle(const Napi::CallbackInfo& info)
3229
: Napi::ObjectWrap<RclHandle>(info), pointer_(nullptr), parent_(nullptr) {}
3330

3431
RclHandle::~RclHandle() {
3532
if (pointer_) Reset();
36-
37-
// tsfn_.Release();
3833
}
3934

4035
Napi::Object RclHandle::Init(Napi::Env env, Napi::Object exports) {
@@ -54,39 +49,15 @@ Napi::Object RclHandle::Init(Napi::Env env, Napi::Object exports) {
5449
}
5550

5651
void RclHandle::SyncProperties() {
57-
// Napi::Env env = Env();
5852
Napi::Env env = rclnodejs::GetEnv();
59-
// if (env.IsNull()) return;
60-
// std::cout << "===before SyncProperties" << std::endl;
61-
6253
Napi::HandleScope scope(env);
63-
// std::cout << "====after SyncProperties" << std::endl;
6454
Napi::Object obj = Napi::Object::New(env);
65-
// std::cout << "after====after SyncProperties" << std::endl;
66-
6755
for (auto& pair : properties_) {
6856
obj.Set(pair.first, Napi::Boolean::New(env, pair.second));
6957
}
70-
7158
properties_obj_ = Napi::Persistent(obj);
7259
}
7360

74-
// void RclHandle::SetBoolProperty(const std::string& name, bool value) {
75-
// // properties_[name] = value;
76-
// // SyncProperties();
77-
// std::lock_guard<std::mutex> lock(property_mutex_);
78-
79-
// // Allocate a new update object
80-
// PropertyUpdate* update = new PropertyUpdate{name, value};
81-
82-
// // Queue the update to be executed on the main thread
83-
// napi_status status = tsfn_.BlockingCall(update);
84-
// if (status != napi_ok) {
85-
// delete update; // Clean up if failed
86-
// // Handle error appropriately (log or handle internally)
87-
// }
88-
// }
89-
9061
Napi::Value RclHandle::PropertiesGetter(const Napi::CallbackInfo& info) {
9162
Napi::Env env = info.Env();
9263

src/rcl_handle.hpp

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414

1515
#ifndef SRC_RCL_HANDLE_HPP_
1616
#define SRC_RCL_HANDLE_HPP_
17+
1718
#include <napi.h>
1819

1920
#include <functional>
20-
#include <iostream>
2121
#include <map>
22-
#include <mutex>
2322
#include <set>
2423
#include <string>
25-
#include <vector>
24+
2625
namespace rclnodejs {
2726

2827
class RclHandle : public Napi::ObjectWrap<RclHandle> {
@@ -43,7 +42,6 @@ class RclHandle : public Napi::ObjectWrap<RclHandle> {
4342
void Reset();
4443
void AddChild(RclHandle* child) { children_.insert(child); }
4544
void RemoveChild(RclHandle* child) { children_.erase(child); }
46-
// void SetBoolProperty(const std::string& name, bool value);
4745
void SyncProperties();
4846

4947
explicit RclHandle(const Napi::CallbackInfo& info);
@@ -57,88 +55,9 @@ class RclHandle : public Napi::ObjectWrap<RclHandle> {
5755
// Property getter
5856
Napi::Value PropertiesGetter(const Napi::CallbackInfo& info);
5957

60-
// Store property updates to be applied later
61-
struct PropertyUpdate {
62-
std::string name;
63-
bool value;
64-
};
65-
66-
std::mutex property_mutex_;
67-
std::vector<PropertyUpdate> pending_property_updates_;
68-
69-
// ThreadSafeFunction to process updates on main thread
70-
static Napi::ThreadSafeFunction tsfn_;
71-
72-
// Thread-safe version to queue property updates
73-
// void SetBoolProperty(const std::string& name, bool value) {
74-
75-
// std::lock_guard<std::mutex> lock(property_mutex_);
76-
// pending_property_updates_.push_back({name, value});
77-
// if (tsfn_) {
78-
// // Queue work to be processed on main thread
79-
// tsfn_.BlockingCall(this, []( Napi::Env env, Napi::Function
80-
// jsCallback, RclHandle* handle) {
81-
// std::cout << "====ProcessPropertyUpdates" << std::endl;
82-
// handle->ProcessPropertyUpdates();
83-
// });
84-
// // napi_status status = tsfn_.BlockingCall(this, [](Napi::Env env,
85-
// Napi::Function jsCallback, RclHandle* handle) {
86-
// // std::cout << "====SetBoolProperty" << std::endl;
87-
// // });
88-
// // if ( status != napi_ok )
89-
// // {
90-
// // std::cout << "===ERRRRRRRRRRRRRrr" << std::endl;
91-
// // }
92-
// }
93-
// }
9458
void SetBoolProperty(const std::string& name, bool value) {
9559
properties_[name] = value;
9660
}
97-
// Process pending property updates on main thread
98-
void ProcessPropertyUpdates() {
99-
std::vector<PropertyUpdate> updates;
100-
{
101-
std::lock_guard<std::mutex> lock(property_mutex_);
102-
updates.swap(pending_property_updates_);
103-
}
104-
105-
Napi::Env env = Env(); // Get env from ObjectWrap
106-
for (const auto& update : updates) {
107-
if (!properties_obj_.IsEmpty()) {
108-
Napi::Object props = properties_obj_.Value().As<Napi::Object>();
109-
props.Set(update.name, Napi::Boolean::New(env, update.value));
110-
}
111-
}
112-
}
113-
114-
// Initialize thread-safe function
115-
static void InitThreadSafeFunction(Napi::Env env) {
116-
if (!tsfn_) {
117-
// std::cout << "====InitThreadSafeFunction" << std::endl;
118-
tsfn_ = Napi::ThreadSafeFunction::New(
119-
env,
120-
Napi::Function::New(env,
121-
[](const Napi::CallbackInfo& info) {
122-
// This runs on the main thread
123-
// Napi::Env env = info.Env();
124-
// RclHandle* handle =
125-
// RclHandle::Unwrap(info[0].As<Napi::Object>());
126-
// handle->ProcessPropertyUpdates();
127-
// std::cout << "====ProcessPropertyUpdates" <<
128-
// std::endl;
129-
}),
130-
"SetBoolProperty",
131-
0, // Max queue size (0 = unlimited)
132-
1); // Number of threads to use);
133-
}
134-
}
135-
136-
// Finalize the thread-safe function
137-
static void CleanupThreadSafeFunction() {
138-
if (tsfn_) {
139-
tsfn_.Release();
140-
}
141-
}
14261

14362
private:
14463
void* pointer_;

0 commit comments

Comments
 (0)