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.
Files changed (68) hide show
  1. package/README.md +3 -3
  2. package/binding.gyp +17 -2
  3. package/lib/client.js +2 -3
  4. package/lib/context.js +8 -0
  5. package/lib/logging.js +26 -9
  6. package/lib/node.js +68 -1
  7. package/lib/publisher.js +8 -0
  8. package/lib/service.js +9 -2
  9. package/lib/subscription.js +8 -0
  10. package/lib/timer.js +32 -0
  11. package/package.json +4 -4
  12. package/rostsd_gen/index.js +167 -67
  13. package/scripts/config.js +1 -0
  14. package/scripts/npmjs-readme.md +3 -3
  15. package/src/addon.cpp +54 -53
  16. package/src/executor.cpp +19 -10
  17. package/src/{executor.hpp → executor.h} +7 -5
  18. package/src/handle_manager.cpp +30 -56
  19. package/src/{handle_manager.hpp → handle_manager.h} +8 -7
  20. package/src/{macros.hpp → macros.h} +7 -5
  21. package/src/rcl_action_client_bindings.cpp +231 -0
  22. package/src/{rcl_action_bindings.hpp → rcl_action_client_bindings.h} +6 -11
  23. package/src/rcl_action_goal_bindings.cpp +117 -0
  24. package/src/rcl_action_goal_bindings.h +26 -0
  25. package/src/rcl_action_server_bindings.cpp +470 -0
  26. package/src/rcl_action_server_bindings.h +26 -0
  27. package/src/rcl_bindings.cpp +42 -1979
  28. package/src/{rcl_bindings.hpp → rcl_bindings.h} +5 -25
  29. package/src/rcl_client_bindings.cpp +183 -0
  30. package/src/rcl_client_bindings.h +26 -0
  31. package/src/rcl_context_bindings.cpp +156 -0
  32. package/src/rcl_context_bindings.h +26 -0
  33. package/src/rcl_graph_bindings.cpp +280 -0
  34. package/src/rcl_graph_bindings.h +26 -0
  35. package/src/rcl_guard_condition_bindings.cpp +75 -0
  36. package/src/rcl_guard_condition_bindings.h +26 -0
  37. package/src/rcl_handle.cpp +41 -57
  38. package/src/{rcl_handle.hpp → rcl_handle.h} +18 -17
  39. package/src/rcl_lifecycle_bindings.cpp +135 -114
  40. package/src/{rcl_lifecycle_bindings.hpp → rcl_lifecycle_bindings.h} +5 -7
  41. package/src/rcl_logging_bindings.cpp +96 -0
  42. package/src/rcl_logging_bindings.h +26 -0
  43. package/src/rcl_names_bindings.cpp +255 -0
  44. package/src/rcl_names_bindings.h +26 -0
  45. package/src/rcl_node_bindings.cpp +447 -0
  46. package/src/rcl_node_bindings.h +26 -0
  47. package/src/rcl_publisher_bindings.cpp +141 -0
  48. package/src/rcl_publisher_bindings.h +26 -0
  49. package/src/rcl_service_bindings.cpp +185 -0
  50. package/src/rcl_service_bindings.h +26 -0
  51. package/src/rcl_subscription_bindings.cpp +335 -0
  52. package/src/rcl_subscription_bindings.h +26 -0
  53. package/src/rcl_time_point_bindings.cpp +194 -0
  54. package/src/rcl_time_point_bindings.h +26 -0
  55. package/src/rcl_timer_bindings.cpp +237 -0
  56. package/src/rcl_timer_bindings.h +26 -0
  57. package/src/rcl_utilities.cpp +166 -1
  58. package/src/{rcl_utilities.hpp → rcl_utilities.h} +21 -3
  59. package/src/shadow_node.cpp +56 -75
  60. package/src/{shadow_node.hpp → shadow_node.h} +18 -17
  61. package/types/context.d.ts +6 -0
  62. package/types/interfaces.d.ts +4377 -0
  63. package/types/node.d.ts +53 -0
  64. package/types/publisher.d.ts +6 -0
  65. package/types/service.d.ts +6 -0
  66. package/types/subscription.d.ts +6 -0
  67. package/types/timer.d.ts +18 -0
  68. 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 SRC_RCL_UTILITIES_HPP_
16
- #define SRC_RCL_UTILITIES_HPP_
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 // SRC_RCL_UTILITIES_HPP_
58
+ #endif // SRC_RCL_UTILITIES_H_
@@ -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.hpp"
15
+ #include "shadow_node.h"
16
16
 
17
17
  #include <memory>
18
18
  #include <vector>
19
19
 
20
- #include "executor.hpp"
21
- #include "handle_manager.hpp"
22
- #include "rcl_handle.hpp"
20
+ #include "executor.h"
21
+ #include "handle_manager.h"
22
+ #include "rcl_handle.h"
23
23
 
24
24
  namespace rclnodejs {
25
25
 
26
- Nan::Persistent<v8::Function> ShadowNode::constructor;
26
+ Napi::FunctionReference ShadowNode::constructor;
27
27
 
28
- ShadowNode::ShadowNode() : handle_manager_(std::make_unique<HandleManager>()) {
29
- executor_ = std::make_unique<Executor>(handle_manager_.get(), this);
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
- StopRunning();
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
- Nan::SetPrototypeMethod(tpl, "start", Start);
47
- Nan::SetPrototypeMethod(tpl, "stop", Stop);
48
- Nan::SetPrototypeMethod(tpl, "syncHandles", SyncHandles);
49
- Nan::SetPrototypeMethod(tpl, "spinOnce", SpinOnce);
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
- v8::Local<v8::Context> context = exports->GetIsolate()->GetCurrentContext();
52
-
53
- constructor.Reset(tpl->GetFunction(context).ToLocalChecked());
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->handle());
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->handle());
65
+ handle_manager_->SynchronizeHandles(this->Value());
70
66
  executor_->SpinOnce(context, timeout);
71
67
  }
72
68
 
73
- NAN_METHOD(ShadowNode::Start) {
74
- auto* me = Nan::ObjectWrap::Unwrap<ShadowNode>(info.Holder());
75
- RclHandle* context_handle = RclHandle::Unwrap<RclHandle>(
76
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
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
- info.GetReturnValue().Set(Nan::Undefined());
83
- }
74
+ rcl_context_t* context = reinterpret_cast<rcl_context_t*>(handle->ptr());
75
+ StartRunning(context, timeout);
84
76
 
85
- NAN_METHOD(ShadowNode::Stop) {
86
- auto* me = Nan::ObjectWrap::Unwrap<ShadowNode>(info.Holder());
87
- if (me) me->StopRunning();
77
+ return info.Env().Undefined();
78
+ }
88
79
 
89
- info.GetReturnValue().Set(Nan::Undefined());
80
+ Napi::Value ShadowNode::Stop(const Napi::CallbackInfo& info) {
81
+ StopRunning();
82
+ return info.Env().Undefined();
90
83
  }
91
84
 
92
- NAN_METHOD(ShadowNode::SpinOnce) {
93
- auto* me = Nan::ObjectWrap::Unwrap<ShadowNode>(info.Holder());
94
- RclHandle* context_handle = RclHandle::Unwrap<RclHandle>(
95
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
96
- auto timeout = Nan::To<int32_t>(info[1]).FromJust();
97
- rcl_context_t* context =
98
- reinterpret_cast<rcl_context_t*>(context_handle->ptr());
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.GetReturnValue().Set(Nan::Undefined());
93
+ return info.Env().Undefined();
102
94
  }
103
95
 
104
- NAN_METHOD(ShadowNode::SyncHandles) {
105
- auto* me = Nan::ObjectWrap::Unwrap<ShadowNode>(info.Holder());
106
- if (me) {
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
- Nan::HandleScope scope;
113
- Nan::AsyncResource res("shadow_node");
102
+ Napi::Env env = Env();
103
+ Napi::HandleScope scope(env);
114
104
 
115
- v8::Local<v8::Array> results = Nan::New<v8::Array>(handles.size());
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
- Nan::Set(results, i, handles[i]->handle());
108
+ results[i] = handles[i]->Value();
119
109
  }
120
110
 
121
- v8::Local<v8::Value> argv[] = {results};
122
-
123
- res.runInAsyncScope(Nan::New(this->persistent()), "execute", 1, argv);
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
- Nan::ThrowError(e.what());
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 SRC_SHADOW_NODE_HPP_
16
- #define SRC_SHADOW_NODE_HPP_
15
+ #ifndef SRC_SHADOW_NODE_H_
16
+ #define SRC_SHADOW_NODE_H_
17
17
 
18
- #include <nan.h>
18
+ #include <napi.h>
19
19
 
20
20
  #include <exception>
21
21
  #include <memory>
22
22
  #include <vector>
23
23
 
24
- #include "executor.hpp"
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 Nan::ObjectWrap, public Executor::Delegate {
31
+ class ShadowNode : public Napi::ObjectWrap<ShadowNode>,
32
+ public Executor::Delegate {
32
33
  public:
33
- static void Init(v8::Local<v8::Object> exports);
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
- private:
45
- ShadowNode();
45
+ explicit ShadowNode(const Napi::CallbackInfo& info);
46
46
  ~ShadowNode();
47
47
 
48
- static void New(const Nan::FunctionCallbackInfo<v8::Value>& info);
49
- static Nan::Persistent<v8::Function> constructor;
50
- static NAN_METHOD(Stop);
51
- static NAN_METHOD(Start);
52
- static NAN_METHOD(SyncHandles);
53
- static NAN_METHOD(SpinOnce);
54
- static NAN_GETTER(HandleGetter);
55
- static NAN_SETTER(HandleSetter);
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 // SRC_SHADOW_NODE_HPP_
64
+ #endif // SRC_SHADOW_NODE_H_
@@ -87,5 +87,11 @@ declare module 'rclnodejs' {
87
87
  * @returns The default Context
88
88
  */
89
89
  static defaultContext(): Context;
90
+
91
+ /**
92
+ * Get the domain ID of this context.
93
+ * @returns domain ID of this context
94
+ */
95
+ domainId(): number;
90
96
  }
91
97
  }