15 #ifndef RCLCPP__CALLBACK_GROUP_HPP_
16 #define RCLCPP__CALLBACK_GROUP_HPP_
24 #include "rclcpp/client.hpp"
25 #include "rclcpp/context.hpp"
26 #include "rclcpp/guard_condition.hpp"
27 #include "rclcpp/publisher_base.hpp"
28 #include "rclcpp/service.hpp"
29 #include "rclcpp/subscription_base.hpp"
30 #include "rclcpp/timer.hpp"
31 #include "rclcpp/visibility_control.hpp"
32 #include "rclcpp/waitable.hpp"
38 namespace node_interfaces
46 enum class CallbackGroupType
96 [[deprecated(
"Use CallbackGroup constructor with context function argument")]]
99 CallbackGroupType group_type,
139 CallbackGroupType group_type,
140 rclcpp::Context::WeakPtr context,
147 template<
typename Function>
148 rclcpp::SubscriptionBase::SharedPtr
149 find_subscription_ptrs_if(Function func)
const
151 return _find_ptrs_if_impl<rclcpp::SubscriptionBase, Function>(func, subscription_ptrs_);
154 template<
typename Function>
155 rclcpp::TimerBase::SharedPtr
156 find_timer_ptrs_if(Function func)
const
158 return _find_ptrs_if_impl<rclcpp::TimerBase, Function>(func, timer_ptrs_);
161 template<
typename Function>
162 rclcpp::ServiceBase::SharedPtr
163 find_service_ptrs_if(Function func)
const
165 return _find_ptrs_if_impl<rclcpp::ServiceBase, Function>(func, service_ptrs_);
168 template<
typename Function>
169 rclcpp::ClientBase::SharedPtr
170 find_client_ptrs_if(Function func)
const
172 return _find_ptrs_if_impl<rclcpp::ClientBase, Function>(func, client_ptrs_);
175 template<
typename Function>
176 rclcpp::Waitable::SharedPtr
177 find_waitable_ptrs_if(Function func)
const
179 return _find_ptrs_if_impl<rclcpp::Waitable, Function>(func, waitable_ptrs_);
208 const CallbackGroupType &
222 std::function<
void(
const rclcpp::SubscriptionBase::SharedPtr &)> sub_func,
223 std::function<
void(
const rclcpp::ServiceBase::SharedPtr &)> service_func,
224 std::function<
void(
const rclcpp::ClientBase::SharedPtr &)> client_func,
225 std::function<
void(
const rclcpp::TimerBase::SharedPtr &)> timer_func,
226 std::function<
void(
const rclcpp::Waitable::SharedPtr &)> waitable_func)
const;
258 rclcpp::GuardCondition::SharedPtr
271 add_publisher(
const rclcpp::PublisherBase::SharedPtr publisher_ptr);
275 add_subscription(
const rclcpp::SubscriptionBase::SharedPtr subscription_ptr);
279 add_timer(
const rclcpp::TimerBase::SharedPtr timer_ptr);
283 add_service(
const rclcpp::ServiceBase::SharedPtr service_ptr);
287 add_client(
const rclcpp::ClientBase::SharedPtr client_ptr);
291 add_waitable(
const rclcpp::Waitable::SharedPtr waitable_ptr);
295 remove_waitable(
const rclcpp::Waitable::SharedPtr waitable_ptr) noexcept;
297 CallbackGroupType type_;
299 mutable std::mutex mutex_;
300 std::atomic_bool associated_with_executor_;
301 std::vector<rclcpp::SubscriptionBase::WeakPtr> subscription_ptrs_;
302 std::vector<rclcpp::TimerBase::WeakPtr> timer_ptrs_;
303 std::vector<rclcpp::ServiceBase::WeakPtr> service_ptrs_;
304 std::vector<rclcpp::ClientBase::WeakPtr> client_ptrs_;
305 std::vector<rclcpp::Waitable::WeakPtr> waitable_ptrs_;
306 std::atomic_bool can_be_taken_from_;
307 const bool automatically_add_to_executor_with_node_;
309 std::shared_ptr<rclcpp::GuardCondition> notify_guard_condition_ =
nullptr;
310 std::recursive_mutex notify_guard_condition_mutex_;
312 rclcpp::Context::WeakPtr context_;
315 template<
typename TypeT,
typename Function>
316 typename TypeT::SharedPtr _find_ptrs_if_impl(
317 Function func,
const std::vector<typename TypeT::WeakPtr> & vect_ptrs)
const
319 std::lock_guard<std::mutex> lock(mutex_);
320 for (
auto & weak_ptr : vect_ptrs) {
321 auto ref_ptr = weak_ptr.lock();
322 if (ref_ptr && func(ref_ptr)) {
326 return typename TypeT::SharedPtr();
RCLCPP_PUBLIC ~CallbackGroup()
Default destructor.
RCLCPP_PUBLIC rclcpp::GuardCondition::SharedPtr get_notify_guard_condition()
Retrieve the guard condition used to signal changes to this callback group.
RCLCPP_PUBLIC std::atomic_bool & get_associated_with_executor_atomic()
Return a reference to the 'associated with executor' atomic boolean.
RCLCPP_PUBLIC CallbackGroup(CallbackGroupType group_type, bool automatically_add_to_executor_with_node=true)
Constructor for CallbackGroup.
RCLCPP_PUBLIC void trigger_notify_guard_condition()
Trigger the notify guard condition.
RCLCPP_PUBLIC void collect_all_ptrs(std::function< void(const rclcpp::SubscriptionBase::SharedPtr &)> sub_func, std::function< void(const rclcpp::ServiceBase::SharedPtr &)> service_func, std::function< void(const rclcpp::ClientBase::SharedPtr &)> client_func, std::function< void(const rclcpp::TimerBase::SharedPtr &)> timer_func, std::function< void(const rclcpp::Waitable::SharedPtr &)> waitable_func) const
Collect all of the entity pointers contained in this callback group.
RCLCPP_PUBLIC bool automatically_add_to_executor_with_node() const
Return true if this callback group should be automatically added to an executor by the node.
RCLCPP_PUBLIC const CallbackGroupType & type() const
Get the group type.
RCLCPP_PUBLIC std::atomic_bool & can_be_taken_from()
Return a reference to the 'can be taken' atomic boolean.
RCLCPP_PUBLIC size_t size() const
Get the total number of entities in this callback group.
Implementation of the NodeServices part of the Node API.
Implementation of the NodeTimers part of the Node API.
Implementation of the NodeTopics part of the Node API.
Implementation of the NodeWaitables part of the Node API.
RCLCPP_PUBLIC void remove_waitable(rclcpp::Waitable::SharedPtr waitable_ptr, rclcpp::CallbackGroup::SharedPtr group) noexcept override
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.