Skip to content

Commit

Permalink
Register language of typesupport for rmw implementation (ros2#63)
Browse files Browse the repository at this point in the history
Add macros for getting type support for a particular language for an rmw implementation
  • Loading branch information
jacquelinekay authored and ahcorde committed Jun 2, 2016
1 parent d5d9881 commit 57b16f7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 21 deletions.
31 changes: 21 additions & 10 deletions rmw/cmake/get_rmw_typesupport.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
# Copyright 2015-2016 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,18 +13,29 @@
# limitations under the License.

#
# Get the type support package name for specific ROS middleware implementation.
# Get the type support package names for a specific RMW implementation.
#
# :param rmw_implementation: the package name of the ROS middleware
# implementation
# :param var: the output variable name containing the package names
# :type var: list of strings
# :param rmw_implementation: the package name of the RMW implementation
# :type rmw_implementation: string
# :param LANGUAGE: Optional flag for the language of the type support to get.
# If language is omitted, type supports for all languages are returned.
# :type LANGUAGE: string
#
# @public
#
macro(get_rmw_typesupport var rmw_implementation)
if(NOT "${ARGN} " STREQUAL " ")
message(FATAL_ERROR "get_rmw_typesupport() called with unused arguments: ${ARGN}")
function(get_rmw_typesupport var rmw_implementation)
cmake_parse_arguments(ARG "" "LANGUAGE" "" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "get_rmw_typesupport() called with unused "
"arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()

ament_index_get_resource(${var} "rmw_implementation" "${rmw_implementation}")
endmacro()
set(resource_type "rmw_typesupport")
if(NOT "${ARG_LANGUAGE} " STREQUAL " ")
string(TOLOWER "${ARG_LANGUAGE}" ARG_LANGUAGE)
set(resource_type "${resource_type}_${ARG_LANGUAGE}")
endif()
ament_index_get_resource(resource "${resource_type}" "${rmw_implementation}")
set(${var} "${resource}" PARENT_SCOPE)
endfunction()
55 changes: 45 additions & 10 deletions rmw/cmake/register_rmw_implementation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,52 @@
#
# Register the current package as a ROS middleware implementation.
#
# :param typesupport_package_name: the package name providing type support for
# for the registered RMW implementation
# :type typesupport_package_name: string
# A valid usage of this function is
# register_rmw_implementation("c:rosidl_typesupport_introspection_c"
# "cpp:rosidl_typesupport_introspection_cpp")
# If there were multiple valid typesupports for one language in a package,
# they would be separated by colons, e.g.
# register_rmw_implementation(
# "cpp:rosidl_typesupport_a_cpp:rosidl_typesupport_b_cpp")
# If there are multiple inputs with the same language flag (first entry) the
# function will error.
# :param ARGN: a list of <language:typesupport> tuples where language is the
# language of the typesupport package and typesupport is the name of the
# package.
# :type ARGN: a list of strings
#
# @public
#
macro(register_rmw_implementation typesupport_package_name)
if(NOT "${ARGN} " STREQUAL " ")
message(FATAL_ERROR "register_rmw_implementation() called with "
"unused arguments: ${ARGN}")
endif()
function(register_rmw_implementation)
set(all_typesupports "")
set(language_labels "")

ament_index_register_resource("rmw_implementation" CONTENT "${typesupport_package_name}")
endmacro()
foreach(arg_raw ${ARGN})
# replace colon with semicolon to turn into a list
string(REPLACE ":" ";" arg "${arg_raw}")
list(LENGTH arg arg_length)
if(arg_length LESS 1)
message(FATAL_ERROR
"register_rmw_implementation() called with invalid input: ${arg_raw}")
endif()
list(GET arg 0 language_label)
list(REMOVE_AT arg 0)
string(TOLOWER "${language_label}" language_label)
# Cache the existing languages labels found (so that we don't have to
# check the ament index twice every loop) and error if we've already
# encountered the language
list(FIND language_labels "${language_label}" label_found)
if(NOT ${label_found} EQUAL -1)
message(FATAL_ERROR
"register_rmw_implementation() got language '${language_label}' "
"multiple times")
endif()
list(APPEND language_labels "${language_label}")
ament_index_register_resource(
"rmw_typesupport_${language_label}" CONTENT "${arg}"
)
list_append_unique(all_typesupports "${arg}")
endforeach()

ament_index_register_resource("rmw_typesupport" CONTENT "${all_typesupports}")
endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# :type var: list of strings
#
function(get_available_rmw_implementations var)
ament_index_get_resources(middleware_implementations "rmw_implementation")
ament_index_get_resources(middleware_implementations "rmw_typesupport")
if(DEFINED middleware_implementations)
list(SORT middleware_implementations)
endif()
Expand Down

0 comments on commit 57b16f7

Please sign in to comment.