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.
Files changed (66) 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 +53 -0
  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/scripts/config.js +1 -0
  13. package/scripts/npmjs-readme.md +3 -3
  14. package/src/addon.cpp +54 -53
  15. package/src/executor.cpp +19 -10
  16. package/src/{executor.hpp → executor.h} +7 -5
  17. package/src/handle_manager.cpp +30 -56
  18. package/src/{handle_manager.hpp → handle_manager.h} +8 -7
  19. package/src/{macros.hpp → macros.h} +7 -5
  20. package/src/rcl_action_client_bindings.cpp +231 -0
  21. package/src/{rcl_action_bindings.hpp → rcl_action_client_bindings.h} +6 -11
  22. package/src/rcl_action_goal_bindings.cpp +117 -0
  23. package/src/rcl_action_goal_bindings.h +26 -0
  24. package/src/rcl_action_server_bindings.cpp +470 -0
  25. package/src/rcl_action_server_bindings.h +26 -0
  26. package/src/rcl_bindings.cpp +42 -2010
  27. package/src/{rcl_bindings.hpp → rcl_bindings.h} +5 -25
  28. package/src/rcl_client_bindings.cpp +183 -0
  29. package/src/rcl_client_bindings.h +26 -0
  30. package/src/rcl_context_bindings.cpp +156 -0
  31. package/src/rcl_context_bindings.h +26 -0
  32. package/src/rcl_graph_bindings.cpp +280 -0
  33. package/src/rcl_graph_bindings.h +26 -0
  34. package/src/rcl_guard_condition_bindings.cpp +75 -0
  35. package/src/rcl_guard_condition_bindings.h +26 -0
  36. package/src/rcl_handle.cpp +41 -57
  37. package/src/{rcl_handle.hpp → rcl_handle.h} +18 -17
  38. package/src/rcl_lifecycle_bindings.cpp +135 -114
  39. package/src/{rcl_lifecycle_bindings.hpp → rcl_lifecycle_bindings.h} +5 -7
  40. package/src/rcl_logging_bindings.cpp +96 -0
  41. package/src/rcl_logging_bindings.h +26 -0
  42. package/src/rcl_names_bindings.cpp +255 -0
  43. package/src/rcl_names_bindings.h +26 -0
  44. package/src/rcl_node_bindings.cpp +447 -0
  45. package/src/rcl_node_bindings.h +26 -0
  46. package/src/rcl_publisher_bindings.cpp +141 -0
  47. package/src/rcl_publisher_bindings.h +26 -0
  48. package/src/rcl_service_bindings.cpp +185 -0
  49. package/src/rcl_service_bindings.h +26 -0
  50. package/src/rcl_subscription_bindings.cpp +335 -0
  51. package/src/rcl_subscription_bindings.h +26 -0
  52. package/src/rcl_time_point_bindings.cpp +194 -0
  53. package/src/rcl_time_point_bindings.h +26 -0
  54. package/src/rcl_timer_bindings.cpp +237 -0
  55. package/src/rcl_timer_bindings.h +26 -0
  56. package/src/rcl_utilities.cpp +166 -1
  57. package/src/{rcl_utilities.hpp → rcl_utilities.h} +21 -3
  58. package/src/shadow_node.cpp +56 -75
  59. package/src/{shadow_node.hpp → shadow_node.h} +18 -17
  60. package/types/context.d.ts +6 -0
  61. package/types/node.d.ts +37 -0
  62. package/types/publisher.d.ts +6 -0
  63. package/types/service.d.ts +6 -0
  64. package/types/subscription.d.ts +6 -0
  65. package/types/timer.d.ts +18 -0
  66. package/src/rcl_action_bindings.cpp +0 -826
package/README.md CHANGED
@@ -43,9 +43,9 @@ npm i rclnodejs@x.y.z
43
43
 
44
44
  #### RCLNODEJS - ROS 2 Version Compatibility
45
45
 
46
- | RCLNODEJS Version | Compatible ROS 2 LTS |
47
- | :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | latest version (currently [v0.33.0](https://github.com/RobotWebTools/rclnodejs/tree/0.33.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
46
+ | RCLNODEJS Version | Compatible ROS 2 LTS |
47
+ | :----------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
48
+ | latest version (currently [v1.0.0](https://github.com/RobotWebTools/rclnodejs/tree/1.0.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
49
49
 
50
50
  ## Documentation
51
51
 
package/binding.gyp CHANGED
@@ -21,17 +21,31 @@
21
21
  './src/addon.cpp',
22
22
  './src/executor.cpp',
23
23
  './src/handle_manager.cpp',
24
- './src/rcl_action_bindings.cpp',
24
+ './src/rcl_action_client_bindings.cpp',
25
+ './src/rcl_action_goal_bindings.cpp',
26
+ './src/rcl_action_server_bindings.cpp',
25
27
  './src/rcl_bindings.cpp',
28
+ './src/rcl_client_bindings.cpp',
29
+ './src/rcl_context_bindings.cpp',
30
+ './src/rcl_graph_bindings.cpp',
31
+ './src/rcl_guard_condition_bindings.cpp',
26
32
  './src/rcl_handle.cpp',
27
33
  './src/rcl_lifecycle_bindings.cpp',
34
+ './src/rcl_logging_bindings.cpp',
35
+ './src/rcl_names_bindings.cpp',
36
+ './src/rcl_node_bindings.cpp',
37
+ './src/rcl_publisher_bindings.cpp',
38
+ './src/rcl_service_bindings.cpp',
39
+ './src/rcl_subscription_bindings.cpp',
40
+ './src/rcl_time_point_bindings.cpp',
41
+ './src/rcl_timer_bindings.cpp',
28
42
  './src/rcl_utilities.cpp',
29
43
  './src/shadow_node.cpp',
30
44
  ],
31
45
  'include_dirs': [
32
46
  '.',
33
- "<!(node -e \"require('nan')\")",
34
47
  '<(ros_include_root)',
48
+ "<!@(node -p \"require('node-addon-api').include\")",
35
49
  ],
36
50
  'cflags!': [
37
51
  '-fno-exceptions'
@@ -51,6 +65,7 @@
51
65
  '-lrcl_lifecycle',
52
66
  '-lrcutils',
53
67
  '-lrcl_yaml_param_parser',
68
+ '-lrcpputils',
54
69
  '-lrmw',
55
70
  '-lrosidl_runtime_c',
56
71
  ],
package/lib/client.js CHANGED
@@ -147,15 +147,14 @@ class Client extends Entity {
147
147
  }
148
148
 
149
149
  let type = this.typeClass.type();
150
- rclnodejs.configureServiceIntrospection(
150
+ rclnodejs.configureClientIntrospection(
151
151
  this.handle,
152
152
  this._nodeHandle,
153
153
  clock.handle,
154
154
  type.interfaceName,
155
155
  type.pkgName,
156
156
  qos,
157
- introspectionState,
158
- false
157
+ introspectionState
159
158
  );
160
159
  }
161
160
  }
package/lib/context.js CHANGED
@@ -219,6 +219,14 @@ class Context {
219
219
  }
220
220
  return defaultContext;
221
221
  }
222
+
223
+ /**
224
+ * Get the domain ID of this context.
225
+ * @returns {Number} domain ID of this context
226
+ */
227
+ get domainId() {
228
+ return rclnodejs.getDomainId(this.handle);
229
+ }
222
230
  }
223
231
 
224
232
  Context._instances = [];
package/lib/logging.js CHANGED
@@ -39,14 +39,31 @@ let LoggingSeverity = {
39
39
 
40
40
  class Caller {
41
41
  constructor() {
42
- this._info = {};
43
- let frame = new Error().stack.split('\n').slice(4, 5)[0];
44
- let results = frame.match(/at\s+(.*)\s+\((.*):(\d*):(\d*)\)/i);
45
-
46
- if (results && results.length === 5) {
47
- this._info['functionName'] = results[1];
48
- this._info['lineNumber'] = results[3];
49
- this._info['fileName'] = path.basename(results[2]);
42
+ this._info = {
43
+ functionName: 'unknown',
44
+ fileName: 'unknown',
45
+ lineNumber: 'unknown',
46
+ };
47
+
48
+ const stackLines = new Error().stack.split('\n');
49
+
50
+ // Adjust the index (usually 3 or 4) to correctly point to the caller frame.
51
+ const callerFrame = stackLines[4] || stackLines[3];
52
+ // Match both named and anonymous function stack frames.
53
+ const frameRegex = /^\s*at\s+(?:(.+)\s+\()?(.+):(\d+):(\d+)\)?$/;
54
+ const match = callerFrame.match(frameRegex);
55
+ if (match && match.length === 5) {
56
+ this._info.functionName = match[1] || '(anonymous)';
57
+ this._info.fileName = path.basename(match[2]);
58
+ this._info.lineNumber = match[3];
59
+ } else {
60
+ // Handle anonymous functions or different stack formats.
61
+ const altMatch = callerFrame.match(/at\s+(.*):(\d+):(\d+)/i);
62
+ if (altMatch && altMatch.length >= 4) {
63
+ this._info.functionName = '(anonymous)';
64
+ this._info.fileName = path.basename(altMatch[1]);
65
+ this._info.lineNumber = altMatch[2];
66
+ }
50
67
  }
51
68
  }
52
69
 
@@ -156,7 +173,7 @@ class Logging {
156
173
  severity,
157
174
  message,
158
175
  caller.functionName,
159
- caller.lineNumber,
176
+ parseInt(caller.lineNumber, 10),
160
177
  caller.fileName
161
178
  );
162
179
  }
package/lib/node.js CHANGED
@@ -21,6 +21,7 @@ const Client = require('./client.js');
21
21
  const Clock = require('./clock.js');
22
22
  const Context = require('./context.js');
23
23
  const debug = require('debug')('rclnodejs:node');
24
+ const DistroUtils = require('./distro.js');
24
25
  const GuardCondition = require('./guard_condition.js');
25
26
  const loader = require('./interface_loader.js');
26
27
  const Logging = require('./logging.js');
@@ -1013,6 +1014,32 @@ class Node extends rclnodejs.ShadowNode {
1013
1014
  return rclnodejs.getServiceNamesAndTypes(this.handle);
1014
1015
  }
1015
1016
 
1017
+ /**
1018
+ * Get a list of publishers on a given topic.
1019
+ * @param {string} topic - the topic name to get the publishers for.
1020
+ * @param {boolean} noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
1021
+ * otherwise it should be a valid ROS topic name.
1022
+ * @returns {Array} - list of publishers
1023
+ */
1024
+ getPublishersInfoByTopic(topic, noDemangle) {
1025
+ return rclnodejs.getPublishersInfoByTopic(this.handle, topic, noDemangle);
1026
+ }
1027
+
1028
+ /**
1029
+ * Get a list of subscriptions on a given topic.
1030
+ * @param {string} topic - the topic name to get the subscriptions for.
1031
+ * @param {boolean} noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
1032
+ * otherwise it should be a valid ROS topic name.
1033
+ * @returns {Array} - list of subscriptions
1034
+ */
1035
+ getSubscriptionsInfoByTopic(topic, noDemangle) {
1036
+ return rclnodejs.getSubscriptionsInfoByTopic(
1037
+ this.handle,
1038
+ topic,
1039
+ noDemangle
1040
+ );
1041
+ }
1042
+
1016
1043
  /**
1017
1044
  * Get the list of nodes discovered by the provided node.
1018
1045
  * @return {Array<string>} - An array of the names.
@@ -1061,6 +1088,32 @@ class Node extends rclnodejs.ShadowNode {
1061
1088
  return rclnodejs.countSubscribers(this.handle, expandedTopic);
1062
1089
  }
1063
1090
 
1091
+ /**
1092
+ * Get the number of clients on a given service name.
1093
+ * @param {string} serviceName - the service name
1094
+ * @returns {Number}
1095
+ */
1096
+ countClients(serviceName) {
1097
+ if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
1098
+ console.warn('countClients is not supported by this version of ROS 2');
1099
+ return null;
1100
+ }
1101
+ return rclnodejs.countClients(this.handle, serviceName);
1102
+ }
1103
+
1104
+ /**
1105
+ * Get the number of services on a given service name.
1106
+ * @param {string} serviceName - the service name
1107
+ * @returns {Number}
1108
+ */
1109
+ countServices(serviceName) {
1110
+ if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
1111
+ console.warn('countServices is not supported by this version of ROS 2');
1112
+ return null;
1113
+ }
1114
+ return rclnodejs.countServices(this.handle, serviceName);
1115
+ }
1116
+
1064
1117
  /**
1065
1118
  * Get the list of parameter-overrides found on the commandline and
1066
1119
  * in the NodeOptions.parameter_overrides property.
package/lib/publisher.js CHANGED
@@ -72,6 +72,14 @@ class Publisher extends Entity {
72
72
  );
73
73
  return new Publisher(handle, typeClass, topic, options);
74
74
  }
75
+
76
+ /**
77
+ * Get the number of subscriptions to this publisher.
78
+ * @returns {number} The number of subscriptions
79
+ */
80
+ get subscriptionCount() {
81
+ return rclnodejs.getSubscriptionCount(this._handle);
82
+ }
75
83
  }
