Make Component Manager public (#1065)

* make functions public & virtual

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* flexible resource index for cmake macros

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* review comments

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* remove superfluous include

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* remove wrong dllexort

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* check for empty plugin & executable args

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* remove commented lines

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* fix typo

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* relax macro constraints

Signed-off-by: Karsten Knese <karsten@openrobotics.org>
This commit is contained in:
Karsten Knese 2020-04-15 19:08:04 -07:00 committed by GitHub
parent 44fa4fe019
commit 50d500e84e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 146 additions and 40 deletions

View file

@ -13,6 +13,9 @@
# limitations under the License.
# register node plugins
ament_index_register_resource(
"rclcpp_components" CONTENT "${_RCLCPP_COMPONENTS__NODES}")
list(REMOVE_DUPLICATES _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES)
foreach(resource_index ${_RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES})
ament_index_register_resource(
${resource_index} CONTENT "${_RCLCPP_COMPONENTS_${resource_index}__NODES}")
endforeach()

View file

@ -22,15 +22,30 @@
# :type target: string
# :param PLUGIN: the plugin name
# :type PLUGIN: string
# :type EXECUTABLE: the node's executable name
# :param EXECUTABLE: the node's executable name
# :type EXECUTABLE: string
# :param RESOURCE_INDEX: the ament resource index to register the components
# :type RESOURCE_INDEX: string
#
macro(rclcpp_components_register_node target)
cmake_parse_arguments(ARGS "" "PLUGIN;EXECUTABLE" "" ${ARGN})
cmake_parse_arguments(ARGS "" "PLUGIN;EXECUTABLE;RESOURCE_INDEX" "" ${ARGN})
if(ARGS_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "rclcpp_components_register_node() called with unused "
"arguments: ${ARGS_UNPARSED_ARGUMENTS}")
endif()
if("${ARGS_PLUGIN}" STREQUAL "")
message(FATAL_ERROR "rclcpp_components_register_node macro requires a PLUGIN argument for target ${target}")
endif()
if("${ARGS_EXECUTABLE}" STREQUAL "")
message(FATAL_ERROR "rclcpp_components_register_node macro requires a EXECUTABLE argument for target ${target}")
endif()
# default to rclcpp_components if not specified otherwise
set(resource_index "rclcpp_components")
if(NOT "${ARGS_RESOURCE_INDEX}" STREQUAL "")
set(resource_index ${ARGS_RESOURCE_INDEX})
message(STATUS "Setting component resource index to non-default value ${resource_index}")
endif()
set(component ${ARGS_PLUGIN})
set(node ${ARGS_EXECUTABLE})
_rclcpp_components_register_package_hook()
@ -39,8 +54,10 @@ macro(rclcpp_components_register_node target)
if(WIN32)
set(_path "bin")
endif()
set(_RCLCPP_COMPONENTS__NODES
"${_RCLCPP_COMPONENTS__NODES}${component};${_path}/$<TARGET_FILE_NAME:${target}>\n")
set(_RCLCPP_COMPONENTS_${resource_index}__NODES
"${_RCLCPP_COMPONENTS_${resource_index}__NODES}${component};${_path}/$<TARGET_FILE_NAME:${target}>\n")
list(APPEND _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES ${resource_index})
configure_file(${rclcpp_components_NODE_TEMPLATE}
${PROJECT_BINARY_DIR}/rclcpp_components/node_main_configured_${node}.cpp.in)
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/rclcpp_components/node_main_${node}.cpp

View file

@ -21,6 +21,8 @@
# :type target: string
# :param ARGN: the unique plugin names being exported using class_loader
# :type ARGN: list of strings
# :param RESOURCE_INDEX: the ament resource index to register the components
# :type RESOURCE_INDEX: string
#
macro(rclcpp_components_register_nodes target)
if(NOT TARGET ${target})
@ -29,6 +31,13 @@ macro(rclcpp_components_register_nodes target)
"rclcpp_components_register_nodes() first argument "
"'${target}' is not a target")
endif()
cmake_parse_arguments(ARGS "" "RESOURCE_INDEX" "" ${ARGN})
# default to rclcpp_components if not specified otherwise
set(resource_index "rclcpp_components")
if(NOT "${ARGS_RESOURCE_INDEX}" STREQUAL "")
set(resource_index ${ARGS_RESOURCE_INDEX})
message(STATUS "Setting component resource index to non-default value ${resource_index}")
endif()
get_target_property(_target_type ${target} TYPE)
if(NOT _target_type STREQUAL "SHARED_LIBRARY")
message(
@ -40,7 +49,7 @@ macro(rclcpp_components_register_nodes target)
if(${ARGC} GREATER 0)
_rclcpp_components_register_package_hook()
set(_unique_names)
foreach(_arg ${ARGN})
foreach(_arg ${ARGS_UNPARSED_ARGUMENTS})
if(_arg IN_LIST _unique_names)
message(
FATAL_ERROR
@ -54,8 +63,9 @@ macro(rclcpp_components_register_nodes target)
else()
set(_path "lib")
endif()
set(_RCLCPP_COMPONENTS__NODES
"${_RCLCPP_COMPONENTS__NODES}${_arg};${_path}/$<TARGET_FILE_NAME:${target}>\n")
set(_RCLCPP_COMPONENTS_${resource_index}__NODES
"${_RCLCPP_COMPONENTS_${resource_index}__NODES}${_arg};${_path}/$<TARGET_FILE_NAME:${target}>\n")
list(APPEND _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES ${resource_index})
endforeach()
endif()
endmacro()