Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/identify-ros-distro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
id: identify
run: |
if ${ROLLING_VAR} == true; then
# echo "::set-output name=distro::rolling"
echo "::set-output name=distro::rolling"
echo "::set-output name=linuxos::ubuntu-22.04"
elif ${HUMBLE_VAR} == true; then
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ generated
types/interfaces.d.ts
dist
build
install
log
.vscode
.project
Expand Down
2 changes: 1 addition & 1 deletion example/publisher-content-filter-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function main() {
console.log(
`Publish temerature message-${++count}: ${temperature} degrees`
);
}, 750);
}, 100);

node.spin();
}
Expand Down
2 changes: 1 addition & 1 deletion example/subscription-content-filter-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ${temperatureMsg.temperature}C`);
if (subscription.hasContentFilter()) {
console.log('Clearing filter');
subscription.clearContentFilter();
} else {
} else if (param < 100) {
param += 10;
console.log('Update topic content-filter, temperature > ', param);
const contentFilter = {
Expand Down
2 changes: 1 addition & 1 deletion lib/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Subscription extends Entity {
*/
clearContentFilter() {
return this.hasContentFilter()
? rclnodejs.setContentFilter(this.handle, { expression: '' })
? rclnodejs.clearContentFilter(this.handle)
: true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"husky": "^4.2.5",
"jsdoc": "^3.6.7",
"lint-staged": "^10.2.11",
"mocha": "^8.0.1",
"mocha": "^10.2.0",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"sinon": "^9.0.2",
Expand Down
7 changes: 7 additions & 0 deletions rosidl_gen/idl_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ function removeEmptyLines(str) {
return str.replace(/^\s*\n/gm, '');
}

/**
* Output generated code to disk. Do not overwrite
* an existing file. If file already exists do nothing.
* @param {string} dir
* @param {string} fileName
* @param {string} code
*/
async function writeGeneratedCode(dir, fileName, code) {
await fse.mkdirs(dir);
await fse.writeFile(path.join(dir, fileName), code);
Expand Down
22 changes: 16 additions & 6 deletions rosidl_gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const packages = require('./packages.js');
const path = require('path');

const generatedRoot = path.join(__dirname, '../generated/');
const installedPackagePaths = process.env.AMENT_PREFIX_PATH.split(
path.delimiter
);

function getInstalledPackagePaths() {
return process.env.AMENT_PREFIX_PATH.split(path.delimiter);
}

async function generateInPath(path) {
const pkgs = await packages.findPackagesInDirectory(path);
Expand All @@ -40,14 +41,23 @@ async function generateAll(forcedGenerating) {
// all the JavaScript files will be created.
const exist = await fse.exists(generatedRoot);
if (forcedGenerating || !exist) {
if (exist) {
// recursively clear all previously generated struct files
await fse.emptyDir(generatedRoot);
}

await fse.copy(
path.join(__dirname, 'generator.json'),
path.join(generatedRoot, 'generator.json')
);

await Promise.all(
installedPackagePaths.map((path) => generateInPath(path))
);
// Process in AMENT_PREFIX_PATH in reverse order to
// such that interfaces defined earlier on the AMENX_PREFIX_PATH
// have higher priority over earlier versions and will override
// them - occurences of this are expected to be rare.
for (let path of getInstalledPackagePaths().reverse()) {
await generateInPath(path);
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions scripts/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ const os = require('os');
const path = require('path');

let rootDir = path.dirname(__dirname);
let actionPath = path.join(rootDir, 'test', 'ros1_actions');
process.env.AMENT_PREFIX_PATH =
process.env.AMENT_PREFIX_PATH + path.delimiter + actionPath;
let msgPath = path.join(rootDir, 'test', 'rclnodejs_test_msgs');
process.env.AMENT_PREFIX_PATH =
process.env.AMENT_PREFIX_PATH + path.delimiter + msgPath;

fs.remove(path.join(path.dirname(__dirname), 'generated'), (err) => {
if (!err) {
Expand Down
59 changes: 46 additions & 13 deletions src/rcl_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <rosidl_generator_c/string_functions.h>
#endif

#include <iostream>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -775,21 +776,21 @@ NAN_METHOD(SetContentFilter) {
info.GetReturnValue().Set(Nan::False());
return;
#else
v8::Local<v8::Context> currentContent = Nan::GetCurrentContext();
v8::Local<v8::Context> currentContext = Nan::GetCurrentContext();
RclHandle* subscription_handle = RclHandle::Unwrap<RclHandle>(
Nan::To<v8::Object>(info[0]).ToLocalChecked());
rcl_subscription_t* subscription =
reinterpret_cast<rcl_subscription_t*>(subscription_handle->ptr());

v8::Local<v8::Object> contentFilter =
info[1]->ToObject(currentContent).ToLocalChecked();
info[1]->ToObject(currentContext).ToLocalChecked();

// expression property is required
std::string expression(*Nan::Utf8String(
Nan::Get(contentFilter, Nan::New("expression").ToLocalChecked())
.ToLocalChecked()
->ToString(currentContent)
.ToLocalChecked()));
Nan::MaybeLocal<v8::Value> jsExpression =
Nan::Get(contentFilter, Nan::New("expression").ToLocalChecked());
Nan::Utf8String utf8_arg(jsExpression.ToLocalChecked());
int len = utf8_arg.length() + 1;
char* expression = reinterpret_cast<char*>(malloc(len * sizeof(char*)));
snprintf(expression, len, "%s", *utf8_arg);

// parameters property (string[]) is optional
int argc = 0;
Expand Down Expand Up @@ -817,17 +818,20 @@ NAN_METHOD(SetContentFilter) {
rcl_subscription_content_filter_options_t options =
rcl_get_zero_initialized_subscription_content_filter_options();

THROW_ERROR_IF_NOT_EQUAL(
RCL_RET_OK,
rcl_subscription_content_filter_options_init(
subscription, expression.c_str(), argc, (const char**)argv, &options),
rcl_get_error_string().str);
THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
rcl_subscription_content_filter_options_set(
subscription,
expression, // expression.c_str(),
argc, (const char**)argv, &options),
rcl_get_error_string().str);

THROW_ERROR_IF_NOT_EQUAL(
RCL_RET_OK, rcl_subscription_set_content_filter(subscription, &options),
rcl_get_error_string().str);

if (argc) {
free(expression);

for (int i = 0; i < argc; i++) {
free(argv[i]);
}
Expand All @@ -838,6 +842,34 @@ NAN_METHOD(SetContentFilter) {
#endif
}

NAN_METHOD(ClearContentFilter) {
#if ROS_VERSION < 2205 // 2205 => Humble+
info.GetReturnValue().Set(Nan::False());
return;
#else
RclHandle* subscription_handle = RclHandle::Unwrap<RclHandle>(
Nan::To<v8::Object>(info[0]).ToLocalChecked());
rcl_subscription_t* subscription =
reinterpret_cast<rcl_subscription_t*>(subscription_handle->ptr());

// create ctf options
rcl_subscription_content_filter_options_t options =
rcl_get_zero_initialized_subscription_content_filter_options();

THROW_ERROR_IF_NOT_EQUAL(
RCL_RET_OK,
rcl_subscription_content_filter_options_init(
subscription, "", 0, (const char**)nullptr, &options),
rcl_get_error_string().str);

THROW_ERROR_IF_NOT_EQUAL(
RCL_RET_OK, rcl_subscription_set_content_filter(subscription, &options),
rcl_get_error_string().str);

info.GetReturnValue().Set(Nan::True());
#endif
}

NAN_METHOD(CreatePublisher) {
v8::Local<v8::Context> currentContent = Nan::GetCurrentContext();
// Extract arguments
Expand Down Expand Up @@ -1933,6 +1965,7 @@ std::vector<BindingMethod> binding_methods = {
{"createSubscription", CreateSubscription},
{"hasContentFilter", HasContentFilter},
{"setContentFilter", SetContentFilter},
{"clearContentFilter", ClearContentFilter},
{"createPublisher", CreatePublisher},
{"publish", Publish},
{"getTopic", GetTopic},
Expand Down
2 changes: 1 addition & 1 deletion test/blocklist.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test-msg-type-py-node.js",
"test-msg-type-cpp-node.js",
"test-cross-lang.js",
"test-generate-messages-bin.js",
"test-message-generation-bin.js",
"test-subscription-content-filter.js"
]
}
9 changes: 9 additions & 0 deletions test/overlay_test_ws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This folder contains an overlay workspace that extends the
geometry_msgs/msg/Point with the additional `data` attribute.

```
float64 x
float64 y
float64 z
string data <---
```
20 changes: 20 additions & 0 deletions test/overlay_test_ws/geometry_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.8)
project(geometry_msgs)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(std_msgs1 REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Point.msg"
)

ament_package()
5 changes: 5 additions & 0 deletions test/overlay_test_ws/geometry_msgs/msg/Point.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This contains the position of a point in free space
float64 x
float64 y
float64 z
string data
19 changes: 19 additions & 0 deletions test/overlay_test_ws/geometry_msgs/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>geometry_msgs</name>
<version>0.1.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">wayne</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rosidl_default_generators</build_depend>

<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msg/Point.idl
msg/Point.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// generated from rosidl_adapter/resource/msg.idl.em
// with input from geometry_msgs/msg/Point.msg
// generated code does not contain a copyright notice


module geometry_msgs {
module msg {
@verbatim (language="comment", text=
"This contains the position of a point in free space")
struct Point {
double x;

double y;

double z;

string data;
};
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This contains the position of a point in free space
float64 x
float64 y
float64 z
string data
3 changes: 0 additions & 3 deletions test/test-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ describe('LifecycleNode test suite', function () {

let rosDistro = process.env.ROS_DISTRO;
let firstChar = rosDistro.charAt(0);
console.log('1st char: ', firstChar);
console.log('> ', firstChar > 'g');

let testNode = new rclnodejs.lifecycle.LifecycleNode(
'TEST_NODE',
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ describe('rclnodejs generate-messages binary-script tests', function () {
fs.mkdirSync(this.tmpPkg);

childProcess.spawnSync('npm', ['init', '-y'], {
stdio: 'inherit',
// stdio: 'inherit',
shell: true,
cwd: this.tmpPkg,
});
childProcess.spawnSync('npm', ['pack', this.cwd], {
stdio: 'inherit',
// stdio: 'inherit',
shell: true,
cwd: this.tmpPkg,
});
Expand All @@ -80,7 +80,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
}
let tgzPath = path.join(this.tmpPkg, tgz);
childProcess.spawnSync('npm', ['install', tgzPath], {
stdio: 'inherit',
// stdio: 'inherit',
shell: true,
cwd: this.tmpPkg,
});
Expand All @@ -90,7 +90,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
if (getNodeVersionInfo()[0] === 10) {
rimraf.sync(generatedFolderPath);
} else {
fs.rmdirSync(generatedFolderPath, { recursive: true });
fs.rmSync(generatedFolderPath, { recursive: true });
}
}
});
Expand All @@ -100,7 +100,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
if (getNodeVersionInfo()[0] === 10) {
rimraf.sync(this.tmpPkg);
} else {
fs.rmdirSync(this.tmpPkg, { recursive: true });
fs.rmSync(this.tmpPkg, { recursive: true });
}
});

Expand All @@ -113,7 +113,10 @@ describe('rclnodejs generate-messages binary-script tests', function () {

it('test generate-ros-messages script operation', function (done) {
let script = createScriptFolderPath(this.tmpPkg);
childProcess.spawnSync(script, [], { stdio: 'inherit', shell: true });
childProcess.spawnSync(script, [], {
// stdio: 'inherit',
shell: true,
});

let generatedFolderPath = createGeneratedFolderPath(this.tmpPkg);
assert.ok(
Expand All @@ -129,7 +132,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {

it('test npx generate-ros-messages script operation', function (done) {
childProcess.spawnSync('npx', [SCRIPT_NAME], {
stdio: 'inherit',
// stdio: 'inherit',
shell: true,
cwd: this.tmpPkg,
});
Expand Down
Loading