rclnodejs 0.33.0 → 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 +53 -0
- 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/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 -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 +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/node.d.ts +37 -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
|
@@ -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/context.d.ts
CHANGED
package/types/node.d.ts
CHANGED
|
@@ -727,6 +727,29 @@ declare module 'rclnodejs' {
|
|
|
727
727
|
*/
|
|
728
728
|
getServiceNamesAndTypes(): Array<NamesAndTypesQueryResult>;
|
|
729
729
|
|
|
730
|
+
/**
|
|
731
|
+
* Get an array of publishers on a given topic.
|
|
732
|
+
*
|
|
733
|
+
* @param topic - The name of the topic.
|
|
734
|
+
* @param noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
|
|
735
|
+
* otherwise it should be a valid ROS topic name.
|
|
736
|
+
* @returns An array of publishers.
|
|
737
|
+
*/
|
|
738
|
+
getPublishersInfoByTopic(topic: string, noDemangle: boolean): Array<object>;
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Get an array of subscriptions on a given topic.
|
|
742
|
+
*
|
|
743
|
+
* @param topic - The name of the topic.
|
|
744
|
+
* @param noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
|
|
745
|
+
* otherwise it should be a valid ROS topic name.
|
|
746
|
+
* @returns An array of subscriptions.
|
|
747
|
+
*/
|
|
748
|
+
getSubscriptionsInfoByTopic(
|
|
749
|
+
topic: string,
|
|
750
|
+
noDemangle: boolean
|
|
751
|
+
): Array<object>;
|
|
752
|
+
|
|
730
753
|
/**
|
|
731
754
|
* Get the list of nodes discovered by the provided node.
|
|
732
755
|
*
|
|
@@ -759,5 +782,19 @@ declare module 'rclnodejs' {
|
|
|
759
782
|
* @returns Number of subscribers on the given topic.
|
|
760
783
|
*/
|
|
761
784
|
countSubscribers(topic: string): number;
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Get the number of clients on a given service name.
|
|
788
|
+
* @param serviceName - The service name.
|
|
789
|
+
* @returns Number of clients.
|
|
790
|
+
*/
|
|
791
|
+
countClients(serviceName: string): number;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Get the number of services on a given service name.
|
|
795
|
+
* @param serviceName - The service name.
|
|
796
|
+
* @returns Number of services.
|
|
797
|
+
*/
|
|
798
|
+
countServices(serviceName: string): number;
|
|
762
799
|
}
|
|
763
800
|
}
|
package/types/publisher.d.ts
CHANGED
|
@@ -14,5 +14,11 @@ 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;
|
|
17
23
|
}
|
|
18
24
|
}
|
package/types/service.d.ts
CHANGED
package/types/subscription.d.ts
CHANGED
|
@@ -66,5 +66,11 @@ declare module 'rclnodejs' {
|
|
|
66
66
|
* @returns True if successful; false otherwise
|
|
67
67
|
*/
|
|
68
68
|
clearContentFilter(): boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the number of publishers to this subscription.
|
|
72
|
+
* @returns The number of publishers
|
|
73
|
+
*/
|
|
74
|
+
publisherCount(): number;
|
|
69
75
|
}
|
|
70
76
|
}
|
package/types/timer.d.ts
CHANGED
|
@@ -45,5 +45,23 @@ declare module 'rclnodejs' {
|
|
|
45
45
|
* @returns The interval value in nanoseconds
|
|
46
46
|
*/
|
|
47
47
|
timeUntilNextCall(): bigint;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Change the timer period.
|
|
51
|
+
* @param period - The new period in nanoseconds.
|
|
52
|
+
*/
|
|
53
|
+
changeTimerPeriod(period: bigint): void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get the timer period.
|
|
57
|
+
* @return The period in nanoseconds.
|
|
58
|
+
*/
|
|
59
|
+
timerPeriod(): bigint;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Call a timer and starts counting again, retrieves actual and expected call time.
|
|
63
|
+
* @return - The timer information.
|
|
64
|
+
*/
|
|
65
|
+
callTimerWithInfo(): object;
|
|
48
66
|
}
|
|
49
67
|
}
|