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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rclnodejs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "ROS2.0 JavaScript client with Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"docs": "cd docs && make",
|
|
27
27
|
"test": "nyc node --expose-gc ./scripts/run_test.js && tsd",
|
|
28
28
|
"lint": "eslint && node ./scripts/cpplint.js",
|
|
29
|
-
"format": "clang-format -i -style=file ./src/*.cpp ./src/*.
|
|
29
|
+
"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}",
|
|
30
30
|
"prepare": "husky",
|
|
31
31
|
"coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
|
|
32
32
|
},
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"fs-extra": "^11.2.0",
|
|
80
80
|
"is-close": "^1.3.3",
|
|
81
81
|
"json-bigint": "^1.0.0",
|
|
82
|
-
"nan": "^2.22.0",
|
|
83
82
|
"terser": "^5.39.0",
|
|
84
|
-
"walk": "^2.3.15"
|
|
83
|
+
"walk": "^2.3.15",
|
|
84
|
+
"node-addon-api": "^8.3.1"
|
|
85
85
|
},
|
|
86
86
|
"husky": {
|
|
87
87
|
"hooks": {
|
package/scripts/config.js
CHANGED
package/scripts/npmjs-readme.md
CHANGED
|
@@ -43,9 +43,9 @@ npm i rclnodejs@x.y.z
|
|
|
43
43
|
|
|
44
44
|
#### RCLNODEJS - ROS 2 Version Compatibility
|
|
45
45
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
| latest version (currently [
|
|
46
|
+
| RCLNODEJS Version | Compatible ROS 2 LTS |
|
|
47
|
+
| :----------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
48
|
+
| latest version (currently [v1.1.0](https://github.com/RobotWebTools/rclnodejs/tree/1.1.0)) | [Kilted](https://github.com/RobotWebTools/rclnodejs/tree/kilted)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy)<br>[Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill) |
|
|
49
49
|
|
|
50
50
|
## Documentation
|
|
51
51
|
|
package/src/addon.cpp
CHANGED
|
@@ -12,29 +12,42 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#include <
|
|
15
|
+
#include <node_api.h>
|
|
16
|
+
#include <rcutils/logging.h>
|
|
16
17
|
|
|
17
|
-
#include "macros.
|
|
18
|
-
#include "
|
|
19
|
-
#include "
|
|
20
|
-
#include "
|
|
21
|
-
#include "
|
|
22
|
-
#include "
|
|
23
|
-
#include "
|
|
24
|
-
#include "
|
|
18
|
+
#include "macros.h"
|
|
19
|
+
#include "rcl_action_client_bindings.h"
|
|
20
|
+
#include "rcl_action_goal_bindings.h"
|
|
21
|
+
#include "rcl_action_server_bindings.h"
|
|
22
|
+
#include "rcl_bindings.h"
|
|
23
|
+
#include "rcl_client_bindings.h"
|
|
24
|
+
#include "rcl_context_bindings.h"
|
|
25
|
+
#include "rcl_graph_bindings.h"
|
|
26
|
+
#include "rcl_guard_condition_bindings.h"
|
|
27
|
+
#include "rcl_handle.h"
|
|
28
|
+
#include "rcl_lifecycle_bindings.h"
|
|
29
|
+
#include "rcl_logging_bindings.h"
|
|
30
|
+
#include "rcl_names_bindings.h"
|
|
31
|
+
#include "rcl_node_bindings.h"
|
|
32
|
+
#include "rcl_publisher_bindings.h"
|
|
33
|
+
#include "rcl_service_bindings.h"
|
|
34
|
+
#include "rcl_subscription_bindings.h"
|
|
35
|
+
#include "rcl_time_point_bindings.h"
|
|
36
|
+
#include "rcl_timer_bindings.h"
|
|
37
|
+
#if ROS_VERSION > 2205 // ROS2 > Humble
|
|
38
|
+
#include "rcl_type_description_service_bindings.h"
|
|
39
|
+
#endif
|
|
40
|
+
#include "rcl_utilities.h"
|
|
41
|
+
#include "shadow_node.h"
|
|
25
42
|
|
|
26
|
-
bool IsRunningInElectronRenderer() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.ToLocalChecked();
|
|
32
|
-
auto process_type =
|
|
33
|
-
Nan::Get(process, Nan::New("type").ToLocalChecked()).ToLocalChecked();
|
|
34
|
-
return process_type->StrictEquals(Nan::New("renderer").ToLocalChecked());
|
|
43
|
+
bool IsRunningInElectronRenderer(const Napi::Env& env) {
|
|
44
|
+
Napi::Object global = env.Global();
|
|
45
|
+
Napi::Object process = global.Get("process").As<Napi::Object>();
|
|
46
|
+
Napi::Value processType = process.Get("type");
|
|
47
|
+
return processType.StrictEquals(Napi::String::New(env, "renderer"));
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
|
|
38
51
|
// workaround process name mangling by chromium
|
|
39
52
|
//
|
|
40
53
|
// rcl logging uses `program_invocation_name` to determine the log file,
|
|
@@ -43,7 +56,7 @@ void InitModule(v8::Local<v8::Object> exports) {
|
|
|
43
56
|
// occurence of ' -' with the null terminator. see:
|
|
44
57
|
// https://unix.stackexchange.com/questions/432419/unexpected-non-null-encoding-of-proc-pid-cmdline
|
|
45
58
|
#if defined(__linux__) && defined(__GLIBC__)
|
|
46
|
-
if (IsRunningInElectronRenderer()) {
|
|
59
|
+
if (IsRunningInElectronRenderer(env)) {
|
|
47
60
|
auto prog_name = program_invocation_name;
|
|
48
61
|
auto end = strstr(prog_name, " -");
|
|
49
62
|
assert(end);
|
|
@@ -51,44 +64,38 @@ void InitModule(v8::Local<v8::Object> exports) {
|
|
|
51
64
|
}
|
|
52
65
|
#endif
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Nan::New<v8::FunctionTemplate>(
|
|
79
|
-
rclnodejs::lifecycle_binding_methods[i].function)
|
|
80
|
-
->GetFunction(context)
|
|
81
|
-
.ToLocalChecked());
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
rclnodejs::ShadowNode::Init(exports);
|
|
85
|
-
rclnodejs::RclHandle::Init(exports);
|
|
67
|
+
rclnodejs::StoreEnv(env);
|
|
68
|
+
// Init the C++ bindings.
|
|
69
|
+
rclnodejs::InitBindings(env, exports);
|
|
70
|
+
rclnodejs::InitActionClientBindings(env, exports);
|
|
71
|
+
rclnodejs::InitActionGoalBindings(env, exports);
|
|
72
|
+
rclnodejs::InitActionServerBindings(env, exports);
|
|
73
|
+
rclnodejs::InitClientBindings(env, exports);
|
|
74
|
+
rclnodejs::InitContextBindings(env, exports);
|
|
75
|
+
rclnodejs::InitGraphBindings(env, exports);
|
|
76
|
+
rclnodejs::InitGuardConditionBindings(env, exports);
|
|
77
|
+
rclnodejs::InitLoggingBindings(env, exports);
|
|
78
|
+
rclnodejs::InitNamesBindings(env, exports);
|
|
79
|
+
rclnodejs::InitNodeBindings(env, exports);
|
|
80
|
+
rclnodejs::InitPublisherBindings(env, exports);
|
|
81
|
+
rclnodejs::InitServiceBindings(env, exports);
|
|
82
|
+
rclnodejs::InitSubscriptionBindings(env, exports);
|
|
83
|
+
rclnodejs::InitTimePointBindings(env, exports);
|
|
84
|
+
rclnodejs::InitTimerBindings(env, exports);
|
|
85
|
+
#if ROS_VERSION > 2205 // ROS2 > Humble
|
|
86
|
+
rclnodejs::InitTypeDescriptionServiceBindings(env, exports);
|
|
87
|
+
#endif
|
|
88
|
+
rclnodejs::InitLifecycleBindings(env, exports);
|
|
89
|
+
rclnodejs::ShadowNode::Init(env, exports);
|
|
90
|
+
rclnodejs::RclHandle::Init(env, exports);
|
|
86
91
|
|
|
87
92
|
#ifdef DEBUG_ON
|
|
88
93
|
int result = rcutils_logging_set_logger_level(PACKAGE_NAME,
|
|
89
94
|
RCUTILS_LOG_SEVERITY_DEBUG);
|
|
90
95
|
RCUTILS_UNUSED(result);
|
|
91
96
|
#endif
|
|
97
|
+
|
|
98
|
+
return exports;
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
NODE_API_MODULE(rclnodejs, InitModule)
|
package/src/executor.cpp
CHANGED
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#include "executor.
|
|
15
|
+
#include "executor.h"
|
|
16
16
|
|
|
17
17
|
#include <rcl/error_handling.h>
|
|
18
18
|
|
|
19
19
|
#include <stdexcept>
|
|
20
20
|
#include <string>
|
|
21
21
|
|
|
22
|
-
#include "handle_manager.
|
|
23
|
-
#include "macros.
|
|
24
|
-
#include "rcl_bindings.
|
|
22
|
+
#include "handle_manager.h"
|
|
23
|
+
#include "macros.h"
|
|
24
|
+
#include "rcl_bindings.h"
|
|
25
25
|
|
|
26
26
|
#ifdef WIN32
|
|
27
27
|
#define UNUSED
|
|
@@ -41,12 +41,14 @@ struct RclResult {
|
|
|
41
41
|
std::string error_msg;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
Executor::Executor(HandleManager* handle_manager,
|
|
44
|
+
Executor::Executor(Napi::Env env, HandleManager* handle_manager,
|
|
45
|
+
Delegate* delegate)
|
|
45
46
|
: async_(nullptr),
|
|
46
47
|
main_thread_(uv_thread_self()),
|
|
47
48
|
handle_manager_(handle_manager),
|
|
48
49
|
delegate_(delegate),
|
|
49
|
-
context_(nullptr)
|
|
50
|
+
context_(nullptr),
|
|
51
|
+
env_(env) {
|
|
50
52
|
running_.store(false);
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -74,12 +76,19 @@ void Executor::SpinOnce(rcl_context_t* context, int32_t time_out) {
|
|
|
74
76
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
|
75
77
|
rcl_ret_t ret = rcl_wait_set_init(&wait_set, 0, 0, 0, 0, 0, 0, context,
|
|
76
78
|
rcl_get_default_allocator());
|
|
77
|
-
if (ret != RCL_RET_OK)
|
|
79
|
+
if (ret != RCL_RET_OK) {
|
|
80
|
+
Napi::Error::New(env_, rcl_get_error_string().str)
|
|
81
|
+
.ThrowAsJavaScriptException();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
78
84
|
|
|
79
85
|
RclResult wait_result = WaitForReadyCallbacks(&wait_set, time_out);
|
|
80
86
|
|
|
81
|
-
if (wait_result.ret != RCL_RET_OK)
|
|
82
|
-
|
|
87
|
+
if (wait_result.ret != RCL_RET_OK) {
|
|
88
|
+
Napi::Error::New(env_, wait_result.error_msg.c_str())
|
|
89
|
+
.ThrowAsJavaScriptException();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
83
92
|
|
|
84
93
|
if (handle_manager_->ready_handles_count() > 0) ExecuteReadyHandles();
|
|
85
94
|
|
|
@@ -87,7 +96,7 @@ void Executor::SpinOnce(rcl_context_t* context, int32_t time_out) {
|
|
|
87
96
|
std::string error_message =
|
|
88
97
|
std::string("Failed to destroy guard waitset:") +
|
|
89
98
|
std::string(rcl_get_error_string().str);
|
|
90
|
-
|
|
99
|
+
Napi::Error::New(env_, error_message.c_str()).ThrowAsJavaScriptException();
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
|
|
@@ -12,9 +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_EXECUTOR_H_
|
|
16
|
+
#define SRC_EXECUTOR_H_
|
|
17
17
|
|
|
18
|
+
#include <napi.h>
|
|
18
19
|
#include <rcl/wait.h>
|
|
19
20
|
#include <uv.h>
|
|
20
21
|
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
#include <exception>
|
|
23
24
|
#include <vector>
|
|
24
25
|
|
|
25
|
-
#include "rcl_handle.
|
|
26
|
+
#include "rcl_handle.h"
|
|
26
27
|
|
|
27
28
|
namespace rclnodejs {
|
|
28
29
|
|
|
@@ -37,7 +38,7 @@ class Executor {
|
|
|
37
38
|
virtual void CatchException(std::exception_ptr e_ptr) = 0;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
Executor(HandleManager* handle_manager, Delegate* delegate);
|
|
41
|
+
Executor(Napi::Env env, HandleManager* handle_manager, Delegate* delegate);
|
|
41
42
|
~Executor();
|
|
42
43
|
|
|
43
44
|
void Start(rcl_context_t* context, int32_t time_out);
|
|
@@ -68,10 +69,11 @@ class Executor {
|
|
|
68
69
|
Delegate* delegate_;
|
|
69
70
|
rcl_context_t* context_;
|
|
70
71
|
int32_t time_out_;
|
|
72
|
+
Napi::Env env_;
|
|
71
73
|
|
|
72
74
|
std::atomic_bool running_;
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
} // namespace rclnodejs
|
|
76
78
|
|
|
77
|
-
#endif //
|
|
79
|
+
#endif // SRC_EXECUTOR_H_
|
package/src/handle_manager.cpp
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#include "handle_manager.
|
|
15
|
+
#include "handle_manager.h"
|
|
16
16
|
|
|
17
17
|
#include <rcl_action/rcl_action.h>
|
|
18
18
|
|
|
19
19
|
#include <utility>
|
|
20
20
|
#include <vector>
|
|
21
21
|
|
|
22
|
-
#include "macros.
|
|
22
|
+
#include "macros.h"
|
|
23
23
|
|
|
24
24
|
namespace rclnodejs {
|
|
25
25
|
|
|
@@ -38,22 +38,16 @@ HandleManager::~HandleManager() {
|
|
|
38
38
|
uv_sem_destroy(&wait_handle_sem_);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
void HandleManager::SynchronizeHandles(const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
Nan::MaybeLocal<v8::Value> guard_conditions =
|
|
52
|
-
Nan::Get(node, Nan::New("_guards").ToLocalChecked());
|
|
53
|
-
Nan::MaybeLocal<v8::Value> action_clients =
|
|
54
|
-
Nan::Get(node, Nan::New("_actionClients").ToLocalChecked());
|
|
55
|
-
Nan::MaybeLocal<v8::Value> action_servers =
|
|
56
|
-
Nan::Get(node, Nan::New("_actionServers").ToLocalChecked());
|
|
41
|
+
void HandleManager::SynchronizeHandles(const Napi::Object& node) {
|
|
42
|
+
Napi::HandleScope scope(node.Env());
|
|
43
|
+
|
|
44
|
+
Napi::Value timers = node.Get("_timers");
|
|
45
|
+
Napi::Value subscriptions = node.Get("_subscriptions");
|
|
46
|
+
Napi::Value clients = node.Get("_clients");
|
|
47
|
+
Napi::Value services = node.Get("_services");
|
|
48
|
+
Napi::Value guard_conditions = node.Get("_guards");
|
|
49
|
+
Napi::Value action_clients = node.Get("_actionClients");
|
|
50
|
+
Napi::Value action_servers = node.Get("_actionServers");
|
|
57
51
|
|
|
58
52
|
uint32_t sum = 0;
|
|
59
53
|
is_synchronizing_.store(true);
|
|
@@ -61,27 +55,17 @@ void HandleManager::SynchronizeHandles(const v8::Local<v8::Object> node) {
|
|
|
61
55
|
ScopedReadWriteLock scoped_lock(&sync_handles_rwlock_,
|
|
62
56
|
ScopedReadWriteLock::LockType::kWrite);
|
|
63
57
|
ClearHandles();
|
|
64
|
-
sum += SynchronizeHandlesByType(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
sum += SynchronizeHandlesByType(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
sum += SynchronizeHandlesByType(
|
|
74
|
-
|
|
75
|
-
&services_);
|
|
76
|
-
sum += SynchronizeHandlesByType(
|
|
77
|
-
Nan::To<v8::Object>(guard_conditions.ToLocalChecked()).ToLocalChecked(),
|
|
78
|
-
&guard_conditions_);
|
|
79
|
-
sum += SynchronizeHandlesByType(
|
|
80
|
-
Nan::To<v8::Object>(action_clients.ToLocalChecked()).ToLocalChecked(),
|
|
81
|
-
&action_clients_);
|
|
82
|
-
sum += SynchronizeHandlesByType(
|
|
83
|
-
Nan::To<v8::Object>(action_servers.ToLocalChecked()).ToLocalChecked(),
|
|
84
|
-
&action_servers_);
|
|
58
|
+
sum += SynchronizeHandlesByType(timers.As<Napi::Object>(), &timers_);
|
|
59
|
+
sum += SynchronizeHandlesByType(subscriptions.As<Napi::Object>(),
|
|
60
|
+
&subscriptions_);
|
|
61
|
+
sum += SynchronizeHandlesByType(clients.As<Napi::Object>(), &clients_);
|
|
62
|
+
sum += SynchronizeHandlesByType(services.As<Napi::Object>(), &services_);
|
|
63
|
+
sum += SynchronizeHandlesByType(guard_conditions.As<Napi::Object>(),
|
|
64
|
+
&guard_conditions_);
|
|
65
|
+
sum += SynchronizeHandlesByType(action_clients.As<Napi::Object>(),
|
|
66
|
+
&action_clients_);
|
|
67
|
+
sum += SynchronizeHandlesByType(action_servers.As<Napi::Object>(),
|
|
68
|
+
&action_servers_);
|
|
85
69
|
}
|
|
86
70
|
is_synchronizing_.store(false);
|
|
87
71
|
|
|
@@ -265,26 +249,16 @@ uint32_t HandleManager::ready_handles_count() {
|
|
|
265
249
|
}
|
|
266
250
|
|
|
267
251
|
uint32_t HandleManager::SynchronizeHandlesByType(
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (typeObject->IsArray()) {
|
|
273
|
-
uint32_t length =
|
|
274
|
-
Nan::To<uint32_t>(
|
|
275
|
-
Nan::Get(typeObject, Nan::New("length").ToLocalChecked())
|
|
276
|
-
.ToLocalChecked())
|
|
277
|
-
.FromJust();
|
|
252
|
+
const Napi::Object& typeObject, std::vector<rclnodejs::RclHandle*>* vec) {
|
|
253
|
+
if (typeObject.IsArray()) {
|
|
254
|
+
uint32_t length = typeObject.Get("length").As<Napi::Number>().Uint32Value();
|
|
278
255
|
|
|
279
256
|
for (uint32_t index = 0; index < length; index++) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
.ToLocalChecked();
|
|
283
|
-
Nan::MaybeLocal<v8::Value> handle =
|
|
284
|
-
Nan::Get(obj, Nan::New("_handle").ToLocalChecked());
|
|
257
|
+
Napi::Object obj = typeObject.Get(index).As<Napi::Object>();
|
|
258
|
+
Napi::Value handle = obj.Get("_handle");
|
|
285
259
|
rclnodejs::RclHandle* rcl_handle =
|
|
286
|
-
|
|
287
|
-
|
|
260
|
+
Napi::ObjectWrap<rclnodejs::RclHandle>::Unwrap(
|
|
261
|
+
handle.As<Napi::Object>());
|
|
288
262
|
vec->push_back(rcl_handle);
|
|
289
263
|
}
|
|
290
264
|
}
|
|
@@ -12,16 +12,17 @@
|
|
|
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_HANDLE_MANAGER_H_
|
|
16
|
+
#define SRC_HANDLE_MANAGER_H_
|
|
17
17
|
|
|
18
|
-
#include <
|
|
18
|
+
#include <napi.h>
|
|
19
19
|
#include <rcl/wait.h>
|
|
20
|
+
#include <uv.h>
|
|
20
21
|
|
|
21
22
|
#include <atomic>
|
|
22
23
|
#include <vector>
|
|
23
24
|
|
|
24
|
-
#include "rcl_handle.
|
|
25
|
+
#include "rcl_handle.h"
|
|
25
26
|
|
|
26
27
|
namespace rclnodejs {
|
|
27
28
|
|
|
@@ -53,7 +54,7 @@ class HandleManager {
|
|
|
53
54
|
HandleManager();
|
|
54
55
|
~HandleManager();
|
|
55
56
|
|
|
56
|
-
void SynchronizeHandles(const
|
|
57
|
+
void SynchronizeHandles(const Napi::Object& node);
|
|
57
58
|
void WaitForSynchronizing();
|
|
58
59
|
|
|
59
60
|
// Waits the handles to be attached from the background thread.
|
|
@@ -89,7 +90,7 @@ class HandleManager {
|
|
|
89
90
|
|
|
90
91
|
protected:
|
|
91
92
|
// Synchronize the handles from `typeObject`.
|
|
92
|
-
uint32_t SynchronizeHandlesByType(const
|
|
93
|
+
uint32_t SynchronizeHandlesByType(const Napi::Object& typeObject,
|
|
93
94
|
std::vector<rclnodejs::RclHandle*>* vec);
|
|
94
95
|
template <typename T>
|
|
95
96
|
void CollectReadyHandlesByType(
|
|
@@ -132,4 +133,4 @@ class HandleManager {
|
|
|
132
133
|
|
|
133
134
|
} // namespace rclnodejs
|
|
134
135
|
|
|
135
|
-
#endif //
|
|
136
|
+
#endif // SRC_HANDLE_MANAGER_H_
|
|
@@ -12,17 +12,19 @@
|
|
|
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_MACROS_H_
|
|
16
|
+
#define SRC_MACROS_H_
|
|
17
|
+
|
|
18
|
+
#include <napi.h>
|
|
17
19
|
|
|
18
20
|
#include "rcutils/logging_macros.h"
|
|
19
21
|
|
|
20
22
|
#define CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE(op, lhs, rhs, message) \
|
|
21
23
|
{ \
|
|
22
24
|
if (lhs op rhs) { \
|
|
23
|
-
Nan::ThrowError(message); \
|
|
24
25
|
rcl_reset_error(); \
|
|
25
|
-
|
|
26
|
+
Napi::Error::New(rclnodejs::GetEnv(), message) \
|
|
27
|
+
.ThrowAsJavaScriptException(); \
|
|
26
28
|
} \
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -43,4 +45,4 @@
|
|
|
43
45
|
#define RCLNODEJS_DEBUG(...)
|
|
44
46
|
#endif
|
|
45
47
|
|
|
46
|
-
#endif //
|
|
48
|
+
#endif // SRC_MACROS_H_
|