ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
waitable.cpp
1 // Copyright 2018 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdexcept>
16 
17 #include "rclcpp/waitable.hpp"
18 
19 using rclcpp::Waitable;
20 
21 size_t
22 Waitable::get_number_of_ready_subscriptions()
23 {
24  return 0u;
25 }
26 
27 size_t
29 {
30  return 0u;
31 }
32 
33 size_t
35 {
36  return 0u;
37 }
38 
39 size_t
41 {
42  return 0u;
43 }
44 
45 size_t
47 {
48  return 0u;
49 }
50 
51 size_t
53 {
54  return 0u;
55 }
56 
57 std::shared_ptr<void>
59 {
60  (void)id;
61  throw std::runtime_error(
62  "Custom waitables should override take_data_by_entity_id "
63  "if they want to use it.");
64 }
65 
66 bool
68 {
69  return in_use_by_wait_set_.exchange(in_use_state);
70 }
71 
72 void
73 Waitable::set_on_ready_callback(std::function<void(size_t, int)> callback)
74 {
75  (void)callback;
76 
77  throw std::runtime_error(
78  "Custom waitables should override set_on_ready_callback "
79  "if they want to use it.");
80 }
81 
82 void
84 {
85  throw std::runtime_error(
86  "Custom waitables should override clear_on_ready_callback if they "
87  "want to use it and make sure to call it on the waitable destructor.");
88 }
89 
90 void
92 {
93  this->add_to_wait_set(*wait_set);
94 }
95 
96 void
98 {
99 #if !defined(_WIN32)
100 # pragma GCC diagnostic push
101 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
102 #else // !defined(_WIN32)
103 # pragma warning(push)
104 # pragma warning(disable: 4996)
105 #endif
106  this->add_to_wait_set(&wait_set);
107 // remove warning suppression
108 #if !defined(_WIN32)
109 # pragma GCC diagnostic pop
110 #else // !defined(_WIN32)
111 # pragma warning(pop)
112 #endif
113 }
114 
115 bool
117 {
118  const rcl_wait_set_t & const_wait_set_ref = *wait_set;
119  return this->is_ready(const_wait_set_ref);
120 }
121 
122 bool
124 {
125 #if !defined(_WIN32)
126 # pragma GCC diagnostic push
127 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
128 #else // !defined(_WIN32)
129 # pragma warning(push)
130 # pragma warning(disable: 4996)
131 #endif
132  // note this const cast is only required to support a deprecated function
133  return this->is_ready(&const_cast<rcl_wait_set_t &>(wait_set));
134 // remove warning suppression
135 #if !defined(_WIN32)
136 # pragma GCC diagnostic pop
137 #else // !defined(_WIN32)
138 # pragma warning(pop)
139 #endif
140 }
141 
142 void
143 Waitable::execute(std::shared_ptr<void> & data)
144 {
145  const std::shared_ptr<void> & const_data = data;
146  this->execute(const_data);
147 }
148 
149 void
150 Waitable::execute(const std::shared_ptr<void> & data)
151 {
152 #if !defined(_WIN32)
153 # pragma GCC diagnostic push
154 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
155 #else // !defined(_WIN32)
156 # pragma warning(push)
157 # pragma warning(disable: 4996)
158 #endif
159  // note this const cast is only required to support a deprecated function
160  this->execute(const_cast<std::shared_ptr<void> &>(data));
161 // remove warning suppression
162 #if !defined(_WIN32)
163 # pragma GCC diagnostic pop
164 #else // !defined(_WIN32)
165 # pragma warning(pop)
166 #endif
167 }
virtual RCLCPP_PUBLIC size_t get_number_of_ready_guard_conditions()
Get the number of ready guard_conditions.
Definition: waitable.cpp:52
virtual RCLCPP_PUBLIC size_t get_number_of_ready_timers()
Get the number of ready timers.
Definition: waitable.cpp:28
virtual RCLCPP_PUBLIC void execute(std::shared_ptr< void > &data)
Deprecated.
Definition: waitable.cpp:143
virtual RCLCPP_PUBLIC std::shared_ptr< void > take_data_by_entity_id(size_t id)
Take the data so that it can be consumed with execute.
Definition: waitable.cpp:58
virtual RCLCPP_PUBLIC size_t get_number_of_ready_clients()
Get the number of ready clients.
Definition: waitable.cpp:34
virtual RCLCPP_PUBLIC bool is_ready(rcl_wait_set_t *wait_set)
Deprecated.
Definition: waitable.cpp:116
virtual RCLCPP_PUBLIC void clear_on_ready_callback()
Unset any callback registered via set_on_ready_callback.
Definition: waitable.cpp:83
virtual RCLCPP_PUBLIC void add_to_wait_set(rcl_wait_set_t *wait_set)
Deprecated.
Definition: waitable.cpp:91
virtual RCLCPP_PUBLIC size_t get_number_of_ready_events()
Get the number of ready events.
Definition: waitable.cpp:40
RCLCPP_PUBLIC bool exchange_in_use_by_wait_set_state(bool in_use_state)
Exchange the "in use by wait set" state for this timer.
Definition: waitable.cpp:67
virtual RCLCPP_PUBLIC size_t get_number_of_ready_services()
Get the number of ready services.
Definition: waitable.cpp:46
virtual RCLCPP_PUBLIC void set_on_ready_callback(std::function< void(size_t, int)> callback)
Set a callback to be called whenever the waitable becomes ready.
Definition: waitable.cpp:73
Container for subscription's, guard condition's, etc to be waited on.
Definition: wait.h:42