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/src/rcl_utilities.cpp
CHANGED
|
@@ -12,16 +12,115 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#include "rcl_utilities.
|
|
15
|
+
#include "rcl_utilities.h"
|
|
16
16
|
|
|
17
17
|
#include <rcl/rcl.h>
|
|
18
18
|
#include <rcl_action/rcl_action.h>
|
|
19
|
+
#include <rmw/topic_endpoint_info.h>
|
|
19
20
|
#include <uv.h>
|
|
20
21
|
|
|
22
|
+
#include <memory>
|
|
21
23
|
#include <string>
|
|
22
24
|
|
|
23
25
|
namespace {
|
|
26
|
+
|
|
27
|
+
const rmw_qos_profile_t* GetQoSProfileFromString(const std::string& profile) {
|
|
28
|
+
const rmw_qos_profile_t* qos_profile = nullptr;
|
|
29
|
+
if (profile == "qos_profile_sensor_data") {
|
|
30
|
+
qos_profile = &rmw_qos_profile_sensor_data;
|
|
31
|
+
} else if (profile == "qos_profile_system_default") {
|
|
32
|
+
qos_profile = &rmw_qos_profile_system_default;
|
|
33
|
+
} else if (profile == "qos_profile_services_default") {
|
|
34
|
+
qos_profile = &rmw_qos_profile_services_default;
|
|
35
|
+
} else if (profile == "qos_profile_parameters") {
|
|
36
|
+
qos_profile = &rmw_qos_profile_parameters;
|
|
37
|
+
} else if (profile == "qos_profile_parameter_events") {
|
|
38
|
+
qos_profile = &rmw_qos_profile_parameter_events;
|
|
39
|
+
} else if (profile == "qos_profile_action_status_default") {
|
|
40
|
+
qos_profile = &rcl_action_qos_profile_status_default;
|
|
41
|
+
} else {
|
|
42
|
+
return &rmw_qos_profile_default;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return qos_profile;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::unique_ptr<rmw_qos_profile_t> GetQosProfileFromObject(
|
|
49
|
+
Napi::Object object) {
|
|
50
|
+
std::unique_ptr<rmw_qos_profile_t> qos_profile =
|
|
51
|
+
std::make_unique<rmw_qos_profile_t>();
|
|
52
|
+
|
|
53
|
+
auto history = object.Get("history");
|
|
54
|
+
auto depth = object.Get("depth");
|
|
55
|
+
auto reliability = object.Get("reliability");
|
|
56
|
+
auto durability = object.Get("durability");
|
|
57
|
+
auto avoid_ros_namespace_conventions =
|
|
58
|
+
object.Get("avoidRosNameSpaceConventions");
|
|
59
|
+
|
|
60
|
+
qos_profile->history = static_cast<rmw_qos_history_policy_t>(
|
|
61
|
+
history.As<Napi::Number>().Uint32Value());
|
|
62
|
+
qos_profile->depth = depth.As<Napi::Number>().Uint32Value();
|
|
63
|
+
qos_profile->reliability = static_cast<rmw_qos_reliability_policy_t>(
|
|
64
|
+
reliability.As<Napi::Number>().Uint32Value());
|
|
65
|
+
qos_profile->durability = static_cast<rmw_qos_durability_policy_t>(
|
|
66
|
+
durability.As<Napi::Number>().Uint32Value());
|
|
67
|
+
qos_profile->avoid_ros_namespace_conventions =
|
|
68
|
+
avoid_ros_namespace_conventions.As<Napi::Boolean>();
|
|
69
|
+
|
|
70
|
+
return qos_profile;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Napi::Value ConvertRMWTimeToDuration(Napi::Env env,
|
|
74
|
+
const rmw_time_t* duration) {
|
|
75
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
76
|
+
obj.Set("seconds", Napi::BigInt::New(env, duration->sec));
|
|
77
|
+
obj.Set("nanoseconds", Napi::Number::New(env, duration->nsec));
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#if ROS_VERSION > 2205 // 2205 == Humble
|
|
82
|
+
Napi::Value ConvertToHashObject(Napi::Env env,
|
|
83
|
+
const rosidl_type_hash_t* type_hash) {
|
|
84
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
85
|
+
obj.Set("version", Napi::Number::New(env, type_hash->version));
|
|
86
|
+
obj.Set("value", Napi::Buffer<char>::Copy(
|
|
87
|
+
env, reinterpret_cast<const char*>(type_hash->value),
|
|
88
|
+
ROSIDL_TYPE_HASH_SIZE));
|
|
89
|
+
return obj;
|
|
90
|
+
}
|
|
91
|
+
#endif
|
|
92
|
+
|
|
93
|
+
Napi::Value ConvertToJSTopicEndpoint(
|
|
94
|
+
Napi::Env env, const rmw_topic_endpoint_info_t* topic_endpoint_info) {
|
|
95
|
+
Napi::Array endpoint_gid = Napi::Array::New(env, RMW_GID_STORAGE_SIZE);
|
|
96
|
+
for (size_t i = 0; i < RMW_GID_STORAGE_SIZE; i++) {
|
|
97
|
+
endpoint_gid.Set(
|
|
98
|
+
i, Napi::Number::New(env, topic_endpoint_info->endpoint_gid[i]));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Napi::Object endpoint = Napi::Object::New(env);
|
|
102
|
+
endpoint.Set("node_name",
|
|
103
|
+
Napi::String::New(env, topic_endpoint_info->node_name));
|
|
104
|
+
endpoint.Set("node_namespace",
|
|
105
|
+
Napi::String::New(env, topic_endpoint_info->node_namespace));
|
|
106
|
+
endpoint.Set("topic_type",
|
|
107
|
+
Napi::String::New(env, topic_endpoint_info->topic_type));
|
|
108
|
+
#if ROS_VERSION > 2205 // 2205 == Humble
|
|
109
|
+
endpoint.Set("topic_type_hash",
|
|
110
|
+
ConvertToHashObject(env, &topic_endpoint_info->topic_type_hash));
|
|
111
|
+
#endif
|
|
112
|
+
endpoint.Set("endpoint_type",
|
|
113
|
+
Napi::Number::New(
|
|
114
|
+
env, static_cast<int>(topic_endpoint_info->endpoint_type)));
|
|
115
|
+
endpoint.Set("endpoint_gid", endpoint_gid);
|
|
116
|
+
endpoint.Set("qos_profile",
|
|
117
|
+
rclnodejs::ConvertToQoS(env, &topic_endpoint_info->qos_profile));
|
|
118
|
+
return endpoint;
|
|
119
|
+
}
|
|
120
|
+
|
|
24
121
|
uv_lib_t g_lib;
|
|
122
|
+
Napi::Env g_env = nullptr;
|
|
123
|
+
|
|
25
124
|
} // namespace
|
|
26
125
|
|
|
27
126
|
namespace rclnodejs {
|
|
@@ -95,4 +194,70 @@ std::string GetErrorMessageAndClear() {
|
|
|
95
194
|
return std::string(uv_dlerror(&g_lib));
|
|
96
195
|
}
|
|
97
196
|
|
|
197
|
+
Napi::Env& GetEnv() { return g_env; }
|
|
198
|
+
|
|
199
|
+
void StoreEnv(Napi::Env current_env) { g_env = current_env; }
|
|
200
|
+
|
|
201
|
+
std::unique_ptr<rmw_qos_profile_t> GetQoSProfile(Napi::Value qos) {
|
|
202
|
+
std::unique_ptr<rmw_qos_profile_t> qos_profile =
|
|
203
|
+
std::make_unique<rmw_qos_profile_t>();
|
|
204
|
+
|
|
205
|
+
if (qos.IsString()) {
|
|
206
|
+
*qos_profile = *GetQoSProfileFromString(qos.As<Napi::String>().Utf8Value());
|
|
207
|
+
} else if (qos.IsObject()) {
|
|
208
|
+
qos_profile = GetQosProfileFromObject(qos.As<Napi::Object>());
|
|
209
|
+
} else {
|
|
210
|
+
return qos_profile;
|
|
211
|
+
}
|
|
212
|
+
return qos_profile;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void ExtractNamesAndTypes(rcl_names_and_types_t names_and_types,
|
|
216
|
+
Napi::Array* result_list) {
|
|
217
|
+
Napi::Env env = result_list->Env();
|
|
218
|
+
|
|
219
|
+
for (size_t i = 0; i < names_and_types.names.size; ++i) {
|
|
220
|
+
Napi::Object item = Napi::Object::New(env);
|
|
221
|
+
std::string topic_name = names_and_types.names.data[i];
|
|
222
|
+
item.Set("name", Napi::String::New(env, names_and_types.names.data[i]));
|
|
223
|
+
|
|
224
|
+
Napi::Array type_list =
|
|
225
|
+
Napi::Array::New(env, names_and_types.types[i].size);
|
|
226
|
+
for (size_t j = 0; j < names_and_types.types[i].size; ++j) {
|
|
227
|
+
type_list.Set(j,
|
|
228
|
+
Napi::String::New(env, names_and_types.types[i].data[j]));
|
|
229
|
+
}
|
|
230
|
+
item.Set("types", type_list);
|
|
231
|
+
result_list->Set(i, item);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
Napi::Value ConvertToQoS(Napi::Env env, const rmw_qos_profile_t* qos_profile) {
|
|
236
|
+
Napi::Object qos = Napi::Object::New(env);
|
|
237
|
+
qos.Set("depth", Napi::Number::New(env, qos_profile->depth));
|
|
238
|
+
qos.Set("history", Napi::Number::New(env, qos_profile->history));
|
|
239
|
+
qos.Set("reliability", Napi::Number::New(env, qos_profile->reliability));
|
|
240
|
+
qos.Set("durability", Napi::Number::New(env, qos_profile->durability));
|
|
241
|
+
qos.Set("lifespan", ConvertRMWTimeToDuration(env, &qos_profile->lifespan));
|
|
242
|
+
qos.Set("deadline", ConvertRMWTimeToDuration(env, &qos_profile->deadline));
|
|
243
|
+
qos.Set("liveliness", Napi::Number::New(env, qos_profile->liveliness));
|
|
244
|
+
qos.Set(
|
|
245
|
+
"liveliness_lease_duration",
|
|
246
|
+
ConvertRMWTimeToDuration(env, &qos_profile->liveliness_lease_duration));
|
|
247
|
+
qos.Set(
|
|
248
|
+
"avoid_ros_namespace_conventions",
|
|
249
|
+
Napi::Boolean::New(env, qos_profile->avoid_ros_namespace_conventions));
|
|
250
|
+
return qos;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
Napi::Array ConvertToJSTopicEndpointInfoList(
|
|
254
|
+
Napi::Env env, const rmw_topic_endpoint_info_array_t* info_array) {
|
|
255
|
+
Napi::Array list = Napi::Array::New(env, info_array->size);
|
|
256
|
+
for (size_t i = 0; i < info_array->size; ++i) {
|
|
257
|
+
rmw_topic_endpoint_info_t topic_endpoint_info = info_array->info_array[i];
|
|
258
|
+
list.Set(i, ConvertToJSTopicEndpoint(env, &topic_endpoint_info));
|
|
259
|
+
}
|
|
260
|
+
return list;
|
|
261
|
+
}
|
|
262
|
+
|
|
98
263
|
} // namespace rclnodejs
|
|
@@ -12,9 +12,14 @@
|
|
|
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_UTILITIES_H_
|
|
16
|
+
#define SRC_RCL_UTILITIES_H_
|
|
17
17
|
|
|
18
|
+
#include <napi.h>
|
|
19
|
+
#include <rcl/graph.h>
|
|
20
|
+
#include <rmw/rmw.h>
|
|
21
|
+
|
|
22
|
+
#include <memory>
|
|
18
23
|
#include <string>
|
|
19
24
|
|
|
20
25
|
struct rosidl_message_type_support_t;
|
|
@@ -35,6 +40,19 @@ const rosidl_action_type_support_t* GetActionTypeSupport(
|
|
|
35
40
|
|
|
36
41
|
std::string GetErrorMessageAndClear();
|
|
37
42
|
|
|
43
|
+
// Store a reference to the environment that can be used for error reporting.
|
|
44
|
+
Napi::Env& GetEnv();
|
|
45
|
+
void StoreEnv(Napi::Env current_env);
|
|
46
|
+
|
|
47
|
+
std::unique_ptr<rmw_qos_profile_t> GetQoSProfile(Napi::Value qos);
|
|
48
|
+
void ExtractNamesAndTypes(rcl_names_and_types_t names_and_types,
|
|
49
|
+
Napi::Array* result_list);
|
|
50
|
+
|
|
51
|
+
Napi::Array ConvertToJSTopicEndpointInfoList(
|
|
52
|
+
Napi::Env env, const rmw_topic_endpoint_info_array_t* info_array);
|
|
53
|
+
|
|
54
|
+
Napi::Value ConvertToQoS(Napi::Env env, const rmw_qos_profile_t* qos_profile);
|
|
55
|
+
|
|
38
56
|
} // namespace rclnodejs
|
|
39
57
|
|
|
40
|
-
#endif //
|
|
58
|
+
#endif // SRC_RCL_UTILITIES_H_
|
package/src/shadow_node.cpp
CHANGED
|
@@ -12,47 +12,43 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
#include "shadow_node.
|
|
15
|
+
#include "shadow_node.h"
|
|
16
16
|
|
|
17
17
|
#include <memory>
|
|
18
18
|
#include <vector>
|
|
19
19
|
|
|
20
|
-
#include "executor.
|
|
21
|
-
#include "handle_manager.
|
|
22
|
-
#include "rcl_handle.
|
|
20
|
+
#include "executor.h"
|
|
21
|
+
#include "handle_manager.h"
|
|
22
|
+
#include "rcl_handle.h"
|
|
23
23
|
|
|
24
24
|
namespace rclnodejs {
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Napi::FunctionReference ShadowNode::constructor;
|
|
27
27
|
|
|
28
|
-
ShadowNode::ShadowNode(
|
|
29
|
-
|
|
28
|
+
ShadowNode::ShadowNode(const Napi::CallbackInfo& info)
|
|
29
|
+
: Napi::ObjectWrap<ShadowNode>(info),
|
|
30
|
+
handle_manager_(std::make_unique<HandleManager>()) {
|
|
31
|
+
executor_ =
|
|
32
|
+
std::make_unique<Executor>(info.Env(), handle_manager_.get(), this);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
ShadowNode::~ShadowNode() {
|
|
33
|
-
Nan::HandleScope scope;
|
|
35
|
+
ShadowNode::~ShadowNode() { StopRunning(); }
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
void ShadowNode::Init(v8::Local<v8::Object> exports) {
|
|
39
|
-
Nan::HandleScope scope;
|
|
40
|
-
|
|
41
|
-
// Prepare constructor template
|
|
42
|
-
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
|
|
43
|
-
tpl->SetClassName(Nan::New("ShadowNode").ToLocalChecked());
|
|
44
|
-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
37
|
+
void ShadowNode::Init(Napi::Env env, Napi::Object exports) {
|
|
38
|
+
Napi::HandleScope scope(env);
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
Napi::Function func =
|
|
41
|
+
DefineClass(env, "ShadowNode",
|
|
42
|
+
{
|
|
43
|
+
InstanceMethod("start", &ShadowNode::Start),
|
|
44
|
+
InstanceMethod("stop", &ShadowNode::Stop),
|
|
45
|
+
InstanceMethod("syncHandles", &ShadowNode::SyncHandles),
|
|
46
|
+
InstanceMethod("spinOnce", &ShadowNode::SpinOnce),
|
|
47
|
+
});
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Nan::Set(exports, Nan::New("ShadowNode").ToLocalChecked(),
|
|
55
|
-
tpl->GetFunction(context).ToLocalChecked());
|
|
49
|
+
constructor = Napi::Persistent(func);
|
|
50
|
+
constructor.SuppressDestruct();
|
|
51
|
+
exports.Set("ShadowNode", func);
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
void ShadowNode::StopRunning() {
|
|
@@ -61,82 +57,67 @@ void ShadowNode::StopRunning() {
|
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
void ShadowNode::StartRunning(rcl_context_t* context, int32_t timeout) {
|
|
64
|
-
handle_manager_->SynchronizeHandles(this->
|
|
60
|
+
handle_manager_->SynchronizeHandles(this->Value());
|
|
65
61
|
executor_->Start(context, timeout);
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
void ShadowNode::RunOnce(rcl_context_t* context, int32_t timeout) {
|
|
69
|
-
handle_manager_->SynchronizeHandles(this->
|
|
65
|
+
handle_manager_->SynchronizeHandles(this->Value());
|
|
70
66
|
executor_->SpinOnce(context, timeout);
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
RclHandle*
|
|
76
|
-
|
|
77
|
-
auto timeout = Nan::To<int32_t>(info[1]).FromJust();
|
|
78
|
-
rcl_context_t* context =
|
|
79
|
-
reinterpret_cast<rcl_context_t*>(context_handle->ptr());
|
|
80
|
-
if (me) me->StartRunning(context, timeout);
|
|
69
|
+
Napi::Value ShadowNode::Start(const Napi::CallbackInfo& info) {
|
|
70
|
+
Napi::Object context_handle = info[0].As<Napi::Object>();
|
|
71
|
+
RclHandle* handle = RclHandle::Unwrap(context_handle);
|
|
72
|
+
int32_t timeout = info[1].As<Napi::Number>().Int32Value();
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
rcl_context_t* context = reinterpret_cast<rcl_context_t*>(handle->ptr());
|
|
75
|
+
StartRunning(context, timeout);
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (me) me->StopRunning();
|
|
77
|
+
return info.Env().Undefined();
|
|
78
|
+
}
|
|
88
79
|
|
|
89
|
-
|
|
80
|
+
Napi::Value ShadowNode::Stop(const Napi::CallbackInfo& info) {
|
|
81
|
+
StopRunning();
|
|
82
|
+
return info.Env().Undefined();
|
|
90
83
|
}
|
|
91
84
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
RclHandle*
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
rcl_context_t* context =
|
|
98
|
-
|
|
99
|
-
if (me) me->RunOnce(context, timeout);
|
|
85
|
+
Napi::Value ShadowNode::SpinOnce(const Napi::CallbackInfo& info) {
|
|
86
|
+
Napi::Object context_handle = info[0].As<Napi::Object>();
|
|
87
|
+
RclHandle* handle = RclHandle::Unwrap(context_handle);
|
|
88
|
+
int32_t timeout = info[1].As<Napi::Number>().Int32Value();
|
|
89
|
+
|
|
90
|
+
rcl_context_t* context = reinterpret_cast<rcl_context_t*>(handle->ptr());
|
|
91
|
+
RunOnce(context, timeout);
|
|
100
92
|
|
|
101
|
-
info.
|
|
93
|
+
return info.Env().Undefined();
|
|
102
94
|
}
|
|
103
95
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
me->handle_manager()->SynchronizeHandles(me->handle());
|
|
108
|
-
}
|
|
96
|
+
Napi::Value ShadowNode::SyncHandles(const Napi::CallbackInfo& info) {
|
|
97
|
+
handle_manager()->SynchronizeHandles(this->Value());
|
|
98
|
+
return info.Env().Undefined();
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
void ShadowNode::Execute(const std::vector<rclnodejs::RclHandle*>& handles) {
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
Napi::Env env = Env();
|
|
103
|
+
Napi::HandleScope scope(env);
|
|
114
104
|
|
|
115
|
-
|
|
105
|
+
Napi::Array results = Napi::Array::New(env, handles.size());
|
|
116
106
|
for (size_t i = 0; i < handles.size(); ++i) {
|
|
117
107
|
handles[i]->SyncProperties();
|
|
118
|
-
|
|
108
|
+
results[i] = handles[i]->Value();
|
|
119
109
|
}
|
|
120
110
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
111
|
+
Napi::Function execute =
|
|
112
|
+
Value().As<Napi::Object>().Get("execute").As<Napi::Function>();
|
|
113
|
+
execute.Call(Value(), {results});
|
|
124
114
|
}
|
|
125
115
|
|
|
126
116
|
void ShadowNode::CatchException(std::exception_ptr e_ptr) {
|
|
127
117
|
try {
|
|
128
118
|
std::rethrow_exception(e_ptr);
|
|
129
119
|
} catch (const std::exception& e) {
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
void ShadowNode::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
|
135
|
-
if (info.IsConstructCall()) {
|
|
136
|
-
// Invoked as constructor: `new ShadowNode(...)`
|
|
137
|
-
ShadowNode* obj = new ShadowNode();
|
|
138
|
-
obj->Wrap(info.This());
|
|
139
|
-
info.GetReturnValue().Set(info.This());
|
|
120
|
+
Napi::Error::New(Env(), e.what()).ThrowAsJavaScriptException();
|
|
140
121
|
}
|
|
141
122
|
}
|
|
142
123
|
|
|
@@ -12,25 +12,26 @@
|
|
|
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_SHADOW_NODE_H_
|
|
16
|
+
#define SRC_SHADOW_NODE_H_
|
|
17
17
|
|
|
18
|
-
#include <
|
|
18
|
+
#include <napi.h>
|
|
19
19
|
|
|
20
20
|
#include <exception>
|
|
21
21
|
#include <memory>
|
|
22
22
|
#include <vector>
|
|
23
23
|
|
|
24
|
-
#include "executor.
|
|
24
|
+
#include "executor.h"
|
|
25
25
|
|
|
26
26
|
namespace rclnodejs {
|
|
27
27
|
|
|
28
28
|
class HandleManager;
|
|
29
29
|
class Executor;
|
|
30
30
|
|
|
31
|
-
class ShadowNode : public
|
|
31
|
+
class ShadowNode : public Napi::ObjectWrap<ShadowNode>,
|
|
32
|
+
public Executor::Delegate {
|
|
32
33
|
public:
|
|
33
|
-
static void Init(
|
|
34
|
+
static void Init(Napi::Env env, Napi::Object exports);
|
|
34
35
|
void StartRunning(rcl_context_t* context, int32_t timeout);
|
|
35
36
|
void StopRunning();
|
|
36
37
|
void RunOnce(rcl_context_t* context, int32_t timeout);
|
|
@@ -41,18 +42,18 @@ class ShadowNode : public Nan::ObjectWrap, public Executor::Delegate {
|
|
|
41
42
|
void Execute(const std::vector<rclnodejs::RclHandle*>& handles) override;
|
|
42
43
|
void CatchException(std::exception_ptr e_ptr) override;
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
ShadowNode();
|
|
45
|
+
explicit ShadowNode(const Napi::CallbackInfo& info);
|
|
46
46
|
~ShadowNode();
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
static
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
private:
|
|
49
|
+
static Napi::FunctionReference constructor;
|
|
50
|
+
|
|
51
|
+
Napi::Value Stop(const Napi::CallbackInfo& info);
|
|
52
|
+
Napi::Value Start(const Napi::CallbackInfo& info);
|
|
53
|
+
Napi::Value SyncHandles(const Napi::CallbackInfo& info);
|
|
54
|
+
Napi::Value SpinOnce(const Napi::CallbackInfo& info);
|
|
55
|
+
Napi::Value HandleGetter(const Napi::CallbackInfo& info);
|
|
56
|
+
void HandleSetter(const Napi::CallbackInfo& info, const Napi::Value& value);
|
|
56
57
|
|
|
57
58
|
std::unique_ptr<HandleManager> handle_manager_;
|
|
58
59
|
std::unique_ptr<Executor> executor_;
|
|
@@ -60,4 +61,4 @@ class ShadowNode : public Nan::ObjectWrap, public Executor::Delegate {
|
|
|
60
61
|
|
|
61
62
|
} // namespace rclnodejs
|
|
62
63
|
|
|
63
|
-
#endif //
|
|
64
|
+
#endif // SRC_SHADOW_NODE_H_
|
package/types/action_client.d.ts
CHANGED
|
@@ -173,5 +173,23 @@ declare module 'rclnodejs' {
|
|
|
173
173
|
* Destroy the underlying action client handle.
|
|
174
174
|
*/
|
|
175
175
|
destroy(): void;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get the number of wait set entities that make up an action entity.
|
|
179
|
+
* @return - The number of subscriptions, guard_conditions, timers, and clients and services.
|
|
180
|
+
*/
|
|
181
|
+
getNumEntities(): object;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Configure introspection.
|
|
185
|
+
* @param clock - Clock to use for service event timestamps
|
|
186
|
+
* @param QoSProfile - QOS profile for the service event publisher
|
|
187
|
+
* @param introspectionState - The state to set introspection to
|
|
188
|
+
*/
|
|
189
|
+
configureIntrospection(
|
|
190
|
+
clock: Clock,
|
|
191
|
+
serviceEventPubQOS: QoS,
|
|
192
|
+
introspectionState: ServiceIntrospectionStates
|
|
193
|
+
): void;
|
|
176
194
|
}
|
|
177
195
|
}
|
package/types/action_server.d.ts
CHANGED
|
@@ -181,5 +181,17 @@ declare module 'rclnodejs' {
|
|
|
181
181
|
* Destroy the action server and all goals.
|
|
182
182
|
*/
|
|
183
183
|
destroy(): void;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Configure introspection.
|
|
187
|
+
* @param clock - Clock to use for service event timestamps
|
|
188
|
+
* @param QoSProfile - QOS profile for the service event publisher
|
|
189
|
+
* @param introspectionState - The state to set introspection to
|
|
190
|
+
*/
|
|
191
|
+
configureIntrospection(
|
|
192
|
+
clock: Clock,
|
|
193
|
+
serviceEventPubQOS: QoS,
|
|
194
|
+
introspectionState: ServiceIntrospectionStates
|
|
195
|
+
): void;
|
|
184
196
|
}
|
|
185
197
|
}
|
package/types/context.d.ts
CHANGED
package/types/lifecycle.d.ts
CHANGED
|
@@ -326,6 +326,13 @@ declare module 'rclnodejs' {
|
|
|
326
326
|
topic: string,
|
|
327
327
|
options?: Options
|
|
328
328
|
): LifecyclePublisher<T>;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Check if state machine is initialized.
|
|
332
|
+
*
|
|
333
|
+
* @returns {boolean} true if the state machine is initialized; otherwise false.
|
|
334
|
+
*/
|
|
335
|
+
get isInitialized(): boolean;
|
|
329
336
|
}
|
|
330
337
|
} // lifecycle namespace
|
|
331
338
|
} // rclnodejs namespace
|
package/types/node.d.ts
CHANGED
|
@@ -142,6 +142,24 @@ declare module 'rclnodejs' {
|
|
|
142
142
|
namespace: string;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Result of Node.getNodeNames() query
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```
|
|
150
|
+
* [
|
|
151
|
+
* { name: 'gazebo', namespace: '/', enclave: '/'},
|
|
152
|
+
* { name: 'robot_state_publisher', namespace: '/', enclave: '/' },
|
|
153
|
+
* { name: 'cam2image', namespace: '/demo' , enclave: '/'}
|
|
154
|
+
* ]
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
type NodeNamesQueryResultWithEnclaves = {
|
|
158
|
+
name: string;
|
|
159
|
+
namespace: string;
|
|
160
|
+
enclave: string;
|
|
161
|
+
};
|
|
162
|
+
|
|
145
163
|
/**
|
|
146
164
|
* Node is the primary entrypoint in a ROS system for communication.
|
|
147
165
|
* It can be used to create ROS entities such as publishers, subscribers,
|
|
@@ -727,6 +745,29 @@ declare module 'rclnodejs' {
|
|
|
727
745
|
*/
|
|
728
746
|
getServiceNamesAndTypes(): Array<NamesAndTypesQueryResult>;
|
|
729
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Get an array of publishers on a given topic.
|
|
750
|
+
*
|
|
751
|
+
* @param topic - The name of the topic.
|
|
752
|
+
* @param noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
|
|
753
|
+
* otherwise it should be a valid ROS topic name.
|
|
754
|
+
* @returns An array of publishers.
|
|
755
|
+
*/
|
|
756
|
+
getPublishersInfoByTopic(topic: string, noDemangle: boolean): Array<object>;
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Get an array of subscriptions on a given topic.
|
|
760
|
+
*
|
|
761
|
+
* @param topic - The name of the topic.
|
|
762
|
+
* @param noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
|
|
763
|
+
* otherwise it should be a valid ROS topic name.
|
|
764
|
+
* @returns An array of subscriptions.
|
|
765
|
+
*/
|
|
766
|
+
getSubscriptionsInfoByTopic(
|
|
767
|
+
topic: string,
|
|
768
|
+
noDemangle: boolean
|
|
769
|
+
): Array<object>;
|
|
770
|
+
|
|
730
771
|
/**
|
|
731
772
|
* Get the list of nodes discovered by the provided node.
|
|
732
773
|
*
|
|
@@ -746,6 +787,13 @@ declare module 'rclnodejs' {
|
|
|
746
787
|
*/
|
|
747
788
|
getNodeNamesAndNamespaces(): Array<NodeNamesQueryResult>;
|
|
748
789
|
|
|
790
|
+
/**
|
|
791
|
+
* Get the list of nodes and their namespaces with enclaves discovered by the provided node.
|
|
792
|
+
*
|
|
793
|
+
* @returns An array of the names, namespaces and enclaves.
|
|
794
|
+
*/
|
|
795
|
+
getNodeNamesAndNamespacesWithEnclaves(): Array<NodeNamesQueryResultWithEnclaves>;
|
|
796
|
+
|
|
749
797
|
/**
|
|
750
798
|
* Return the number of publishers on a given topic.
|
|
751
799
|
* @param topic - The name of the topic.
|
|
@@ -759,5 +807,26 @@ declare module 'rclnodejs' {
|
|
|
759
807
|
* @returns Number of subscribers on the given topic.
|
|
760
808
|
*/
|
|
761
809
|
countSubscribers(topic: string): number;
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Get the number of clients on a given service name.
|
|
813
|
+
* @param serviceName - The service name.
|
|
814
|
+
* @returns Number of clients.
|
|
815
|
+
*/
|
|
816
|
+
countClients(serviceName: string): number;
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Get the number of services on a given service name.
|
|
820
|
+
* @param serviceName - The service name.
|
|
821
|
+
* @returns Number of services.
|
|
822
|
+
*/
|
|
823
|
+
countServices(serviceName: string): number;
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Get the fully qualified name of the node.
|
|
827
|
+
*
|
|
828
|
+
* @returns String containing the fully qualified name of the node.
|
|
829
|
+
*/
|
|
830
|
+
getFullyQualifiedName(): string;
|
|
762
831
|
}
|
|
763
832
|
}
|
package/types/publisher.d.ts
CHANGED
|
@@ -14,5 +14,28 @@ declare module 'rclnodejs' {
|
|
|
14
14
|
* @param message - The message to be sent.
|
|
15
15
|
*/
|
|
16
16
|
publish(message: MessageType<T> | Buffer): void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get the number of subscriptions to this publisher.
|
|
20
|
+
* @returns The number of subscriptions
|
|
21
|
+
*/
|
|
22
|
+
subscriptionCount(): number;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wait until all published message data is acknowledged or until the specified timeout elapses
|
|
26
|
+
*
|
|
27
|
+
* If the timeout is negative then this function will block indefinitely until all published
|
|
28
|
+
* message data is acknowledged.
|
|
29
|
+
* If the timeout is 0 then it will check if all published message has been acknowledged without
|
|
30
|
+
* waiting.
|
|
31
|
+
* If the timeout is greater than 0 then it will return after that period of time has elapsed or
|
|
32
|
+
* all published message data is acknowledged.
|
|
33
|
+
*
|
|
34
|
+
* Raises an error if failed, such as the middleware not supporting this feature.
|
|
35
|
+
*
|
|
36
|
+
* @param {timeout} timeout - The duration to wait for all published message data to be acknowledged in nanoseconds.
|
|
37
|
+
* @return {boolean} `true` if all published message data is acknowledged before the timeout, otherwise `false`.
|
|
38
|
+
*/
|
|
39
|
+
waitForAllAcked(timeout: bigint): boolean;
|
|
17
40
|
}
|
|
18
41
|
}
|