issue a warning if publishing on a not active publisher (#574)
* issue a warning if publishing on a not active publisher * Adding a logger private member in LifecyclePublisher for avoiding creating a new one echa call
This commit is contained in:
parent
b600c18121
commit
e30f31551e
2 changed files with 29 additions and 3 deletions
|
@ -91,7 +91,8 @@ def is_supported_feature_combination(feature_combination):
|
|||
*/
|
||||
#define RCLCPP_@(severity)@(suffix)(logger, @(''.join([p + ', ' for p in get_macro_parameters(feature_combination).keys()]))...) \
|
||||
static_assert( \
|
||||
::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
|
||||
::std::is_same<typename std::remove_reference<decltype(logger)>::type, \
|
||||
typename ::rclcpp::Logger>::value, \
|
||||
"First argument to logging macros must be an rclcpp::Logger"); \
|
||||
RCUTILS_LOG_@(severity)@(suffix)_NAMED( \
|
||||
@{params = get_macro_parameters(feature_combination).keys()}@
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include "rclcpp/publisher.hpp"
|
||||
|
||||
#include "rclcpp/logging.hpp"
|
||||
|
||||
namespace rclcpp_lifecycle
|
||||
{
|
||||
/// base class with only
|
||||
|
@ -62,8 +64,10 @@ public:
|
|||
std::shared_ptr<MessageAlloc> allocator)
|
||||
: rclcpp::Publisher<MessageT, Alloc>(
|
||||
node_base, topic, publisher_options, allocator),
|
||||
enabled_(false)
|
||||
{}
|
||||
enabled_(false),
|
||||
logger_(rclcpp::get_logger("LifecyclePublisher"))
|
||||
{
|
||||
}
|
||||
|
||||
~LifecyclePublisher() {}
|
||||
|
||||
|
@ -77,6 +81,10 @@ public:
|
|||
publish(std::unique_ptr<MessageT, MessageDeleter> & msg)
|
||||
{
|
||||
if (!enabled_) {
|
||||
RCLCPP_WARN(logger_,
|
||||
"Trying to publish message on the topic '%s', but the publisher is not activated",
|
||||
this->get_topic_name());
|
||||
|
||||
return;
|
||||
}
|
||||
rclcpp::Publisher<MessageT, Alloc>::publish(msg);
|
||||
|
@ -92,6 +100,10 @@ public:
|
|||
publish(const std::shared_ptr<MessageT> & msg)
|
||||
{
|
||||
if (!enabled_) {
|
||||
RCLCPP_WARN(logger_,
|
||||
"Trying to publish message on the topic '%s', but the publisher is not activated",
|
||||
this->get_topic_name());
|
||||
|
||||
return;
|
||||
}
|
||||
rclcpp::Publisher<MessageT, Alloc>::publish(msg);
|
||||
|
@ -107,6 +119,10 @@ public:
|
|||
publish(std::shared_ptr<const MessageT> msg)
|
||||
{
|
||||
if (!enabled_) {
|
||||
RCLCPP_WARN(logger_,
|
||||
"Trying to publish message on the topic '%s', but the publisher is not activated",
|
||||
this->get_topic_name());
|
||||
|
||||
return;
|
||||
}
|
||||
rclcpp::Publisher<MessageT, Alloc>::publish(msg);
|
||||
|
@ -122,6 +138,10 @@ public:
|
|||
publish(const MessageT & msg)
|
||||
{
|
||||
if (!enabled_) {
|
||||
RCLCPP_WARN(logger_,
|
||||
"Trying to publish message on the topic '%s', but the publisher is not activated",
|
||||
this->get_topic_name());
|
||||
|
||||
return;
|
||||
}
|
||||
rclcpp::Publisher<MessageT, Alloc>::publish(msg);
|
||||
|
@ -146,6 +166,10 @@ public:
|
|||
publish(std::shared_ptr<const MessageT> & msg)
|
||||
{
|
||||
if (!enabled_) {
|
||||
RCLCPP_WARN(logger_,
|
||||
"Trying to publish message on the topic '%s', but the publisher is not activated",
|
||||
this->get_topic_name());
|
||||
|
||||
return;
|
||||
}
|
||||
rclcpp::Publisher<MessageT, Alloc>::publish(msg);
|
||||
|
@ -171,6 +195,7 @@ public:
|
|||
|
||||
private:
|
||||
bool enabled_ = false;
|
||||
rclcpp::Logger logger_;
|
||||
};
|
||||
|
||||
} // namespace rclcpp_lifecycle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue