.. _program_listing_file__tmp_ws_src_examples_rclcpp_wait_set_include_wait_set_random_listener.hpp: Program Listing for File random_listener.hpp ============================================ |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/examples/rclcpp/wait_set/include/wait_set/random_listener.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2021, Apex.AI 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 WAIT_SET__RANDOM_LISTENER_HPP_ #define WAIT_SET__RANDOM_LISTENER_HPP_ #include #include #include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" class RandomListener : public rclcpp::Node { using subscription_list = std::vector::SharedPtr>; public: RandomListener() : Node("random_listener") { auto print_msg = [this](std_msgs::msg::String::UniquePtr msg) { RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str()); }; sub1_ = this->create_subscription("topicA", 10, print_msg); sub2_ = this->create_subscription("topicB", 10, print_msg); sub3_ = this->create_subscription("topicC", 10, print_msg); } subscription_list get_subscriptions() const { return {sub1_, sub2_, sub3_}; } private: rclcpp::Subscription::SharedPtr sub1_; rclcpp::Subscription::SharedPtr sub2_; rclcpp::Subscription::SharedPtr sub3_; }; #endif // WAIT_SET__RANDOM_LISTENER_HPP_