From 427eab6dceef645a92a7860fe6bfaa2c91cf4449 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Mon, 18 Jun 2018 18:38:54 -0700 Subject: [PATCH] print service pairs as well (#124) * print service pairs as well * add variable to template header --- include/ros1_bridge/bridge.hpp | 5 ++++- resource/get_mappings.cpp.em | 18 +++++++++++++++++- ros1_bridge/__init__.py | 5 +++-- src/dynamic_bridge.cpp | 11 ++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/ros1_bridge/bridge.hpp b/include/ros1_bridge/bridge.hpp index d38e55a8..21f4bdd4 100755 --- a/include/ros1_bridge/bridge.hpp +++ b/include/ros1_bridge/bridge.hpp @@ -59,7 +59,10 @@ get_2to1_mapping( std::string & ros1_type_name); std::map -get_all_mappings_2to1(); +get_all_message_mappings_2to1(); + +std::map +get_all_service_mappings_2to1(); std::shared_ptr get_factory( diff --git a/resource/get_mappings.cpp.em b/resource/get_mappings.cpp.em index 94b8826c..90bbfef8 100644 --- a/resource/get_mappings.cpp.em +++ b/resource/get_mappings.cpp.em @@ -13,6 +13,8 @@ @# Context: @# - mappings (list of ros1_bridge.Mapping) @# Mapping between messages as well as their fields +@# - services (list of dictionaries) +@# Mapping between services as well as their fields @############################################### @ #include @@ -60,7 +62,7 @@ get_2to1_mapping(const std::string & ros2_type_name, std::string & ros1_type_nam } std::map -get_all_mappings_2to1() +get_all_message_mappings_2to1() { static std::map mappings = { @[for m in mappings]@ @@ -73,4 +75,18 @@ get_all_mappings_2to1() return mappings; } +std::map +get_all_service_mappings_2to1() +{ + static std::map mappings = { +@[for s in services]@ + { + "@(s['ros2_package'])/@(s['ros2_name'])", // ROS 2 + "@(s['ros1_package'])/@(s['ros1_name'])" // ROS 1 + }, +@[end for]@ + }; + return mappings; +} + } // namespace ros1_bridge diff --git a/ros1_bridge/__init__.py b/ros1_bridge/__init__.py index 74f4d811..727efa1f 100644 --- a/ros1_bridge/__init__.py +++ b/ros1_bridge/__init__.py @@ -66,13 +66,14 @@ def generate_cpp(output_path, template_dir): data = generate_messages() + data.update(generate_services()) template_file = os.path.join(template_dir, 'get_mappings.cpp.em') output_file = os.path.join(output_path, 'get_mappings.cpp') - data_for_template = {'mappings': data['mappings']} + data_for_template = { + 'mappings': data['mappings'], 'services': data['services']} expand_template(template_file, data_for_template, output_file) - data.update(generate_services()) unique_package_names = set(data['ros2_package_names_msg'] + data['ros2_package_names_srv']) # skip builtin_interfaces since there is a custom implementation unique_package_names -= {'builtin_interfaces'} diff --git a/src/dynamic_bridge.cpp b/src/dynamic_bridge.cpp index c36bb75e..4ee4abf6 100644 --- a/src/dynamic_bridge.cpp +++ b/src/dynamic_bridge.cpp @@ -97,7 +97,7 @@ bool parse_command_options( } if (get_flag_option(args, "--print-pairs")) { - auto mappings_2to1 = ros1_bridge::get_all_mappings_2to1(); + auto mappings_2to1 = ros1_bridge::get_all_message_mappings_2to1(); if (mappings_2to1.size() > 0) { printf("Supported ROS 2 <=> ROS 1 message type conversion pairs:\n"); for (auto & pair : mappings_2to1) { @@ -106,6 +106,15 @@ bool parse_command_options( } else { printf("No message type conversion pairs supported.\n"); } + mappings_2to1 = ros1_bridge::get_all_service_mappings_2to1(); + if (mappings_2to1.size() > 0) { + printf("Supported ROS 2 <=> ROS 1 service type conversion pairs:\n"); + for (auto & pair : mappings_2to1) { + printf(" - '%s' (ROS 2) <=> '%s' (ROS 1)\n", pair.first.c_str(), pair.second.c_str()); + } + } else { + printf("No service type conversion pairs supported.\n"); + } return false; }