Skip to content

Commit 2ac2dc2

Browse files
author
Mauro Passerino
committed
Merge branch 'master' into mauro/add-rmw-listener-apis-merge-master
Signed-off-by: Mauro Passerino <[email protected]>
2 parents d760ba3 + 1c61751 commit 2ac2dc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3520
-486
lines changed

rclcpp/CHANGELOG.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
Changelog for package rclcpp
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
11.0.0 (2021-05-18)
6+
-------------------
7+
* Allow declare uninitialized parameters (`#1673 <https://github.com/ros2/rclcpp/issues/1673>`_)
8+
* Fix syntax issue with gcc (`#1674 <https://github.com/ros2/rclcpp/issues/1674>`_)
9+
* [service] Don't use a weak_ptr to avoid leaking (`#1668 <https://github.com/ros2/rclcpp/issues/1668>`_)
10+
* Contributors: Ivan Santiago Paunovic, Jacob Perron, William Woodall
11+
12+
10.0.0 (2021-05-11)
13+
-------------------
14+
* Fix doc typo (`#1663 <https://github.com/ros2/rclcpp/issues/1663>`_)
15+
* [rclcpp] Type Adaptation feature (`#1557 <https://github.com/ros2/rclcpp/issues/1557>`_)
16+
* Do not attempt to use void allocators for memory allocation. (`#1657 <https://github.com/ros2/rclcpp/issues/1657>`_)
17+
* Keep custom allocator in publisher and subscription options alive. (`#1647 <https://github.com/ros2/rclcpp/issues/1647>`_)
18+
* Fix get_publishers_subscriptions_info_by_topic test in test_node.cpp (`#1648 <https://github.com/ros2/rclcpp/issues/1648>`_)
19+
* Use OnShutdown callback handle instead of OnShutdown callback (`#1639 <https://github.com/ros2/rclcpp/issues/1639>`_)
20+
* use dynamic_pointer_cast to detect allocator mismatch in intra process manager (`#1643 <https://github.com/ros2/rclcpp/issues/1643>`_)
21+
* Increase cppcheck timeout to 500s (`#1634 <https://github.com/ros2/rclcpp/issues/1634>`_)
22+
* Clarify node parameters docs (`#1631 <https://github.com/ros2/rclcpp/issues/1631>`_)
23+
* Contributors: Audrow Nash, Barry Xu, Jacob Perron, Michel Hidalgo, Shane Loretz, William Woodall
24+
525
9.0.2 (2021-04-14)
626
------------------
727
* Avoid returning loan when none was obtained. (`#1629 <https://github.com/ros2/rclcpp/issues/1629>`_)

rclcpp/include/rclcpp/any_subscription_callback.hpp

Lines changed: 627 additions & 103 deletions
Large diffs are not rendered by default.

rclcpp/include/rclcpp/context.hpp

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <typeindex>
2424
#include <typeinfo>
2525
#include <unordered_map>
26+
#include <unordered_set>
2627
#include <utility>
2728
#include <vector>
2829

@@ -47,6 +48,17 @@ class ContextAlreadyInitialized : public std::runtime_error
4748
/// Forward declare WeakContextsWrapper
4849
class WeakContextsWrapper;
4950

51+
class OnShutdownCallbackHandle
52+
{
53+
friend class Context;
54+
55+
public:
56+
using OnShutdownCallbackType = std::function<void ()>;
57+
58+
private:
59+
std::weak_ptr<OnShutdownCallbackType> callback;
60+
};
61+
5062
/// Context which encapsulates shared state between nodes and other similar entities.
5163
/**
5264
* A context also represents the lifecycle between init and shutdown of rclcpp.
@@ -80,7 +92,7 @@ class Context : public std::enable_shared_from_this<Context>
8092
*
8193
* Note that this function does not setup any signal handlers, so if you want
8294
* it to be shutdown by the signal handler, then you need to either install
83-
* them manually with rclcpp::install_signal_handers() or use rclcpp::init().
95+
* them manually with rclcpp::install_signal_handlers() or use rclcpp::init().
8496
* In addition to installing the signal handlers, the shutdown_on_sigint
8597
* of the InitOptions needs to be `true` for this context to be shutdown by
8698
* the signal handler, otherwise it will be passed over.
@@ -177,7 +189,7 @@ class Context : public std::enable_shared_from_this<Context>
177189
bool
178190
shutdown(const std::string & reason);
179191

180-
using OnShutdownCallback = std::function<void ()>;
192+
using OnShutdownCallback = OnShutdownCallbackHandle::OnShutdownCallbackType;
181193

182194
/// Add a on_shutdown callback to be called when shutdown is called for this context.
183195
/**
@@ -203,23 +215,47 @@ class Context : public std::enable_shared_from_this<Context>
203215
OnShutdownCallback
204216
on_shutdown(OnShutdownCallback callback);
205217

206-
/// Return the shutdown callbacks as const.
218+
/// Add a on_shutdown callback to be called when shutdown is called for this context.
219+
/**
220+
* These callbacks will be called in the order they are added as the second
221+
* to last step in shutdown().
222+
*
223+
* When shutdown occurs due to the signal handler, these callbacks are run
224+
* asynchronously in the dedicated singal handling thread.
225+
*
226+
* Also, shutdown() may be called from the destructor of this function.
227+
* Therefore, it is not safe to throw exceptions from these callbacks.
228+
* Instead, log errors or use some other mechanism to indicate an error has
229+
* occurred.
230+
*
231+
* On shutdown callbacks may be registered before init and after shutdown,
232+
* and persist on repeated init's.
233+
*
234+
* \param[in] callback the on_shutdown callback to be registered
235+
* \return the created callback handle
236+
*/
237+
RCLCPP_PUBLIC
238+
virtual
239+
OnShutdownCallbackHandle
240+
add_on_shutdown_callback(OnShutdownCallback callback);
241+
242+
/// Remove an registered on_shutdown callbacks.
207243
/**
208-
* Using the returned reference is not thread-safe with calls that modify
209-
* the list of "on shutdown" callbacks, i.e. on_shutdown().
244+
* \param[in] callback_handle the on_shutdown callback handle to be removed.
245+
* \return true if the callback is found and removed, otherwise false.
210246
*/
211247
RCLCPP_PUBLIC
212-
const std::vector<OnShutdownCallback> &
213-
get_on_shutdown_callbacks() const;
248+
virtual
249+
bool
250+
remove_on_shutdown_callback(const OnShutdownCallbackHandle & callback_handle);
214251

215252
/// Return the shutdown callbacks.
216253
/**
217-
* Using the returned reference is not thread-safe with calls that modify
218-
* the list of "on shutdown" callbacks, i.e. on_shutdown().
254+
* Returned callbacks are a copy of the registered callbacks.
219255
*/
220256
RCLCPP_PUBLIC
221-
std::vector<OnShutdownCallback> &
222-
get_on_shutdown_callbacks();
257+
std::vector<OnShutdownCallback>
258+
get_on_shutdown_callbacks() const;
223259

224260
/// Return the internal rcl context.
225261
RCLCPP_PUBLIC
@@ -299,8 +335,8 @@ class Context : public std::enable_shared_from_this<Context>
299335
// attempt to acquire another sub context.
300336
std::recursive_mutex sub_contexts_mutex_;
301337

302-
std::vector<OnShutdownCallback> on_shutdown_callbacks_;
303-
std::mutex on_shutdown_callbacks_mutex_;
338+
std::unordered_set<std::shared_ptr<OnShutdownCallback>> on_shutdown_callbacks_;
339+
mutable std::mutex on_shutdown_callbacks_mutex_;
304340

305341
/// Condition variable for timed sleep (see sleep_for).
306342
std::condition_variable interrupt_condition_variable_;

