Skip to content

Commit

Permalink
Service introspection (#127)
Browse files Browse the repository at this point in the history
* preliminary c ts impl for service introspection msg gen
* preliminary cpp ts impl for service introspection msg gen

Signed-off-by: Brian Chen <[email protected]>
Signed-off-by: Jacob Perron <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
ihasdapie authored Feb 2, 2023
1 parent a9d8f7f commit 0d4a26b
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 10 deletions.
1 change: 1 addition & 0 deletions rosidl_typesupport_c/resource/msg__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ header_files = [
'rosidl_runtime_c/message_type_support_struct.h',
include_base + '__struct.h',
include_base + '__type_support.h',
include_base + '__functions.h',
]
if len(type_supports) != 1:
header_files += [
Expand Down
20 changes: 19 additions & 1 deletion rosidl_typesupport_c/resource/srv__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ TEMPLATE(
type_supports=type_supports)
}@

@{
TEMPLATE(
'msg__type_support.cpp.em',
package_name=package_name, interface_path=interface_path,
message=service.event_message, include_directives=include_directives,
type_supports=type_supports)
}@

@{
from rosidl_pycommon import convert_camel_case_to_lower_case_underscore
include_parts = [package_name] + list(interface_path.parents[0].parts) + [
Expand All @@ -33,6 +41,8 @@ if len(type_supports) != 1:
'rosidl_typesupport_c/type_support_map.h',
]
header_files.append('rosidl_typesupport_interface/macros.h')
header_files.append('service_msgs/msg/service_event_info.h')
header_files.append('builtin_interfaces/msg/time.h')
}@
@[for header_file in header_files]@
@[ if header_file in include_directives]@
Expand All @@ -53,7 +63,6 @@ namespace @(ns)

namespace rosidl_typesupport_c
{

typedef struct _@(service.namespaced_type.name)_type_support_ids_t
{
const char * typesupport_identifier[@(len(type_supports))];
Expand Down Expand Up @@ -109,6 +118,15 @@ static const rosidl_service_type_support_t @(service.namespaced_type.name)_servi
rosidl_typesupport_c__typesupport_identifier,
reinterpret_cast<const type_support_map_t *>(&_@(service.namespaced_type.name)_service_typesupport_map),
rosidl_typesupport_c__get_service_typesupport_handle_function,
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_CREATE_EVENT_MESSAGE_SYMBOL_NAME(
rosidl_typesupport_c,
@(',\n '.join(service.namespaced_type.namespaced_name()))
),
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_DESTROY_EVENT_MESSAGE_SYMBOL_NAME(
rosidl_typesupport_c,
@(',\n '.join(service.namespaced_type.namespaced_name()))
),
&@(service.namespaced_type.name)_Event_message_type_support_handle
};

} // namespace rosidl_typesupport_c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rosidl_message_type_support_t get_rosidl_message_type_support(const char * ident

rosidl_service_type_support_t get_rosidl_service_type_support(const char * identifier)
{
return {identifier, nullptr, nullptr};
return {identifier, nullptr, nullptr, nullptr, nullptr, nullptr};
}

type_support_map_t get_typesupport_map(void ** library_array)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ constexpr const char * symbols[map_size] = {

rosidl_service_type_support_t get_rosidl_service_type_support(const char * identifier)
{
return {identifier, nullptr, nullptr};
return {identifier, nullptr, nullptr, nullptr, nullptr, nullptr};
}

type_support_map_t get_typesupport_map(void ** library_array)
Expand Down
2 changes: 1 addition & 1 deletion rosidl_typesupport_c/test/test_type_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static const rosidl_message_type_support_t message_type_support = {
};

static const rosidl_service_type_support_t service_type_support = {
0, 0, 0
0, 0, 0, 0, 0, 0
};

const rosidl_message_type_support_t * test_message_type_support() {return &message_type_support;}
Expand Down
14 changes: 12 additions & 2 deletions rosidl_typesupport_cpp/resource/srv__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ TEMPLATE(
type_supports=type_supports)
}@

@{
TEMPLATE(
'msg__type_support.cpp.em',
package_name=package_name, interface_path=interface_path,
message=service.event_message, include_directives=include_directives,
type_supports=type_supports)
}@

@{
from rosidl_pycommon import convert_camel_case_to_lower_case_underscore
include_parts = [package_name] + list(interface_path.parents[0].parts) + [
Expand All @@ -24,11 +32,11 @@ include_base = '/'.join(include_parts)
header_files = [
'cstddef',
'rosidl_runtime_c/service_type_support_struct.h',
'rosidl_typesupport_cpp/service_type_support.hpp',
include_base + '__struct.hpp',
]
if len(type_supports) != 1:
header_files.append('rosidl_typesupport_cpp/identifier.hpp')
header_files.append('rosidl_typesupport_cpp/service_type_support.hpp')
if len(type_supports) != 1:
header_files += [
'rosidl_typesupport_c/type_support_map.h',
Expand Down Expand Up @@ -76,7 +84,6 @@ typedef struct _@(service.namespaced_type.name)_type_support_symbol_names_t
{
const char * symbol_name[@(len(type_supports))];
} _@(service.namespaced_type.name)_type_support_symbol_names_t;

#define STRINGIFY_(s) #s
#define STRINGIFY(s) STRINGIFY_(s)

Expand Down Expand Up @@ -113,6 +120,9 @@ static const rosidl_service_type_support_t @(service.namespaced_type.name)_servi
::rosidl_typesupport_cpp::typesupport_identifier,
reinterpret_cast<const type_support_map_t *>(&_@(service.namespaced_type.name)_service_typesupport_map),
::rosidl_typesupport_cpp::get_service_typesupport_handle_function,
&::rosidl_typesupport_cpp::service_create_event_message<@('::'.join([package_name, *interface_path.parents[0].parts, service.namespaced_type.name]))>,
&::rosidl_typesupport_cpp::service_destroy_event_message<@('::'.join([package_name, *interface_path.parents[0].parts, service.namespaced_type.name]))>,
::rosidl_typesupport_cpp::get_message_type_support_handle<@('::'.join([package_name, *interface_path.parents[0].parts, service.namespaced_type.name]))_Event>(),
};

} // namespace rosidl_typesupport_cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rosidl_message_type_support_t get_rosidl_message_type_support(const char * ident

rosidl_service_type_support_t get_rosidl_service_type_support(const char * identifier)
{
return {identifier, nullptr, nullptr};
return {identifier, nullptr, nullptr, nullptr, nullptr, nullptr};
}

type_support_map_t get_typesupport_map(void ** library_array)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ constexpr const char * symbols[map_size] = {

rosidl_service_type_support_t get_rosidl_service_type_support(const char * identifier)
{
return {identifier, nullptr, nullptr};
return {identifier, nullptr, nullptr, nullptr, nullptr, nullptr};
}

type_support_map_t get_typesupport_map(void ** library_array)
Expand Down
4 changes: 2 additions & 2 deletions rosidl_typesupport_cpp/test/test_type_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const rosidl_service_type_support_t * test_service_type_support();
#endif

static const rosidl_message_type_support_t message_type_support = {
0, 0, 0
nullptr, nullptr, nullptr
};

static const rosidl_service_type_support_t service_type_support = {
0, 0, 0
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
};

const rosidl_message_type_support_t * test_message_type_support() {return &message_type_support;}
Expand Down
43 changes: 43 additions & 0 deletions rosidl_typesupport_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.8)
project(rosidl_typesupport_tests)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(rosidl_cmake REQUIRED)
find_package(ament_cmake_gtest REQUIRED)
find_package(test_interface_files REQUIRED)
find_package(rcutils REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
${test_interface_files_MSG_FILES}
${test_interface_files_SRV_FILES}
${test_interface_files_ACTION_FILES}
SKIP_INSTALL
)

rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
rosidl_get_typesupport_target(c_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_c")

ament_add_gtest(test_service_typesupport_cpp
test/rosidl_typesupport_cpp/test_service_typesupport.cpp
)
target_link_libraries(test_service_typesupport_cpp
"${cpp_typesupport_target}"
)

ament_add_gtest(test_service_typesupport_c
test/rosidl_typesupport_c/test_service_typesupport.cpp
)
target_link_libraries(test_service_typesupport_c
"${c_typesupport_target}"
)
endif()

ament_package()
27 changes: 27 additions & 0 deletions rosidl_typesupport_tests/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rosidl_typesupport_tests</name>
<version>2.2.0</version>
<description>Test rosidl_typesupport_c and rosidl_typesupport_cpp packages</description>
<maintainer email="[email protected]">Jacob Perron</maintainer>
<license>Apache License 2.0</license>
<author email="[email protected]">Brian Chen</author>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>rcutils</test_depend>
<test_depend>rosidl_cmake</test_depend>
<test_depend>rosidl_typesupport_c</test_depend>
<test_depend>rosidl_typesupport_cpp</test_depend>
<test_depend>test_interface_files</test_depend>
<test_depend>service_msgs</test_depend>
<test_depend>action_msgs</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading

0 comments on commit 0d4a26b

Please sign in to comment.