1 #ifndef PUBLISHER_HANDLER_HPP
2 #define PUBLISHER_HANDLER_HPP
13 template <
class TopicType>
21 template <
class TopicType>
26 std::scoped_lock lock(mutex_publisher_);
28 publisher_ = nh.advertise<TopicType>(address, buffer_size, latch);
34 throttle_min_dt_ = 1.0 / rate;
43 last_time_published_ = ros::Time(0);
46 publisher_initialized_ =
true;
53 template <
class TopicType>
56 if (!publisher_initialized_) {
61 std::scoped_lock lock(mutex_publisher_);
65 if ((ros::Time::now() - last_time_published_).toSec() < throttle_min_dt_) {
69 last_time_published_ = ros::Time::now();
73 publisher_.publish(msg);
76 ROS_ERROR(
"exception caught during publishing topic '%s'", publisher_.getTopic().c_str());
85 template <
class TopicType>
88 if (!publisher_initialized_) {
93 std::scoped_lock lock(mutex_publisher_);
97 if ((ros::Time::now() - last_time_published_).toSec() < throttle_min_dt_) {
101 last_time_published_ = ros::Time::now();
105 publisher_.publish(msg);
108 ROS_ERROR(
"exception caught during publishing topic '%s'", publisher_.getTopic().c_str());
117 template <
class TopicType>
120 if (!publisher_initialized_) {
125 std::scoped_lock lock(mutex_publisher_);
129 if ((ros::Time::now() - last_time_published_).toSec() < throttle_min_dt_) {
133 last_time_published_ = ros::Time::now();
137 publisher_.publish(msg);
140 ROS_ERROR(
"exception caught during publishing topic '%s'", publisher_.getTopic().c_str());
149 template <
class TopicType>
153 std::scoped_lock lock(mutex_publisher_);
155 return publisher_.getNumSubscribers();
167 template <
class TopicType>
170 if (
this == &other) {
175 this->impl_ = other.impl_;
185 template <
class TopicType>
189 this->impl_ = other.impl_;
197 template <
class TopicType>
199 const double& rate) {
201 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(nh, address, buffer_size, latch, rate);
208 template <
class TopicType>
218 template <
class TopicType>
228 template <
class TopicType>
238 template <
class TopicType>
241 return impl_->getNumSubscribers();
248 #endif // PUBLISHER_HANDLER_HPP