76
84
 
77
85
  module.exports = Publisher;
package/lib/service.js CHANGED
@@ -138,10 +138,17 @@ class Service extends Entity {
138
138
  type.interfaceName,
139
139
  type.pkgName,
140
140
  qos,
141
- introspectionState,
142
- true
141
+ introspectionState
143
142
  );
144
143
  }
144
+
145
+ /**
146
+ * Get the options of this service.
147
+ * @return {object} The options of this service.
148
+ */
149
+ getOptions() {
150
+ return rclnodejs.getOptions(this._handle);
151
+ }
145
152
  }
146
153
 
147
154
  module.exports = Service;
@@ -116,6 +116,14 @@ class Subscription extends Entity {
116
116
  ? rclnodejs.clearContentFilter(this.handle)
117
117
  : true;
118
118
  }
119
+
120
+ /**
121
+ * Get the number of publishers to this subscription.
122
+ * @returns {number} The number of publishers
123
+ */
124
+ get publisherCount() {
125
+ return rclnodejs.getPublisherCount(this._handle);
126
+ }
119
127
  }
120
128
 
121
129
  module.exports = Subscription;
package/lib/timer.js CHANGED
@@ -15,6 +15,7 @@
15
15
  'use strict';
16
16
 
17
17
  const rclnodejs = require('bindings')('rclnodejs');
18
+ const DistroUtils = require('./distro.js');
18
19
 
19
20
  /**
20
21
  * @class - Class representing a Timer in ROS
@@ -86,6 +87,37 @@ class Timer {
86
87
  timeUntilNextCall() {
87
88
  return rclnodejs.timerGetTimeUntilNextCall(this._handle);
88
89
  }
90
+
91
+ /**
92
+ * Change the timer period.
93
+ * @param {bigint} period - The new period in nanoseconds.
94
+ * @return {undefined}
95
+ */
96
+ changeTimerPeriod(period) {
97
+ rclnodejs.changeTimerPeriod(this._handle, period);
98
+ }
99
+
100
+ /**
101
+ * Get the timer period.
102
+ * @return {bigint} - The period in nanoseconds.
103
+ */
104
+ get timerPeriod() {
105
+ return rclnodejs.getTimerPeriod(this._handle);
106
+ }
107
+
108
+ /**
109
+ * Call a timer and starts counting again, retrieves actual and expected call time.
110
+ * @return {object} - The timer information.
111
+ */
112
+ callTimerWithInfo() {
113
+ if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
114
+ console.warn(
115
+ 'callTimerWithInfo is not supported by this version of ROS 2'
116
+ );
117
+ return;
118
+ }
119
+ return rclnodejs.callTimerWithInfo(this._handle);
120
+ }
89
121
  }
90
122
 
91
123
  module.exports = Timer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rclnodejs",
3
- "version": "0.33.0",
3
+ "version": "1.0.0",
4
4
  "description": "ROS2.0 JavaScript client with Node.js",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "docs": "cd docs && make",
27
27
  "test": "nyc node --expose-gc ./scripts/run_test.js && tsd",
28
28
  "lint": "eslint && node ./scripts/cpplint.js",
29
- "format": "clang-format -i -style=file ./src/*.cpp ./src/*.hpp && npx --yes prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark,rostsd_gen}/**/*.{js,md,ts}\" ./*.{js,md,ts}",
29
+ "format": "clang-format -i -style=file ./src/*.cpp ./src/*.h && npx --yes prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark,rostsd_gen}/**/*.{js,md,ts}\" ./*.{js,md,ts}",
30
30
  "prepare": "husky",
31
31
  "coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
32
32
  },
@@ -79,9 +79,9 @@
79
79
  "fs-extra": "^11.2.0",
80
80
  "is-close": "^1.3.3",
81
81
  "json-bigint": "^1.0.0",
