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.
Files changed (77) hide show
  1. package/README.md +3 -3
  2. package/binding.gyp +25 -2
  3. package/lib/action/client.js +40 -0
  4. package/lib/action/server.js +21 -0
  5. package/lib/client.js +3 -4
  6. package/lib/context.js +8 -0
  7. package/lib/distro.js +2 -0
  8. package/lib/lifecycle.js +9 -0
  9. package/lib/logging.js +26 -9
  10. package/lib/node.js +81 -1
  11. package/lib/node_options.js +21 -1
  12. package/lib/publisher.js +27 -0
  13. package/lib/service.js +10 -3
  14. package/lib/subscription.js +8 -0
  15. package/lib/timer.js +32 -0
  16. package/lib/type_description_service.js +82 -0
  17. package/package.json +4 -4
  18. package/scripts/config.js +1 -0
  19. package/scripts/npmjs-readme.md +3 -3
  20. package/src/addon.cpp +60 -53
  21. package/src/executor.cpp +19 -10
  22. package/src/{executor.hpp → executor.h} +7 -5
  23. package/src/handle_manager.cpp +30 -56
  24. package/src/{handle_manager.hpp → handle_manager.h} +8 -7
  25. package/src/{macros.hpp → macros.h} +7 -5
  26. package/src/rcl_action_client_bindings.cpp +306 -0
  27. package/src/{rcl_action_bindings.hpp → rcl_action_client_bindings.h} +6 -11
  28. package/src/rcl_action_goal_bindings.cpp +117 -0
  29. package/src/rcl_action_goal_bindings.h +26 -0
  30. package/src/rcl_action_server_bindings.cpp +520 -0
  31. package/src/rcl_action_server_bindings.h +26 -0
  32. package/src/rcl_bindings.cpp +42 -2010
  33. package/src/{rcl_bindings.hpp → rcl_bindings.h} +5 -25
  34. package/src/rcl_client_bindings.cpp +183 -0
  35. package/src/rcl_client_bindings.h +26 -0
  36. package/src/rcl_context_bindings.cpp +156 -0
  37. package/src/rcl_context_bindings.h +26 -0
  38. package/src/rcl_graph_bindings.cpp +280 -0
  39. package/src/rcl_graph_bindings.h +26 -0
  40. package/src/rcl_guard_condition_bindings.cpp +75 -0
  41. package/src/rcl_guard_condition_bindings.h +26 -0
  42. package/src/rcl_handle.cpp +41 -57
  43. package/src/{rcl_handle.hpp → rcl_handle.h} +18 -17
  44. package/src/rcl_lifecycle_bindings.cpp +148 -114
  45. package/src/{rcl_lifecycle_bindings.hpp → rcl_lifecycle_bindings.h} +5 -7
  46. package/src/rcl_logging_bindings.cpp +96 -0
  47. package/src/rcl_logging_bindings.h +26 -0
  48. package/src/rcl_names_bindings.cpp +255 -0
  49. package/src/rcl_names_bindings.h +26 -0
  50. package/src/rcl_node_bindings.cpp +476 -0
  51. package/src/rcl_node_bindings.h +26 -0
  52. package/src/rcl_publisher_bindings.cpp +160 -0
  53. package/src/rcl_publisher_bindings.h +26 -0
  54. package/src/rcl_service_bindings.cpp +185 -0
  55. package/src/rcl_service_bindings.h +26 -0
  56. package/src/rcl_subscription_bindings.cpp +335 -0
  57. package/src/rcl_subscription_bindings.h +26 -0
  58. package/src/rcl_time_point_bindings.cpp +194 -0
  59. package/src/rcl_time_point_bindings.h +26 -0
  60. package/src/rcl_timer_bindings.cpp +237 -0
  61. package/src/rcl_timer_bindings.h +26 -0
  62. package/src/rcl_type_description_service_bindings.cpp +79 -0
  63. package/src/rcl_type_description_service_bindings.h +27 -0
  64. package/src/rcl_utilities.cpp +166 -1
  65. package/src/{rcl_utilities.hpp → rcl_utilities.h} +21 -3
  66. package/src/shadow_node.cpp +56 -75
  67. package/src/{shadow_node.hpp → shadow_node.h} +18 -17
  68. package/types/action_client.d.ts +18 -0
  69. package/types/action_server.d.ts +12 -0
  70. package/types/context.d.ts +6 -0
  71. package/types/lifecycle.d.ts +7 -0
  72. package/types/node.d.ts +69 -0
  73. package/types/publisher.d.ts +23 -0
  74. package/types/service.d.ts +6 -0
  75. package/types/subscription.d.ts +6 -0
  76. package/types/timer.d.ts +18 -0
  77. package/src/rcl_action_bindings.cpp +0 -826
@@ -12,47 +12,45 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- #include "rcl_lifecycle_bindings.hpp"
15
+ #include "rcl_lifecycle_bindings.h"
16
16
 
17
+ #include <lifecycle_msgs/msg/transition_event.h>
18
+ #include <lifecycle_msgs/srv/change_state.h>
19
+ #include <lifecycle_msgs/srv/get_available_states.h>
20
+ #include <lifecycle_msgs/srv/get_available_transitions.h>
21
+ #include <lifecycle_msgs/srv/get_state.h>
17
22
  #include <rcl/error_handling.h>
18
23
  #include <rcl_lifecycle/rcl_lifecycle.h>
19
24
 
20
25
  #include <memory>
21
26
  #include <string>
22
- #include <vector>
23
27
 
24
- #include "lifecycle_msgs/msg/transition_event.h"
25
- #include "lifecycle_msgs/srv/change_state.h"
26
- #include "lifecycle_msgs/srv/get_available_states.h"
27
- #include "lifecycle_msgs/srv/get_available_transitions.h"
28
- #include "lifecycle_msgs/srv/get_state.h"
29
- #include "macros.hpp"
30
- #include "rcl_handle.hpp"
31
- #include "rcl_utilities.hpp"
28
+ #include "macros.h"
29
+ #include "rcl_handle.h"
30
+ #include "rcl_utilities.h"
32
31
 
