ATOS
roschannel.hpp
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 #pragma once
7 
8 #include <rclcpp/rclcpp.hpp>
9 #include <string>
10 #include <functional>
11 
12 namespace ROSChannels {
13 
14 template<typename T>
15 class BasePub {
16 public:
17  BasePub(rclcpp::Node& node,
18  const std::string& topicName,
19  const rclcpp::QoS& qos = rclcpp::QoS(rclcpp::KeepAll()))
20  : pub(node.create_publisher<T>(topicName, qos)) {}
21  BasePub() = delete;
22  typename rclcpp::Publisher<T>::SharedPtr pub;
23  inline virtual void publish(const T& msg) { assert(pub); pub->publish(msg); };
24 };
25 
26 template<typename T>
27 class BaseSub {
28 public:
29  BaseSub(rclcpp::Node& node,
30  const std::string& topicName,
31  std::function<void(const typename T::SharedPtr)> callback,
32  const rclcpp::QoS& qos = rclcpp::QoS(rclcpp::KeepAll()))
33  : sub(node.create_subscription<T>(topicName, qos, callback)) {}
34  BaseSub() = delete;
35  typename rclcpp::Subscription<T>::SharedPtr sub;
36 };
37 
38 } // namespace ROSChannels
Definition: roschannel.hpp:15
Definition: roschannel.hpp:27
ROSChannels namespace.
Definition: cartesiantrajectorychannel.hpp:11