Skip to content

Commit

Permalink
print service pairs as well (#124)
Browse files Browse the repository at this point in the history
* print service pairs as well

* add variable to template header
  • Loading branch information
dirk-thomas authored Jun 19, 2018
1 parent f61f615 commit 427eab6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion include/ros1_bridge/bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ get_2to1_mapping(
std::string & ros1_type_name);

std::map<std::string, std::string>
get_all_mappings_2to1();
get_all_message_mappings_2to1();

std::map<std::string, std::string>
get_all_service_mappings_2to1();

std::shared_ptr<FactoryInterface>
get_factory(
Expand Down
18 changes: 17 additions & 1 deletion resource/get_mappings.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -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 <map>
Expand Down Expand Up @@ -60,7 +62,7 @@ get_2to1_mapping(const std::string & ros2_type_name, std::string & ros1_type_nam
}

std::map<std::string, std::string>
get_all_mappings_2to1()
get_all_message_mappings_2to1()
{
static std::map<std::string, std::string> mappings = {
@[for m in mappings]@
Expand All @@ -73,4 +75,18 @@ get_all_mappings_2to1()
return mappings;
}

std::map<std::string, std::string>
get_all_service_mappings_2to1()
{
static std::map<std::string, std::string> 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
5 changes: 3 additions & 2 deletions ros1_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
11 changes: 10 additions & 1 deletion src/dynamic_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 427eab6

Please sign in to comment.