33
32
  namespace rclnodejs {
34
33
 
35
- static v8::Local<v8::Object> wrapState(const rcl_lifecycle_state_t* state) {
36
- v8::Local<v8::Object> jsState = Nan::New<v8::Object>();
37
- Nan::Set(jsState, Nan::New("id").ToLocalChecked(), Nan::New(state->id));
38
- Nan::Set(jsState, Nan::New("label").ToLocalChecked(),
39
- Nan::New(state->label).ToLocalChecked());
34
+ static Napi::Object wrapState(Napi::Env env,
35
+ const rcl_lifecycle_state_t* state) {
36
+ Napi::Object jsState = Napi::Object::New(env);
37
+ jsState.Set("id", state->id);
38
+ jsState.Set("label", state->label);
40
39
  return jsState;
41
40
  }
42
41
 
43
- static v8::Local<v8::Object> wrapTransition(
44
- const rcl_lifecycle_transition_t* transition) {
45
- v8::Local<v8::Object> jsTransition = Nan::New<v8::Object>();
46
- Nan::Set(jsTransition, Nan::New("id").ToLocalChecked(),
47
- Nan::New(transition->id));
48
- Nan::Set(jsTransition, Nan::New("label").ToLocalChecked(),
49
- Nan::New(transition->label).ToLocalChecked());
42
+ static Napi::Object wrapTransition(
43
+ Napi::Env env, const rcl_lifecycle_transition_t* transition) {
44
+ Napi::Object jsTransition = Napi::Object::New(env);
45
+ jsTransition.Set("id", transition->id);
46
+ jsTransition.Set("label", transition->label);
50
47
  return jsTransition;
51
48
  }
52
49
 
53
- NAN_METHOD(CreateLifecycleStateMachine) {
54
- RclHandle* node_handle = RclHandle::Unwrap<RclHandle>(
55
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
50
+ Napi::Value CreateLifecycleStateMachine(const Napi::CallbackInfo& info) {
51
+ Napi::Env env = info.Env();
52
+
53
+ RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
56
54
  rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
57
55
 
58
56
  rcl_lifecycle_state_machine_t* state_machine =
@@ -76,7 +74,7 @@ NAN_METHOD(CreateLifecycleStateMachine) {
76
74
  #if ROS_VERSION >= 2105
77
75
  rcl_lifecycle_state_machine_options_t options =
78
76
  rcl_lifecycle_get_default_state_machine_options();
79
- options.enable_com_interface = Nan::To<bool>(info[1]).FromJust();
77
+ options.enable_com_interface = info[1].As<Napi::Boolean>().Value();
80
78
 
81
79
  THROW_ERROR_IF_NOT_EQUAL(
82
80
  RCL_RET_OK,
@@ -84,8 +82,8 @@ NAN_METHOD(CreateLifecycleStateMachine) {
84
82
  gat, gtg, &options),
85
83
  rcl_get_error_string().str);
86
84
 
87
- auto js_obj =
88
- RclHandle::NewInstance(state_machine, node_handle, [node](void* ptr) {
85
+ auto js_obj = RclHandle::NewInstance(
86
+ env, state_machine, node_handle, [node](void* ptr) {
89
87
  rcl_lifecycle_state_machine_t* state_machine =
90
88
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(ptr);
91
89
  rcl_ret_t ret = rcl_lifecycle_state_machine_fini(state_machine, node);
@@ -103,7 +101,7 @@ NAN_METHOD(CreateLifecycleStateMachine) {
103
101
  rcl_get_error_string().str);
104
102
 
105
103
  auto js_obj = RclHandle::NewInstance(
106
- state_machine, node_handle, [node, node_options](void* ptr) {
104
+ env, state_machine, node_handle, [node, node_options](void* ptr) {
107
105
  rcl_lifecycle_state_machine_t* state_machine =
108
106
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(ptr);
109
107
  rcl_ret_t ret = rcl_lifecycle_state_machine_fini(
@@ -113,116 +111,122 @@ NAN_METHOD(CreateLifecycleStateMachine) {
113
111
  });
114
112
  #endif
115
113
 
116
- info.GetReturnValue().Set(js_obj);
114
+ return js_obj;
117
115
  }
118
116
 
119
- NAN_METHOD(GetCurrentLifecycleState) {
120
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
121
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
117
+ Napi::Value GetCurrentLifecycleState(const Napi::CallbackInfo& info) {
118
+ Napi::Env env = info.Env();
119
+
120
+ RclHandle* state_machine_handle =
121
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
122
122
  rcl_lifecycle_state_machine_t* state_machine =
123
123
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
124
124
  state_machine_handle->ptr());
125
125
 
126
126
  const rcl_lifecycle_state_t* current_state = state_machine->current_state;
127
- info.GetReturnValue().Set(wrapState(current_state));
127
+ return wrapState(env, current_state);
128
128
  }
129
129
 
130
- NAN_METHOD(GetLifecycleTransitionByLabel) {
131
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
132
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
130
+ Napi::Value GetLifecycleTransitionByLabel(const Napi::CallbackInfo& info) {
131
+ Napi::Env env = info.Env();
132
+
133
+ RclHandle* state_machine_handle =
134
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
133
135
  rcl_lifecycle_state_machine_t* state_machine =
134
136
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
135
137
  state_machine_handle->ptr());
136
138
 
137
- std::string transition_label(*Nan::Utf8String(info[1]));
139
+ std::string transition_label = info[1].As<Napi::String>();
138
140
 
139
141
  auto transition = rcl_lifecycle_get_transition_by_label(
140
142
  state_machine->current_state, transition_label.c_str());
141
143
 
142
- info.GetReturnValue().Set(transition == nullptr ? Nan::New<v8::Object>()
143
- : wrapTransition(transition));
144
+ return transition == nullptr ? Napi::Object::New(env)
145
+ : wrapTransition(env, transition);
144
146
  }
145
147
 
146
148
  // return all registered states
147
- NAN_METHOD(GetLifecycleStates) {
148
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
149
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
149
+ Napi::Value GetLifecycleStates(const Napi::CallbackInfo& info) {
150
+ Napi::Env env = info.Env();
151
+
152
+ RclHandle* state_machine_handle =
153
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
150
154
  rcl_lifecycle_state_machine_t* state_machine =
151
155
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
152
156
  state_machine_handle->ptr());
153
157
 
154
- v8::Local<v8::Array> states = Nan::New<v8::Array>();
158
+ Napi::Array states = Napi::Array::New(env);
155
159
 
156
160
  for (uint8_t i = 0; i < state_machine->transition_map.states_size; ++i) {
157
161
  const rcl_lifecycle_state_t state = state_machine->transition_map.states[i];
158
- v8::Local<v8::Object> jsState = wrapState(&state);
159
- Nan::Set(states, i, jsState);
162
+ Napi::Object jsState = wrapState(env, &state);
163
+ states[i] = jsState;
160
164
  }
161
165
 
162
- info.GetReturnValue().Set(states);
166
+ return states;
163
167
  }
164
168
 
165
169
  // return all registered transitions
166
- NAN_METHOD(GetLifecycleTransitions) {
167
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
168
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
170
+ Napi::Value GetLifecycleTransitions(const Napi::CallbackInfo& info) {
171
+ Napi::Env env = info.Env();
172
+
173
+ RclHandle* state_machine_handle =
174
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
169
175
  rcl_lifecycle_state_machine_t* state_machine =
170
176
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
171
177
  state_machine_handle->ptr());
172
178
 
173
- v8::Local<v8::Array> jsTransitions = Nan::New<v8::Array>();
179
+ Napi::Array jsTransitions = Napi::Array::New(env);
174
180
 
175
181
  for (uint8_t i = 0; i < state_machine->transition_map.transitions_size; ++i) {
176
182
  auto transition = state_machine->transition_map.transitions[i];
177
- v8::Local<v8::Object> jsTransitionDesc = Nan::New<v8::Object>();
178
- Nan::Set(jsTransitionDesc, Nan::New("transition").ToLocalChecked(),
179
- wrapTransition(&transition));
180
- Nan::Set(jsTransitionDesc, Nan::New("start_state").ToLocalChecked(),
181
- wrapState(transition.start));
182
- Nan::Set(jsTransitionDesc, Nan::New("goal_state").ToLocalChecked(),
183
- wrapState(transition.goal));
184
-
185
- Nan::Set(jsTransitions, i, jsTransitionDesc);
183
+ Napi::Object jsTransitionDesc = Napi::Object::New(env);
184
+ jsTransitionDesc.Set("transition", wrapTransition(env, &transition));
185
+ jsTransitionDesc.Set("start_state", wrapState(env, transition.start));
186
+ jsTransitionDesc.Set("goal_state", wrapState(env, transition.goal));
187
+
188
+ jsTransitions[i] = jsTransitionDesc;
186
189
  }
187
190
 
188
- info.GetReturnValue().Set(jsTransitions);
191
+ return jsTransitions;
189
192
  }
190
193
 
191
194
  // return the transitions available from the current state
192
- NAN_METHOD(GetAvailableLifecycleTransitions) {
193
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
194
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
195
+ Napi::Value GetAvailableLifecycleTransitions(const Napi::CallbackInfo& info) {
196
+ Napi::Env env = info.Env();
197
+
198
+ RclHandle* state_machine_handle =
199
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
195
200
  rcl_lifecycle_state_machine_t* state_machine =
196
201
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
197
202
  state_machine_handle->ptr());
198
203
 
199
- v8::Local<v8::Array> jsTransitions = Nan::New<v8::Array>();
204
+ Napi::Array jsTransitions = Napi::Array::New(env);
200
205
 
201
206
  for (uint8_t i = 0; i < state_machine->current_state->valid_transition_size;
202
207
  ++i) {
203
208
  auto transition = state_machine->current_state->valid_transitions[i];
204
- v8::Local<v8::Object> jsTransitionDesc = Nan::New<v8::Object>();
205
- Nan::Set(jsTransitionDesc, Nan::New("transition").ToLocalChecked(),
206
- wrapTransition(&transition));
207
- Nan::Set(jsTransitionDesc, Nan::New("start_state").ToLocalChecked(),
208
- wrapState(transition.start));
209
- Nan::Set(jsTransitionDesc, Nan::New("goal_state").ToLocalChecked(),
210
- wrapState(transition.goal));
211
-
212
- Nan::Set(jsTransitions, i, jsTransitionDesc);
209
+ Napi::Object jsTransitionDesc = Napi::Object::New(env);
210
+ jsTransitionDesc.Set("transition", wrapTransition(env, &transition));
211
+ jsTransitionDesc.Set("start_state", wrapState(env, transition.start));
212
+ jsTransitionDesc.Set("goal_state", wrapState(env, transition.goal));
213
+
214
+ jsTransitions[i] = jsTransitionDesc;
213
215
  }
214
216
 
215
- info.GetReturnValue().Set(jsTransitions);
217
+ return jsTransitions;
216
218
  }
217
219
 
218
- NAN_METHOD(GetLifecycleSrvNameAndHandle) {
219
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
220
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
220
+ Napi::Value GetLifecycleSrvNameAndHandle(const Napi::CallbackInfo& info) {
221
+ Napi::Env env = info.Env();
222
+
223
+ RclHandle* state_machine_handle =
224
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
221
225
  rcl_lifecycle_state_machine_t* state_machine =
222
226
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
223
227
  state_machine_handle->ptr());
224
228
 
225
- std::string lifecycle_srv_field_name(*Nan::Utf8String(info[1]));
229
+ std::string lifecycle_srv_field_name = info[1].As<Napi::String>();
226
230
 
227
231
  rcl_service_t* service = nullptr;
228
232
  if (lifecycle_srv_field_name.compare("srv_get_state") == 0) {
@@ -242,27 +246,28 @@ NAN_METHOD(GetLifecycleSrvNameAndHandle) {
242
246
  std::string service_name = rcl_service_get_service_name(service);
243
247
 
244
248
  // build result object {name: <srv_name>, handle: <rcl handle of service_t>}
245
- v8::Local<v8::Object> named_srv_obj = Nan::New<v8::Object>();
246
- Nan::Set(named_srv_obj, Nan::New("name").ToLocalChecked(),
247
- Nan::New(service_name).ToLocalChecked());
249
+ Napi::Object named_srv_obj = Napi::Object::New(env);
250
+ named_srv_obj.Set("name", service_name);
248
251
 
249
252
  // Note: lifecycle Services are created and managed by their
250
253
  // rcl_lifecycle_state_machine. Thus we must not manually
251
254
  // free the lifecycle_state_machine's service pointers.
252
- auto srv_handle = RclHandle::NewInstance(service, nullptr, nullptr);
255
+ auto srv_handle = RclHandle::NewInstance(env, service, nullptr, nullptr);
253
256
 
254
- Nan::Set(named_srv_obj, Nan::New("handle").ToLocalChecked(), srv_handle);
255
- info.GetReturnValue().Set(named_srv_obj);
257
+ named_srv_obj.Set("handle", srv_handle);
258
+ return named_srv_obj;
256
259
  }
257
260
 
258
261
  // return null if transition exists from current state
259
- NAN_METHOD(TriggerLifecycleTransitionById) {
260
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
261
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
262
+ Napi::Value TriggerLifecycleTransitionById(const Napi::CallbackInfo& info) {
263
+ Napi::Env env = info.Env();
264
+
265
+ RclHandle* state_machine_handle =
266
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
262
267
  rcl_lifecycle_state_machine_t* state_machine =
263
268
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
264
269
  state_machine_handle->ptr());
265
- int transition_id = Nan::To<int64_t>(info[1]).FromJust();
270
+ int transition_id = info[1].As<Napi::Number>().Int64Value();
266
271
 
267
272
  bool publish = true;
268
273
 
@@ -272,17 +277,19 @@ NAN_METHOD(TriggerLifecycleTransitionById) {
272
277
  rcl_get_error_string().str);
273
278
 
274
279
  const rcl_lifecycle_state_t* current_state = state_machine->current_state;
275
- info.GetReturnValue().Set(wrapState(current_state));
280
+ return wrapState(env, current_state);
276
281
  }
277
282
 
278
283
  // return null if transition exists from current state
279
- NAN_METHOD(TriggerLifecycleTransitionByLabel) {
280
- RclHandle* state_machine_handle = RclHandle::Unwrap<RclHandle>(
281
- Nan::To<v8::Object>(info[0]).ToLocalChecked());
284
+ Napi::Value TriggerLifecycleTransitionByLabel(const Napi::CallbackInfo& info) {
285
+ Napi::Env env = info.Env();
286
+
287
+ RclHandle* state_machine_handle =
288
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
282
289
  rcl_lifecycle_state_machine_t* state_machine =
283
290
  reinterpret_cast<rcl_lifecycle_state_machine_t*>(
284
291
  state_machine_handle->ptr());
285
- std::string transition_label(*Nan::Utf8String(info[1]));
292
+ std::string transition_label = info[1].As<Napi::String>();
286
293
 
287
294
  bool publish = true;
288
295
 
@@ -293,7 +300,7 @@ NAN_METHOD(TriggerLifecycleTransitionByLabel) {
293
300
  rcl_get_error_string().str);
294
301
 
295
302
  const rcl_lifecycle_state_t* current_state = state_machine->current_state;
296
- info.GetReturnValue().Set(wrapState(current_state));
303
+ return wrapState(env, current_state);
297
304
  }
298
305
 
299
306
  static const char* transitionId2Label(int callback_ret) {
@@ -340,29 +347,56 @@ static const char* transitionId2Label(int callback_ret) {
340
347
  return rcl_lifecycle_transition_error_label;
341
348
  }
342
349
 
343
- NAN_METHOD(GetLifecycleTransitionIdToLabel) {
344
- int callback_ret = Nan::To<int64_t>(info[0]).FromJust();
350
+ Napi::Value GetLifecycleTransitionIdToLabel(const Napi::CallbackInfo& info) {
351
+ Napi::Env env = info.Env();
352
+ int callback_ret = info[0].As<Napi::Number>().Int64Value();
345
353
  const char* transition_label = transitionId2Label(callback_ret);
346
- info.GetReturnValue().Set(Nan::New(transition_label).ToLocalChecked());
354
+ return Napi::String::New(env, transition_label);
347
355
  }
348
356
 
349
- NAN_METHOD(GetLifecycleShutdownTransitionLabel) {
350
- info.GetReturnValue().Set(
351
- Nan::New(rcl_lifecycle_shutdown_label).ToLocalChecked());
357
+ Napi::Value GetLifecycleShutdownTransitionLabel(
358
+ const Napi::CallbackInfo& info) {
359
+ Napi::Env env = info.Env();
360
+ return Napi::String::New(env, rcl_lifecycle_shutdown_label);
352
361
  }
353
362
 
354
- std::vector<BindingMethod> lifecycle_binding_methods = {
355
- {"createLifecycleStateMachine", CreateLifecycleStateMachine},
356
- {"getCurrentLifecycleState", GetCurrentLifecycleState},
357
- {"getLifecycleTransitionByLabel", GetLifecycleTransitionByLabel},
358
- {"getLifecycleStates", GetLifecycleStates},
359
- {"getLifecycleTransitions", GetLifecycleTransitions},
360
- {"getAvailableLifecycleTransitions", GetAvailableLifecycleTransitions},
361
- {"triggerLifecycleTransitionById", TriggerLifecycleTransitionById},
362
- {"triggerLifecycleTransitionByLabel", TriggerLifecycleTransitionByLabel},
363
- {"getLifecycleSrvNameAndHandle", GetLifecycleSrvNameAndHandle},
364
- {"getLifecycleTransitionIdToLabel", GetLifecycleTransitionIdToLabel},
365
- {"getLifecycleShutdownTransitionLabel",
366
- GetLifecycleShutdownTransitionLabel}};
363
+ Napi::Value IsInitialized(const Napi::CallbackInfo& info) {
364
+ Napi::Env env = info.Env();
365
+ RclHandle* state_machine_handle =
366
+ RclHandle::Unwrap(info[0].As<Napi::Object>());
367
+ rcl_lifecycle_state_machine_t* state_machine =
368
+ reinterpret_cast<rcl_lifecycle_state_machine_t*>(
369
+ state_machine_handle->ptr());
370
+ const bool is_initialized =
371
+ RCL_RET_OK == rcl_lifecycle_state_machine_is_initialized(state_machine);
372
+ return Napi::Boolean::New(env, is_initialized);
373
+ }
374
+
375
+ Napi::Object InitLifecycleBindings(Napi::Env env, Napi::Object exports) {
376
+ exports.Set("createLifecycleStateMachine",
377
+ Napi::Function::New(env, CreateLifecycleStateMachine));
378
+ exports.Set("getCurrentLifecycleState",
379
+ Napi::Function::New(env, GetCurrentLifecycleState));
380
+ exports.Set("getLifecycleTransitionByLabel",
381
+ Napi::Function::New(env, GetLifecycleTransitionByLabel));
382
+ exports.Set("getLifecycleStates",
383
+ Napi::Function::New(env, GetLifecycleStates));
384
+ exports.Set("getLifecycleTransitions",
385
+ Napi::Function::New(env, GetLifecycleTransitions));
386
+ exports.Set("getAvailableLifecycleTransitions",
387
+ Napi::Function::New(env, GetAvailableLifecycleTransitions));
388
+ exports.Set("triggerLifecycleTransitionById",
389
+ Napi::Function::New(env, TriggerLifecycleTransitionById));
390
+ exports.Set("triggerLifecycleTransitionByLabel",
391
+ Napi::Function::New(env, TriggerLifecycleTransitionByLabel));
392
+ exports.Set("getLifecycleSrvNameAndHandle",
393
+ Napi::Function::New(env, GetLifecycleSrvNameAndHandle));
394
+ exports.Set("getLifecycleTransitionIdToLabel",
395
+ Napi::Function::New(env, GetLifecycleTransitionIdToLabel));
396
+ exports.Set("getLifecycleShutdownTransitionLabel",
397
+ Napi::Function::New(env, GetLifecycleShutdownTransitionLabel));
398
+ exports.Set("isInitialized", Napi::Function::New(env, IsInitialized));
399
+ return exports;
400
+ }
367
401
 
368
402
  } // namespace rclnodejs
@@ -12,17 +12,15 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- #ifndef SRC_RCL_LIFECYCLE_BINDINGS_HPP_
16
- #define SRC_RCL_LIFECYCLE_BINDINGS_HPP_
15
+ #ifndef SRC_RCL_LIFECYCLE_BINDINGS_H_
16
+ #define SRC_RCL_LIFECYCLE_BINDINGS_H_
17
17
 
18
- #include <vector>
19
-
20
- #include "rcl_bindings.hpp"
18
+ #include <napi.h>
21
19
 
22
20
  namespace rclnodejs {
23
21
 
24
- extern std::vector<BindingMethod> lifecycle_binding_methods;
22
+ Napi::Object InitLifecycleBindings(Napi::Env env, Napi::Object exports);
25
23
 
26
24
  } // namespace rclnodejs
27
25
 
28
- #endif // SRC_RCL_LIFECYCLE_BINDINGS_HPP_
26
+ #endif // SRC_RCL_LIFECYCLE_BINDINGS_H_
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
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_logging_bindings.h"
16
+
17
+ #include <rcl/error_handling.h>
18
+ #include <rcl/rcl.h>
19
+
20
+ #include <string>
21
+
22
+ #include "macros.h"
23
+ #include "rcl_utilities.h"
24
+
25
+ namespace rclnodejs {
26
+
27
+ Napi::Value setLoggerLevel(const Napi::CallbackInfo& info) {
28
+ Napi::Env env = info.Env();
29
+
30
+ std::string name = info[0].As<Napi::String>().Utf8Value();
31
+ int level = info[1].As<Napi::Number>().Int64Value();
32
+
33
+ rcutils_ret_t ret = rcutils_logging_set_logger_level(name.c_str(), level);
34
+ if (ret != RCUTILS_RET_OK) {
35
+ Napi::Error::New(env, rcutils_get_error_string().str)
36
+ .ThrowAsJavaScriptException();
37
+ rcutils_reset_error();
38
+ }
39
+ return env.Undefined();
40
+ }
41
+
42
+ Napi::Value GetLoggerEffectiveLevel(const Napi::CallbackInfo& info) {
43
+ Napi::Env env = info.Env();
44
+
45
+ std::string name = info[0].As<Napi::String>().Utf8Value();
46
+ int logger_level = rcutils_logging_get_logger_effective_level(name.c_str());
47
+
48
+ if (logger_level < 0) {
49
+ Napi::Error::New(env, rcutils_get_error_string().str)
50
+ .ThrowAsJavaScriptException();
51
+ rcutils_reset_error();
52
+ return env.Undefined();
53
+ }
54
+ return Napi::Number::New(env, logger_level);
55
+ }
56
+
57
+ Napi::Value Log(const Napi::CallbackInfo& info) {
58
+ Napi::Env env = info.Env();
59
+
60
+ std::string name = info[0].As<Napi::String>().Utf8Value();
61
+ int severity = info[1].As<Napi::Number>().Int64Value();
62
+ std::string message = info[2].As<Napi::String>().Utf8Value();
63
+ std::string function_name = info[3].As<Napi::String>().Utf8Value();
64
+ size_t line_number = info[4].As<Napi::Number>().Int64Value();
65
+ std::string file_name = info[5].As<Napi::String>().Utf8Value();
66
+ bool enabled = rcutils_logging_logger_is_enabled_for(name.c_str(), severity);
67
+
68
+ if (enabled) {
69
+ rcutils_log_location_t logging_location = {function_name.c_str(),
70
+ file_name.c_str(), line_number};
71
+ rcutils_log(&logging_location, severity, name.c_str(), "%s",
72
+ message.c_str());
73
+ }
74
+
75
+ return Napi::Boolean::New(env, enabled);
76
+ }
77
+
78
+ Napi::Value IsEnableFor(const Napi::CallbackInfo& info) {
79
+ Napi::Env env = info.Env();
80
+
81
+ std::string name = info[0].As<Napi::String>().Utf8Value();
82
+ int severity = info[1].As<Napi::Number>().Int64Value();
83
+ bool enabled = rcutils_logging_logger_is_enabled_for(name.c_str(), severity);
84
+ return Napi::Boolean::New(env, enabled);
85
+ }
86
+
87
+ Napi::Object InitLoggingBindings(Napi::Env env, Napi::Object exports) {
88
+ exports.Set("setLoggerLevel", Napi::Function::New(env, setLoggerLevel));
89
+ exports.Set("getLoggerEffectiveLevel",
90
+ Napi::Function::New(env, GetLoggerEffectiveLevel));
91
+ exports.Set("log", Napi::Function::New(env, Log));
92
+ exports.Set("isEnableFor", Napi::Function::New(env, IsEnableFor));
93
+ return exports;
94
+ }
95
+
96
+ } // namespace rclnodejs
@@ -0,0 +1,26 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
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_LOGGING_BINDINGS_H_
16
+ #define SRC_RCL_LOGGING_BINDINGS_H_
17
+
18
+ #include <napi.h>
19
+
20
+ namespace rclnodejs {
21
+
22
+ Napi::Object InitLoggingBindings(Napi::Env env, Napi::Object exports);
23
+
24
+ }
25
+
26
+ #endif // SRC_RCL_LOGGING_BINDINGS_H_