Skip to content

Commit

Permalink
Fix converter plugin choices for record (ros2#897)
Browse files Browse the repository at this point in the history
* Fix converter plugin choices. 1 - provide Converter class as an option for record. 2 - fix naming for CLI choices due to _converter suffix logic

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
  • Loading branch information
emersonknapp authored Oct 29, 2021
1 parent 22511b9 commit db89639
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def add_arguments(self, parser, cli_name): # noqa: D102

compression_format_choices = get_registered_compressors()
serialization_choices = get_registered_serializers()
converter_suffix = '_converter'
serialization_choices = {
f[:-len(converter_suffix)]
for f in serialization_choices
if f.endswith(converter_suffix)
}

parser.add_argument(
'-a', '--all', action='store_true',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class SerializationFormatConverter
: public SerializationFormatSerializer, public SerializationFormatDeserializer
{
public:
static std::string get_package_name()
{
return "rosbag2_cpp";
}

static std::string get_base_class_name()
{
return "rosbag2_cpp::converter_interfaces::SerializationFormatConverter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ class SerializationFormatConverterFactoryImpl
}
}

ROSBAG2_CPP_LOG_INFO(
"No plugin found providing serialization format. "
"Falling back to checking RMW implementations.");
ROSBAG2_CPP_LOG_INFO_STREAM(
"No plugin found providing serialization format '" << format << "'. " <<
"Falling back to checking RMW implementations.");
try {
return std::make_unique<RMWImplementedConverter>(format);
} catch (const std::runtime_error & ex) {
Expand Down
8 changes: 6 additions & 2 deletions rosbag2_py/src/rosbag2_py/_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ std::unordered_set<std::string> get_registered_compressors()

std::unordered_set<std::string> get_registered_serializers()
{
return rosbag2_cpp::plugins::get_class_plugins
<rosbag2_cpp::converter_interfaces::SerializationFormatSerializer>();
auto serializers = rosbag2_cpp::plugins::get_class_plugins<
rosbag2_cpp::converter_interfaces::SerializationFormatSerializer>();
auto converters = rosbag2_cpp::plugins::get_class_plugins<
rosbag2_cpp::converter_interfaces::SerializationFormatConverter>();
serializers.insert(converters.begin(), converters.end());
return serializers;
}

} // namespace rosbag2_py
Expand Down
5 changes: 4 additions & 1 deletion rosbag2_py/test/test_sequential_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,7 @@ def test_serialization_plugin_list():
:return:
"""
serialization_formats = rosbag2_py.get_registered_serializers()
assert 's_converter' in serialization_formats
assert 's_converter' in serialization_formats, \
'get_registered_serializers should return SerializationFormatSerializer plugins'
assert 'a_converter' in serialization_formats, \
'get_registered_serializers should also return SerializationFormatConverter plugins'

0 comments on commit db89639

Please sign in to comment.