15 #ifndef CONCEALER__SUBSCRIBER_HPP_
16 #define CONCEALER__SUBSCRIBER_HPP_
21 #include <rclcpp/rclcpp.hpp>
26 template <
typename...>
29 template <
typename Message>
32 typename Message::ConstSharedPtr current_value = std::make_shared<const Message>();
36 auto operator()() const -> Message {
return *std::atomic_load(¤t_value); }
38 template <
typename Autoware,
typename Callback>
40 const std::string & topic,
const rclcpp::QoS & quality_of_service, Autoware & autoware,
41 const Callback & callback)
43 available<Message>() ? autoware.template create_subscription<Message>(
44 topic, quality_of_service,
45 [this, callback](const typename Message::ConstSharedPtr & message) {
46 if (std::atomic_store(¤t_value, message); current_value) {
54 template <
typename Autoware>
56 const std::string & topic,
const rclcpp::QoS & quality_of_service, Autoware & autoware)
58 available<Message>() ? autoware.template create_subscription<Message>(
59 topic, quality_of_service,
60 [this](const typename Message::ConstSharedPtr & message) {
61 std::atomic_store(¤t_value, message);
68 template <
typename Message,
typename T,
typename... Ts>
71 typename Message::ConstSharedPtr current_value =
nullptr;
77 if (
auto value = std::atomic_load(¤t_value)) {
84 template <
typename Autoware,
typename Callback>
86 const std::string & topic,
const rclcpp::QoS & quality_of_service, Autoware & autoware,
87 const Callback & callback)
88 :
Subscriber<T, Ts...>(topic, quality_of_service, autoware, callback),
90 available<Message>() ? autoware.template create_subscription<Message>(
91 topic, quality_of_service,
92 [this, callback](const typename Message::ConstSharedPtr & message) {
93 if (std::atomic_store(¤t_value, message); current_value) {
101 template <
typename Autoware>
103 const std::string & topic,
const rclcpp::QoS & quality_of_service, Autoware & autoware)
104 :
Subscriber<T, Ts...>(topic, quality_of_service, autoware),
106 available<Message>() ? autoware.template create_subscription<Message>(
107 topic, quality_of_service,
108 [this](const typename Message::ConstSharedPtr & message) {
109 std::atomic_store(¤t_value, message);
116 template <
typename... Messages>
119 using type = std::tuple<Messages...>;
123 template <
typename F,
typename T,
typename... Ts>
126 if constexpr (0 <
sizeof...(Ts)) {
127 return f(x) or
any(f,
static_cast<const Subscriber<Ts...
> &>(x));
133 template <
typename... Ts>
137 auto subscription_available = [](
const auto & x) {
return static_cast<bool>(x.subscription); };
139 if (not
any(subscription_available,
static_cast<const Subscriber<Messages...
> &>(*
this))) {
141 "No viable subscription for topic ", std::quoted(topic),
" in ",
142 getParameter<std::string>(
"architecture_type"),
".");
Definition: autoware_universe.hpp:40
constexpr auto available() -> bool
Definition: available.hpp:21
Definition: lanelet_wrapper.hpp:39
auto any(F f, T &&x, Ts &&... xs)
Definition: follow_trajectory.cpp:36
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: exception.hpp:27
Subscriber(const std::string &topic, const rclcpp::QoS &quality_of_service, Autoware &autoware, const Callback &callback)
Definition: subscriber.hpp:85
auto operator()() const -> Message
Definition: subscriber.hpp:75
rclcpp::Subscription< Message >::SharedPtr subscription
Definition: subscriber.hpp:73
Subscriber(const std::string &topic, const rclcpp::QoS &quality_of_service, Autoware &autoware)
Definition: subscriber.hpp:102
Definition: subscriber.hpp:31
auto operator()() const -> Message
Definition: subscriber.hpp:36
Subscriber(const std::string &topic, const rclcpp::QoS &quality_of_service, Autoware &autoware, const Callback &callback)
Definition: subscriber.hpp:39
rclcpp::Subscription< Message >::SharedPtr subscription
Definition: subscriber.hpp:34
Subscriber(const std::string &topic, const rclcpp::QoS &quality_of_service, Autoware &autoware)
Definition: subscriber.hpp:55
std::tuple< Messages... > type
Definition: subscriber.hpp:119
std::tuple_element_t< 0, type > primary_type
Definition: subscriber.hpp:121
Subscriber(const std::string &topic, Ts &&... xs)
Definition: subscriber.hpp:134
constexpr auto any(F f, const Subscriber< T, Ts... > &x) -> bool
Definition: subscriber.hpp:124
Definition: subscriber.hpp:27