Skip to content

Commit

Permalink
Hardcoded typesupport for Fibonacci action (ros2/rcl_interfaces#47)
Browse files Browse the repository at this point in the history
* msg and srv in actions folder

* Add uniquely named messages and services

* Add hand made action typesupport

* respose -> result request

* respose -> response

* Use goal info in more places

* Fix feedback symbol

* Generate from .action file

* Hardcoded typesupport works with generated msg and srv

* C typesupport returns rcl_action_type_support_t

* Function to get typsupport struct from C++ typesupport

* rosidl_typesupport_cpp namespace

* Fix include guard

* Fix linter test failures

* Fix dll linkage on Windows

* Fix windows linking issue by having separate visibility macro
  • Loading branch information
sloretz authored Nov 9, 2018
1 parent 860ec4f commit 18bedba
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 1 deletion.
48 changes: 47 additions & 1 deletion test_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.5)

project(test_msgs)

# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
Expand All @@ -12,6 +17,7 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(action_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

set(msg_files
Expand All @@ -34,18 +40,58 @@ set(srv_files
"srv/Primitives.srv"
)

set(action_files
"action/Fibonacci.action"
)

rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
${srv_files}
DEPENDENCIES builtin_interfaces
${action_files}
DEPENDENCIES builtin_interfaces action_msgs
ADD_LINTER_TESTS
)

add_library(test_msgs_hardcoded_typesupport SHARED
src/fibonacci__typesupport.cpp
src/fibonacci__typesupport.c)
add_dependencies(test_msgs_hardcoded_typesupport
${PROJECT_NAME}
)
target_link_libraries(test_msgs_hardcoded_typesupport
${_AMENT_EXPORT_LIBRARIES})
target_include_directories(test_msgs_hardcoded_typesupport PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c
${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c
${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_cpp
${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp
include
)
# Separate visibility macro because this is a separate library from one created
# by rosidl_generator_c for messages and services
target_compile_definitions(test_msgs_hardcoded_typesupport
PRIVATE "ROSIDL_GENERATOR_C_BUILDING_DLL_test_msgs_ACTION")

ament_target_dependencies(test_msgs_hardcoded_typesupport
"rosidl_generator_c"
"rosidl_typesupport_c"
"rosidl_generator_cpp"
"action_msgs"
)

ament_export_libraries(test_msgs_hardcoded_typesupport)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

install(
TARGETS test_msgs_hardcoded_typesupport
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

if(DEFINED PYTHON_INSTALL_DIR)
install(DIRECTORY src/test_msgs
DESTINATION "${PYTHON_INSTALL_DIR}/")
Expand Down
8 changes: 8 additions & 0 deletions test_msgs/action/Fibonacci.action
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#goal definition
int32 order
---
#result definition
int32[] sequence
---
#feedback
int32[] sequence
37 changes: 37 additions & 0 deletions test_msgs/include/test_msgs/action/fibonacci.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// TODO(sloretz) generated code should not contain a copyright notice

#ifndef TEST_MSGS__ACTION__FIBONACCI_H_
#define TEST_MSGS__ACTION__FIBONACCI_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <action_msgs/msg/goal_info.h>
#include <action_msgs/msg/goal_status_array.h>
#include <action_msgs/srv/cancel_goal.h>
#include <test_msgs/action/fibonacci__feedback.h>
#include <test_msgs/action/fibonacci__goal.h>
#include <test_msgs/action/fibonacci__result.h>
#include "test_msgs/action/fibonacci__type_support.h"

#ifdef __cplusplus
}
#endif

#endif // TEST_MSGS__ACTION__FIBONACCI_H_
27 changes: 27 additions & 0 deletions test_msgs/include/test_msgs/action/fibonacci.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef TEST_MSGS__ACTION__FIBONACCI_HPP_
#define TEST_MSGS__ACTION__FIBONACCI_HPP_

#include <action_msgs/msg/goal_info.hpp>
#include <action_msgs/msg/goal_status_array.hpp>
#include <action_msgs/srv/cancel_goal.hpp>
#include <test_msgs/action/fibonacci__goal.hpp>
#include <test_msgs/action/fibonacci__result.hpp>
#include <test_msgs/action/fibonacci__feedback.hpp>
#include <test_msgs/action/fibonacci__struct.hpp>
#include "rosidl_generator_c/action_type_support_struct.h"

#endif // TEST_MSGS__ACTION__FIBONACCI_HPP_
49 changes: 49 additions & 0 deletions test_msgs/include/test_msgs/action/fibonacci__struct.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// TODO(sloretz) generated code should not contain a copyright notice

#ifndef TEST_MSGS__ACTION__FIBONACCI__STRUCT_HPP_
#define TEST_MSGS__ACTION__FIBONACCI__STRUCT_HPP_

#include <action_msgs/msg/goal_info.hpp>
#include <action_msgs/msg/goal_status_array.hpp>
#include <action_msgs/srv/cancel_goal.hpp>
#include <test_msgs/action/fibonacci__goal.hpp>
#include <test_msgs/action/fibonacci__result.hpp>
#include <test_msgs/action/fibonacci__feedback.hpp>

namespace test_msgs
{
namespace action
{
struct Fibonacci
{
// Typedefs handy for rcl and rclcpp
using CancelGoalService = action_msgs::srv::CancelGoal;
using GoalStatusMessage = action_msgs::msg::GoalStatusArray;
using GoalRequestService = test_msgs::action::Fibonacci_Goal;
using GoalResultService = test_msgs::action::Fibonacci_Result;

// Typedefs handy for user
using Goal = GoalRequestService::Request;
using Result = GoalResultService::Response;
using Feedback = test_msgs::action::Fibonacci_Feedback;
};

typedef struct Fibonacci Fibonacci;
} // namespace action
} // namespace test_msgs

#endif // TEST_MSGS__ACTION__FIBONACCI__STRUCT_HPP_
42 changes: 42 additions & 0 deletions test_msgs/include/test_msgs/action/fibonacci__type_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// TODO(sloretz) generated code should not contain a copyright notice

#ifndef TEST_MSGS__ACTION__FIBONACCI__TYPE_SUPPORT_H_
#define TEST_MSGS__ACTION__FIBONACCI__TYPE_SUPPORT_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "rosidl_generator_c/action_type_support_struct.h"
#include "rosidl_typesupport_interface/macros.h"

#include "test_msgs/action/rosidl_generator_c__visibility_control.h"

/* *INDENT-OFF* */
// Forward declare the get type support functions for this type.
ROSIDL_GENERATOR_C_PUBLIC_test_msgs_ACTION
const rosidl_action_type_support_t *
ROSIDL_TYPESUPPORT_INTERFACE__ACTION_SYMBOL_NAME(
rosidl_typesupport_c, test_msgs, action, Fibonacci)();
/* *INDENT-ON* */

#ifdef __cplusplus
}
#endif

#endif // TEST_MSGS__ACTION__FIBONACCI__TYPE_SUPPORT_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// TODO(sloretz) generated code should not contain a copyright notice

#ifndef TEST_MSGS__ACTION__ROSIDL_GENERATOR_C__VISIBILITY_CONTROL_H_
#define TEST_MSGS__ACTION__ROSIDL_GENERATOR_C__VISIBILITY_CONTROL_H_

#ifdef __cplusplus
extern "C"
{
#endif

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define ROSIDL_GENERATOR_C_EXPORT_test_msgs_ACTION __attribute__ ((dllexport))
#define ROSIDL_GENERATOR_C_IMPORT_test_msgs_ACTION __attribute__ ((dllimport))
#else
#define ROSIDL_GENERATOR_C_EXPORT_test_msgs_ACTION __declspec(dllexport)
#define ROSIDL_GENERATOR_C_IMPORT_test_msgs_ACTION __declspec(dllimport)
#endif
#ifdef ROSIDL_GENERATOR_C_BUILDING_DLL_test_msgs_ACTION
#define ROSIDL_GENERATOR_C_PUBLIC_test_msgs_ACTION ROSIDL_GENERATOR_C_EXPORT_test_msgs_ACTION
#else
#define ROSIDL_GENERATOR_C_PUBLIC_test_msgs_ACTION ROSIDL_GENERATOR_C_IMPORT_test_msgs_ACTION
#endif
#else
#define ROSIDL_GENERATOR_C_EXPORT_test_msgs_ACTION __attribute__ ((visibility("default")))
#define ROSIDL_GENERATOR_C_IMPORT_test_msgs_ACTION
#if __GNUC__ >= 4
#define ROSIDL_GENERATOR_C_PUBLIC_test_msgs_ACTION __attribute__ ((visibility("default")))
#else
#define ROSIDL_GENERATOR_C_PUBLIC_test_msgs_ACTION
#endif
#endif

#ifdef __cplusplus
}
#endif

#endif // TEST_MSGS__ACTION__ROSIDL_GENERATOR_C__VISIBILITY_CONTROL_H_
1 change: 1 addition & 0 deletions test_msgs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<build_depend>builtin_interfaces</build_depend>

<depend>action_msgs</depend>
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>

Expand Down
51 changes: 51 additions & 0 deletions test_msgs/src/fibonacci__typesupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <action_msgs/msg/goal_info.h>
#include <action_msgs/msg/goal_status_array.h>
#include <action_msgs/srv/cancel_goal.h>
#include <rosidl_generator_c/action_type_support_struct.h>
#include <test_msgs/action/fibonacci__goal.h>
#include <test_msgs/action/fibonacci__result.h>
#include <test_msgs/action/fibonacci__feedback.h>

#include "test_msgs/action/fibonacci__type_support.h"
#include "test_msgs/msg/rosidl_generator_c__visibility_control.h"


static rosidl_action_type_support_t _test_msgs__action__Fibonacci__typesupport_c;

const rosidl_action_type_support_t *
ROSIDL_TYPESUPPORT_INTERFACE__ACTION_SYMBOL_NAME(
rosidl_typesupport_c, test_msgs, action, Fibonacci)()
{
// Thread-safe by always writing the same values to the static struct
_test_msgs__action__Fibonacci__typesupport_c.goal_service_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_c, test_msgs, action, Fibonacci_Goal)();
_test_msgs__action__Fibonacci__typesupport_c.result_service_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_c, test_msgs, action, Fibonacci_Result)();
_test_msgs__action__Fibonacci__typesupport_c.cancel_service_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_c, action_msgs, srv, CancelGoal)();
_test_msgs__action__Fibonacci__typesupport_c.feedback_message_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(
rosidl_typesupport_c, test_msgs, action, Fibonacci_Feedback)();
_test_msgs__action__Fibonacci__typesupport_c.status_message_type_support =
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(
rosidl_typesupport_c, action_msgs, msg, GoalStatusArray)();

return &_test_msgs__action__Fibonacci__typesupport_c;
}
Loading

0 comments on commit 18bedba

Please sign in to comment.