diff --git a/rclcpp/CMakeLists.txt b/rclcpp/CMakeLists.txt index 6dd03e2..4ec6c3d 100644 --- a/rclcpp/CMakeLists.txt +++ b/rclcpp/CMakeLists.txt @@ -8,9 +8,16 @@ ament_export_dependencies(ros_middleware_interface) ament_export_include_directories(include) -ament_package() +ament_package( + CONFIG_EXTRAS rclcpp-extras.cmake +) install( DIRECTORY include/ DESTINATION include ) + +install( + DIRECTORY src/ + DESTINATION src/rclcpp +) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index e19f338..7b69631 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -112,6 +112,12 @@ private: } /* namespace node */ } /* namespace rclcpp */ +#define RCLCPP_REGISTER_NODE(Class) rclcpp::node::Node::SharedPtr \ +create_node() \ +{ \ + return rclcpp::node::Node::SharedPtr(new Class(rclcpp::contexts::default_context::DefaultContext::make_shared())); \ +} + #ifndef RCLCPP_RCLCPP_NODE_IMPL_HPP_ // Template implementations #include "node_impl.hpp" diff --git a/rclcpp/include/rclcpp/rclcpp.hpp b/rclcpp/include/rclcpp/rclcpp.hpp index 97b41bf..72ca557 100644 --- a/rclcpp/include/rclcpp/rclcpp.hpp +++ b/rclcpp/include/rclcpp/rclcpp.hpp @@ -53,6 +53,10 @@ using rclcpp::subscription::SubscriptionBase; using rclcpp::subscription::Subscription; using rclcpp::rate::GenericRate; using rclcpp::rate::WallRate; +using rclcpp::timer::GenericTimer; +using rclcpp::timer::TimerBase; +using rclcpp::timer::WallTimer; +typedef rclcpp::context::Context::SharedPtr ContextSharedPtr; using rclcpp::utilities::ok; using rclcpp::utilities::init; using rclcpp::utilities::sleep_for; diff --git a/rclcpp/rclcpp-extras.cmake b/rclcpp/rclcpp-extras.cmake new file mode 100644 index 0000000..8eab569 --- /dev/null +++ b/rclcpp/rclcpp-extras.cmake @@ -0,0 +1,13 @@ +# copied from rclcpp/rclcpp-extras.cmake + +set(rclcpp_node_main_SRC "${rclcpp_DIR}/../../../src/rclcpp/node_main.cpp") + +function(rclcpp_create_node_main node_library_target) + if(NOT TARGET ${node_library_target}) + message(FATAL_ERROR "rclcpp_create_node_main() the first argument must be a valid target name") + endif() + set(executable_name_ ${node_library_target}_node) + add_executable(${executable_name_} ${rclcpp_node_main_SRC}) + target_link_libraries(${executable_name_} ${node_library_target}) + install(TARGETS ${executable_name_} DESTINATION bin) +endfunction() diff --git a/rclcpp/src/node_main.cpp b/rclcpp/src/node_main.cpp new file mode 100644 index 0000000..510b1bf --- /dev/null +++ b/rclcpp/src/node_main.cpp @@ -0,0 +1,29 @@ +/* Copyright 2014 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 + +// This forward declaration is implemented by the RCLCPP_REGISTER_NODE macro +rclcpp::Node::SharedPtr create_node(); + +int main(int argc, char **argv) +{ + rclcpp::init(argc, argv); + rclcpp::executors::SingleThreadedExecutor executor; + rclcpp::Node::SharedPtr node = create_node(); + executor.add_node(node); + executor.spin(); + return 0; +}