Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use converters when playing back files #56

Merged
merged 29 commits into from
Nov 23, 2018

Conversation

Martin-Idel-SI
Copy link
Contributor

@Martin-Idel-SI Martin-Idel-SI commented Oct 31, 2018

This PR lays the foundations for using converters to play (and record) bagfiles with different middleware serialization formats.

Content of this PR:

  • The "deleted lines" are nearly all related to mocking rosbag2_storage::StorageFactory for testing the new functionality. Nothing really happens here.
  • This PR adds a converter, which loads converter plugins and then, given a SerializedBagMessage converts it to a SerializedBagMessage of (potentially) another format.
  • To do this, we need to allocate a ROS2-Message of unknown type at compile time.

Pointer to how the ROS message allocation/deallocation works:

  1. We use the rosidl_introspection_typesupport_t.
  2. Given the message, we allocate a chunk of memory (and zero it - this is necessary) according to the size of the message from the introspection type support.
  3. For all members, we must now recursively do the following:
  • For primitive data types or arrays of primitives, we are done as they live inside the allocated message
  • For std::string and std::vector<bool> the zero-allocated memory does not work correctly, so we have to overwrite the memory with a true empty string or empty vector. All other vectors seem to work correctly.
  1. This message now works - we can cast it to the correct type and assign values, and pass it somewhere, etc.
  2. When it's time to deallocate, we need to recursively free all memory. This implies
  • For strings, deleting the content of the string
  • For vectors, deleting the content of the vector
  • For arrays, deleting the content of the array if it's not an array of primitives
  • Finally deallocating the content of the message itself.

As of now, the methods have a drawback in that any further dynamic memory allocation uses the free store (new). The allocator of the message is only used to allocate the bare message struct. I think that it might be possible to pass the allocator around except for nested message types, as I don't know the type of the vector to allocate.

Note: The way the converter plugins are used in the SequentialReader is not yet final and will be changed in a followup PR, which will additionally store serialization format information on a per topic basis.

Martin-Idel-SI and others added 17 commits November 9, 2018 10:04
- Added mocks for storage and converters (and factories)
- Use convert only if necessary (different input and output formats),
  converters are only loaded if really necessary.
- Allocate_ros2_message is public to enable extensive tests for this function.
- Helper function to get any typesupport by name
- Helper function for empty ros2_message
- Treats most messages already.
- Some combinations of nested messages with arrays are still missing
- Cleanup of DynamicArrayNested messages is failing
- Main difficulty is the cleanup of the allocated ros2_message which
needs to be done manually
- The test_ros2_message is intended to be run with valgrind and there
should be no leaks or problems with free!
Swapping with empty container seems more stable than deleting the data
pointer of the container.
rosbag2/test/rosbag2/types/test_ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/test/rosbag2/types/test_ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/test/rosbag2/types/test_ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/test/rosbag2/types/test_ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/test/rosbag2/types/test_ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/include/rosbag2/types/ros2_message.hpp Outdated Show resolved Hide resolved
rosbag2/src/rosbag2/types/ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/src/rosbag2/types/ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/src/rosbag2/types/ros2_message.cpp Outdated Show resolved Hide resolved
rosbag2/src/rosbag2/types/ros2_message.cpp Show resolved Hide resolved
- The TODO comments have been removed because they're no longer relevant: they have been discussed in the PR review
@botteroa-si
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@botteroa-si
Copy link
Contributor

New CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@botteroa-si
Copy link
Contributor

New CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

- Big strings are not treated with small string optimization and need
  to be checked, too.
@anhosi
Copy link
Contributor

anhosi commented Nov 15, 2018

@Karsten1987 As discussed I added allocation tests for bigger strings (no small string optimization) and nested arrays. The cleanup actually already covered these cases.
These new tests require two new messages types in test_msgs and will not compile until those are available. -> so no CI for now.

msg->allocator.deallocate(msg->message, msg->allocator.state);
delete msg;
};
auto deleter = std::bind(&deallocate_ros2_message, std::placeholders::_1, intro_ts_members);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keeping the lambda? This change does not compile on Windows VS2017.

@anhosi
Copy link
Contributor

anhosi commented Nov 21, 2018

New round of CI

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@Karsten1987 Karsten1987 mentioned this pull request Nov 23, 2018
@Karsten1987 Karsten1987 merged commit cb28689 into ros2:master Nov 23, 2018
@anhosi anhosi deleted the feature/use_converters branch November 23, 2018 08:24
Copy link
Contributor

@anhosi anhosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Karsten1987 Why did you want all these functions to be exported? They are not intended for direct use (except maybe deallocate_ros2_message). Should we put them in a nested namespace (e.g. rosbag2::ros2_message) instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants