6 impl(
const ros::NodeHandle& nh) : m_nh(nh)
11 void publish(
const std::string name,
const T& msg)
13 std::scoped_lock lck(m_mtx);
14 const std::string msg_md5 = ros::message_traits::MD5Sum<T>::value();
15 const std::string msg_datatype = ros::message_traits::DataType<T>::value();
16 if (m_publishers.count(name) == 0)
17 m_publishers.emplace(name, pub_info_t{m_nh.advertise<T>(name, 10), msg_md5, msg_datatype});
19 const auto& pub_info = m_publishers.at(name);
20 if (pub_info.msg_md5 ==
"*" ||
22 pub_info.msg_md5 == msg_md5)
24 pub_info.pub.publish(msg);
28 ROS_ERROR_STREAM(
"[DynamicPublisher]: Trying to publish message of type [" << msg_datatype <<
"/" << msg_md5
29 <<
"] on a publisher with type [" << pub_info.datatype <<
"/" << pub_info.msg_md5 <<
"], ignoring!");
42 std::unordered_map<std::string, pub_info_t> m_publishers;
46 void DynamicPublisher::publish(
const std::string name,
const T& msg)
48 m_impl->publish(name, msg);