Skip to content

Commit

Permalink
update C and C++ typesupport to use IDL-based extension point
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Nov 26, 2018
1 parent f253d72 commit f3330ed
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 964 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Open Source Robotics Foundation, Inc.
# Copyright 2016-2018 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 @@ -14,66 +14,49 @@

set(_output_path
"${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c/${PROJECT_NAME}")
set(_generated_files "")
foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES})
get_filename_component(_extension "${_idl_file}" EXT)
get_filename_component(_parent_folder "${_idl_file}" DIRECTORY)
set(_generated_sources "")
foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES})
string(REGEX REPLACE ":([^:]*)$" "/\\1" _abs_idl_file "${_idl_tuple}")
get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY)
get_filename_component(_parent_folder "${_parent_folder}" NAME)
if(_extension STREQUAL ".msg")
set(_allowed_parent_folders "msg" "srv" "action")
if(NOT _parent_folder IN_LIST _allowed_parent_folders)
message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}")
endif()
elseif(_extension STREQUAL ".srv")
set(_allowed_parent_folders "srv" "action")
if(NOT _parent_folder IN_LIST _allowed_parent_folders)
message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}")
endif()
else()
message(FATAL_ERROR "Interface file with unknown extension: ${_idl_file}")
endif()
get_filename_component(_msg_name "${_idl_file}" NAME_WE)
string_camel_case_to_lower_case_underscore("${_msg_name}" _header_name)
list(APPEND _generated_files
get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE)
string_camel_case_to_lower_case_underscore("${_idl_name}" _header_name)
list(APPEND _generated_sources
"${_output_path}/${_parent_folder}/${_header_name}__type_support.cpp"
)
endforeach()

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_INTERFACE_FILES})
get_filename_component(_extension "${_idl_file}" EXT)
if(_extension STREQUAL ".msg")
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endif()
endforeach()
endforeach()

set(target_dependencies
"${rosidl_typesupport_c_BIN}"
${rosidl_typesupport_c_GENERATOR_FILES}
"${rosidl_typesupport_c_TEMPLATE_DIR}/action__type_support.c.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/srv__type_support.cpp.em"
${rosidl_generate_interfaces_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
if(NOT EXISTS "${dep}")
get_property(is_generated SOURCE "${dep}" PROPERTY GENERATED)
if(NOT ${_is_generated})
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
endforeach()

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_c_TEMPLATE_DIR}"
Expand All @@ -82,7 +65,7 @@ rosidl_write_generator_arguments(

get_used_typesupports(typesupports "rosidl_typesupport_c")
add_custom_command(
OUTPUT ${_generated_files}
OUTPUT ${_generated_sources}
COMMAND ${PYTHON_EXECUTABLE} ${rosidl_typesupport_c_BIN}
--generator-arguments-file "${generator_arguments_file}"
--typesupports ${typesupports}
Expand All @@ -103,7 +86,7 @@ configure_file(

set(_target_suffix "__rosidl_typesupport_c")

add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${rosidl_typesupport_c_LIBRARY_TYPE} ${_generated_files})
add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${rosidl_typesupport_c_LIBRARY_TYPE} ${_generated_sources})
if(rosidl_generate_interfaces_LIBRARY_NAME)
set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix}
PROPERTIES OUTPUT_NAME "${rosidl_generate_interfaces_LIBRARY_NAME}${_target_suffix}")
Expand Down Expand Up @@ -172,7 +155,7 @@ if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
endif()

if(BUILD_TESTING AND rosidl_generate_interfaces_ADD_LINTER_TESTS)
if(NOT _generated_files STREQUAL "")
if(NOT _generated_sources STREQUAL "")
find_package(ament_cmake_cppcheck REQUIRED)
ament_cppcheck(
TESTNAME "cppcheck_rosidl_typesupport_c"
Expand Down
83 changes: 45 additions & 38 deletions rosidl_typesupport_c/resource/action__type_support.c.em
Original file line number Diff line number Diff line change
@@ -1,52 +1,59 @@
// generated from
// rosidl_typesupport_c/resource/action__type_support_c.em
// generated code does not contain a copyright notice

@#######################################################################
@# EmPy template for generating <action>__type_support.c files
@#
@# Context:
@# - spec (rosidl_parser.ActionSpecification)
@# Parsed specification of the .action file
@# - subfolder (string)
@# The subfolder / subnamespace of the message, usually 'action'
@# - get_header_filename_from_msg_name (function)
@#######################################################################
@

#include <action_msgs/msg/goal_status_array.h>
#include <action_msgs/srv/cancel_goal.h>

#include <@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.action_name))__feedback.h>
#include <@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.action_name))__goal.h>
#include <@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.action_name))__result.h>


#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.action_name))__type_support.h"


static rosidl_action_type_support_t _@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c;
@# Included from rosidl_typesupport_c/resource/idl__type_support.c.em
@{
from rosidl_cmake import convert_camel_case_to_lower_case_underscore
include_parts = [package_name] + list(interface_path.parents[0].parts) + \
[convert_camel_case_to_lower_case_underscore(interface_path.stem)]
include_base = '/'.join(include_parts)

header_files = (
'action_msgs/msg/goal_status_array.h',
'action_msgs/srv/cancel_goal.h',
include_base + '.h',
include_base + '__type_support.h',
)
}@
@[for header_file in header_files]@
@[ if header_file in include_directives]@
// already included above
// @
@[ else]@
@{include_directives.add(header_file)}@
@[ end if]@
#include "@(header_file)"
@[end for]@

static rosidl_action_type_support_t _@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c;

#ifdef __cplusplus
extern "C"
{
#endif

ROSIDL_TYPESUPPORT_C_EXPORT_@(package_name)
const rosidl_action_type_support_t *
ROSIDL_TYPESUPPORT_INTERFACE__ACTION_SYMBOL_NAME(
rosidl_typesupport_c, @(spec.pkg_name), @(subfolder), @(spec.action_name))()
rosidl_typesupport_c, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(interface_path.stem))()
{
// Thread-safe by always writing the same values to the static struct
_@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c.goal_service_type_support =
_@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c.goal_service_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_c, @(spec.pkg_name), @(subfolder), @(spec.action_name)_Goal)();
_@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c.result_service_type_support =
rosidl_typesupport_c, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(interface_path.stem)_Action_Goal)();
_@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c.result_service_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_c, @(spec.pkg_name), @(subfolder), @(spec.action_name)_Result)();
_@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c.cancel_service_type_support =
rosidl_typesupport_c, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(interface_path.stem)_Action_Result)();
_@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c.cancel_service_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_c, action_msgs, srv, CancelGoal)();
_@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c.feedback_message_type_support =
_@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c.feedback_message_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(
rosidl_typesupport_c, @(spec.pkg_name), @(subfolder), @(spec.action_name)_Feedback)();
_@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c.status_message_type_support =
rosidl_typesupport_c, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(interface_path.stem)_Feedback)();
_@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c.status_message_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(
rosidl_typesupport_c, action_msgs, msg, GoalStatusArray)();

return &_@(spec.pkg_name)__@(subfolder)__@(spec.action_name)__typesupport_c;
return &_@('__'.join([package_name] + list(interface_path.parents[0].parts)))__@(interface_path.stem)__typesupport_c;
}

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit f3330ed

Please sign in to comment.