Skip to content

Commit bb3794d

Browse files
committed
Support get_type_description service via parameter
1 parent b3cf4a7 commit bb3794d

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lib/type_description_service.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const loader = require('./interface_loader.js');
1818
const rclnodejs = require('bindings')('rclnodejs');
1919
const Service = require('./service.js');
2020

21+
const {
22+
ParameterType,
23+
Parameter,
24+
ParameterDescriptor,
25+
} = require('../lib/parameter.js');
26+
2127
// This class is used to create a TypeDescriptionService which can be used to
2228
// retrieve information about types used by the node’s publishers, subscribers,
2329
// services or actions.
@@ -32,10 +38,30 @@ class TypeDescriptionService {
3238
'type_description_interfaces/srv/GetTypeDescription'
3339
);
3440
this._typeDescriptionService = null;
41+
42+
this._enabled = false;
43+
const startTypeDescriptionServiceParam = 'start_type_description_service';
44+
if (!node.hasParameter(startTypeDescriptionServiceParam)) {
45+
node.declareParameter(
46+
new Parameter(
47+
startTypeDescriptionServiceParam,
48+
ParameterType.PARAMETER_BOOL,
49+
true
50+
),
51+
new ParameterDescriptor(
52+
startTypeDescriptionServiceParam,
53+
ParameterType.PARAMETER_BOOL,
54+
'If enabled, start the ~/get_type_description service.',
55+
true
56+
)
57+
);
58+
}
59+
const param = node.getParameter(startTypeDescriptionServiceParam);
60+
this._enabled = param.value;
3561
}
3662

3763
start() {
38-
if (this._typeDescriptionService) {
64+
if (!this._enabled || this._typeDescriptionService) {
3965
return;
4066
}
4167

test/test-type-description-service.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const assertUtils = require('./utils.js');
1919
const DistroUtils = require('../lib/distro.js');
2020
const rclnodejs = require('../index.js');
2121
const TypeDescriptionService = require('../lib/type_description_service.js');
22+
const { exec } = require('child_process');
2223

2324
describe('type description service test suite', function () {
2425
this.timeout(60 * 1000);
@@ -73,4 +74,22 @@ describe('type description service test suite', function () {
7374
done();
7475
});
7576
});
77+
78+
it('Test type description service configured by parameter', function (done) {
79+
exec(
80+
'ros2 param list /test_type_description_service',
81+
(error, stdout, stderr) => {
82+
if (error || stderr) {
83+
done(
84+
new Error(
85+
'Test type description service configured by parameter failed.'
86+
)
87+
);
88+
}
89+
if (stdout.includes('start_type_description_service')) {
90+
done();
91+
}
92+
}
93+
);
94+
});
7695
});

0 commit comments

Comments
 (0)