Skip to content

Commit bdf63fb

Browse files
authored
Disable methods not supported by humble (#1119)
This PR disables methods that are not supported by ROS 2 Humble by conditionally skipping tests and excluding bindings and functionality when running on that distribution. - Tests for timer and node methods now skip execution on Humble. - C++ and JavaScript bindings for timer and node methods are conditionally compiled/invoked based on the ROS version. Fix: #1118
1 parent eab439d commit bdf63fb

File tree

7 files changed

+42
-0
lines changed

7 files changed

+42
-0
lines changed

lib/node.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Client = require('./client.js');
2121
const Clock = require('./clock.js');
2222
const Context = require('./context.js');
2323
const debug = require('debug')('rclnodejs:node');
24+
const DistroUtils = require('./distro.js');
2425
const GuardCondition = require('./guard_condition.js');
2526
const loader = require('./interface_loader.js');
2627
const Logging = require('./logging.js');
@@ -1093,6 +1094,10 @@ class Node extends rclnodejs.ShadowNode {
10931094
* @returns {Number}
10941095
*/
10951096
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+
}
10961101
return rclnodejs.countClients(this.handle, serviceName);
10971102
}
10981103

@@ -1102,6 +1107,10 @@ class Node extends rclnodejs.ShadowNode {
11021107
* @returns {Number}
11031108
*/
11041109
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+
}
11051114
return rclnodejs.countServices(this.handle, serviceName);
11061115
}
11071116

lib/timer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'use strict';
1616

1717
const rclnodejs = require('bindings')('rclnodejs');
18+
const DistroUtils = require('./distro.js');
1819

1920
/**
2021
* @class - Class representing a Timer in ROS
@@ -109,6 +110,12 @@ class Timer {
109110
* @return {object} - The timer information.
110111
*/
111112
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+
}
112119
return rclnodejs.callTimerWithInfo(this._handle);
113120
}
114121
}

src/rcl_node_bindings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ Napi::Value CountSubscribers(const Napi::CallbackInfo& info) {
348348
return Napi::Number::New(env, static_cast<int32_t>(count));
349349
}
350350

351+
#if ROS_VERSION > 2205 // 2205 == Humble
351352
Napi::Value CountClients(const Napi::CallbackInfo& info) {
352353
Napi::Env env = info.Env();
353354

@@ -377,6 +378,7 @@ Napi::Value CountServices(const Napi::CallbackInfo& info) {
377378

378379
return Napi::Number::New(env, count);
379380
}
381+
#endif
380382

381383
Napi::Value GetNodeNames(const Napi::CallbackInfo& info) {
382384
Napi::Env env = info.Env();
@@ -432,8 +434,10 @@ Napi::Object InitNodeBindings(Napi::Env env, Napi::Object exports) {
432434
Napi::Function::New(env, ActionGetNamesAndTypes));
433435
exports.Set("countPublishers", Napi::Function::New(env, CountPublishers));
434436
exports.Set("countSubscribers", Napi::Function::New(env, CountSubscribers));
437+
#if ROS_VERSION > 2205 // 2205 == Humble
435438
exports.Set("countClients", Napi::Function::New(env, CountClients));
436439
exports.Set("countServices", Napi::Function::New(env, CountServices));
440+
#endif
437441
exports.Set("getNodeNames", Napi::Function::New(env, GetNodeNames));
438442
return exports;
439443
}

src/rcl_timer_bindings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Napi::Value GetTimerPeriod(const Napi::CallbackInfo& info) {
195195
return Napi::BigInt::New(env, period_nsec);
196196
}
197197

198+
#if ROS_VERSION > 2205 // 2205 == Humble
198199
Napi::Value CallTimerWithInfo(const Napi::CallbackInfo& info) {
199200
Napi::Env env = info.Env();
200201
RclHandle* timer_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
@@ -212,6 +213,7 @@ Napi::Value CallTimerWithInfo(const Napi::CallbackInfo& info) {
212213
Napi::BigInt::New(env, call_info.actual_call_time));
213214
return timer_info;
214215
}
216+
#endif
215217

216218
Napi::Object InitTimerBindings(Napi::Env env, Napi::Object exports) {
217219
exports.Set("createTimer", Napi::Function::New(env, CreateTimer));
@@ -226,7 +228,9 @@ Napi::Object InitTimerBindings(Napi::Env env, Napi::Object exports) {
226228
Napi::Function::New(env, TimerGetTimeUntilNextCall));
227229
exports.Set("changeTimerPeriod", Napi::Function::New(env, ChangeTimerPeriod));
228230
exports.Set("getTimerPeriod", Napi::Function::New(env, GetTimerPeriod));
231+
#if ROS_VERSION > 2205 // 2205 == Humble
229232
exports.Set("callTimerWithInfo", Napi::Function::New(env, CallTimerWithInfo));
233+
#endif
230234
return exports;
231235
}
232236

src/rcl_utilities.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Napi::Value ConvertRMWTimeToDuration(Napi::Env env,
7878
return obj;
7979
}
8080

81+
#if ROS_VERSION > 2205 // 2205 == Humble
8182
Napi::Value ConvertToHashObject(Napi::Env env,
8283
const rosidl_type_hash_t* type_hash) {
8384
Napi::Object obj = Napi::Object::New(env);
@@ -87,6 +88,7 @@ Napi::Value ConvertToHashObject(Napi::Env env,
8788
ROSIDL_TYPE_HASH_SIZE));
8889
return obj;
8990
}
91+
#endif
9092