rclcpp/include/rclcpp/create_subscription.hpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ template<
4747
typename MessageT,
4848
typename CallbackT,
4949
typename AllocatorT,
50-
typename CallbackMessageT,
5150
typename SubscriptionT,
5251
typename MessageMemoryStrategyT,
5352
typename NodeParametersT,
54-
typename NodeTopicsT>
53+
typename NodeTopicsT,
54+
typename ROSMessageType = typename SubscriptionT::ROSMessageType>
5555
typename std::shared_ptr<SubscriptionT>
5656
create_subscription(
5757
NodeParametersT & node_parameters,
@@ -70,7 +70,7 @@ create_subscription(
7070
using rclcpp::node_interfaces::get_node_topics_interface;
7171
auto node_topics_interface = get_node_topics_interface(node_topics);
7272

73-
std::shared_ptr<rclcpp::topic_statistics::SubscriptionTopicStatistics<CallbackMessageT>>
73+
std::shared_ptr<rclcpp::topic_statistics::SubscriptionTopicStatistics<ROSMessageType>>
7474
subscription_topic_stats = nullptr;
7575

7676
if (rclcpp::detail::resolve_enable_topic_statistics(
@@ -92,11 +92,11 @@ create_subscription(
9292
qos);
9393

9494
subscription_topic_stats = std::make_shared<
95-
rclcpp::topic_statistics::SubscriptionTopicStatistics<CallbackMessageT>
95+
rclcpp::topic_statistics::SubscriptionTopicStatistics<ROSMessageType>
9696
>(node_topics_interface->get_node_base_interface()->get_name(), publisher);
9797

9898
std::weak_ptr<
99-
rclcpp::topic_statistics::SubscriptionTopicStatistics<CallbackMessageT>
99+
rclcpp::topic_statistics::SubscriptionTopicStatistics<ROSMessageType>
100100
> weak_subscription_topic_stats(subscription_topic_stats);
101101
auto sub_call_back = [weak_subscription_topic_stats]() {
102102
auto subscription_topic_stats = weak_subscription_topic_stats.lock();
@@ -153,7 +153,6 @@ create_subscription(
153153
* \tparam MessageT
154154
* \tparam CallbackT
155155
* \tparam AllocatorT
156-
* \tparam CallbackMessageT
157156
* \tparam SubscriptionT
158157
* \tparam MessageMemoryStrategyT
159158
* \tparam NodeT
@@ -171,13 +170,8 @@ template<
171170
typename MessageT,
172171
typename CallbackT,
173172
typename AllocatorT = std::allocator<void>,
174-
typename CallbackMessageT =
175-
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type,
176-
typename SubscriptionT = rclcpp::Subscription<CallbackMessageT, AllocatorT>,
177-
typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<
178-
CallbackMessageT,
179-
AllocatorT
180-
>,
173+
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
174+
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType,
181175
typename NodeT>
182176
typename std::shared_ptr<SubscriptionT>
183177
create_subscription(
@@ -194,7 +188,7 @@ create_subscription(
194188
)
195189
{
196190
return rclcpp::detail::create_subscription<
197-
MessageT, CallbackT, AllocatorT, CallbackMessageT, SubscriptionT, MessageMemoryStrategyT>(
191+
MessageT, CallbackT, AllocatorT, SubscriptionT, MessageMemoryStrategyT>(
198192
node, node, topic_name, qos, std::forward<CallbackT>(callback), options, msg_mem_strat);
199193
}
200194

@@ -206,13 +200,8 @@ template<
206200
typename MessageT,
207201
typename CallbackT,
208202
typename AllocatorT = std::allocator<void>,
209-
typename CallbackMessageT =
210-
typename rclcpp::subscription_traits::has_message_type<CallbackT>::type,
211-
typename SubscriptionT = rclcpp::Subscription<CallbackMessageT, AllocatorT>,
212-
typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<
213-
CallbackMessageT,
214-
AllocatorT
215-
>>
203+
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
204+
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
216205
typename std::shared_ptr<SubscriptionT>
217206
create_subscription(
218207
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr & node_parameters,
@@ -229,7 +218,7 @@ create_subscription(
229218
)
230219
{
231220
return rclcpp::detail::create_subscription<
232-
MessageT, CallbackT, AllocatorT, CallbackMessageT, SubscriptionT, MessageMemoryStrategyT>(
221+
MessageT, CallbackT, AllocatorT, SubscriptionT, MessageMemoryStrategyT>(
233222
node_parameters, node_topics, topic_name, qos,
234223
std::forward<CallbackT>(callback), options, msg_mem_strat);
235224
}

rclcpp/include/rclcpp/exceptions/exceptions.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,17 @@ class ParameterModifiedInCallbackException : public std::runtime_error
282282
using std::runtime_error::runtime_error;
283283
};
284284

285-
/// Thrown when a parameter override wasn't provided and one was required.
286-
class NoParameterOverrideProvided : public std::runtime_error
285+
/// Thrown when an uninitialized parameter is accessed.
286+
class ParameterUninitializedException : public std::runtime_error
287287
{
288288
public:
289289
/// Construct an instance.
290290
/**
291291
* \param[in] name the name of the parameter.
292292
* \param[in] message custom exception message.
293293
*/
294-
explicit NoParameterOverrideProvided(const std::string & name)
295-
: std::runtime_error("parameter '" + name + "' requires an user provided parameter override")
294+
explicit ParameterUninitializedException(const std::string & name)
295+
: std::runtime_error("parameter '" + name + "' is not initialized")
296296
{}
297297
};
298298

rclcpp/include/rclcpp/executor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "rcl/guard_condition.h"
3131
#include "rcl/wait.h"
3232

33+
#include "rclcpp/context.hpp"
3334
#include "rclcpp/contexts/default_context.hpp"
3435
#include "rclcpp/guard_condition.hpp"
3536
#include "rclcpp/executor_options.hpp"
@@ -571,6 +572,9 @@ class Executor
571572
/// nodes that are associated with the executor
572573
std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>
573574
weak_nodes_ RCPPUTILS_TSA_GUARDED_BY(mutex_);
575+
576+
/// shutdown callback handle registered to Context
577+
rclcpp::OnShutdownCallbackHandle shutdown_callback_handle_;
574578
};
575579

576580
} // namespace rclcpp

0 commit comments

Comments
 (0)