82
- "nan": "^2.22.0",
83
82
  "terser": "^5.39.0",
84
- "walk": "^2.3.15"
83
+ "walk": "^2.3.15",
84
+ "node-addon-api": "^8.3.1"
85
85
  },
86
86
  "husky": {
87
87
  "hooks": {
package/scripts/config.js CHANGED
@@ -29,6 +29,7 @@ const dependencies = [
29
29
  'builtin_interfaces',
30
30
  'rcl_lifecycle',
31
31
  'lifecycle_msgs',
32
+ 'rcpputils',
32
33
  'rosidl_runtime_c',
33
34
  'rosidl_dynamic_typesupport',
34
35
  'type_description_interfaces',
@@ -43,9 +43,9 @@ npm i rclnodejs@x.y.z
43
43
 
44
44
  #### RCLNODEJS - ROS 2 Version Compatibility
45
45
 
46
- | RCLNODEJS Version | Compatible ROS 2 LTS |
47
- | :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | latest version (currently [v0.33.0](https://github.com/RobotWebTools/rclnodejs/tree/0.33.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
46
+ | RCLNODEJS Version | Compatible ROS 2 LTS |
47
+ | :----------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
48
+ | latest version (currently [v1.0.0](https://github.com/RobotWebTools/rclnodejs/tree/1.0.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
49
49
 
50
50
  ## Documentation
51
51
 
package/src/addon.cpp CHANGED
@@ -12,29 +12,39 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- #include <nan.h>
15
+ #include <node_api.h>
16
+ #include <rcutils/logging.h>
16
17
 
17
- #include "macros.hpp"
18
- #include "rcl_action_bindings.hpp"
19
- #include "rcl_bindings.hpp"
20
- #include "rcl_handle.hpp"
21
- #include "rcl_lifecycle_bindings.hpp"
22
- #include "rcutils/logging.h"
23
- #include "rcutils/macros.h"
24
- #include "shadow_node.hpp"
18
+ #include "macros.h"
19
+ #include "rcl_action_client_bindings.h"
20
+ #include "rcl_action_goal_bindings.h"
21
+ #include "rcl_action_server_bindings.h"
22
+ #include "rcl_bindings.h"
23
+ #include "rcl_client_bindings.h"
24
+ #include "rcl_context_bindings.h"
25
+ #include "rcl_graph_bindings.h"
26
+ #include "rcl_guard_condition_bindings.h"
27
+ #include "rcl_handle.h"
28
+ #include "rcl_lifecycle_bindings.h"
29
+ #include "rcl_logging_bindings.h"
30
+ #include "rcl_names_bindings.h"
31
+ #include "rcl_node_bindings.h"
32
+ #include "rcl_publisher_bindings.h"
33
+ #include "rcl_service_bindings.h"
34
+ #include "rcl_subscription_bindings.h"
35
+ #include "rcl_time_point_bindings.h"
36
+ #include "rcl_timer_bindings.h"
37
+ #include "rcl_utilities.h"
38
+ #include "shadow_node.h"
25
39
 
26
- bool IsRunningInElectronRenderer() {
27
- auto global = Nan::GetCurrentContext()->Global();
28
- auto process =
29
- Nan::To<v8::Object>(Nan::Get(global, Nan::New("process").ToLocalChecked())
30
- .ToLocalChecked())
31
- .ToLocalChecked();
32
- auto process_type =
33
- Nan::Get(process, Nan::New("type").ToLocalChecked()).ToLocalChecked();
34
- return process_type->StrictEquals(Nan::New("renderer").ToLocalChecked());
40
+ bool IsRunningInElectronRenderer(const Napi::Env& env) {
41
+ Napi::Object global = env.Global();
42
+ Napi::Object process = global.Get("process").As<Napi::Object>();
43
+ Napi::Value processType = process.Get("type");
44
+ return processType.StrictEquals(Napi::String::New(env, "renderer"));
35
45
  }
36
46
 
37
- void InitModule(v8::Local<v8::Object> exports) {
47
+ Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
38
48
  // workaround process name mangling by chromium
39
49
  //
40
50
  // rcl logging uses `program_invocation_name` to determine the log file,
@@ -43,7 +53,7 @@ void InitModule(v8::Local<v8::Object> exports) {
43
53
  // occurence of ' -' with the null terminator. see:
44
54
  // https://unix.stackexchange.com/questions/432419/unexpected-non-null-encoding-of-proc-pid-cmdline
45
55
  #if defined(__linux__) && defined(__GLIBC__)
46
- if (IsRunningInElectronRenderer()) {
56
+ if (IsRunningInElectronRenderer(env)) {
47
57
  auto prog_name = program_invocation_name;
48
58
  auto end = strstr(prog_name, " -");
49
59
  assert(end);
@@ -51,44 +61,35 @@ void InitModule(v8::Local<v8::Object> exports) {
51
61
  }
52
62
  #endif
53
63
 
54
- v8::Local<v8::Context> context = exports->GetIsolate()->GetCurrentContext();
55
-
56
- for (uint32_t i = 0; i < rclnodejs::binding_methods.size(); i++) {
57
- Nan::Set(
58
- exports, Nan::New(rclnodejs::binding_methods[i].name).ToLocalChecked(),
59
- Nan::New<v8::FunctionTemplate>(rclnodejs::binding_methods[i].function)
60
- ->GetFunction(context)
61
- .ToLocalChecked());
62
- }
63
-
64
- for (uint32_t i = 0; i < rclnodejs::action_binding_methods.size(); i++) {
65
- Nan::Set(
66
- exports,
67
- Nan::New(rclnodejs::action_binding_methods[i].name).ToLocalChecked(),
68
- Nan::New<v8::FunctionTemplate>(
69
- rclnodejs::action_binding_methods[i].function)
70
- ->GetFunction(context)
71
- .ToLocalChecked());
72
- }
73
-
74
- for (uint32_t i = 0; i < rclnodejs::lifecycle_binding_methods.size(); i++) {
75
- Nan::Set(
76
- exports,
77
- Nan::New(rclnodejs::lifecycle_binding_methods[i].name).ToLocalChecked(),
78
- Nan::New<v8::FunctionTemplate>(
79
- rclnodejs::lifecycle_binding_methods[i].function)
80
- ->GetFunction(context)
81
- .ToLocalChecked());
82
- }
83
-
84
- rclnodejs::ShadowNode::Init(exports);
85
- rclnodejs::RclHandle::Init(exports);
64
+ rclnodejs::StoreEnv(env);
65
+ // Init the C++ bindings.
66
+ rclnodejs::InitBindings(env, exports);
67
+ rclnodejs::InitActionClientBindings(env, exports);
68
+ rclnodejs::InitActionGoalBindings(env, exports);
69
+ rclnodejs::InitActionServerBindings(env, exports);
70
+ rclnodejs::InitClientBindings(env, exports);
71
+ rclnodejs::InitContextBindings(env, exports);
72
+ rclnodejs::InitGraphBindings(env, exports);
73
+ rclnodejs::InitGuardConditionBindings(env, exports);
74
+ rclnodejs::InitLoggingBindings(env, exports);
75
+ rclnodejs::InitNamesBindings(env, exports);
76
+ rclnodejs::InitNodeBindings(env, exports);
77
+ rclnodejs::InitPublisherBindings(env, exports);
78
+ rclnodejs::InitServiceBindings(env, exports);
79
+ rclnodejs::InitSubscriptionBindings(env, exports);
80
+ rclnodejs::InitTimePointBindings(env, exports);
81
+ rclnodejs::InitTimerBindings(env, exports);
82
+ rclnodejs::InitLifecycleBindings(env, exports);
83
+ rclnodejs::ShadowNode::Init(env, exports);
84
+ rclnodejs::RclHandle::Init(env, exports);
86
85
 
87
86
  #ifdef DEBUG_ON
88
87
  int result = rcutils_logging_set_logger_level(PACKAGE_NAME,
89
88
  RCUTILS_LOG_SEVERITY_DEBUG);
90
89
  RCUTILS_UNUSED(result);
91
90
  #endif
91
+
92
+ return exports;
92
93
  }
93
94
 
94
- NODE_MODULE(rclnodejs, InitModule);
95
+ NODE_API_MODULE(rclnodejs, InitModule)
package/src/executor.cpp CHANGED
@@ -12,16 +12,16 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- #include "executor.hpp"
15
+ #include "executor.h"
16
16
 
17
17
  #include <rcl/error_handling.h>
18
18
 
19
19
  #include <stdexcept>
20
20
  #include <string>
21
21
 
22
- #include "handle_manager.hpp"
23
- #include "macros.hpp"
24
- #include "rcl_bindings.hpp"
22
+ #include "handle_manager.h"
23
+ #include "macros.h"
24
+ #include "rcl_bindings.h"
25
25
 
26
26
  #ifdef WIN32
27
27
  #define UNUSED
@@ -41,12 +41,14 @@ struct RclResult {
41
41
  std::string error_msg;
42
42
  };
43
43
 
44
- Executor::Executor(HandleManager* handle_manager, Delegate* delegate)
44
+ Executor::Executor(Napi::Env env, HandleManager* handle_manager,
45
+ Delegate* delegate)
45
46
  : async_(nullptr),
46
47
  main_thread_(uv_thread_self()),
47
48
  handle_manager_(handle_manager),
48
49
  delegate_(delegate),
49
- context_(nullptr) {
50
+ context_(nullptr),
51
+ env_(env) {
50
52
  running_.store(false);
51
53
  }
52
54
 
@@ -74,12 +76,19 @@ void Executor::SpinOnce(rcl_context_t* context, int32_t time_out) {
74
76
  rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
75
77
  rcl_ret_t ret = rcl_wait_set_init(&wait_set, 0, 0, 0, 0, 0, 0, context,
76
78
  rcl_get_default_allocator());
77
- if (ret != RCL_RET_OK) Nan::ThrowError(rcl_get_error_string().str);
79
+ if (ret != RCL_RET_OK) {
80
+ Napi::Error::New(env_, rcl_get_error_string().str)
81
+ .ThrowAsJavaScriptException();
82
+ return;
83
+ }
78
84
 
79
85
  RclResult wait_result = WaitForReadyCallbacks(&wait_set, time_out);
80
86
 
81
- if (wait_result.ret != RCL_RET_OK)
82
- Nan::ThrowError(wait_result.error_msg.c_str());
87
+ if (wait_result.ret != RCL_RET_OK) {
88
+ Napi::Error::New(env_, wait_result.error_msg.c_str())
89
+ .ThrowAsJavaScriptException();
90
+ return;
91
+ }
83
92
 
84
93
  if (handle_manager_->ready_handles_count() > 0) ExecuteReadyHandles();
85
94
 
@@ -87,7 +96,7 @@ void Executor::SpinOnce(rcl_context_t* context, int32_t time_out) {
87
96
  std::string error_message =
88
97
  std::string("Failed to destroy guard waitset:") +
89
98
  std::string(rcl_get_error_string().str);
90
- Nan::ThrowError(error_message.c_str());
99
+ Napi::Error::New(env_, error_message.c_str()).ThrowAsJavaScriptException();
91
100
  }
92
101
  }
93
102
 
@@ -12,9 +12,10 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- #ifndef SRC_EXECUTOR_HPP_
16
- #define SRC_EXECUTOR_HPP_
15
+ #ifndef SRC_EXECUTOR_H_
16
+ #define SRC_EXECUTOR_H_
17
17
 
18
+ #include <napi.h>
18
19
  #include <rcl/wait.h>
19
20
  #include <uv.h>
20
21
 
@@ -22,7 +23,7 @@
22
23
  #include <exception>
23
24
  #include <vector>
24
25
 
25
- #include "rcl_handle.hpp"
26
+ #include "rcl_handle.h"
26
27
 
27
28
  namespace rclnodejs {
28
29
 
@@ -37,7 +38,7 @@ class Executor {
37
38
  virtual void CatchException(std::exception_ptr e_ptr) = 0;
38
39
  };
39
40
 
40
- Executor(HandleManager* handle_manager, Delegate* delegate);
41
+ Executor(Napi::Env env, HandleManager* handle_manager, Delegate* delegate);
41
42
  ~Executor();
42
43
 
43
44
  void Start(rcl_context_t* context, int32_t time_out);
@@ -68,10 +69,11 @@ class Executor {
68
69
  Delegate* delegate_;
69
70
  rcl_context_t* context_;
70
71
  int32_t time_out_;
72
+ Napi::Env env_;
71
73
 
72
74
  std::atomic_bool running_;
73
75
  };
74
76
 
75
77
  } // namespace rclnodejs
76
78
 
77
- #endif // SRC_EXECUTOR_HPP_
79
+ #endif // SRC_EXECUTOR_H_