9193
Napi::Value ConvertToJSTopicEndpoint(
9294
Napi::Env env, const rmw_topic_endpoint_info_t* topic_endpoint_info) {
@@ -103,8 +105,10 @@ Napi::Value ConvertToJSTopicEndpoint(
103105
Napi::String::New(env, topic_endpoint_info->node_namespace));
104106
endpoint.Set("topic_type",
105107
Napi::String::New(env, topic_endpoint_info->topic_type));
108+
#if ROS_VERSION > 2205 // 2205 == Humble
106109
endpoint.Set("topic_type_hash",
107110
ConvertToHashObject(env, &topic_endpoint_info->topic_type_hash));
111+
#endif
108112
endpoint.Set("endpoint_type",
109113
Napi::Number::New(
110114
env, static_cast<int>(topic_endpoint_info->endpoint_type)));

test/test-node.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const IsClose = require('is-close');
1818
const assert = require('assert');
1919
const rclnodejs = require('../index.js');
2020
const assertUtils = require('./utils.js');
21+
const DistroUtils = require('../lib/distro.js');
2122
const { NodeOptions } = require('../index.js');
2223
const assertThrowsError = assertUtils.assertThrowsError;
2324
const Context = require('../lib/context.js');
@@ -422,6 +423,10 @@ describe('rcl node methods testing', function () {
422423
});
423424

424425
it('node.countClients', function () {
426+
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
427+
this.skip();
428+
return;
429+
}
425430
const node = rclnodejs.createNode('publisher_node');
426431
const AddTwoInts = 'example_interfaces/srv/AddTwoInts';
427432
node.createClient(AddTwoInts, 'add_two_ints');
@@ -432,6 +437,10 @@ describe('rcl node methods testing', function () {
432437
});
433438

434439
it('node.countServices', function () {
440+
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
441+
this.skip();
442+
return;
443+
}
435444
const node = rclnodejs.createNode('publisher_node');
436445
const AddTwoInts = 'example_interfaces/srv/AddTwoInts';
437446
node.createService(AddTwoInts, 'add_two_ints', (req) => {});

test/test-timer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
const assert = require('assert');
1818
const rclnodejs = require('../index.js');
19+
const DistroUtils = require('../lib/distro.js');
1920

2021
const TIMER_INTERVAL = BigInt('100000000');
2122
describe('rclnodejs Timer class testing', function () {
@@ -154,6 +155,10 @@ describe('rclnodejs Timer class testing', function () {
154155
});
155156

156157
it('timer.callTimerWithInfo', function (done) {
158+
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
159+
this.skip();
160+
return;
161+
}
157162
const timer = node.createTimer(BigInt('100000000'), () => {});
158163
const info = timer.callTimerWithInfo();
159164
assert.deepStrictEqual(typeof info.expectedCallTime, 'bigint');

0 commit comments

Comments
 (0)