diff --git a/rclcpp_action/CMakeLists.txt b/rclcpp_action/CMakeLists.txt new file mode 100644 index 0000000..cb5c8c1 --- /dev/null +++ b/rclcpp_action/CMakeLists.txt @@ -0,0 +1,91 @@ +cmake_minimum_required(VERSION 3.5) + +project(rclcpp_action) + +find_package(ament_cmake_ros REQUIRED) +find_package(action_msgs REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rcl_action REQUIRED) +find_package(rosidl_generator_cpp REQUIRED) + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +include_directories(include) + +set(${PROJECT_NAME}_SRCS + src/client.cpp + src/server.cpp + src/server_goal_handle.cpp +) + +add_library(${PROJECT_NAME} + ${${PROJECT_NAME}_SRCS}) + +ament_target_dependencies(${PROJECT_NAME} + "action_msgs" + "rcl_action" + "rclcpp" + "rosidl_generator_c" + "rosidl_generator_cpp") + +# Causes the visibility macros to use dllexport rather than dllimport, +# which is appropriate when building the dll but not consuming it. +target_compile_definitions(${PROJECT_NAME} + PRIVATE "RCLCPP_ACTION_BUILDING_LIBRARY") + +install( + DIRECTORY include/ + DESTINATION include) + +install( + TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +# specific order: dependents before dependencies +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}) + +ament_export_dependencies(ament_cmake) +ament_export_dependencies(action_msgs) +ament_export_dependencies(rclcpp) +ament_export_dependencies(rcl_action) +ament_export_dependencies(rosidl_generator_c) +ament_export_dependencies(rosidl_generator_cpp) + +if(BUILD_TESTING) + find_package(ament_cmake_gtest REQUIRED) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() + + ament_add_gtest(test_client test/test_client.cpp) + if(TARGET test_client) + ament_target_dependencies(test_client + "test_msgs" + ) + target_link_libraries(test_client + ${PROJECT_NAME} + ) + endif() + + ament_add_gtest(test_server test/test_server.cpp) + if(TARGET test_server) + ament_target_dependencies(test_server + "test_msgs" + ) + target_link_libraries(test_server + ${PROJECT_NAME} + ) + endif() + +endif() + +ament_package() diff --git a/rclcpp_action/include/rclcpp_action/client.hpp b/rclcpp_action/include/rclcpp_action/client.hpp new file mode 100644 index 0000000..8a227f0 --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/client.hpp @@ -0,0 +1,99 @@ +// 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 RCLCPP_ACTION__CLIENT_HPP_ +#define RCLCPP_ACTION__CLIENT_HPP_ + + +#include +#include +#include +#include + +#include +#include +#include + +#include "rclcpp_action/client_goal_handle.hpp" +#include "rclcpp_action/visibility_control.hpp" + + +namespace rclcpp_action +{ +// Forward declaration +class ClientBaseImpl; + +/// Base Action Client implementation +/// It is responsible for interfacing with the C action client API. +class ClientBase +{ +public: + // TODO(sloretz) NodeLoggingInterface when it can be gotten off a node + RCLCPP_ACTION_PUBLIC + ClientBase( + rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, + const std::string & name, + const rosidl_action_type_support_t * type_support); + + RCLCPP_ACTION_PUBLIC + virtual ~ClientBase(); + + // TODO(sloretz) add a link between this class and callbacks in the templated + +private: + std::unique_ptr pimpl_; +}; + + +/// Templated Action Client class +/// It is responsible for getting the C action type support struct from the C++ type, and +/// calling user callbacks with goal handles of the appropriate type. +template +class Client : public ClientBase +{ +public: + RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Client) + + using FeedbackCallback = std::function>, const typename ACTION::Feedback)>; + + Client( + rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, + const std::string & name + ) + : ClientBase( + node_base, + name, + rosidl_typesupport_cpp::get_action_type_support_handle()) + { + // TODO(sloretz) what's the link that causes a feedback topic to be called ? + } + + ClientGoalHandle + async_send_goal(typename ACTION::Goal * goal, FeedbackCallback callback = nullptr); + + RCLCPP_ACTION_PUBLIC + std::future + async_cancel_all_goals(); + + RCLCPP_ACTION_PUBLIC + std::future + async_cancel_goals_before(rclcpp::Time); + + virtual ~Client() + { + } +}; +} // namespace rclcpp_action +#endif // RCLCPP_ACTION__CLIENT_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp b/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp new file mode 100644 index 0000000..87a663c --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp @@ -0,0 +1,57 @@ +// 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 RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_ +#define RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_ + +#include + +#include +#include + +#include "rclcpp_action/visibility_control.hpp" + +namespace rclcpp_action +{ +// Forward declarations +template +class Client; + +template +class ClientGoalHandle +{ +public: + virtual ~ClientGoalHandle(); + + /// TODO(sloretz) examples have this on client as `async_cancel_goal(goal_handle)` + std::future + async_cancel(); + + std::future + async_result(); + +private: + // The templated Server creates goal handles + friend Client; + + ClientGoalHandle(rcl_action_client_t * rcl_client, const rcl_action_goal_info_t rcl_info); + + // TODO(sloretz) shared pointer to keep rcl_client_ alive while goal handles are alive + rcl_action_client_t * rcl_client_; + rcl_action_goal_info_t rcl_info_; +}; +} // namespace rclcpp_action + +#include // NOLINT(build/include_order) +#endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/client_goal_handle_impl.hpp b/rclcpp_action/include/rclcpp_action/client_goal_handle_impl.hpp new file mode 100644 index 0000000..cd2bf1a --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/client_goal_handle_impl.hpp @@ -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. + +#ifndef RCLCPP_ACTION__CLIENT_GOAL_HANDLE_IMPL_HPP_ +#define RCLCPP_ACTION__CLIENT_GOAL_HANDLE_IMPL_HPP_ + +#include + +namespace rclcpp_action +{ +template +ClientGoalHandle::ClientGoalHandle( + rcl_action_client_t * rcl_client, + const rcl_action_goal_info_t rcl_info +) +: rcl_client_(rcl_client), rcl_info_(rcl_info) +{ +} + +template +ClientGoalHandle::~ClientGoalHandle() +{ +} + +template +std::future +ClientGoalHandle::async_cancel() +{ + throw std::runtime_error("Failed to cancel goal"); +} + +template +std::future +ClientGoalHandle::async_result() +{ + throw std::runtime_error("Failed to get result future"); +} +} // namespace rclcpp_action + +#endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_IMPL_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/create_client.hpp b/rclcpp_action/include/rclcpp_action/create_client.hpp new file mode 100644 index 0000000..8f6381c --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/create_client.hpp @@ -0,0 +1,40 @@ +// 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 RCLCPP_ACTION__CREATE_CLIENT_HPP_ +#define RCLCPP_ACTION__CREATE_CLIENT_HPP_ + +#include + +#include +#include + +#include "rclcpp_action/client.hpp" +#include "rclcpp_action/visibility_control.hpp" + +namespace rclcpp_action +{ +template +typename Client::SharedPtr +create_client( + rclcpp::Node * node, + const std::string & name) +{ + return Client::make_shared( + node->get_node_base_interface(), + name); +} +} // namespace rclcpp_action +#endif // RCLCPP_ACTION__CREATE_CLIENT_HPP_ +// TODO(sloretz) rclcpp_action::create_client<>(node, action_name); diff --git a/rclcpp_action/include/rclcpp_action/create_server.hpp b/rclcpp_action/include/rclcpp_action/create_server.hpp new file mode 100644 index 0000000..50ad292 --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/create_server.hpp @@ -0,0 +1,43 @@ +// 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 RCLCPP_ACTION__CREATE_SERVER_HPP_ +#define RCLCPP_ACTION__CREATE_SERVER_HPP_ + +#include + +#include +#include + +#include "rclcpp_action/server.hpp" +#include "rclcpp_action/visibility_control.hpp" + +namespace rclcpp_action +{ +template +typename Server::SharedPtr +create_server( + rclcpp::Node * node, + const std::string & name, + typename Server::GoalCallback handle_goal, + typename Server::CancelCallback handle_cancel) +{ + return Server::make_shared( + node->get_node_base_interface(), + name, + handle_goal, + handle_cancel); +} +} // namespace rclcpp_action +#endif // RCLCPP_ACTION__CREATE_SERVER_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/rclcpp_action.hpp b/rclcpp_action/include/rclcpp_action/rclcpp_action.hpp new file mode 100644 index 0000000..8ee34c6 --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/rclcpp_action.hpp @@ -0,0 +1,39 @@ +// 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. + +/** \mainpage rclcpp_action: ROS Action Client Library for C++ + * + * `rclcpp_action` provides the canonical C++ API for interacting with ROS Actions. + * It consists of these main components: + * + * - TODO(jacobperron): Finish docs + * - Action Client + * - Action Server + */ + +#ifndef RCLCPP_ACTION__RCLCPP_ACTION_HPP_ +#define RCLCPP_ACTION__RCLCPP_ACTION_HPP_ + +#include +#include + +#include "rclcpp_action/client.hpp" +#include "rclcpp_action/client_goal_handle.hpp" +#include "rclcpp_action/create_client.hpp" +#include "rclcpp_action/create_server.hpp" +#include "rclcpp_action/server.hpp" +#include "rclcpp_action/server_goal_handle.hpp" +#include "rclcpp_action/visibility_control.hpp" + +#endif // RCLCPP_ACTION__RCLCPP_ACTION_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/server.hpp b/rclcpp_action/include/rclcpp_action/server.hpp new file mode 100644 index 0000000..fefa1c5 --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/server.hpp @@ -0,0 +1,95 @@ +// 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 RCLCPP_ACTION__SERVER_HPP_ +#define RCLCPP_ACTION__SERVER_HPP_ + +#include +#include +#include + +#include +#include +#include + +#include "rclcpp_action/visibility_control.hpp" +#include "rclcpp_action/server_goal_handle.hpp" + +namespace rclcpp_action +{ +// Forward declaration +class ServerBaseImpl; + +/// Base Action Server implementation +/// It is responsible for interfacing with the C action server API. +class ServerBase +{ +public: + // TODO(sloretz) NodeLoggingInterface when it can be gotten off a node + // TODO(sloretz) accept clock instance + RCLCPP_ACTION_PUBLIC + ServerBase( + rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, + const std::string & name, + const rosidl_action_type_support_t * type_support); + + RCLCPP_ACTION_PUBLIC + virtual ~ServerBase(); + + // TODO(sloretz) add a link between this class and callbacks in the server class + +private: + std::unique_ptr pimpl_; +}; + + +/// Templated Action Server class +/// It is responsible for getting the C action type support struct from the C++ type, and +/// calling user callbacks with goal handles of the appropriate type. +template +class Server : public ServerBase +{ +public: + RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Server) + + using GoalCallback = std::function; + using CancelCallback = std::function>)>; + + // TODO(sloretz) accept clock instance + Server( + rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, + const std::string & name, + GoalCallback handle_goal, + CancelCallback handle_cancel + ) + : ServerBase( + node_base, + name, + rosidl_typesupport_cpp::get_action_type_support_handle()), + handle_goal_(handle_goal), + handle_cancel_(handle_cancel) + { + // TODO(sloretz) what's the link that causes `handle_goal_` and `handle_cancel_` to be called? + } + + virtual ~Server() + { + } + +private: + GoalCallback handle_goal_; + CancelCallback handle_cancel_; +}; +} // namespace rclcpp_action +#endif // RCLCPP_ACTION__SERVER_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp b/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp new file mode 100644 index 0000000..e2ee1cb --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp @@ -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. + +#ifndef RCLCPP_ACTION__SERVER_GOAL_HANDLE_HPP_ +#define RCLCPP_ACTION__SERVER_GOAL_HANDLE_HPP_ + +#include + +#include +#include + +#include "rclcpp_action/visibility_control.hpp" + +namespace rclcpp_action +{ +template +class ServerGoalHandle +{ +public: + virtual ~ServerGoalHandle(); + + /// Indicate if client has requested this goal be cancelled. + /// \return true if a cancelation request has been accepted for this goal. + virtual bool + is_cancel_request() const = 0; + + /// Send an update about the progress of a goal. + virtual void + publish_feedback(const typename ACTION::Feedback * feedback_msg) = 0; + + // TODO(sloretz) `set_cancelled`, `set_succeeded`, `set_aborted` + + // TODO(sloretz) examples has this attribute as 'goal' + /// The original request message describing the goal. + const typename ACTION::Goal goal_; + +protected: + explicit ServerGoalHandle(const typename ACTION::Goal goal) + : goal_(goal) {} +}; +} // namespace rclcpp_action + +#include // NOLINT(build/include_order) +#endif // RCLCPP_ACTION__SERVER_GOAL_HANDLE_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/server_goal_handle_impl.hpp b/rclcpp_action/include/rclcpp_action/server_goal_handle_impl.hpp new file mode 100644 index 0000000..132de08 --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/server_goal_handle_impl.hpp @@ -0,0 +1,76 @@ +// 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 RCLCPP_ACTION__SERVER_GOAL_HANDLE_IMPL_HPP_ +#define RCLCPP_ACTION__SERVER_GOAL_HANDLE_IMPL_HPP_ + +#include +#include + +#include + +namespace rclcpp_action +{ +template +class Server; + +template +class ServerGoalHandleImpl : public ServerGoalHandle +{ +public: + virtual ~ServerGoalHandleImpl() + { + } + + bool + is_cancel_request() const override + { + rcl_action_goal_state_t state = GOAL_STATE_UNKNOWN; + if (RCL_RET_OK != rcl_action_goal_handle_get_status(rcl_handle_.get(), &state)) { + // TODO(sloretz) more specific exception + throw std::runtime_error("Failed to get goal handle state"); + } + return GOAL_STATE_CANCELING == state; + } + + void + publish_feedback(const typename ACTION::Feedback * feedback_msg) override + { + (void)feedback_msg; + // TODO(sloretz) what is ros_message and how does IntraProcessmessage come into play? + // if (RCL_RET_OK != rcl_action_publish_feedback(rcl_server_, ros_message) { + // // TODO(sloretz) more specific exception + // throw std::runtime_error("Failed to publish feedback"); + // } + throw std::runtime_error("Failed to publish feedback"); + } + +protected: + ServerGoalHandleImpl( + rcl_action_server_t * rcl_server, + const typename ACTION::Goal goal, + rcl_action_goal_handle_t * rcl_handle + ) + : rcl_server_(rcl_server), rcl_handle_(rcl_handle), ServerGoalHandle(goal) + { + } + +private: + friend Server; + std::shared_ptr rcl_server_; + std::shared_ptr rcl_handle_; +}; +} // namespace rclcpp_action + +#endif // RCLCPP_ACTION__SERVER_GOAL_HANDLE_IMPL_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/visibility_control.hpp b/rclcpp_action/include/rclcpp_action/visibility_control.hpp new file mode 100644 index 0000000..32b03dd --- /dev/null +++ b/rclcpp_action/include/rclcpp_action/visibility_control.hpp @@ -0,0 +1,56 @@ +// 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. + +/* This header must be included by all rclcpp headers which declare symbols + * which are defined in the rclcpp library. When not building the rclcpp + * library, i.e. when using the headers in other package's code, the contents + * of this header change the visibility of certain symbols which the rclcpp + * library cannot have, but the consuming code must have inorder to link. + */ + +#ifndef RCLCPP_ACTION__VISIBILITY_CONTROL_HPP_ +#define RCLCPP_ACTION__VISIBILITY_CONTROL_HPP_ + +// 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 RCLCPP_ACTION_EXPORT __attribute__ ((dllexport)) + #define RCLCPP_ACTION_IMPORT __attribute__ ((dllimport)) + #else + #define RCLCPP_ACTION_EXPORT __declspec(dllexport) + #define RCLCPP_ACTION_IMPORT __declspec(dllimport) + #endif + #ifdef RCLCPP_ACTION_BUILDING_LIBRARY + #define RCLCPP_ACTION_PUBLIC RCLCPP_ACTION_EXPORT + #else + #define RCLCPP_ACTION_PUBLIC RCLCPP_ACTION_IMPORT + #endif + #define RCLCPP_ACTION_PUBLIC_TYPE RCLCPP_ACTION_PUBLIC + #define RCLCPP_ACTION_LOCAL +#else + #define RCLCPP_ACTION_EXPORT __attribute__ ((visibility("default"))) + #define RCLCPP_ACTION_IMPORT + #if __GNUC__ >= 4 + #define RCLCPP_ACTION_PUBLIC __attribute__ ((visibility("default"))) + #define RCLCPP_ACTION_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define RCLCPP_ACTION_PUBLIC + #define RCLCPP_ACTION_LOCAL + #endif + #define RCLCPP_ACTION_PUBLIC_TYPE +#endif + +#endif // RCLCPP_ACTION__VISIBILITY_CONTROL_HPP_ diff --git a/rclcpp_action/package.xml b/rclcpp_action/package.xml new file mode 100644 index 0000000..eafa8a7 --- /dev/null +++ b/rclcpp_action/package.xml @@ -0,0 +1,32 @@ + + + + rclcpp_action + 0.5.1 + Adds action APIs for C++. + Dirk Thomas + Apache License 2.0 + + ament_cmake_ros + + rosidl_generator_cpp + rosidl_generator_c + + rosidl_generator_c + rosidl_generator_cpp + + action_msgs + rclcpp + rcl_action + + ament_cmake + + ament_cmake_gtest + ament_lint_auto + ament_lint_common + test_msgs + + + ament_cmake + + diff --git a/rclcpp_action/src/client.cpp b/rclcpp_action/src/client.cpp new file mode 100644 index 0000000..a094e63 --- /dev/null +++ b/rclcpp_action/src/client.cpp @@ -0,0 +1,41 @@ +// 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 + +#include + +using rclcpp_action::ClientBase; + +namespace rclcpp_action +{ +class ClientBaseImpl +{ +}; +} + +ClientBase::ClientBase( + rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, + const std::string & name, + const rosidl_action_type_support_t * type_support) +{ + // TODO(sloretz) use rcl_action API when available + (void)node_base; + (void)name; + (void)type_support; +} + +ClientBase::~ClientBase() +{ +} diff --git a/rclcpp_action/src/server.cpp b/rclcpp_action/src/server.cpp new file mode 100644 index 0000000..bac9d21 --- /dev/null +++ b/rclcpp_action/src/server.cpp @@ -0,0 +1,41 @@ +// 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 + +#include + +using rclcpp_action::ServerBase; + +namespace rclcpp_action +{ +class ServerBaseImpl +{ +}; +} + +ServerBase::ServerBase( + rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, + const std::string & name, + const rosidl_action_type_support_t * type_support) +{ + // TODO(sloretz) use rcl_action API when available + (void)node_base; + (void)name; + (void)type_support; +} + +ServerBase::~ServerBase() +{ +} diff --git a/rclcpp_action/src/server_goal_handle.cpp b/rclcpp_action/src/server_goal_handle.cpp new file mode 100644 index 0000000..eae7f88 --- /dev/null +++ b/rclcpp_action/src/server_goal_handle.cpp @@ -0,0 +1,15 @@ +// 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 diff --git a/rclcpp_action/test/test_client.cpp b/rclcpp_action/test/test_client.cpp new file mode 100644 index 0000000..72cb792 --- /dev/null +++ b/rclcpp_action/test/test_client.cpp @@ -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. + +#include + +#include +#include +#include +#include + +#include + +#include "rclcpp_action/create_client.hpp" +#include "rclcpp_action/client.hpp" + +class TestClient : public ::testing::Test +{ +protected: + static void SetUpTestCase() + { + rclcpp::init(0, nullptr); + } +}; + +TEST_F(TestClient, construction_and_destruction) +{ + auto node = std::make_shared("my_node", "/rclcpp_action/test/client"); + + auto ac = rclcpp_action::create_client(node.get(), "fibonacci"); + (void)ac; +} diff --git a/rclcpp_action/test/test_server.cpp b/rclcpp_action/test/test_server.cpp new file mode 100644 index 0000000..b6dea88 --- /dev/null +++ b/rclcpp_action/test/test_server.cpp @@ -0,0 +1,46 @@ +// 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 +#include +#include +#include + +#include + +#include + +#include "rclcpp_action/create_server.hpp" +#include "rclcpp_action/server.hpp" + + +class TestServer : public ::testing::Test +{ +protected: + static void SetUpTestCase() + { + rclcpp::init(0, nullptr); + } +}; + +TEST_F(TestServer, construction_and_destruction) +{ + auto node = std::make_shared("my_node", "/rclcpp_action/test/server"); + + using GoalHandle = rclcpp_action::ServerGoalHandle; + auto as = rclcpp_action::create_server(node.get(), "fibonacci", + [](rcl_action_goal_info_t &, test_msgs::action::Fibonacci::Goal *) {}, + [](std::shared_ptr) {}); + (void)as; +}