Skip to content

Commit

Permalink
Static type support initial
Browse files Browse the repository at this point in the history
Signed-off-by: Your Name <[email protected]>

Default to OFF

Signed-off-by: Your Name <[email protected]>

Linter

Signed-off-by: Your Name <[email protected]>

Fix

Signed-off-by: Your Name <[email protected]>

Refactor

Reafactor

Signed-off-by: Your Name <[email protected]>

Lint

Signed-off-by: Your Name <[email protected]>
  • Loading branch information
pablogs9 authored and Your Name committed May 14, 2021
1 parent 3bd7d81 commit 897c820
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
20 changes: 17 additions & 3 deletions rosidl_typesupport_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.5)

project(rosidl_typesupport_c)

option(ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT "Enable static typesupport" OFF)

# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
Expand All @@ -16,13 +18,17 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

find_package(ament_cmake_ros REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rcutils REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
find_package(rcpputils REQUIRED)
endif()

ament_export_dependencies(rcpputils)
ament_export_dependencies(rosidl_runtime_c)
ament_export_dependencies(rosidl_typesupport_interface)
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
ament_export_dependencies(rcpputils)
endif()

ament_export_include_directories(include)

Expand All @@ -36,15 +42,23 @@ if(WIN32)
target_compile_definitions(${PROJECT_NAME}
PRIVATE "ROSIDL_TYPESUPPORT_C_BUILDING_DLL")
endif()
target_compile_definitions(${PROJECT_NAME}
PRIVATE
$<$<BOOL:${ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT}>:ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT>
)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

ament_target_dependencies(${PROJECT_NAME}
"rcpputils"
"rcutils"
"rosidl_runtime_c"
)
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
ament_target_dependencies(${PROJECT_NAME}
"rcpputils"
)
endif()
ament_export_libraries(${PROJECT_NAME})
ament_export_targets(${PROJECT_NAME})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ if(NOT typesupports MATCHES ";")
${rosidl_generate_interfaces_TARGET}__${typesupports})
else()
if("${rosidl_typesupport_c_LIBRARY_TYPE}" STREQUAL "STATIC")
message(FATAL_ERROR "Multiple typesupports [${typesupports}] but static "
"linking was requested")
target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix}
PRIVATE
ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
)
endif()
endif()

Expand All @@ -151,6 +153,7 @@ add_dependencies(
add_dependencies(
${rosidl_generate_interfaces_TARGET}${_target_suffix}
${rosidl_generate_interfaces_TARGET}__rosidl_generator_c
${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_c
)

if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
Expand Down
21 changes: 21 additions & 0 deletions rosidl_typesupport_c/resource/msg__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,34 @@ typedef struct _@(message.structure.namespaced_type.name)_type_support_data_t
void * data[@(len(type_supports))];
} _@(message.structure.namespaced_type.name)_type_support_data_t;

#ifdef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
#ifdef __cplusplus
extern "C"
{
#endif
@[for type_support in sorted(type_supports)]@
rosidl_message_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name))();
@[end for]@
#ifdef __cplusplus
}
#endif

static _@(message.structure.namespaced_type.name)_type_support_data_t _@(message.structure.namespaced_type.name)_message_typesupport_data = {
{
@[for type_support in sorted(type_supports)]@
(void*) ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name)),
@[end for]@
}
};
#else
static _@(message.structure.namespaced_type.name)_type_support_data_t _@(message.structure.namespaced_type.name)_message_typesupport_data = {
{
@[for type_support in sorted(type_supports)]@
0, // will store the shared library later
@[end for]@
}
};
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT

static const type_support_map_t _@(message.structure.namespaced_type.name)_message_typesupport_map = {
@(len(type_supports)),
Expand Down
21 changes: 21 additions & 0 deletions rosidl_typesupport_c/resource/srv__type_support.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,34 @@ typedef struct _@(service.namespaced_type.name)_type_support_data_t
void * data[@(len(type_supports))];
} _@(service.namespaced_type.name)_type_support_data_t;

#ifdef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
#ifdef __cplusplus
extern "C"
{
#endif
@[for type_support in sorted(type_supports)]@
rosidl_service_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name))();
@[end for]@
#ifdef __cplusplus
}
#endif

static _@(service.namespaced_type.name)_type_support_data_t _@(service.namespaced_type.name)_service_typesupport_data = {
{
@[for type_support in sorted(type_supports)]@
(void*) ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name)),
@[end for]@
}
};
#else
static _@(service.namespaced_type.name)_type_support_data_t _@(service.namespaced_type.name)_service_typesupport_data = {
{
@[for type_support in sorted(type_supports)]@
0, // will store the shared library later
@[end for]@
}
};
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT

static const type_support_map_t _@(service.namespaced_type.name)_service_typesupport_map = {
@(len(type_supports)),
Expand Down
12 changes: 10 additions & 2 deletions rosidl_typesupport_c/src/type_support_dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef TYPE_SUPPORT_DISPATCH_HPP_
#define TYPE_SUPPORT_DISPATCH_HPP_

#ifndef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT

#include <cstddef>
#include <cstdio>
#include <cstring>
Expand All @@ -24,6 +26,9 @@
#include <string>

#include "rcpputils/shared_library.hpp"

#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT

#include "rcutils/error_handling.h"
#include "rcutils/snprintf.h"
#include "rosidl_typesupport_c/identifier.h"
Expand All @@ -50,6 +55,8 @@ get_typesupport_handle_function(
if (strcmp(map->typesupport_identifier[i], identifier) != 0) {
continue;
}
typedef const TypeSupport * (* funcSignature)(void);
#ifndef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
rcpputils::SharedLibrary * lib = nullptr;

if (!map->data[i]) {
Expand Down Expand Up @@ -103,9 +110,10 @@ get_typesupport_handle_function(
map->symbol_name[i], e.what());
return nullptr;
}

typedef const TypeSupport * (* funcSignature)(void);
funcSignature func = reinterpret_cast<funcSignature>(sym);
#else
funcSignature func = reinterpret_cast<funcSignature>(map->data[i]);
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
const TypeSupport * ts = func();
return ts;
}
Expand Down

0 comments on commit 897c820

Please sign in to comment.