rclnodejs 0.32.5 → 1.0.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 +17 -2
- package/lib/client.js +2 -3
- package/lib/context.js +8 -0
- package/lib/logging.js +26 -9
- package/lib/node.js +68 -1
- package/lib/publisher.js +8 -0
- package/lib/service.js +9 -2
- package/lib/subscription.js +8 -0
- package/lib/timer.js +32 -0
- package/package.json +4 -4
- package/rostsd_gen/index.js +167 -67
- package/scripts/config.js +1 -0
- package/scripts/npmjs-readme.md +3 -3
- package/src/addon.cpp +54 -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 +231 -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 +470 -0
- package/src/rcl_action_server_bindings.h +26 -0
- package/src/rcl_bindings.cpp +42 -1979
- 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 +135 -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 +447 -0
- package/src/rcl_node_bindings.h +26 -0
- package/src/rcl_publisher_bindings.cpp +141 -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_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/context.d.ts +6 -0
- package/types/interfaces.d.ts +4377 -0
- package/types/node.d.ts +53 -0
- package/types/publisher.d.ts +6 -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/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_
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Copyright (c) 2020 Matt Richard. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include "rcl_action_client_bindings.h"
|
|
16
|
+
|
|
17
|
+
#include <rcl/error_handling.h>
|
|
18
|
+
#include <rcl/rcl.h>
|
|
19
|
+
#include <rcl_action/rcl_action.h>
|
|
20
|
+
|
|
21
|
+
#include <string>
|
|
22
|
+
|
|
23
|
+
#include "handle_manager.h"
|
|
24
|
+
#include "macros.h"
|
|
25
|
+
#include "rcl_handle.h"
|
|
26
|
+
#include "rcl_utilities.h"
|
|
27
|
+
|
|
28
|
+
namespace rclnodejs {
|
|
29
|
+
|
|
30
|
+
Napi::Value ActionCreateClient(const Napi::CallbackInfo& info) {
|
|
31
|
+
Napi::Env env = info.Env();
|
|
32
|
+
|
|
33
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
34
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
35
|
+
std::string action_name = info[1].As<Napi::String>().Utf8Value();
|
|
36
|
+
std::string interface_name = info[2].As<Napi::String>().Utf8Value();
|
|
37
|
+
std::string package_name = info[3].As<Napi::String>().Utf8Value();
|
|
38
|
+
|
|
39
|
+
const rosidl_action_type_support_t* ts =
|
|
40
|
+
GetActionTypeSupport(package_name, interface_name);
|
|
41
|
+
|
|
42
|
+
if (ts) {
|
|
43
|
+
rcl_action_client_options_t action_client_ops =
|
|
44
|
+
rcl_action_client_get_default_options();
|
|
45
|
+
|
|
46
|
+
auto goal_service_qos = GetQoSProfile(info[4]);
|
|
47
|
+
auto result_service_qos = GetQoSProfile(info[5]);
|
|
48
|
+
auto cancel_service_qos = GetQoSProfile(info[6]);
|
|
49
|
+
auto feedback_topic_qos = GetQoSProfile(info[7]);
|
|
50
|
+
auto status_topic_qos = GetQoSProfile(info[8]);
|
|
51
|
+
|
|
52
|
+
if (goal_service_qos) {
|
|
53
|
+
action_client_ops.goal_service_qos = *goal_service_qos;
|
|
54
|
+
}
|
|
55
|
+
if (result_service_qos) {
|
|
56
|
+
action_client_ops.result_service_qos = *result_service_qos;
|
|
57
|
+
}
|
|
58
|
+
if (cancel_service_qos) {
|
|
59
|
+
action_client_ops.cancel_service_qos = *cancel_service_qos;
|
|
60
|
+
}
|
|
61
|
+
if (feedback_topic_qos) {
|
|
62
|
+
action_client_ops.feedback_topic_qos = *feedback_topic_qos;
|
|
63
|
+
}
|
|
64
|
+
if (status_topic_qos) {
|
|
65
|
+
action_client_ops.status_topic_qos = *status_topic_qos;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
rcl_action_client_t* action_client = reinterpret_cast<rcl_action_client_t*>(
|
|
69
|
+
malloc(sizeof(rcl_action_client_t)));
|
|
70
|
+
*action_client = rcl_action_get_zero_initialized_client();
|
|
71
|
+
|
|
72
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
73
|
+
rcl_action_client_init(action_client, node, ts, action_name.c_str(),
|
|
74
|
+
&action_client_ops),
|
|
75
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
76
|
+
auto js_obj = RclHandle::NewInstance(
|
|
77
|
+
env, action_client, node_handle, [node](void* ptr) {
|
|
78
|
+
rcl_action_client_t* action_client =
|
|
79
|
+
reinterpret_cast<rcl_action_client_t*>(ptr);
|
|
80
|
+
rcl_ret_t ret = rcl_action_client_fini(action_client, node);
|
|
81
|
+
free(ptr);
|
|
82
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return js_obj;
|
|
86
|
+
} else {
|
|
87
|
+
Napi::Error::New(env, GetErrorMessageAndClear())
|
|
88
|
+
.ThrowAsJavaScriptException();
|
|
89
|
+
return env.Undefined();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Napi::Value ActionServerIsAvailable(const Napi::CallbackInfo& info) {
|
|
94
|
+
Napi::Env env = info.Env();
|
|
95
|
+
|
|
96
|
+
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
97
|
+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
|
|
98
|
+
RclHandle* action_client_handle =
|
|
99
|
+
RclHandle::Unwrap(info[1].As<Napi::Object>());
|
|
100
|
+
rcl_action_client_t* action_client =
|
|
101
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
102
|
+
|
|
103
|
+
bool is_available;
|
|
104
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
105
|
+
RCL_RET_OK,
|
|
106
|
+
rcl_action_server_is_available(node, action_client, &is_available),
|
|
107
|
+
rcl_get_error_string().str);
|
|
108
|
+
|
|
109
|
+
return Napi::Boolean::New(env, is_available);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Napi::Value ActionSendGoalRequest(const Napi::CallbackInfo& info) {
|
|
113
|
+
Napi::Env env = info.Env();
|
|
114
|
+
|
|
115
|
+
RclHandle* action_client_handle =
|
|
116
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
117
|
+
rcl_action_client_t* action_client =
|
|
118
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
119
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
120
|
+
|
|
121
|
+
int64_t sequence_number;
|
|
122
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
123
|
+
rcl_action_send_goal_request(action_client, buffer, &sequence_number),
|
|
124
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
125
|
+
|
|
126
|
+
return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Napi::Value ActionTakeCancelRequest(const Napi::CallbackInfo& info) {
|
|
130
|
+
Napi::Env env = info.Env();
|
|
131
|
+
|
|
132
|
+
RclHandle* action_server_handle =
|
|
133
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
134
|
+
rcl_action_server_t* action_server =
|
|
135
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
136
|
+
rmw_request_id_t* header =
|
|
137
|
+
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
|
|
138
|
+
|
|
139
|
+
void* taken_request = info[1].As<Napi::Buffer<char>>().Data();
|
|
140
|
+
rcl_ret_t ret =
|
|
141
|
+
rcl_action_take_cancel_request(action_server, header, taken_request);
|
|
142
|
+
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) {
|
|
143
|
+
auto js_obj = RclHandle::NewInstance(env, header, nullptr,
|
|
144
|
+
[](void* ptr) { free(ptr); });
|
|
145
|
+
return js_obj;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return env.Undefined();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
Napi::Value ActionSendResultRequest(const Napi::CallbackInfo& info) {
|
|
152
|
+
Napi::Env env = info.Env();
|
|
153
|
+
|
|
154
|
+
RclHandle* action_client_handle =
|
|
155
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
156
|
+
rcl_action_client_t* action_client =
|
|
157
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
158
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
159
|
+
|
|
160
|
+
int64_t sequence_number;
|
|
161
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
162
|
+
rcl_action_send_result_request(action_client, buffer, &sequence_number),
|
|
163
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
164
|
+
|
|
165
|
+
return Napi::Number::New(env, static_cast<int32_t>(sequence_number));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
Napi::Value ActionTakeFeedback(const Napi::CallbackInfo& info) {
|
|
169
|
+
Napi::Env env = info.Env();
|
|
170
|
+
|
|
171
|
+
RclHandle* action_client_handle =
|
|
172
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
173
|
+
rcl_action_client_t* action_client =
|
|
174
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
175
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
176
|
+
|
|
177
|
+
rcl_ret_t ret = rcl_action_take_feedback(action_client, buffer);
|
|
178
|
+
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
179
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
180
|
+
.ThrowAsJavaScriptException();
|
|
181
|
+
rcl_reset_error();
|
|
182
|
+
return Napi::Boolean::New(env, false);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
186
|
+
return Napi::Boolean::New(env, true);
|
|
187
|
+
}
|
|
188
|
+
return env.Undefined();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
Napi::Value ActionTakeStatus(const Napi::CallbackInfo& info) {
|
|
192
|
+
Napi::Env env = info.Env();
|
|
193
|
+
|
|
194
|
+
RclHandle* action_client_handle =
|
|
195
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
196
|
+
rcl_action_client_t* action_client =
|
|
197
|
+
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr());
|
|
198
|
+
void* buffer = info[1].As<Napi::Buffer<char>>().Data();
|
|
199
|
+
|
|
200
|
+
rcl_ret_t ret = rcl_action_take_status(action_client, buffer);
|
|
201
|
+
if (ret != RCL_RET_OK && ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
202
|
+
rcl_reset_error();
|
|
203
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
204
|
+
.ThrowAsJavaScriptException();
|
|
205
|
+
return Napi::Boolean::New(env, false);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (ret != RCL_RET_ACTION_CLIENT_TAKE_FAILED) {
|
|
209
|
+
return Napi::Boolean::New(env, true);
|
|
210
|
+
}
|
|
211
|
+
return env.Undefined();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
Napi::Object InitActionClientBindings(Napi::Env env, Napi::Object exports) {
|
|
215
|
+
exports.Set("actionCreateClient",
|
|
216
|
+
Napi::Function::New(env, ActionCreateClient));
|
|
217
|
+
exports.Set("actionServerIsAvailable",
|
|
218
|
+
Napi::Function::New(env, ActionServerIsAvailable));
|
|
219
|
+
exports.Set("actionSendGoalRequest",
|
|
220
|
+
Napi::Function::New(env, ActionSendGoalRequest));
|
|
221
|
+
exports.Set("actionTakeCancelRequest",
|
|
222
|
+
Napi::Function::New(env, ActionTakeCancelRequest));
|
|
223
|
+
exports.Set("actionSendResultRequest",
|
|
224
|
+
Napi::Function::New(env, ActionSendResultRequest));
|
|
225
|
+
exports.Set("actionTakeFeedback",
|
|
226
|
+
Napi::Function::New(env, ActionTakeFeedback));
|
|
227
|
+
exports.Set("actionTakeStatus", Napi::Function::New(env, ActionTakeStatus));
|
|
228
|
+
return exports;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
} // namespace rclnodejs
|
|
@@ -12,20 +12,15 @@
|
|
|
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_ACTION_CLIENT_BINDINGS_H_
|
|
16
|
+
#define SRC_RCL_ACTION_CLIENT_BINDINGS_H_
|
|
17
17
|
|
|
18
|
-
#include <
|
|
19
|
-
#include <rcl/rcl.h>
|
|
20
|
-
|
|
21
|
-
#include <vector>
|
|
22
|
-
|
|
23
|
-
#include "rcl_bindings.hpp"
|
|
18
|
+
#include <napi.h>
|
|
24
19
|
|
|
25
20
|
namespace rclnodejs {
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
Napi::Object InitActionClientBindings(Napi::Env env, Napi::Object exports);
|
|
28
23
|
|
|
29
|
-
}
|
|
24
|
+
}
|
|
30
25
|
|
|
31
|
-
#endif //
|
|
26
|
+
#endif // SRC_RCL_ACTION_CLIENT_BINDINGS_H_
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright (c) 2020 Matt Richard. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include "rcl_action_goal_bindings.h"
|
|
16
|
+
|
|
17
|
+
#include <rcl/error_handling.h>
|
|
18
|
+
#include <rcl/rcl.h>
|
|
19
|
+
#include <rcl_action/rcl_action.h>
|
|
20
|
+
|
|
21
|
+
#include "handle_manager.h"
|
|
22
|
+
#include "macros.h"
|
|
23
|
+
#include "rcl_handle.h"
|
|
24
|
+
#include "rcl_utilities.h"
|
|
25
|
+
|
|
26
|
+
namespace rclnodejs {
|
|
27
|
+
|
|
28
|
+
Napi::Value ActionAcceptNewGoal(const Napi::CallbackInfo& info) {
|
|
29
|
+
Napi::Env env = info.Env();
|
|
30
|
+
|
|
31
|
+
RclHandle* action_server_handle =
|
|
32
|
+
RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
33
|
+
rcl_action_server_t* action_server =
|
|
34
|
+
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr());
|
|
35
|
+
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
|
|
36
|
+
info[1].As<Napi::Buffer<char>>().Data());
|
|
37
|
+
|
|
38
|
+
rcl_action_goal_handle_t* new_goal =
|
|
39
|
+
rcl_action_accept_new_goal(action_server, buffer);
|
|
40
|
+
if (!new_goal) {
|
|
41
|
+
Napi::Error::New(env, rcl_get_error_string().str)
|
|
42
|
+
.ThrowAsJavaScriptException();
|
|
43
|
+
rcl_reset_error();
|
|
44
|
+
return env.Undefined();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
rcl_action_goal_handle_t* goal_handle =
|
|
48
|
+
reinterpret_cast<rcl_action_goal_handle_t*>(
|
|
49
|
+
malloc(sizeof(rcl_action_goal_handle_t)));
|
|
50
|
+
*goal_handle = *new_goal;
|
|
51
|
+
auto js_obj =
|
|
52
|
+
RclHandle::NewInstance(env, goal_handle, nullptr, [](void* ptr) {
|
|
53
|
+
rcl_action_goal_handle_t* goal_handle =
|
|
54
|
+
reinterpret_cast<rcl_action_goal_handle_t*>(ptr);
|
|
55
|
+
rcl_ret_t ret = rcl_action_goal_handle_fini(goal_handle);
|
|
56
|
+
free(ptr);
|
|
57
|
+
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return js_obj;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Napi::Value ActionUpdateGoalState(const Napi::CallbackInfo& info) {
|
|
64
|
+
Napi::Env env = info.Env();
|
|
65
|
+
|
|
66
|
+
RclHandle* goal_handle_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
67
|
+
rcl_action_goal_handle_t* goal_handle =
|
|
68
|
+
reinterpret_cast<rcl_action_goal_handle_t*>(goal_handle_handle->ptr());
|
|
69
|
+
rcl_action_goal_event_t event = static_cast<rcl_action_goal_event_t>(
|
|
70
|
+
info[1].As<Napi::Number>().Int32Value());
|
|
71
|
+
|
|
72
|
+
THROW_ERROR_IF_NOT_EQUAL(rcl_action_update_goal_state(goal_handle, event),
|
|
73
|
+
RCL_RET_OK, rcl_get_error_string().str);
|
|
74
|
+
|
|
75
|
+
return env.Undefined();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Napi::Value ActionGoalHandleIsActive(const Napi::CallbackInfo& info) {
|
|
79
|
+
Napi::Env env = info.Env();
|
|
80
|
+
|
|
81
|
+
RclHandle* goal_handle_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
82
|
+
rcl_action_goal_handle_t* goal_handle =
|
|
83
|
+
reinterpret_cast<rcl_action_goal_handle_t*>(goal_handle_handle->ptr());
|
|
84
|
+
|
|
85
|
+
bool is_active = rcl_action_goal_handle_is_active(goal_handle);
|
|
86
|
+
|
|
87
|
+
return Napi::Boolean::New(env, is_active);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Napi::Value ActionGoalHandleGetStatus(const Napi::CallbackInfo& info) {
|
|
91
|
+
Napi::Env env = info.Env();
|
|
92
|
+
|
|
93
|
+
RclHandle* goal_handle_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
|
|
94
|
+
rcl_action_goal_handle_t* goal_handle =
|
|
95
|
+
reinterpret_cast<rcl_action_goal_handle_t*>(goal_handle_handle->ptr());
|
|
96
|
+
|
|
97
|
+
rcl_action_goal_state_t status;
|
|
98
|
+
THROW_ERROR_IF_NOT_EQUAL(
|
|
99
|
+
rcl_action_goal_handle_get_status(goal_handle, &status), RCL_RET_OK,
|
|
100
|
+
rcl_get_error_string().str);
|
|
101
|
+
|
|
102
|
+
return Napi::Number::New(env, static_cast<int32_t>(status));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Napi::Object InitActionGoalBindings(Napi::Env env, Napi::Object exports) {
|
|
106
|
+
exports.Set("actionAcceptNewGoal",
|
|
107
|
+
Napi::Function::New(env, ActionAcceptNewGoal));
|
|
108
|
+
exports.Set("actionUpdateGoalState",
|
|
109
|
+
Napi::Function::New(env, ActionUpdateGoalState));
|
|
110
|
+
exports.Set("actionGoalHandleIsActive",
|
|
111
|
+
Napi::Function::New(env, ActionGoalHandleIsActive));
|
|
112
|
+
exports.Set("actionGoalHandleGetStatus",
|
|
113
|
+
Napi::Function::New(env, ActionGoalHandleGetStatus));
|
|
114
|
+
return exports;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
} // namespace rclnodejs
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2020 Matt Richard. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#ifndef SRC_RCL_ACTION_GOAL_BINDINGS_H_
|
|
16
|
+
#define SRC_RCL_ACTION_GOAL_BINDINGS_H_
|
|
17
|
+
|
|
18
|
+
#include <napi.h>
|
|
19
|
+
|
|
20
|
+
namespace rclnodejs {
|
|
21
|
+
|
|
22
|
+
Napi::Object InitActionGoalBindings(Napi::Env env, Napi::Object exports);
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#endif // SRC_RCL_ACTION_GOAL_BINDINGS_H_
|